Imports CharterDotCom.WebSite.Library.BLCommon
Imports System.Configuration
Imports CharterDotCom.CommonEntities.Library
Imports CharterDotCom.CommonEntities.Library.Enumerations
Imports CharterDotCom.CommonEntities.Library.EntityMemberServices
'Imports CharterDotCom.CommonEntities.Library.EntityEBSServices
Imports CharterDotCom.CommonEntities.Library.EntitySupport
Imports CharterDotCom.CommonEntities.Library.EntitySearch
Imports CharterDotCom.CommonEntities.Library.EntityWebConfig
'Imports CharterDotCom.CommonEntities.Library.EntityG2BServices
Imports System.Xml
Imports System.Text
Imports System.Web


Public Class BLSiteManager
    Inherits SiteClient

    Private _ChannelLineUp As BLChannelLineUp
    Private configdata_ebs As XmlNode
    Private configdata_support As XmlNode
    Private billinsystemcode As String
    Private FTACode As String
    Private findServiceability As Boolean = True
    Private SiteKey As String
    'Private serviceabilityResults() As EntityEBSServices.GetServiceabilityResponseServiceabilityResult

    Public Sub New()

    End Sub

    Public Sub New(ByVal DictionaryOfVariables As Dictionary(Of String, Object))
        If DictionaryOfVariables.ContainsKey("_ChannelLineUp") Then
            If Not (DictionaryOfVariables("_ChannelLineUp") Is Nothing) Then
                Me._ChannelLineUp = CType(DictionaryOfVariables("_ChannelLineUp"), BLChannelLineUp)
            End If
        End If
        If DictionaryOfVariables.ContainsKey("SiteKey") Then
            If Not (DictionaryOfVariables("SiteKey") Is Nothing) Then
                Me.SiteKey = CType(DictionaryOfVariables("SiteKey"), String)
            End If
        End If
    End Sub

    Public ReadOnly Property ValuesForSetSession() As Dictionary(Of String, Object)
        Get
            Dim VarList As New Dictionary(Of String, Object)
            VarList.Add("_ChannelLineUp", Me._ChannelLineUp)
            VarList.Add("SiteKey", SiteKey)
            Return VarList
        End Get
    End Property
    Friend ReadOnly Property ChannelLineUp() As BLChannelLineUp
        Get
            Return _ChannelLineUp
        End Get
    End Property



#Region "SEARCH SUPPORT"
    Public Overrides Function SearchSite(ByVal SearchString As String) As ISearchResultCollection
        Try
            '#################################################
            'THIS IS USED TO MAINTAIN STATE BETWEEN CALLS.
            'EACH TIME A METHOD IS CALLED THE STATE NEEDS 
            'TO BE RESTORED TO THIS OBJECT BY CALLING 
            'PopulateLocalVariables()
            '#################################################
            PopulateLocalVariables(TrackingID)

            Dim iProvider As ISearchProvider = CType(Activator.GetObject(GetType(ISearchProvider), CStr(HttpContext.Current.Application("RemoteURL_SearchProvider"))), ISearchProvider)
            Dim objResponse As SearchSiteResponse = CType(iProvider.SearchSite(SearchString), SearchSiteResponse)
            Dim outResponse As New BLSearchResultCollection




            If Not (objResponse Is Nothing) Then
                If Not (objResponse.SearchResultCollection Is Nothing) Then
                    outResponse.results = New List(Of ISearchResult)
                    For Each objResponseResult As EntitySearch.SearchResult In objResponse.SearchResultCollection.results
                        Dim lResult As New BLSearchResult

                        lResult.BinaryDocumentMimeType = objResponseResult.BinaryDocumentMimeType
                        lResult.CreateDate = objResponseResult.CreateDate

                        lResult.DocumentID = objResponseResult.DocumentID
                        lResult.HMTL = objResponseResult.HMTL

                        Select Case objResponseResult.MimeType
                            Case EntitySearch.MimeType.CONTENT_ARTICLE_FROM_DB
                                lResult.MimeType = CharterDotCom.CommonEntities.Library.Enumerations.MimeType.CONTENT_ARTICLE_FROM_DB
                            Case EntitySearch.MimeType.SUPPORT_ARTICLE_FROM_DB
                                lResult.MimeType = CharterDotCom.CommonEntities.Library.Enumerations.MimeType.SUPPORT_ARTICLE_FROM_DB
                            Case EntitySearch.MimeType.PDF
                                lResult.MimeType = CharterDotCom.CommonEntities.Library.Enumerations.MimeType.PDF
                            Case EntitySearch.MimeType.DOC
                                lResult.MimeType = CharterDotCom.CommonEntities.Library.Enumerations.MimeType.DOC
                            Case EntitySearch.MimeType.TXT
                                lResult.MimeType = CharterDotCom.CommonEntities.Library.Enumerations.MimeType.TXT
                        End Select

                        lResult.ParentFolderID = objResponseResult.ParentFolderID

                        Select Case objResponseResult.resultType
                            Case EntitySearch.SearchResultType.Site
                                lResult.resultType = CharterDotCom.CommonEntities.Library.Enumerations.SearchResultType.Site
                            Case EntitySearch.SearchResultType.Support
                                lResult.resultType = CharterDotCom.CommonEntities.Library.Enumerations.SearchResultType.Support
                        End Select
                        lResult.Score = objResponseResult.Score
                        lResult.Summary = objResponseResult.Summary
                        lResult.Title = objResponseResult.Title
                        lResult.URL = objResponseResult.URL

                        outResponse.results.Add(lResult)
                    Next
                End If
            End If

            Return outResponse


        Catch ex As Exception
            BLCommon.LogException(ex, ExceptionSeverity.Catastrophic)
            Throw ex
        End Try
    End Function
    Public Overrides Function SearchSupport(ByVal SearchString As String) As ISearchResultCollection
        Try
            '#################################################
            'THIS IS USED TO MAINTAIN STATE BETWEEN CALLS.
            'EACH TIME A METHOD IS CALLED THE STATE NEEDS 
            'TO BE RESTORED TO THIS OBJECT BY CALLING 
            'PopulateLocalVariables()
            '#################################################
            PopulateLocalVariables(TrackingID)

            Dim iProvider As ISearchProvider = CType(Activator.GetObject(GetType(ISearchProvider), CStr(HttpContext.Current.Application("RemoteURL_SearchProvider"))), ISearchProvider)
            Dim objResponse As SearchSupportResponse = CType(iProvider.SearchSupport(SearchString), SearchSupportResponse)
            Dim outResponse As New BLSearchResultCollection




            If Not (objResponse Is Nothing) Then
                If Not (objResponse.SearchResultCollection Is Nothing) Then
                    outResponse.results = New List(Of ISearchResult)
                    For Each objResponseResult As EntitySearch.SearchResult In objResponse.SearchResultCollection.results
                        Dim lResult As New BLSearchResult

                        lResult.BinaryDocumentMimeType = objResponseResult.BinaryDocumentMimeType
                        lResult.CreateDate = objResponseResult.CreateDate

                        lResult.DocumentID = objResponseResult.DocumentID
                        lResult.HMTL = objResponseResult.HMTL

                        Select Case objResponseResult.MimeType
                            Case EntitySearch.MimeType.CONTENT_ARTICLE_FROM_DB
                                lResult.MimeType = CharterDotCom.CommonEntities.Library.Enumerations.MimeType.CONTENT_ARTICLE_FROM_DB
                            Case EntitySearch.MimeType.SUPPORT_ARTICLE_FROM_DB
                                lResult.MimeType = CharterDotCom.CommonEntities.Library.Enumerations.MimeType.SUPPORT_ARTICLE_FROM_DB
                            Case EntitySearch.MimeType.PDF
                                lResult.MimeType = CharterDotCom.CommonEntities.Library.Enumerations.MimeType.PDF
                            Case EntitySearch.MimeType.DOC
                                lResult.MimeType = CharterDotCom.CommonEntities.Library.Enumerations.MimeType.DOC
                            Case EntitySearch.MimeType.TXT
                                lResult.MimeType = CharterDotCom.CommonEntities.Library.Enumerations.MimeType.TXT
                        End Select

                        lResult.ParentFolderID = objResponseResult.ParentFolderID

                        Select Case objResponseResult.resultType
                            Case EntitySearch.SearchResultType.Site
                                lResult.resultType = CharterDotCom.CommonEntities.Library.Enumerations.SearchResultType.Site
                            Case EntitySearch.SearchResultType.Support
                                lResult.resultType = CharterDotCom.CommonEntities.Library.Enumerations.SearchResultType.Support
                        End Select
                        lResult.Score = objResponseResult.Score
                        lResult.Summary = objResponseResult.Summary
                        lResult.Title = objResponseResult.Title
                        lResult.URL = objResponseResult.URL

                        outResponse.results.Add(lResult)
                    Next
                End If
            End If

            Return outResponse


        Catch ex As Exception
            BLCommon.LogException(ex, ExceptionSeverity.Catastrophic)
            Throw ex
        End Try
    End Function
