Imports CharterDotCom.CommonEntities.Library
Partial Class LoadTest_ErrorLogReport
    Inherits System.Web.UI.Page

    Protected Sub GetErrorMessages_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles GetErrorMessages.Click
        Try
            '###########################################
            'LOGG THE ERROR MESSAGE TO THE ERROR QUEUE
            '###########################################
            Dim tempErrorQLoc As String = ConfigurationManager.AppSettings("ErrorQueueLocation")
            Dim ErrorQueueLocation As String = Environment.MachineName & tempErrorQLoc
            Dim lMessageQComponent As New MessageQComponent
            Dim lmessages As System.Messaging.Message() = lMessageQComponent.GetAllMessages(ErrorQueueLocation)

            If Not lmessages Is Nothing Then
                If lmessages.Length > 0 Then
                    For Each lmessage As System.Messaging.Message In lmessages
                        Dim buffIn(lmessage.BodyStream.Length) As Byte
                        lmessage.BodyStream.Position = 0
                        lmessage.BodyStream.Read(buffIn, 0, lmessage.BodyStream.Length)

                        Dim ltextbox As New TextBox
                        ltextbox.Width = "600"
                        ltextbox.Rows = "3"
                        ltextbox.TextMode = TextBoxMode.MultiLine
                        ltextbox.Text = System.Text.Encoding.ASCII.GetString(buffIn)
                        Panel1.Controls.Add(ltextbox)
                    Next
                Else
                    '############
                    'NO MESSAGES
                    '############
                    Dim noMsgLable As New Label
                    noMsgLable.Text = "No messages to display. . ."
                    Panel1.Controls.Add(noMsgLable)
                End If
            Else
                '############
                'NO MESSAGES
                '############
                Dim noMsgLable As New Label
                noMsgLable.Text = "No messages to display. . ."
                Panel1.Controls.Add(noMsgLable)

            End If



        Catch ex As Exception
            '##########################################
            'IF THIS FAILS, JUST SKIP THE LOGGING PART
            '##########################################
            Response.Write(ex.Message)

        End Try
    End Sub

    Protected Sub PurgeErrorMessages_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles PurgeErrorMessages.Click
        Try
            '###########################################
            'LOGG THE ERROR MESSAGE TO THE ERROR QUEUE
            '###########################################
            Dim tempErrorQLoc As String = ConfigurationManager.AppSettings("ErrorQueueLocation")
            Dim ErrorQueueLocation As String = Environment.MachineName & tempErrorQLoc
            Dim lMessageQComponent As New MessageQComponent
            lMessageQComponent.PurgeAllMessages(ErrorQueueLocation)

            Response.Write("<h1>Messages for server " & Environment.MachineName & " have been purged.<h1>")

        Catch ex As Exception
            '##########################################
            'IF THIS FAILS, JUST SKIP THE LOGGING PART
            '##########################################
            Response.Write(ex.Message)
        End Try
    End Sub
End Class
