Imports System.Xml
Imports System.Xml.Serialization
Imports System.Configuration
Imports System.Web
Imports System.Collections.Generic
Imports System.Data
Imports System.Net

Public Class CMSContentManager

    Private _CMSAdmin As CMS.CMSService

    Public Shared Function Instance() As CMS.CMSService
        Try

            'Dim netCredential As NetworkCredential

            'netCredential = New Net.NetworkCredential("test", "test")

            Dim a As New CMS.CMSService


            'a.Credentials = netCredential.GetCredential(New Uri("http://localhost/CharterDotCom_CMSWebServices/Service.asmx"), "Basic")

            a.Credentials = Net.CredentialCache.DefaultNetworkCredentials

            Dim url As String = a.Url

            Return a
        Catch ex As Exception
            Throw ex
        End Try
    End Function

    Public Sub New()
        _CMSAdmin = New CMS.CMSService
        _CMSAdmin.Credentials = Net.CredentialCache.DefaultNetworkCredentials
        Dim url As String = _CMSAdmin.Url
    End Sub

    Public Function GetTemplateID(ByVal RoleID As Integer) As DataTable
        Try
            Dim TemplateIDs As String = _CMSAdmin.ValidateUser(Replace(HttpContext.Current.User.Identity.Name, "CHTR\", ""), RoleID)
            Dim obj As DataSet = _CMSAdmin.GetTemplate(TemplateIDs)
            If obj IsNot Nothing AndAlso obj.Tables.Count > 0 Then
                Return obj.Tables(0)
            Else
                Return Nothing
            End If
        Catch ex As Exception
            Return Nothing
        End Try
    End Function

  Public Function GetUserControl(ByVal TemplateID as Integer) As DataTable
    Try
      Dim obj As DataSet = _CMSAdmin.GetUserControlList(TemplateID)
      If obj IsNot Nothing AndAlso obj.Tables.Count > 0 Then
        Return obj.Tables(0)
      Else
        Return Nothing
      End If
        Catch ex As Exception
            Return Nothing
        End Try
  End Function

  Public Function GetPendingVersions(ByVal TemplateID As Integer) As DataTable
    Try
      Dim obj As DataSet = _CMSAdmin.GetPendingVersions(TemplateID)
      If obj IsNot Nothing AndAlso obj.Tables.Count > 0 Then
        Return obj.Tables(0)
      Else
        Return Nothing
      End If
        Catch ex As Exception
            Return Nothing
        End Try
  End Function

  Public Function GetApprovedVersions(ByVal TemplateID As Integer) As DataTable
    Try
      Dim obj As DataSet = _CMSAdmin.GetApprovedVersions(TemplateID)
      If obj IsNot Nothing AndAlso obj.Tables.Count > 0 Then
        Return obj.Tables(0)
      Else
        Return Nothing
      End If
        Catch ex As Exception
            Return Nothing
        End Try
  End Function


  Public Function DeleteEdits(ByVal ID As Integer)
        Return Nothing
    End Function

    Public Function Authenticate(ByVal username As String, ByVal password As String ) As  CMS.UserInfo 
    
    
        Return _CMSAdmin.Authenticate(username, password)
     
    End Function


End Class