#End Region

#Region "WEB CONFIGURATION SETTINGS SECTION"
    Public Overrides Function GetWebConfigSettings(ByVal RequestLocation As String) As IWebConfigSettingsCollection
        Try
            '#################################################
            'THIS IS USED TO MAINTAIN STATE BETWEEN CALLS.
            'EACH TIME A METHOD IS CALLED THE STATE NEEDS 
            'TO BE RESTORED TO THIS OBJECT BY CALLING 
            'PopulateLocalVariables()
            '#################################################
            PopulateLocalVariables(TrackingID)

            Dim iProvider As IWebConfigProvider = CType(Activator.GetObject(GetType(IWebConfigProvider), CStr(HttpContext.Current.Application("RemoteURL_WebConfigProvider"))), IWebConfigProvider)
            Dim objResponse As GetWebConfigSettingsResponse = CType(iProvider.GetWebConfigSettings(RequestLocation), GetWebConfigSettingsResponse)
            Dim outResponse As New BLWebConfigSettingsCollection


            If Not (objResponse Is Nothing) Then
                If Not (objResponse.BLWebConfigSettingsCollection Is Nothing) Then
                    If Not (objResponse.BLWebConfigSettingsCollection.WebConfigSetting Is Nothing) Then
                        outResponse.WebConfigSetting = New List(Of IWebConfigSetting)
                        For Each objConfigSetting As EntityWebConfig.WebConfigSetting In objResponse.BLWebConfigSettingsCollection.WebConfigSetting
                            Dim lWebConfigSetting As New BLWebConfigSetting
                            lWebConfigSetting.ID = objConfigSetting.ID
                            lWebConfigSetting.key = objConfigSetting.key
                            lWebConfigSetting.XMLData = objConfigSetting.XMLData

                            outResponse.WebConfigSetting.Add(lWebConfigSetting)
                        Next
                    End If
                End If
            End If

            Return outResponse


        Catch ex As Exception
            BLCommon.LogException(ex, ExceptionSeverity.Catastrophic)
            Throw ex
        End Try
    End Function

#End Region



