Imports System.Collections.Generic
Imports CharterDotCom.CommonEntities.Library
Imports System.Data
Imports System.Xml

Partial Class _ViewFile
    Inherits AdminPage

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not (Page.IsPostBack) Then
            With ddlXMLFiles
                .Items.Clear()
                Dim Files() As String
                Dim xmlFileList As List(Of String) = New List(Of String)
                Files = CMSContentManager.Instance.GetBinaryFiles("XML")
                If Not Files Is Nothing Then
                    xmlFileList.AddRange(Files)
                End If
                .DataSource = xmlFileList
                .DataBind()
            End With

            Dim fileName As String = Request.QueryString("file")
            Dim fileExtension As String

            Dim lastDotPosition As Integer = fileName.LastIndexOf(".")
            fileExtension = fileName.Substring(lastDotPosition)
            fileName = fileName.Substring(0, lastDotPosition)

            Select Case fileExtension
                Case ".ccswf"
                    pnlFlash.Visible = True
                    pnlXML.Visible = False
                    pnlFLV.Visible = False
                    pnlUnknownType.Visible = False
                Case ".ccxml"
                    pnlFlash.Visible = False
                    pnlXML.Visible = True
                    pnlFLV.Visible = False
                    pnlUnknownType.Visible = False

                    Dim doc As XmlDocument = New XmlDocument()
                    Dim serverPath As String
                    If Request.ServerVariables("HTTP_HOST").ToLower() = "localhost" Then
                        serverPath = "http://" & Request.ServerVariables("HTTP_HOST") & "/BL.RemotingHost/Admin/xml/"
                    Else
                        serverPath = "http://" & Request.ServerVariables("HTTP_HOST") & "/Admin/xml/"
                    End If
                    doc.Load(serverPath & fileName & fileExtension)
                    xmlView.DocumentContent = doc.OuterXml
                Case ".ccflv"
                    pnlFlash.Visible = False
                    pnlXML.Visible = False
                    pnlFLV.Visible = True
                    pnlUnknownType.Visible = False

                Case Else
                    pnlFlash.Visible = False
                    pnlXML.Visible = False
                    pnlFLV.Visible = False
                    pnlUnknownType.Visible = True
            End Select

            Dim xmlFile As String = Request.QueryString("xml")

            If Not (xmlFile Is Nothing) AndAlso xmlFile.Length > 0 Then
                lastDotPosition = xmlFile.LastIndexOf(".")
                xmlFile = xmlFile.Substring(0, lastDotPosition)
                ddlXMLFiles.SelectedValue = xmlFile
            End If
        End If

    End Sub

    Protected Sub btnLoad_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLoad.Click

        Dim url As String = "ViewFile.aspx?file=" & Request.QueryString("file") & "&xml="

        url += ddlXMLFiles.SelectedValue & ".ccxml"

        Response.Redirect(url)

    End Sub

    Protected Sub ddlXMLFiles_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlXMLFiles.SelectedIndexChanged

    End Sub

End Class
