Imports SupportProvider
'Imports CommonECGEntities.EntitySupport

Imports CharterDotCom.CommonEntities.Library
Imports System.Xml
Imports System.Collections.Generic
Imports Microsoft.Practices.EnterpriseLibrary.Data
Imports System.Data

Partial Class TestSupport
    Inherits System.Web.UI.Page

    Private _provider As ISupportProvider


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If IsPostBack Then
      Dim lProvider As CharterDotCom.CommonEntities.Library.ISupportProvider = CType(Activator.GetObject(GetType(ISupportProvider), CStr(System.Web.HttpContext.Current.Application("RemoteURL_SupportProvider"))), ISupportProvider)

            Me.Provider = lProvider
        End If
    End Sub
    Private Property Provider() As ISupportProvider
        Get
            Return _provider
        End Get
        Set(ByVal value As ISupportProvider)
            _provider = value
        End Set
    End Property

    Protected Sub btnGetAllDocuments_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGetAllDocuments.Click
        Dim objresult As New Dictionary(Of String, Object)
        Try
            objresult = Me.Provider.GetAllDocuments()

            If objresult.Count > 0 Then
                Response.Write("Support is working <br>")
                For Each item As Dictionary(Of String, Object) In objresult.Values
                    Response.Write("<br>" & item("Title"))
                Next
            Else
                Response.Write("no document records returned from DB: ")
            End If
        Catch ex As Exception
            Response.Write(ex.Message)
        End Try
    End Sub

    Protected Sub btnGetConfig_Click(sender As Object, e As System.EventArgs) Handles btnGetConfig.Click
        Dim lConfigProvider As New Service
        Dim setting As String = "localhost.WEBSERVER"
        Dim dt As DataTable
        Dim ds As New Data.DataSet
        Dim strOut As String = ""

        Try
            dt = lConfigProvider.GetProviderSettings(setting)
            strOut = strOut & "<table>" & vbNewLine
            strOut = strOut & "<tr><td><b>CONFIGLOCATION</b></td><td><b>KEY Value</b></td><td><b>XMLDATA Value</b></td></tr>" & vbNewLine

            ds = lConfigProvider.GetWebConfig(setting)
            For Each row As Data.DataRow In ds.Tables(0).Rows
                Application.Lock()
                Application.Remove(row.Item("Key"))
                Application.Add(row.Item("Key"), row.Item("XMLData"))
                Application.UnLock()
                strOut = strOut & "<tr><td>" & row.Item(0) & " </td><td>" & row.Item("Key") & " </td><td> " & "" & row.Item("XMLData") & " </td></tr>" & vbNewLine
            Next
            strOut = strOut & "</table>" & vbNewLine
            Response.Write(strOut)
        Catch ex As Exception
            Response.Write("Error accessing Config: " & ex.Message)
        End Try

    End Sub
End Class