#Region "SUPPORT METHODS AND FUNCTIONS V2"


    Public Overrides Sub AddDocumentComments(ByVal Comments As String, ByVal CreatedBy As String, ByVal DocumentID As Integer, ByVal Helpful As Boolean, ByVal Rating As Integer)
        '#################################################
        'THIS IS USED TO MAINTAIN STATE BETWEEN CALLS.
        'EACH TIME A METHOD IS CALLED THE STATE NEEDS 
        'TO BE RESTORED TO THIS OBJECT BY CALLING 
        'PopulateLocalVariables()
        '#################################################
        PopulateLocalVariables(TrackingID)

        Try
            Dim iProvider As ISupportProvider = CType(Activator.GetObject(GetType(ISupportProvider), CStr(HttpContext.Current.Application("RemoteURL_SupportProvider"))), ISupportProvider)
            Dim objRequest As New EntitySupport.AddDocumentCommentsRequest

            objRequest.Comments = Comments
            objRequest.CreatedBy = CreatedBy
            objRequest.DocumentID = DocumentID
            objRequest.Helpful = Helpful
            objRequest.Rating = Rating


            '##########
            'EXECUTE
            '##########
            iProvider.AddDocumentComments(objRequest, 99)


        Catch ex As Exception
            BLCommon.LogException(ex, ExceptionSeverity.Catastrophic)
            Throw ex
        End Try
    End Sub
    Public Overrides Function GetRelatedDocuments(ByVal ID As Integer) As Dictionary(Of String, Object)
        Try
            '#################################################
            'THIS IS USED TO MAINTAIN STATE BETWEEN CALLS.
            'EACH TIME A METHOD IS CALLED THE STATE NEEDS 
            'TO BE RESTORED TO THIS OBJECT BY CALLING 
            'PopulateLocalVariables()
            '#################################################
            PopulateLocalVariables(TrackingID)

            Dim iProvider As ISupportProvider = CType(Activator.GetObject(GetType(ISupportProvider), CStr(HttpContext.Current.Application("RemoteURL_SupportProvider"))), ISupportProvider)
            Return iProvider.GetRelatedDocuments(ID)


        Catch ex As Exception
            BLCommon.LogException(ex, ExceptionSeverity.Catastrophic)
            Throw ex
        End Try
    End Function
    Public Overrides Sub RemoveDocumentRelation(ByVal ID As Integer, ByRef IDtoRemove As Integer)
        Try
            '#################################################
            'THIS IS USED TO MAINTAIN STATE BETWEEN CALLS.
            'EACH TIME A METHOD IS CALLED THE STATE NEEDS 
            'TO BE RESTORED TO THIS OBJECT BY CALLING 
            'PopulateLocalVariables()
            '#################################################
            PopulateLocalVariables(TrackingID)

            Dim iProvider As ISupportProvider = CType(Activator.GetObject(GetType(ISupportProvider), CStr(HttpContext.Current.Application("RemoteURL_SupportProvider"))), ISupportProvider)
            iProvider.RemoveDocumentRelation(ID, IDtoRemove, 99)

        Catch ex As Exception
            BLCommon.LogException(ex, ExceptionSeverity.Catastrophic)
            Throw ex
        End Try
    End Sub
    Public Overrides Function GetAllDocuments() As Dictionary(Of String, Object)
        Try
            '#################################################
            'THIS IS USED TO MAINTAIN STATE BETWEEN CALLS.
            'EACH TIME A METHOD IS CALLED THE STATE NEEDS 
            'TO BE RESTORED TO THIS OBJECT BY CALLING 
            'PopulateLocalVariables()
            '#################################################
            PopulateLocalVariables(TrackingID)

            Dim iProvider As ISupportProvider = CType(Activator.GetObject(GetType(ISupportProvider), CStr(HttpContext.Current.Application("RemoteURL_SupportProvider"))), ISupportProvider)
            Return iProvider.GetAllDocuments()


        Catch ex As Exception
            BLCommon.LogException(ex, ExceptionSeverity.Catastrophic)
            Throw ex
        End Try
    End Function
    Public Overrides Sub RelateDocument(ByVal ID As Integer, ByRef IDtoRelate As Integer)
        Try
            '#################################################
            'THIS IS USED TO MAINTAIN STATE BETWEEN CALLS.
            'EACH TIME A METHOD IS CALLED THE STATE NEEDS 
            'TO BE RESTORED TO THIS OBJECT BY CALLING 
            'PopulateLocalVariables()
            '#################################################
            PopulateLocalVariables(TrackingID)

            Dim iProvider As ISupportProvider = CType(Activator.GetObject(GetType(ISupportProvider), CStr(HttpContext.Current.Application("RemoteURL_SupportProvider"))), ISupportProvider)
            iProvider.RelateDocument(ID, IDtoRelate, 99)

        Catch ex As Exception
            BLCommon.LogException(ex, ExceptionSeverity.Catastrophic)
            Throw ex
        End Try
    End Sub
    Public Overrides Function AddDocument(ByVal folderID As Integer, ByVal HTML As String, ByVal ID As Integer, ByVal KeyWords As String, ByVal Summary As String, ByVal Title As String) As Integer
        Try
            '#################################################
            'THIS IS USED TO MAINTAIN STATE BETWEEN CALLS.
            'EACH TIME A METHOD IS CALLED THE STATE NEEDS 
            'TO BE RESTORED TO THIS OBJECT BY CALLING 
            'PopulateLocalVariables()
            '#################################################
            PopulateLocalVariables(TrackingID)

            Dim iProvider As ISupportProvider = CType(Activator.GetObject(GetType(ISupportProvider), CStr(HttpContext.Current.Application("RemoteURL_SupportProvider"))), ISupportProvider)
            Return iProvider.AddDocument(folderID, HTML, ID, KeyWords, Summary, Title, 99)


        Catch ex As Exception
            BLCommon.LogException(ex, ExceptionSeverity.Catastrophic)
            Throw ex
        End Try
    End Function
    Public Overrides Function AddFolder(ByVal ID As Integer, ByVal Name As String, ByVal NumberOfChildren As Integer, ByVal ParentFolderID As Integer) As Integer
        Try
            '#################################################
            'THIS IS USED TO MAINTAIN STATE BETWEEN CALLS.
            'EACH TIME A METHOD IS CALLED THE STATE NEEDS 
            'TO BE RESTORED TO THIS OBJECT BY CALLING 
            'PopulateLocalVariables()
            '#################################################
            PopulateLocalVariables(TrackingID)

            Dim iProvider As ISupportProvider = CType(Activator.GetObject(GetType(ISupportProvider), CStr(HttpContext.Current.Application("RemoteURL_SupportProvider"))), ISupportProvider)
            Return iProvider.AddFolder(ID, Name, NumberOfChildren, ParentFolderID, 99)


        Catch ex As Exception
            BLCommon.LogException(ex, ExceptionSeverity.Catastrophic)
            Throw ex
        End Try
    End Function
    Public Overrides Sub DeleteDocument(ByVal documentID As Integer)
        Try
            '#################################################
            'THIS IS USED TO MAINTAIN STATE BETWEEN CALLS.
            'EACH TIME A METHOD IS CALLED THE STATE NEEDS 
            'TO BE RESTORED TO THIS OBJECT BY CALLING 
            'PopulateLocalVariables()
            '#################################################
            PopulateLocalVariables(TrackingID)

            Dim iProvider As ISupportProvider = CType(Activator.GetObject(GetType(ISupportProvider), CStr(HttpContext.Current.Application("RemoteURL_SupportProvider"))), ISupportProvider)
            iProvider.DeleteDocument(documentID, 99)


        Catch ex As Exception
            BLCommon.LogException(ex, ExceptionSeverity.Catastrophic)
            Throw ex
        End Try
    End Sub
    Public Overrides Sub DeleteFolder(ByVal FolderID As Integer)
        Try
            '#################################################
            'THIS IS USED TO MAINTAIN STATE BETWEEN CALLS.
            'EACH TIME A METHOD IS CALLED THE STATE NEEDS 
            'TO BE RESTORED TO THIS OBJECT BY CALLING 
            'PopulateLocalVariables()
            '#################################################
            PopulateLocalVariables(TrackingID)

            Dim iProvider As ISupportProvider = CType(Activator.GetObject(GetType(ISupportProvider), CStr(HttpContext.Current.Application("RemoteURL_SupportProvider"))), ISupportProvider)
            iProvider.DeleteFolder(FolderID, 99)


        Catch ex As Exception
            BLCommon.LogException(ex, ExceptionSeverity.Catastrophic)
            Throw ex
        End Try
    End Sub
    Public Overrides Function GetDistinctKeyWords() As Dictionary(Of String, Object)
        Try
            '#################################################
            'THIS IS USED TO MAINTAIN STATE BETWEEN CALLS.
            'EACH TIME A METHOD IS CALLED THE STATE NEEDS 
            'TO BE RESTORED TO THIS OBJECT BY CALLING 
            'PopulateLocalVariables()
            '#################################################
            PopulateLocalVariables(TrackingID)

            Dim iProvider As ISupportProvider = CType(Activator.GetObject(GetType(ISupportProvider), CStr(HttpContext.Current.Application("RemoteURL_SupportProvider"))), ISupportProvider)
            Return iProvider.GetDistinctKeyWords()


        Catch ex As Exception
            BLCommon.LogException(ex, ExceptionSeverity.Catastrophic)
            Throw ex
        End Try
    End Function
    Public Overrides Function GetDocument(ByVal documentID As Integer) As Dictionary(Of String, Object)
        Try
            '#################################################
            'THIS IS USED TO MAINTAIN STATE BETWEEN CALLS.
            'EACH TIME A METHOD IS CALLED THE STATE NEEDS 
            'TO BE RESTORED TO THIS OBJECT BY CALLING 
            'PopulateLocalVariables()
            '#################################################
            PopulateLocalVariables(TrackingID)

            Dim iProvider As ISupportProvider = CType(Activator.GetObject(GetType(ISupportProvider), CStr(HttpContext.Current.Application("RemoteURL_SupportProvider"))), ISupportProvider)



            ' iProvider.GetEligibility("1", "2", "3", "4", "5")


            Return iProvider.GetDocument(documentID)


        Catch ex As Exception
            BLCommon.LogException(ex, ExceptionSeverity.Catastrophic)
            Throw ex
        End Try
    End Function
    Public Overrides Function GetEligibility(ByVal account As String, ByVal mac As String, ByVal phone As String, ByVal zipAccount As String, ByVal zipPhone As String) As String
        Try
            '#################################################
            'THIS IS USED TO MAINTAIN STATE BETWEEN CALLS.
            'EACH TIME A METHOD IS CALLED THE STATE NEEDS 
            'TO BE RESTORED TO THIS OBJECT BY CALLING 
            'PopulateLocalVariables()
            '#################################################
            PopulateLocalVariables(TrackingID)

            Dim iProvider As ISupportProvider = CType(Activator.GetObject(GetType(ISupportProvider), CStr(HttpContext.Current.Application("RemoteURL_SupportProvider"))), ISupportProvider)
            Return iProvider.GetEligibility(account, mac, phone, zipAccount,zipPhone)

        Catch ex As Exception
            BLCommon.LogException(ex, ExceptionSeverity.Catastrophic)
            Throw ex
        End Try
    End Function

    Public Overrides Function GetAllFolders() As System.Data.DataTable
        Try
            PopulateLocalVariables(TrackingID)

            Dim iProvider As ISupportProvider = CType(Activator.GetObject(GetType(ISupportProvider), CStr(HttpContext.Current.Application("RemoteURL_SupportProvider"))), ISupportProvider)
            Return iProvider.GetAllFolders()

        Catch ex As Exception
            BLCommon.LogException(ex, ExceptionSeverity.Catastrophic)
            Throw ex
        End Try

    End Function

    Public Overrides Function GetDocumentFolders() As Dictionary(Of String, Object)
        Try
            '#################################################
            'THIS IS USED TO MAINTAIN STATE BETWEEN CALLS.
            'EACH TIME A METHOD IS CALLED THE STATE NEEDS 
            'TO BE RESTORED TO THIS OBJECT BY CALLING 
            'PopulateLocalVariables()
            '#################################################
            PopulateLocalVariables(TrackingID)

            Dim iProvider As ISupportProvider = CType(Activator.GetObject(GetType(ISupportProvider), CStr(HttpContext.Current.Application("RemoteURL_SupportProvider"))), ISupportProvider)
            Return iProvider.GetDocumentFolders()


        Catch ex As Exception
            BLCommon.LogException(ex, ExceptionSeverity.Catastrophic)
            Throw ex
        End Try
    End Function
    Public Overrides Function GetDocumentFolders(ByVal parentFolderID As Integer) As Dictionary(Of String, Object)
        Try
            '#################################################
            'THIS IS USED TO MAINTAIN STATE BETWEEN CALLS.
            'EACH TIME A METHOD IS CALLED THE STATE NEEDS 
            'TO BE RESTORED TO THIS OBJECT BY CALLING 
            'PopulateLocalVariables()
            '#################################################
            PopulateLocalVariables(TrackingID)

            Dim iProvider As ISupportProvider = CType(Activator.GetObject(GetType(ISupportProvider), CStr(HttpContext.Current.Application("RemoteURL_SupportProvider"))), ISupportProvider)
            Return iProvider.GetDocumentFolders(parentFolderID)


        Catch ex As Exception
            BLCommon.LogException(ex, ExceptionSeverity.Catastrophic)
            Throw ex
        End Try
    End Function
    Public Overrides Function GetFolder(ByVal folderID As Integer) As Dictionary(Of String, Object)
        Try
            '#################################################
            'THIS IS USED TO MAINTAIN STATE BETWEEN CALLS.
            'EACH TIME A METHOD IS CALLED THE STATE NEEDS 
            'TO BE RESTORED TO THIS OBJECT BY CALLING 
            'PopulateLocalVariables()
            '#################################################
            PopulateLocalVariables(TrackingID)

            Dim iProvider As ISupportProvider = CType(Activator.GetObject(GetType(ISupportProvider), CStr(HttpContext.Current.Application("RemoteURL_SupportProvider"))), ISupportProvider)
            Return iProvider.GetFolder(folderID)


        Catch ex As Exception
            BLCommon.LogException(ex, ExceptionSeverity.Catastrophic)
            Throw ex
        End Try
    End Function
    'Public Overrides Function GetFolderDocuments(ByVal folderID As Integer) As Dictionary(Of String, Object)
    '    Try
    '        '#################################################
    '        'THIS IS USED TO MAINTAIN STATE BETWEEN CALLS.
    '        'EACH TIME A METHOD IS CALLED THE STATE NEEDS 
    '        'TO BE RESTORED TO THIS OBJECT BY CALLING 
    '        'PopulateLocalVariables()
    '        '#################################################
    '        PopulateLocalVariables(TrackingID)

    '        Dim iProvider As ISupportProvider = CType(Activator.GetObject(GetType(ISupportProvider), CStr(HttpContext.Current.Application("RemoteURL_SupportProvider"))), ISupportProvider)
    '        Return iProvider.GetFolderDocuments(folderID)


    '    Catch ex As Exception
    '        BLCommon.LogException(ex, ExceptionSeverity.Catastrophic)
    '        Throw ex
    '    End Try
    'End Function
    Public Overrides Sub MoveDocument(ByVal documentID As Integer, ByVal newFolderID As Integer)
        Try
            '#################################################
            'THIS IS USED TO MAINTAIN STATE BETWEEN CALLS.
            'EACH TIME A METHOD IS CALLED THE STATE NEEDS 
            'TO BE RESTORED TO THIS OBJECT BY CALLING 
            'PopulateLocalVariables()
            '#################################################
            PopulateLocalVariables(TrackingID)

            Dim iProvider As ISupportProvider = CType(Activator.GetObject(GetType(ISupportProvider), CStr(HttpContext.Current.Application("RemoteURL_SupportProvider"))), ISupportProvider)
            iProvider.MoveDocument(documentID, newFolderID, 99)


        Catch ex As Exception
            BLCommon.LogException(ex, ExceptionSeverity.Catastrophic)
            Throw ex
        End Try
    End Sub
    Public Overrides Sub UpdateDocument(ByVal HTML As String, ByVal ID As Integer, ByVal KeyWords As String, ByVal Summary As String, ByVal Title As String)
        Try
            '#################################################
            'THIS IS USED TO MAINTAIN STATE BETWEEN CALLS.
            'EACH TIME A METHOD IS CALLED THE STATE NEEDS 
            'TO BE RESTORED TO THIS OBJECT BY CALLING 
            'PopulateLocalVariables()
            '#################################################
            PopulateLocalVariables(TrackingID)

            Dim iProvider As ISupportProvider = CType(Activator.GetObject(GetType(ISupportProvider), CStr(HttpContext.Current.Application("RemoteURL_SupportProvider"))), ISupportProvider)
            iProvider.UpdateDocument(HTML, ID, KeyWords, Summary, Title, 99)


        Catch ex As Exception
            BLCommon.LogException(ex, ExceptionSeverity.Catastrophic)
            Throw ex
        End Try
    End Sub
    Public Overrides Sub UpdateFolder(ByVal ID As Integer, ByVal Name As String, ByVal NumberOfChildren As Integer, ByVal ParentFolderID As Integer)
        Try
            '#################################################
            'THIS IS USED TO MAINTAIN STATE BETWEEN CALLS.
            'EACH TIME A METHOD IS CALLED THE STATE NEEDS 
            'TO BE RESTORED TO THIS OBJECT BY CALLING 
            'PopulateLocalVariables()
            '#################################################
            PopulateLocalVariables(TrackingID)

            Dim iProvider As ISupportProvider = CType(Activator.GetObject(GetType(ISupportProvider), CStr(HttpContext.Current.Application("RemoteURL_SupportProvider"))), ISupportProvider)
            iProvider.UpdateFolder(ID, Name, NumberOfChildren, ParentFolderID, 99)


        Catch ex As Exception
            BLCommon.LogException(ex, ExceptionSeverity.Catastrophic)
            Throw ex
        End Try
    End Sub
    'Public Overrides Sub DeleteKeyWords(ByVal documentID As Integer)
    '    Try
    '        '#################################################
    '        'THIS IS USED TO MAINTAIN STATE BETWEEN CALLS.
    '        'EACH TIME A METHOD IS CALLED THE STATE NEEDS 
    '        'TO BE RESTORED TO THIS OBJECT BY CALLING 
    '        'PopulateLocalVariables()
    '        '#################################################
    '        PopulateLocalVariables(TrackingID)

    '        Dim iProvider As ISupportProvider = New SupportProvider.ProviderManager(configdata_support)
    '        iProvider.DeleteKeyWords(documentID)


    '    Catch ex As Exception
    'Common.LogException(ex, ExceptionSeverity.Catastrophic)
    'Throw ex
    '    End Try
    'End Sub
    'Public Overrides Sub AddKeyWords(ByVal documentID As Integer, ByRef keyWords As String)
    '    Try
    '        '#################################################
    '        'THIS IS USED TO MAINTAIN STATE BETWEEN CALLS.
    '        'EACH TIME A METHOD IS CALLED THE STATE NEEDS 
    '        'TO BE RESTORED TO THIS OBJECT BY CALLING 
    '        'PopulateLocalVariables()
    '        '#################################################
    '        PopulateLocalVariables(TrackingID)

    '        Dim iProvider As ISupportProvider = New SupportProvider.ProviderManager(configdata_support)
    '        iProvider.AddKeyWords(documentID, keyWords)


    '    Catch ex As Exception
    'Common.LogException(ex, ExceptionSeverity.Catastrophic)
    'Throw ex
    '    End Try
    'End Sub

    Public Overrides Function GetBinaryDocument(ByVal ID As Integer) As KeyValuePair(Of String, Byte())
        Try
            PopulateLocalVariables(TrackingID)

            Dim iProvider As ISupportProvider = CType(Activator.GetObject(GetType(ISupportProvider), CStr(HttpContext.Current.Application("RemoteURL_SupportProvider"))), ISupportProvider)
            Return iProvider.GetBinaryDocument(ID)

        Catch ex As Exception
            Dim aex As New ApplicationException("Error retriving Document")
            BLCommon.LogException(aex, ExceptionSeverity.Catastrophic)
            Throw aex
        End Try
    End Function


