Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports Microsoft.Practices.EnterpriseLibrary.Data
Imports System.Xml
Imports System.Collections.Generic
Imports system.io

<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class CharterDotComServices
    Inherits System.Web.Services.WebService


    <WebMethod()> _
    Public Function ResetCacheBy(ByVal key As String, ByVal CacheType As String) As Boolean
        'Case ApplicationKey.ResetCache.ToLower()
        Try
            Dim strTemplateKey As String = String.Empty
            If key.ToLower().Trim() <> ConfigurationManager.AppSettings("SiteSettings") Then
                Return False
            End If

            Dim wsConfigProvider As New ConfigProvider.Service
            wsConfigProvider.Url = ConfigurationManager.AppSettings("ConfigProvider.service")
            Dim ds As New Data.DataSet
            ds = wsConfigProvider.GetWebConfig(ConfigurationManager.AppSettings("ConfigLocation"))

            For Each row As Data.DataRow In ds.Tables(0).Rows
                Select Case row.Item("Key").ToString().ToLower()
                    Case ApplicationKey.ResetCache.ToLower()
                        If CStr(row.Item("XMLData")) = "true" Then


                            If Not (CacheType Is Nothing) Then
                                Select Case CacheType.ToUpper().Trim()
                                    Case "ALL"
                                        If Context.Cache.Count > 0 Then
                                            Dim custenum As IDictionaryEnumerator
                                            custenum = Context.Cache.GetEnumerator()
                                            custenum.MoveNext()
                                            Dim i As Integer
                                            For i = 1 To Context.Cache.Count
                                                Context.Cache.Remove(CStr(custenum.Key))
                                                custenum.MoveNext()
                                            Next
                                        End If
                                    Case Else
                                        '##########################
                                        'SKIP THIS CACHE REFRESH
                                        '##########################
                                End Select
                            End If

                        End If
                        Return True
                End Select
            Next
        Catch ex As Exception
            ex.Message.ToString()
        End Try
    End Function

    <WebMethod()> _
    Public Function ResetCache(ByVal TemplateID As Integer, ByVal key As String) As Boolean
        Try
            'remove the template header information
            'Application.Remove("templateHeaderInfo")
            Dim strKey As String
            Dim strTemplateKey As String = String.Empty
            If key.ToLower().Trim() <> ConfigurationManager.AppSettings("SiteSettings") Then
                Return False
            End If
            If TemplateID = 0 Then
                strKey = CacheKey.OutputCacheDurationKey
            Else
                strKey = "Template" & TemplateID
                strTemplateKey = "Template." & TemplateID
            End If
            For Each entry As DictionaryEntry In Context.Cache
                If entry.Key = strKey Then
                    Context.Cache.Remove(strKey)
                End If
                If entry.Key = strTemplateKey Then
                    Context.Cache.Remove(strTemplateKey)
                End If
            Next
            'If Context.Cache.Count > 0 Then
            '    Dim custenum As IDictionaryEnumerator
            '    custenum = Context.Cache.GetEnumerator()
            '    custenum.MoveNext()
            '    Dim i As Integer
            '    For i = 1 To Context.Cache.Count
            '        If custenum.Key = strKey Then
            '            Context.Cache.Remove(strKey)
            '            Return True
            '            Exit For
            '        End If
            '        custenum.MoveNext()
            '    Next
            'End If
            Return False
        Catch ex As Exception
            Return False
        End Try
    End Function


    <WebMethod()> _
   Public Function ChangeSiteSettings(ByVal key As String) As Boolean
        Try
            If key.ToLower().Trim() <> ConfigurationManager.AppSettings("SiteSettings") Then
                Return False
            End If
            Dim wsConfigProvider As New ConfigProvider.Service
            wsConfigProvider.Url = ConfigurationManager.AppSettings("ConfigProvider.service")
            Dim ds As New Data.DataSet
            ds = wsConfigProvider.GetWebConfig(ConfigurationManager.AppSettings("ConfigLocation"))

            Call Me.setInitialApplicationConfigurationValues(ds)

            Return True
        Catch exDB As Exception
            Return False
        Finally
        End Try
    End Function

    Public Sub setInitialApplicationConfigurationValues(ByVal ds As Data.DataSet)
        For Each row As Data.DataRow In ds.Tables(0).Rows
            Select Case row.Item("Key").ToString().ToLower()
                Case "redirects"
                    Dim doc As New XmlDocument
                    doc.LoadXml(row.Item("XMLData").ToString)
                    Dim redirectsection As XmlNode = doc.DocumentElement
                    Dim redirectDictionary As New StringDictionary()
                    If Not redirectsection Is Nothing Then

                        For Each node As XmlNode In redirectsection.ChildNodes
                            If Not redirectDictionary.ContainsKey(node.Attributes("currentURL").Value) Then
                                redirectDictionary.Add(node.Attributes("currentURL").Value, node.Attributes("activeURL").Value)

                            End If
                        Next

                    End If
                    Application.Lock()
                    Application.Remove("redirects")
                    Application.Add("redirects", redirectDictionary)
                    Application.UnLock()
                Case "hbxpages"
                    Dim doc As New XmlDocument
                    doc.LoadXml(row.Item("XMLData").ToString)
                    Dim pageSection As XmlNode = doc.DocumentElement
                    Dim pageDictionary As New Generic.Dictionary(Of String, String)
                    Dim url, mlc, pn As String
                    If Not pageSection Is Nothing Then
                        For Each pageNode As XmlNode In pageSection.ChildNodes
                            url = String.Empty
                            mlc = String.Empty
                            pn = String.Empty
                            For Each node As XmlNode In pageNode.ChildNodes
                                Select Case node.Name
                                    Case "url"
                                        'url = "/UI" & node.InnerText
                                        url = node.InnerText
                                        url = url.ToUpper
                                        ' issue 15850
                                    Case "hbxObj.mlc", "utag_data.page_level1"
                                        mlc = node.InnerText
                                    Case "hbxObj.pn", "utag_data.page_level2"
                                        pn = node.InnerText
                                End Select
                            Next
                            If Not (url = String.Empty OrElse pageDictionary.ContainsKey(url)) Then
                                pageDictionary.Add(url, pn & "@" & mlc)
                            End If
                        Next
                    End If
                    Application.Lock()
                    Application.Remove("hbxpages")
                    Application.Add("hbxpages", pageDictionary)
                    Application.UnLock()
                Case ApplicationKey.ResetCache.ToLower()
                    If CStr(row.Item("XMLData")) = "true" Then
                        If Context.Cache.Count > 0 Then
                            Dim custenum As IDictionaryEnumerator
                            custenum = Context.Cache.GetEnumerator()
                            custenum.MoveNext()
                            Dim i As Integer
                            For i = 1 To Context.Cache.Count
                                Context.Cache.Remove(CStr(custenum.Key))
                                custenum.MoveNext()
                            Next
                        End If
                    End If
                Case "usercontrol"
                    'do nothing  
                Case "providers"
                    'do nothing  
                Case "receivers"
                    Dim doc As New XmlDocument
                    doc.LoadXml(CStr(row.Item("XMLData")))
                    Dim receivers As New Collections.Generic.Dictionary(Of String, CharterDotCom.WebSite.Library.BLCommon.Receivers)
                    For Each receiverData As XmlNode In doc.DocumentElement.ChildNodes
                        receivers.Add(receiverData.InnerText, CType(receiverData.Attributes("ID").Value, CharterDotCom.WebSite.Library.BLCommon.Receivers))
                    Next
                    Application.Lock()
                    Application.Remove("Receivers")
                    Application.Add("Receivers", receivers)
                    Application.UnLock()
                    doc = Nothing

                Case "showpricelist"
                    Dim doc As New XmlDocument
                    doc.LoadXml(row.Item("XMLData").ToString)
                    Dim idlist As New Generic.List(Of String)
                    For Each pageNode As XmlNode In doc.ChildNodes
                        For Each node As XmlNode In pageNode.ChildNodes
                            If node.Attributes("id") IsNot Nothing Then
                                idlist.Add(node.Attributes("id").Value)
                            End If
                        Next
                    Next
                    Application.Lock()
                    Application.Remove(ApplicationKey.ShowPrice)
                    Application.Add(ApplicationKey.ShowPrice, idlist)
                    Application.UnLock()
                Case ApplicationKey.XSSStringList
                    'do nothing

                Case ApplicationKey.MyAccountRetUNameStepList.ToLower
                    'JPirkey: MyAccount Apr 2010 FOR TESTING ONLY!!
                    'Obtain list from the Application object, if it doesn't exist, pull from the database.
                    'Dim sStepSequenceKeys As String = "PhoneAccount:1\ZipCode:2\SecurityQuestion:3\EnterPwd:4\ChangePwd:5"
                    Dim sStepSequenceKeys As String = row.Item("XMLData").ToString
                    Dim StepList As List(Of MyAccountStepList)
                    Dim sSteps() As String = Split(sStepSequenceKeys, "\")

                    If StepList Is Nothing Then
                        StepList = New List(Of MyAccountStepList)
                    End If
                    'steps are delimited by "\" and each step is split by the ":" which provides the order of the step
                    For Each stp As String In sSteps
                        Dim masStep As New MyAccountStepList
                        masStep.QueryName = stp.Split(":")(0).ToString
                        masStep.Sequence = stp.Split(":")(1).ToString
                        StepList.Add(masStep)
                    Next

                    Application.Lock()
                    Application.Remove(ApplicationKey.MyAccountRetUNameStepList)
                    Application.Add(ApplicationKey.MyAccountRetUNameStepList, StepList)
                    Application.UnLock()

                Case Else
                    Application.Lock()
                    Application.Remove(row.Item("Key").ToString())
                    Application.Add(row.Item("Key").ToString(), row.Item("XMLData"))
                    Application.UnLock()
            End Select
        Next




        '#################################################################################################
        '####################   M O D I F I C A T I O N        4/30/2007    ROD COPELAND #################
        '#################################################################################################
        'THIS FUNCTIONALITY IS USED FOR ERROR DISPLAYING. AN ERROR CODE GETS RETURNED FROM A WEBSERVICE
        'OR AN ERROR OCCURS IN THE APPLICAITON, THEN THE ERROR CODE IS SEARCHED FOR IN THE DICTIONARY 
        'AND THE CCOM MESSAGE ASSOCISTED WITH THAT IS DISPLAYED TO THE USER.
        'JUST BECAUSE THE ERROR MESSAGES DONT LOAD BECAUSE OF A PROBLEM, DOESN'T MEAN ITS A SHOW STOPPER.  
        'TRAP THE EXCEPTION AND CONTINUE TO LOAD THE APPLICATION.
        '#################################################################################################
        Try
            If ds.Tables.Count > 1 Then
                Dim lErrorCodesCollection As New Dictionary(Of String, CharterDotCom.CommonEntities.Library.ErrorCodes.ErrorMapRecord)

                For Each row As Data.DataRow In ds.Tables(1).Rows
                    Dim lErrorMapRecord As New CharterDotCom.CommonEntities.Library.ErrorCodes.ErrorMapRecord
                    If Not (row.Item("ID") Is System.DBNull.Value) Then
                        If Not (row.Item("ID") Is Nothing) Then
                            lErrorMapRecord.DB_ID = CType(row.Item("ID"), Integer)
                        End If
                    End If
                    If Not (row.Item("DATA_SOURCE_NAME") Is System.DBNull.Value) Then
                        If Not (row.Item("DATA_SOURCE_NAME") Is Nothing) Then
                            lErrorMapRecord.dataSourceName = CType(row.Item("DATA_SOURCE_NAME"), String)
                        End If
                    End If
                    If Not (row.Item("DATA_SOURCE_LOCATION") Is System.DBNull.Value) Then
                        If Not (row.Item("DATA_SOURCE_LOCATION") Is Nothing) Then
                            lErrorMapRecord.dataSourceLocation = CType(row.Item("DATA_SOURCE_LOCATION"), String)
                        End If
                    End If
                    If Not (row.Item("DATA_SOURCE_ERROR_CODE") Is System.DBNull.Value) Then
                        If Not (row.Item("DATA_SOURCE_ERROR_CODE") Is Nothing) Then
                            lErrorMapRecord.dataSourceErrorCode = CType(row.Item("DATA_SOURCE_ERROR_CODE"), String)
                        End If
                    End If
                    If Not (row.Item("DATA_SOURCE_ERROR_MESSAGE") Is System.DBNull.Value) Then
                        If Not (row.Item("DATA_SOURCE_ERROR_MESSAGE") Is Nothing) Then
                            lErrorMapRecord.dataSourceErrorMessage = CType(row.Item("DATA_SOURCE_ERROR_MESSAGE"), String)
                        End If
                    End If
                    If Not (row.Item("CCOM_RELATED_ERROR_CODE") Is System.DBNull.Value) Then
                        If Not (row.Item("CCOM_RELATED_ERROR_CODE") Is Nothing) Then
                            lErrorMapRecord.ccomRelatedErrorCode = CType(row.Item("CCOM_RELATED_ERROR_CODE"), String)
                        End If
                    End If
                    If Not (row.Item("CCOM_DISPLAY_MESSAGE") Is System.DBNull.Value) Then
                        If Not (row.Item("CCOM_DISPLAY_MESSAGE") Is Nothing) Then
                            lErrorMapRecord.ccomDisplayMessage = CType(row.Item("CCOM_DISPLAY_MESSAGE"), String)
                        End If
                    End If
                    If Not (row.Item("CREATE_DATE") Is System.DBNull.Value) Then
                        If Not (row.Item("CREATE_DATE") Is Nothing) Then
                            lErrorMapRecord.createDate = CType(row.Item("CREATE_DATE"), Date)
                        End If
                    End If

                    lErrorCodesCollection.Add(lErrorMapRecord.dataSourceName & lErrorMapRecord.dataSourceErrorCode, lErrorMapRecord)
                Next

                Application.Lock()
                Application.Remove("ERROR_CODE_MAPPING_COLLECTION")
                Application.Add("ERROR_CODE_MAPPING_COLLECTION", lErrorCodesCollection)
                Application.UnLock()

            End If
        Catch ex As Exception
            Throw New Exception("the exception is occuring while trying to work with the Error Code Collection. - " & ex.Message)
        End Try
        '#################################################################################################
        '####################   M O D I F I C A T I O N        4/30/2007    ROD COPELAND #################
        '#################################################################################################


        '#################################################################################################
        '####################   M O D I F I C A T I O N        7/03/2007    ROD COPELAND #################
        '#################################################################################################
        '
        '#################################################################################################
        Try
            If ds.Tables.Count > 2 Then
                Dim WebCrawledPageCollection As New Dictionary(Of String, WebCrawledPage)

                For Each row As Data.DataRow In ds.Tables(2).Rows
                    Dim lRecord As New WebCrawledPage
                    If Not (row.Item("ID") Is System.DBNull.Value) Then
                        If Not (row.Item("ID") Is Nothing) Then
                            lRecord.DBTableID = CType(row.Item("ID"), Integer)
                        End If
                    End If
                    If Not (row.Item("KEYWORDS") Is System.DBNull.Value) Then
                        If Not (row.Item("KEYWORDS") Is Nothing) Then
                            lRecord.PageKeywords = CType(row.Item("KEYWORDS").ToString().Trim(), String)
                        End If
                    End If
                    If Not (row.Item("HBX_PAGE_NAME") Is System.DBNull.Value) Then
                        If Not (row.Item("HBX_PAGE_NAME") Is Nothing) Then
                            lRecord.HBXPageName = CType(row.Item("HBX_PAGE_NAME").ToString().Trim(), String)
                        End If
                    End If
                    If Not (row.Item("HBX_PAGE_CATEGORY") Is System.DBNull.Value) Then
                        If Not (row.Item("HBX_PAGE_CATEGORY") Is Nothing) Then
                            lRecord.HBXPageCategory = CType(row.Item("HBX_PAGE_CATEGORY").ToString().Trim(), String)
                        End If
                    End If
                    If Not (row.Item("PAGE_DESCRIPTION") Is System.DBNull.Value) Then
                        If Not (row.Item("PAGE_DESCRIPTION") Is Nothing) Then
                            lRecord.PageDescription = CType(row.Item("PAGE_DESCRIPTION").ToString().Trim(), String)
                        End If
                    End If
                    If Not (row.Item("PAGE_STYLESHEET_URL") Is System.DBNull.Value) Then
                        If Not (row.Item("PAGE_STYLESHEET_URL") Is Nothing) Then
                            lRecord.StyleSheetURL = CType(row.Item("PAGE_STYLESHEET_URL").ToString().Trim(), String)
                        End If
                    End If
                    If Not (row.Item("PAGE_SEARCH_TEXT") Is System.DBNull.Value) Then
                        If Not (row.Item("PAGE_SEARCH_TEXT") Is Nothing) Then
                            lRecord.searchWords = CType(row.Item("PAGE_SEARCH_TEXT").ToString().Trim(), String)
                        End If
                    End If
                    If Not (row.Item("PAGE_SEARCH_RANKING") Is System.DBNull.Value) Then
                        If Not (row.Item("PAGE_SEARCH_RANKING") Is Nothing) Then
                            lRecord.SearchRanking = CType(row.Item("PAGE_SEARCH_RANKING"), Integer)
                        End If
                    End If

                    If Not (row.Item("CREATE_DATE") Is System.DBNull.Value) Then
                        If Not (row.Item("CREATE_DATE") Is Nothing) Then
                            lRecord.CreateDate = CType(row.Item("CREATE_DATE"), Date)
                        End If
                    End If
                    If Not (row.Item("MODIFY_DATE") Is System.DBNull.Value) Then
                        If Not (row.Item("MODIFY_DATE") Is Nothing) Then
                            lRecord.ModifiedDate = CType(row.Item("MODIFY_DATE"), Date)
                        End If
                    End If
                    If Not (row.Item("PAGE_URL") Is System.DBNull.Value) Then
                        If Not (row.Item("PAGE_URL") Is Nothing) Then
                            lRecord.pageURL = CType(row.Item("PAGE_URL").ToString().Trim(), String)
                        End If
                    End If
                    If Not (row.Item("TITLE") Is System.DBNull.Value) Then
                        If Not (row.Item("TITLE") Is Nothing) Then
                            lRecord.Title = CType(row.Item("TITLE").ToString().Trim(), String)
                        End If
                    End If


                    If Not WebCrawledPageCollection.ContainsKey(lRecord.pageURL) Then
                        WebCrawledPageCollection.Add(lRecord.pageURL, lRecord)
                    End If
                Next

                Application.Lock()
                Application.Remove("WEB_CRAWLED_PAGE_COLLECTION")
                Application.Add("WEB_CRAWLED_PAGE_COLLECTION", WebCrawledPageCollection)
                Application.UnLock()

            End If
        Catch ex As Exception
            Throw New Exception("The exception is occuring while trying to work with the Web Crawled Page Collection. - " & ex.Message)
        End Try
        '#################################################################################################
        '####################   M O D I F I C A T I O N        7/03/2007    ROD COPELAND #################
        '#################################################################################################


        '#################################################################################################
        '####################   M O D I F I C A T I O N        8/15/2007    ROD COPELAND #################
        '#################################################################################################
        'THIS FUNCTIONALITY WAS ADDED FOR THE URL REDIRECT SOLUTION.
        'BUILD REDIRECT COLLECTION AND CREATE ANY REDIRECT FOLDERS THAT NEED TO EXIST.
        'EACH REDIRECT FOLDER NEEDS TO HAVE A DEFAULT.ASPX PAGE SO THAT IIS WILL PASS THE REDIRECT 
        'REQUEST TO ASPNET TO HANDLE.  WITHOUT THE DEFAULT.ASPX, THE FOLDER REDIRECT WILL NOT GET TO THIS 
        'APPLICATIONS HTTPMODULE, IIS WILL JUST RESPOND BACK TO THE USER WITH LIKE 404 ERROR (SOMETHING 
        'CLOSE TO THAT).
        '#################################################################################################
        Try
            If ds.Tables.Count > 3 Then
                Dim lRedirectURLCollection As New Dictionary(Of String, String)
                Dim SEOCollectionForward As New Dictionary(Of String, String)

                For Each row As Data.DataRow In ds.Tables(3).Rows
                    If Not (row.Item("REQUEST_URL") Is System.DBNull.Value) Then
                        If Not (row.Item("REQUEST_URL") Is Nothing) Then
                            If Not (row.Item("REDIRECT_URL") Is System.DBNull.Value) Then
                                If Not (row.Item("REDIRECT_URL") Is Nothing) Then
                                    '######################################################################################
                                    'THIS CONDITION ALLOWS THE UI TO BE RAN ON THE LOCALHOST FOR 
                                    'DEVELOPMENT PURPOSES WITHOUT CREATING REDIRECT FOLDERS ON DEVELOPMENT MACHINES
                                    '######################################################################################
                                    Dim strMachineName As String = Environment.MachineName.ToUpper()
                                    Select Case strMachineName
                                        Case "KSTLINTC64V6855" 'JOHN CORTRIGHT
                                        Case "KSTLINTC20V5109" ' Jude Naes
                                        Case "KSTLUSRS64V09YS" ' Jim Gilbert
                                        Case "KSTLMWEB65"      'CHARTER.COM DEV BOX

                                        Case Else
                                            '########################################################
                                            'CREATE REDIRECT DIRECOTIRES IF THEY DONT EXIST ALREADY
                                            '########################################################
                                            'IF DIRECTORY DOESNT EXIST ALREADY IIS WILL NOT PASS THE 
                                            'REQUEST TO ASPNET TO HANDLE IN THE HTTPMODULE.
                                            '########################################################
                                            Dim lPath As String = CType(row.Item("REQUEST_URL").ToString().ToLower().Trim(), String)
                                            '##################################################
                                            ''MAKE SURE ITS NOT A FILE REQUEST AT THE ROOT.                                       
                                            '##################################################
                                            If lPath.LastIndexOf("/") > 0 Then
                                                lPath = lPath.Substring(1, lPath.LastIndexOf("/") - 1)
                                            Else
                                                '####################################
                                                'NO DIRECTORIES TO CREATE, JUST SKIP
                                                '####################################                                                        
                                            End If

                                            Dim directoriesInPath() As String = lPath.Split(CType("/", Char))
                                            Dim tempPath As String = Server.MapPath("~") & "\"
                                            Dim folderIndex As Integer = 0
                                            For i As Integer = 0 To directoriesInPath.Length - 1
                                                If Not (Directory.Exists(tempPath & directoriesInPath(i))) Then
                                                    '#######################
                                                    'CREATE THE DIRECTORY
                                                    '#######################
                                                    Directory.CreateDirectory(tempPath & directoriesInPath(i))
                                                End If

                                                '##############################
                                                'UPDATE THE PATH WITH NEW NAME 
                                                '##############################
                                                tempPath = tempPath & directoriesInPath(i) & "\"



                                                '############################################################
                                                'MODIFICATION   ROD COPELAND    7/18/2008   ISSUE ID 2374
                                                'ADDING THE SEARCH ENGINE OPTIMIZATION USAGE INDICATOR
                                                '############################################################
                                                Dim useSEOFile As Boolean = False
                                                If Not (row.Item("SEOUse") Is System.DBNull.Value) Then
                                                    If Not (row.Item("SEOUse") Is Nothing) Then
                                                        If CType(row.Item("SEOUse"), Boolean) = True Then
                                                            useSEOFile = True
                                                        End If
                                                    End If
                                                End If

                                                '################################################
                                                'SEE IF THE DEFAULT FILES EXIST OUT THERE YET.
                                                'IF NOT, GO AHEAD AND CREATE THEM FOR EACH FOLDER.
                                                '################################################
                                                Try
                                                    If useSEOFile Then
                                                        '#######################################################################
                                                        'CREATE THE FILES IN THE LAST DIRECTORY IN THE PATH RATHER THAN EVERY 
                                                        'DIRECTORY AS IT IS IN THE FOLDER REDIRECTS.
                                                        'OVERWRITE FILES IN THE FINAL LOCATION.
                                                        'THE DEFAULT.ASPX.VB INHERIT'S FROM THE BASE CLASS SEOPAGE WHICH 
                                                        'DETERMINES WHICH URL TO DO A TRANSFER TO.
                                                        'IN THE EVENT THAT A PERSON SELECT TO MAKE AN EXISTING FOLDER REDIRECT INTO 
                                                        'A SEO REDIRECT, THEY WOULD HAVE REMOVED THE RECORD USED AT THE HANDLER AND 
                                                        'REQUESTS WOULD THEN BE HITTING THE BLANK DEFAULT.ASPX PAGES. WHEN THE SEO 
                                                        'PAGE IS ADDED IN THE DB, THE SEO DEFAULT.ASPX IS MEANT TO OVERWRITE THE 
                                                        'BLANK PAGE WITH A PAGE THAT INHERITS FROM THE SEO BASE CLASS.  FYI...
                                                        '#######################################################################
                                                        If folderIndex >= directoriesInPath.GetUpperBound(0) Then
                                                            If File.Exists(tempPath & "Readme.txt") Then
                                                                Dim strFile As String = tempPath & "Readme.txt"
                                                                File.SetAttributes(strFile, FileAttributes.Normal)
                                                            End If
                                                            File.Copy(Server.MapPath("~") & "\" & "SEORedirects\Readme.txt", tempPath & "Readme.txt", True)

                                                            If File.Exists(tempPath & "Default.aspx.vb") Then
                                                                Dim strFile As String = tempPath & "Default.aspx.vb"
                                                                File.SetAttributes(strFile, FileAttributes.Normal)
                                                            End If
                                                            File.Copy(Server.MapPath("~") & "\" & "SEORedirects\Default.aspx.vb", tempPath & "Default.aspx.vb", True)

                                                            If File.Exists(tempPath & "Default.aspx") Then
                                                                Dim strFile As String = tempPath & "Default.aspx"
                                                                File.SetAttributes(strFile, FileAttributes.Normal)
                                                            End If
                                                            File.Copy(Server.MapPath("~") & "\" & "SEORedirects\Default.aspx", tempPath & "Default.aspx", True)
                                                        End If
                                                    Else
                                                        '##########################################################################################
                                                        'THESE ARE BLANK PAGES THAT REDIRECT THE USER TO THE HOME PAGE IF YOU REQUEST 
                                                        'THE PAGES DIRECTLY. THE PAGES DIRECTLY NEVER GET HIT DIRECTLY, THE HANDLER CATCHES THE 
                                                        'REQUEST AND REDIRECTS BEFORE SERVING THE ORIGNIAL PAGE REQUESTED. UNLESS OFCOURSE 
                                                        'THE FOLDER REDIRECT HANDLER DOES NOT HAVE AN ENTRY FOR THAT SPECIFIC FOLDER. IN 
                                                        'THAT CASE THE ORIGINAL DEFAULT.ASPX WILL GET HIT.
                                                        '##########################################################################################
                                                        If File.Exists(tempPath & "Readme.txt") Then
                                                            Dim strFile As String = tempPath & "Readme.txt"
                                                            File.SetAttributes(strFile, FileAttributes.Normal)
                                                        End If
                                                        File.Copy(Server.MapPath("~") & "\" & "Redirects\Readme.txt", tempPath & "Readme.txt", True)

                                                        If File.Exists(tempPath & "Default.aspx.vb") Then
                                                            Dim strFile As String = tempPath & "Default.aspx.vb"
                                                            File.SetAttributes(strFile, FileAttributes.Normal)
                                                        End If
                                                        File.Copy(Server.MapPath("~") & "\" & "Redirects\Default.aspx.vb", tempPath & "Default.aspx.vb", True)

                                                        If File.Exists(tempPath & "Default.aspx") Then
                                                            Dim strFile As String = tempPath & "Default.aspx"
                                                            File.SetAttributes(strFile, FileAttributes.Normal)
                                                        End If
                                                        File.Copy(Server.MapPath("~") & "\" & "Redirects\Default.aspx", tempPath & "Default.aspx", True)
                                                    End If
                                                Catch ex As Exception
                                                    '#######################################
                                                    'SKIP THIS FILE, CONTINUE WITH OTHERS
                                                    '#######################################
                                                End Try
                                                folderIndex = folderIndex + 1
                                            Next
                                    End Select

                                    '############################################################
                                    'MODIFICATION   ROD COPELAND    7/18/2008   ISSUE ID 2374
                                    'ADDING THE SEARCH ENGINE OPTIMIZATION USAGE INDICATOR
                                    '############################################################
                                    Dim isFolderRedirect As Boolean = True
                                    If Not (row.Item("SEOUse") Is System.DBNull.Value) Then
                                        If Not (row.Item("SEOUse") Is Nothing) Then
                                            If CType(row.Item("SEOUse"), Boolean) = True Then
                                                isFolderRedirect = False
                                            Else
                                                isFolderRedirect = True
                                            End If
                                        Else
                                            isFolderRedirect = True
                                        End If
                                    Else
                                        isFolderRedirect = True
                                    End If

                                    If isFolderRedirect Then
                                        '##################################
                                        'ADD PATHS TO REDIRECT COLLECTION
                                        '##################################
                                        lRedirectURLCollection.Add(CType(row.Item("REQUEST_URL").ToString().ToLower().Trim(), String), CType(row.Item("REDIRECT_URL").ToString().ToLower().Trim(), String))
                                    Else
                                        '############################################################
                                        'MODIFICATION   ROD COPELAND    7/18/2008   ISSUE ID 2374
                                        'ADDING THE SEARCH ENGINE OPTIMIZATION USAGE INDICATOR
                                        '############################################################
                                        SEOCollectionForward.Add(row.Item("REQUEST_URL").ToString().ToLower().Trim(), row.Item("REDIRECT_URL").ToString().ToLower().Trim())
                                    End If

                                End If
                            End If
                        End If
                    End If
                Next

                Application.Lock()

                Application.Remove("SEARCH_ENGINE_OPTIMIZATION_URL_COLLECTION")
                Application.Add("SEARCH_ENGINE_OPTIMIZATION_URL_COLLECTION", SEOCollectionForward)

                Application.Remove("URL_REDIRECT_MAPPING_COLLECTION")
                Application.Add("URL_REDIRECT_MAPPING_COLLECTION", lRedirectURLCollection)

                Application.UnLock()

            End If
        Catch ex As Exception
            Throw New Exception("the exception is occuring while trying to work with the URL Redirect Mapping Collection. - " & ex.Message)
        End Try
        '#################################################################################################
        '####################   M O D I F I C A T I O N        8/15/2007    ROD COPELAND #################
        '#################################################################################################





        '#################################################################################################
        '####################   M O D I F I C A T I O N        5/8/2008    JONATHAN PARKS ################
        '#################################################################################################
        ' THIS SHOULD BRING BACK A LIST OF THE INVALID XSS STRINGS WE WANT TO IDENTIFY
        '#################################################################################################
        Try
            If ds.Tables.Count > 4 Then
                Dim lXSSList As New List(Of String)
                For Each row As Data.DataRow In ds.Tables(4).Rows
                    If Not (row.Item("InvalidQueryStringText") Is System.DBNull.Value) Then
                        If Not (row.Item("InvalidQueryStringText") Is Nothing) Then
                            lXSSList.Add(row.Item("InvalidQueryStringText").ToString.ToLower)
                        End If
                    End If
                Next

                Application.Lock()
                Application.Remove(ApplicationKey.XSSStringList)
                Application.Add(ApplicationKey.XSSStringList, lXSSList)
                Application.UnLock()

            End If
        Catch ex As Exception
            Throw New Exception("the exception is occuring while trying to work with the XSSConfig invalid querystring text list. - " & ex.Message)
        End Try
        '#################################################################################################
        '####################   M O D I F I C A T I O N        5/8/2008    JONATHAN PARKS ################
        '#################################################################################################        






        '#################################################################################################
        '####################   M O D I F I C A T I O N        10/02/2007    ROD COPELAND #################
        '#################################################################################################
        'THIS SHOULD BRING BACK A LIST OF THE GENERAL Security QUESTIONS USED FOR MYACCOUNT
        '#################################################################################################
        Try

            If ds.Tables.Count > 5 Then
                Dim lQuestionList As New List(Of String)
                For Each row As Data.DataRow In ds.Tables("SecretQuestionTable").Rows
                    If Not (row.Item("Question") Is System.DBNull.Value) Then
                        If Not (row.Item("Question") Is Nothing) Then
                            If Not row.Item("Question").ToString().Trim().Contains("Customer did not choose.") Then
                                lQuestionList.Add(row.Item("Question").ToString)
                            End If
                        End If
                    End If
                Next

                Application.Lock()
                Application.Remove("MYACCOUNT_GENERALQUESTIONLIST")
                Application.Add("MYACCOUNT_GENERALQUESTIONLIST", lQuestionList)
                Application.UnLock()

            End If
        Catch ex As Exception
            Throw New Exception("the exception is occuring while trying to work with the URL Redirect Mapping Collection. - " & ex.Message)
        End Try
        '#################################################################################################
        '####################   M O D I F I C A T I O N        8/15/2007    ROD COPELAND #################
        '#################################################################################################

    End Sub
End Class