#End Region


#Region "Populate Channel Line Up (CLU) Functions"

    Private Function DoesNotExist(ByVal lList As Dictionary(Of String, ISingleChannel), ByVal lLookUpID As String) As Boolean
        Try
            Dim results As Boolean = True

            For Each item As ISingleChannel In lList.Values
                Dim lKey As String
                lKey = item.channelNumber.ToString()
                lKey = lKey & item.channelName.ToString().Replace(" ", "")
                lKey = lKey & item.serviceLevel.ToString().Replace(" ", "")

                If lKey = lLookUpID Then
                    results = False
                End If
            Next

            Return results


        Catch ex As Exception
            BLCommon.LogException(ex, ExceptionSeverity.Catastrophic)
            Throw ex
        End Try
    End Function

    Public Overrides Function GetChannelLineup(ByVal trackingid As String, ByVal AddressLine1 As String, ByVal AddressLine2 As String, ByVal ZipCode As String, ByVal HDTVOnly As Boolean) As IChannelLineUp
        Try
            Dim objChannelLineup As IChannelLineUp
            PopulateLocalVariables(trackingid)
            Dim am As New BLAccountManager(CType(Session(AccountManagerKey), Dictionary(Of String, Object)))
            If Not am.serviceabilityResults Is Nothing Then
                For Each obj As EntityEBSServices.GetServiceabilityResponseServiceabilityResult In am.serviceabilityResults.ServiceabilityResult
                    If Not obj.LocationAvailableServices Is Nothing Then
                        If AddressLine1 = obj.LocationAvailableServices.AddressLine1 And AddressLine2 = obj.LocationAvailableServices.AddressLine2 And ZipCode = obj.LocationAvailableServices.ZipCode Then
                            billinsystemcode = obj.LocationAvailableServices.BillingSystem
                            FTACode = obj.LocationAvailableServices.FTA
                            findServiceability = False
                        End If
                    End If
                Next
            End If

            If findServiceability Then
                If GetServiceabilityByAddress(AddressLine1, AddressLine2, ZipCode) Then
                    If HDTVOnly Then
                        objChannelLineup = GetLineupByID(FTACode, "HDTV", billinsystemcode)
                        'Persist Address information if the user hasn't localized yet, in order to prepopulate while localizing
                        If Not objChannelLineup Is Nothing Then
                            If am.account.UserStatus = UserStatus.UnIdentified Or am.account.UserStatus = UserStatus.Arealized Then
                                am.account.Address = New BLAddress(AddressLine1, AddressLine2, "", "", ZipCode, "")
                                SetSession(AccountManagerKey, am.ValuesForSetSession())
                            End If
                        End If
                        Return objChannelLineup
                    Else
                        objChannelLineup = GetLineupByID(FTACode, "", billinsystemcode)
                        'Persist Address information if the user hasn't localized yet, in order to prepopulate while localizing
                        If Not objChannelLineup Is Nothing Then
                            If am.account.UserStatus = UserStatus.UnIdentified Or am.account.UserStatus = UserStatus.Arealized Then
                                am.account.Address = New BLAddress(AddressLine1, AddressLine2, "", "", ZipCode, "")
                                SetSession(AccountManagerKey, am.ValuesForSetSession())
                            End If
                        End If
                        Return objChannelLineup
                    End If
                Else
                    Return Nothing
                End If
            Else
                If HDTVOnly Then
                    objChannelLineup = GetLineupByID(FTACode, "HDTV", billinsystemcode)
                    'Persist Address information if the user hasn't localized yet, in order to prepopulate while localizing
                    If Not objChannelLineup Is Nothing Then
                        If am.account.UserStatus = UserStatus.UnIdentified Or am.account.UserStatus = UserStatus.Arealized Then
                            am.account.Address = New BLAddress(AddressLine1, AddressLine2, "", "", ZipCode, "")
                            SetSession(AccountManagerKey, am.ValuesForSetSession())
                        End If
                    End If
                    Return objChannelLineup
                Else
                    objChannelLineup = GetLineupByID(FTACode, "", billinsystemcode)
                    'Persist Address information if the user hasn't localized yet, in order to prepopulate while localizing
                    If Not objChannelLineup Is Nothing Then
                        If am.account.UserStatus = UserStatus.UnIdentified Or am.account.UserStatus = UserStatus.Arealized Then
                            am.account.Address = New BLAddress(AddressLine1, AddressLine2, "", "", ZipCode, "")
                            SetSession(AccountManagerKey, am.ValuesForSetSession())
                        End If
                    End If
                    Return objChannelLineup
                End If
            End If
        Catch ex As Exception
            BLCommon.LogException(ex, ExceptionSeverity.Fatal)
            Throw ex
        End Try
    End Function

    Private Function GetServiceabilityByAddress(ByVal addr1 As String, ByVal addr2 As String, ByVal zipcode As String) As Boolean
        'TODO: call serviceability provider by passing account object
        ' then take out all this code for populating accounting object

        Try
            ' call serviceability provider with address
            'Dim lProvider As IEBSServicesProvider = providerFactory.CreateProvider(Of IEBSServicesProvider)(Common.AssemblyName)
            Dim lProvider As IEBSServicesProvider = CType(Activator.GetObject(GetType(IEBSServicesProvider), CStr(HttpContext.Current.Application("RemoteURL_EBSServicesProvider"))), IEBSServicesProvider)
            Dim sc As New EntityEBSServices.ServiceabilityCriteria
            Dim scaddress As New EntityEBSServices.ServiceabilityCriteriaAddress
            Dim objrequest As New EntityEBSServices.GetServiceabilityRequest
            Dim objresponse As EntityEBSServices.GetServiceabilityResponse

            With scaddress
                .AddressLine1 = addr1
                .AddressLine2 = addr2
                .ZipCode = zipcode
                .CleansedAddress = False
                .ZipCode4 = ""
            End With

            With sc
                .Item = scaddress
                .ItemElementName = EntityEBSServices.ItemChoiceType.Address
            End With

            objrequest.Criteria = sc
            objresponse = CType(lProvider.GetServiceability(objrequest), EntityEBSServices.GetServiceabilityResponse)
            If Not objresponse.ServiceabilityResult Is Nothing AndAlso objresponse.ServiceabilityResult.Length > 0 Then

                'Dim am As New BLAccountManager(CType(Session(AccountManagerKey), Dictionary(Of String, Object)))
                'am.serviceabilityResults = objresponse
                'SetSession(AccountManagerKey, am.ValuesForSetSession)

                '################################################################################################
                'PER GREG KOCH, THERE ARE TIMES WITH WE NEED TO PAD THE FTA NUMBER THAT COMES BACK FROM THE 
                'SERVICEABILITY WEB SERVICE.  SINCE WE TAKE THE FTA NUMBER THAT IS RETURNED FROM SERVICEABILTIY 
                'AND DIRECTY PASS IT BACK INTO THE CHANNEL LINE UP (CLU) WEB SERVICE, THE CLU ws IS EXPECTING 
                'THE FTA VALUE TO BE 4 DIGITS LONG.  TO ADDRESS THIS ISSUE, GREG SAID WHEN THE LENGTH IS LESS 
                'THAN 4, PAD THE VALUE WITH LEADING ZEROS.
                '################################################################################################
                If Not (objresponse.ServiceabilityResult(0) Is Nothing) Then
                    If Not (objresponse.ServiceabilityResult(0).LocationAvailableServices Is Nothing) Then
                        billinsystemcode = objresponse.ServiceabilityResult(0).LocationAvailableServices.BillingSystem
                        Dim strTempFTA As String = objresponse.ServiceabilityResult(0).LocationAvailableServices.FTA

                        Select Case objresponse.ServiceabilityResult(0).LocationAvailableServices.BillingProvider
                            Case "ICOMS"
                                FTACode = strTempFTA
                            Case Else
                                FTACode = strTempFTA.PadLeft(4, CChar("0"))
                        End Select
                        Return True
                    End If
                End If

            Else
                BLCommon.LogException(New Exception("Account Manager - Serviceaability failed with  reason as:" & objresponse.ExceptionMessage & "-" & objresponse.ExceptionStackTrace), ExceptionSeverity.Fatal)
                Return False
                Exit Function
            End If


        Catch ex As Exception
            BLCommon.LogException(ex, ExceptionSeverity.Catastrophic)
            Throw ex
        End Try
    End Function

    Public Function GetLineupByID(ByVal FTA As String, ByVal ServiceLevelName As String, ByVal SystemCode As String) As BLChannelLineUp
        Try
            Dim iProvider As IEBSServicesProvider = CType(Activator.GetObject(GetType(IEBSServicesProvider), CStr(HttpContext.Current.Application("RemoteURL_EBSServicesProvider"))), IEBSServicesProvider)

            ' Dim cm As New BLCatalogManager(CType(Session(Common.CatalogManagerKey), Dictionary(Of String, Object)))

            Dim objRequest As New EntityEBSServices.GetLineupByIDRequest
            Dim providerResponse As EntityEBSServices.GetLineupByIDResponse

            objRequest.SystemInfo = New EntityEBSServices.SystemInfo
            objRequest.SystemInfo.FTA = FTA
            objRequest.SystemInfo.ServiceLevelName = ServiceLevelName
            objRequest.SystemInfo.SystemCode = SystemCode

            providerResponse = CType(iProvider.GetLineupByID(objRequest), EntityEBSServices.GetLineupByIDResponse)


            If Not (providerResponse.SingleLineup Is Nothing) Then
                _ChannelLineUp = New BLChannelLineUp
                _ChannelLineUp.LineupID = providerResponse.SingleLineup.LineupID
                _ChannelLineUp.LineupName = providerResponse.SingleLineup.LineupName

                If Not (providerResponse.SingleLineup.LineupChannels Is Nothing) Then
                    _ChannelLineUp.ChannelLineUp = New Dictionary(Of String, ISingleChannel)
                    For i2 As Integer = 0 To providerResponse.SingleLineup.LineupChannels.GetUpperBound(0)
                        Dim lSingleChannel As New BLSingleChannel
                        lSingleChannel.channelName = providerResponse.SingleLineup.LineupChannels(i2).ChannelName
                        lSingleChannel.channelNumber = providerResponse.SingleLineup.LineupChannels(i2).ChannelNumber
                        lSingleChannel.serviceLevel = providerResponse.SingleLineup.LineupChannels(i2).ServiceLevel

                        Dim lKey As String
                        lKey = providerResponse.SingleLineup.LineupChannels(i2).ChannelNumber.ToString()
                        lKey = lKey & providerResponse.SingleLineup.LineupChannels(i2).ChannelName.ToString().Replace(" ", "")
                        lKey = lKey & providerResponse.SingleLineup.LineupChannels(i2).ServiceLevel.ToString().Replace(" ", "")

                        If DoesNotExist(_ChannelLineUp.ChannelLineUp, lKey) Then
                            _ChannelLineUp.ChannelLineUp.Add(lKey.ToString(), lSingleChannel)
                        End If
                    Next

                End If
                Return _ChannelLineUp
            Else
                Return Nothing
            End If


        Catch ex As Exception
            BLCommon.LogException(ex, ExceptionSeverity.Catastrophic)
            Throw ex
        End Try

    End Function

    Public Overrides Sub GetLineupBySystemFTA(ByVal trackingID As String, ByVal FTA As String, ByVal SystemCode As String)
        Try
            Dim iProvider As IEBSServicesProvider = CType(Activator.GetObject(GetType(IEBSServicesProvider), CStr(HttpContext.Current.Application("RemoteURL_EBSServicesProvider"))), IEBSServicesProvider)

            Dim cm As New BLCatalogManager(CType(Session(BLCommon.CatalogManagerKey), Dictionary(Of String, Object)))

            Dim objRequest As New EntityEBSServices.GetLineupBySystemFTARequest
            Dim providerResponse As EntityEBSServices.GetLineupBySystemFTAResponse

            objRequest.SystemInfo = New EntityEBSServices.SystemInfo
            objRequest.SystemInfo.FTA = FTA
            objRequest.SystemInfo.SystemCode = SystemCode

            providerResponse = CType(iProvider.GetLineupBySystemFTA(objRequest), EntityEBSServices.GetLineupBySystemFTAResponse)

            If Not (providerResponse.SingleLineup Is Nothing) Then
                _ChannelLineUp = New BLChannelLineUp
                _ChannelLineUp.LineupID = providerResponse.SingleLineup.LineupID
                _ChannelLineUp.LineupName = providerResponse.SingleLineup.LineupName

                If Not (providerResponse.SingleLineup.LineupChannels Is Nothing) Then
                    _ChannelLineUp.ChannelLineUp = New Dictionary(Of String, ISingleChannel)
                    For i2 As Integer = 0 To providerResponse.SingleLineup.LineupChannels.GetUpperBound(0)
                        Dim lSingleChannel As New BLSingleChannel
                        lSingleChannel.channelName = providerResponse.SingleLineup.LineupChannels(i2).ChannelName
                        lSingleChannel.channelNumber = providerResponse.SingleLineup.LineupChannels(i2).ChannelNumber
                        lSingleChannel.serviceLevel = providerResponse.SingleLineup.LineupChannels(i2).ServiceLevel

                        Dim lKey As String
                        lKey = providerResponse.SingleLineup.LineupChannels(i2).ChannelNumber.ToString()
                        lKey = lKey & providerResponse.SingleLineup.LineupChannels(i2).ChannelName.ToString().Replace(" ", "")
                        lKey = lKey & providerResponse.SingleLineup.LineupChannels(i2).ServiceLevel.ToString().Replace(" ", "")

                        If DoesNotExist(_ChannelLineUp.ChannelLineUp, lKey) Then
                            _ChannelLineUp.ChannelLineUp.Add(lKey.ToString(), lSingleChannel)
                        End If
                    Next
                End If
            End If


        Catch ex As Exception
            BLCommon.LogException(ex, ExceptionSeverity.Catastrophic)
            Throw ex
        End Try

    End Sub

    Public Overrides Sub GetLineupByZipZip4(ByVal trackingID As String, ByVal Zip As String, ByVal Zip4 As String)
        Try
            Dim iProvider As IEBSServicesProvider = CType(Activator.GetObject(GetType(IEBSServicesProvider), CStr(HttpContext.Current.Application("RemoteURL_EBSServicesProvider"))), IEBSServicesProvider)
            Dim cm As New BLCatalogManager(CType(Session(BLCommon.CatalogManagerKey), Dictionary(Of String, Object)))



            Dim objRequest As New EntityEBSServices.GetLineupByZipZip4Request
            Dim providerResponse As EntityEBSServices.GetLineupByZipZip4Response

            objRequest.ZipInfo = New EntityEBSServices.ZipInfo
            objRequest.ZipInfo.Zip = Zip
            objRequest.ZipInfo.Zip4 = Zip4

            providerResponse = CType(iProvider.GetLineupByZipZip4(objRequest), EntityEBSServices.GetLineupByZipZip4Response)


            If Not (providerResponse.SingleLineup Is Nothing) Then
                _ChannelLineUp = New BLChannelLineUp
                _ChannelLineUp.LineupID = providerResponse.SingleLineup.LineupID
                _ChannelLineUp.LineupName = providerResponse.SingleLineup.LineupName

                If Not (providerResponse.SingleLineup.LineupChannels Is Nothing) Then
                    _ChannelLineUp.ChannelLineUp = New Dictionary(Of String, ISingleChannel)
                    For i2 As Integer = 0 To providerResponse.SingleLineup.LineupChannels.GetUpperBound(0)
                        Dim lSingleChannel As New BLSingleChannel
                        lSingleChannel.channelName = providerResponse.SingleLineup.LineupChannels(i2).ChannelName
                        lSingleChannel.channelNumber = providerResponse.SingleLineup.LineupChannels(i2).ChannelNumber
                        lSingleChannel.serviceLevel = providerResponse.SingleLineup.LineupChannels(i2).ServiceLevel

                        Dim lKey As String
                        lKey = providerResponse.SingleLineup.LineupChannels(i2).ChannelNumber.ToString()
                        lKey = lKey & providerResponse.SingleLineup.LineupChannels(i2).ChannelName.ToString().Replace(" ", "")
                        lKey = lKey & providerResponse.SingleLineup.LineupChannels(i2).ServiceLevel.ToString().Replace(" ", "")

                        If DoesNotExist(_ChannelLineUp.ChannelLineUp, lKey) Then
                            _ChannelLineUp.ChannelLineUp.Add(lKey.ToString(), lSingleChannel)
                        End If
                    Next
                End If
            End If

        Catch ex As Exception
            BLCommon.LogException(ex, ExceptionSeverity.Catastrophic)
            Throw ex
        End Try

    End Sub


#End Region

#Region "CONTACT US"
    Public Overrides Function ContactUsByEmail(ByVal trackingID As String, ByVal fName As String, ByVal lName As String, ByVal streetAddress As String, ByVal city As String, ByVal state As String, ByVal zip As String, ByVal phoneNumber As String, ByVal fromEmail As String, ByVal subject As String, ByVal body As String) As Boolean
        Try
            PopulateLocalVariables(trackingID)
            Dim toEmail As String = CType(System.Web.HttpContext.Current.Application(BLCommon.CHARTER_EMAIL_RECEIVER), String)
            'body = body + ControlChars.NewLine + fName + " " + lName
            If (streetAddress = String.Empty And city = String.Empty And state = String.Empty And zip = String.Empty) Then

                body = "Web Form ID: 002" + "<br/>" + "Subject:  " + subject + "<br>" + "-----------------------------------------------------------" + "<br/>" + "Customer Information" + "<br/>" + "-----------------------------------------------------------" + "<br/>" + "Name:  " + fName + " " + lName + "<br/>" + "Phone:  " + phoneNumber + "<br/>" + "E-mail:  " + fromEmail + "<br/>" + "-----------------------------------------------------------" + "<br/>" + "Message:" + "<br/>" + "-----------------------------------------------------------" + "<br/>" + body
            Else
                body = "Web Form ID: 002" + "<br/>" + "Subject:  " + subject + "<br>" + "-----------------------------------------------------------" + "<br/>" + "Customer Information" + "<br/>" + "-----------------------------------------------------------" + "<br/>" + "Name:  " + fName + " " + lName + "<br/>" + "Address: " + streetAddress + "<br/>" + "&#09;" + city + ", " + state + " " + zip + "<br/>" + "Phone:  " + phoneNumber + "<br/>" + "E-mail:  " + fromEmail + "<br/>" + "-----------------------------------------------------------" + "<br/>" + "Message:" + "<br/>" + "-----------------------------------------------------------" + "<br/>" + body
            End If

            Dim iMail As ISupportProvider = CType(Activator.GetObject(GetType(ISupportProvider), CStr(System.Web.HttpContext.Current.Application("RemoteURL_SupportProvider"))), ISupportProvider)
            iMail.SendEMail(fromEmail, toEmail, subject, body.ToString, True)

            Return True
        Catch ex As Exception
            Dim aex As New ApplicationException("Cannot send email at this time", ex)
            BLCommon.LogException(aex, ExceptionSeverity.Medium)
            Throw ex
        End Try
    End Function


#End Region

#Region "OTHER"

    Public Overrides Sub SubscribeForUpdates(ByVal trackingID As String, ByVal eMail As String, ByVal cable As Boolean, ByVal data As Boolean, ByVal voice As Boolean)
        ' not yet decided on what to do
    End Sub

    Public Overrides Function GetSearchXml(ByVal trackingID As String) As String
        PopulateLocalVariables(trackingID)
        Dim iProvider As ISearchProvider = CType(Activator.GetObject(GetType(ISearchProvider), CStr(HttpContext.Current.Application("RemoteURL_SearchProvider"))), ISearchProvider)
        Try
            Dim objresult As EntityG2BServices.EntityUIRules = CType(iProvider.GetSearchXML(), EntityG2BServices.EntityUIRules)
            If Not objresult.Exception Then
                Return objresult.Data
            Else
                BLCommon.LogException(New Exception("Site Manager - Get Search xml failed as:" & objresult.ExceptionMessage & " - " & objresult.ExceptionStackTrace), ExceptionSeverity.High)
                Return Nothing
            End If
        Catch ex As Exception
            Dim aex As New ApplicationException("Site Manager - Get Search xml failed ", ex)
            BLCommon.LogException(aex, ExceptionSeverity.Fatal)
            Throw aex
        Finally
            iProvider = Nothing
        End Try
    End Function

    Protected Overrides Sub PopulateLocalVariables(ByVal trackingID As String)
        Try

            If Not (trackingID Is Nothing) Then
                MyBase.TrackingID = trackingID
                Dim sessionEntry As Object = Session(BLCommon.SiteManagerKey)
                If Not sessionEntry Is Nothing Then
                    Dim lManager As New BLSiteManager(CType(sessionEntry, Dictionary(Of String, Object)))
                    Me._ChannelLineUp = lManager._ChannelLineUp
                    Me.SiteKey = lManager.SiteKey
                End If

                'Dim lProviderSection As ProviderSectionHandler = CType(System.Web.HttpContext.Current.Application("ProviderSection"), ProviderSectionHandler)
                'configdata_ebs = lProviderSection.ProviderData("EBSServicesProvider")
                'configdata_support = lProviderSection.ProviderData("SupportProvider")

            End If
        Catch ex As Exception
            BLCommon.LogException(ex, ExceptionSeverity.Catastrophic)
            Throw ex
        End Try

    End Sub

    Public Overrides Function GetKey(ByVal trackingid As String) As String
        Try
            PopulateLocalVariables(trackingid)
            Return Me.SiteKey
        Catch ex As Exception
            Throw ex
        End Try
    End Function

    Public Overrides Sub SetKey(ByVal trackingID As String, ByVal SiteKey As String)
        Try
            MyBase.TrackingID = trackingID
            Me.SiteKey = SiteKey
            SetSession(BLCommon.SiteManagerKey, ValuesForSetSession())
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

#End Region

#Region "Register for Services"

    Public Overrides Function PreRegisterForUpdate(ByVal trackingID As String, ByVal fName As String, ByVal lname As String, _
         ByVal street As String, ByVal apt As String, ByVal city As String, ByVal state As String, ByVal zip As String, ByVal phone As String, ByVal email As String) As Boolean

        Try

            PopulateLocalVariables(trackingID)

            Dim iProvider As ISearchProvider = CType(Activator.GetObject(GetType(ISearchProvider), CStr(HttpContext.Current.Application("RemoteURL_SearchProvider"))), ISearchProvider)
            Dim request As New RegisterForUpdatesRequest(lname, fName, street, apt, city, state, zip, phone, email, trackingID)
            If iProvider.RegisterForUpdates(request) Then Return True
            Return False
        Catch ex As Exception
            Dim aex As New ApplicationException("Cannot register at this time", ex)
            LogException(aex, ExceptionSeverity.Low)
            Throw aex
        End Try
    End Function

    Public Overrides Function RequestForFollowUp(ByVal trackingID As String, ByVal fName As String, ByVal lname As String, _
              ByVal street As String, ByVal apt As String, ByVal city As String, ByVal state As String, ByVal zip As String, _
              ByVal phone As String, ByVal email As String, ByVal cable As Boolean, ByVal hsd As Boolean, ByVal telephone As Boolean) As Boolean

        Dim body As StringBuilder

        If System.Web.HttpContext.Current.Application("FOLLOW-UP_MAIL_RECEIVER") IsNot Nothing Then
            Dim toEmail As String = CType(System.Web.HttpContext.Current.Application("FOLLOW-UP_MAIL_RECEIVER"), String)
            'Dim com As New BLContentManager(CType(Session(ContentManagerKey), Dictionary(Of String, Object)))
            'Dim b As String = com.GetContent(trackingID, "OrderConfirmationEMail", "1", OwnerType.Other.ToString)

            Dim message As String = String.Empty
            Dim subject As String = "Request for Follow-Up"


            body = New System.Text.StringBuilder("<table width=""80%""><tr><td style=""height: 21px"">Subject: [Subject]</td></tr><tr><td>-----------------------------------------------------------<br />Customer Information <br />-----------------------------------------------------------<br /></td></tr><tr><td>Name:    [FirstName] [LastName]</td></tr><tr><td>Address: [Street] &nbsp; [Apt]</td></tr><tr><td>[City], [State] [Zip]</td></tr><tr><td>Phone:   [Phone]</td></tr><tr><td>E-mail:  [Email]</td></tr><tr><td>-----------------------------------------------------------<br />Message:<br />-----------------------------------------------------------<br /></td></tr><tr><td>[Message]</td></tr></table>")


            body.Replace("[Subject]", subject)

            body.Replace("[FirstName]", fName)
            body.Replace("[LastName]", lname)
            body.Replace("[Street]", street)
            body.Replace("[Apt]", apt)
            body.Replace("[City]", city)
            body.Replace("[State]", state)
            body.Replace("[Zip]", zip)
            body.Replace("[Phone]", phone)
            body.Replace("[Email]", email)

            If cable Then
                message = "New Cable TV services and features<br/>"
            End If
            If hsd Then
                message = message & "New High-Speed Internet service and features<br/>"
            End If
            If telephone Then
                message = message & "New Charter Telephone services and features<br/>"
            End If

            body.Replace("[Message]", message)

            Dim iMail As ISupportProvider = CType(Activator.GetObject(GetType(ISupportProvider), CStr(System.Web.HttpContext.Current.Application("RemoteURL_SupportProvider"))), ISupportProvider)
            iMail.SendEMail(email, toEmail, subject, body.ToString, True)
            Return True
        Else
            Return False
        End If
    End Function


#End Region



End Class
