Imports System.Runtime.Remoting.Channels
Imports System.Collections.Generic
Imports CharterDotCom.WebSite.Library
Imports CharterDotCom.CommonEntities.Library
Imports System.Web


Public Class Common

  Public Shared Sub RegisterChannels()
    Dim prop As IDictionary
    Dim objChannel As Http.HttpChannel
    Try
      'Reg channel only when one is not registered.
      If ChannelServices.RegisteredChannels.Length = 0 Then
        prop = New Hashtable()
        prop("name") = "Channel1"
        'prop("port") = "0"

        objChannel = New Http.HttpChannel(prop, New BinaryClientFormatterSinkProvider(), New BinaryServerFormatterSinkProvider())
        ChannelServices.RegisterChannel(objChannel, False)
      End If
    Catch ex As Exception
      Throw ex
    Finally
      If Not prop Is Nothing Then
        prop = Nothing
      End If
      If Not objChannel Is Nothing Then
        objChannel = Nothing
      End If
    End Try

  End Sub

#Region "Manage Session Data"
  Friend Shared Sub AddToSession(ByVal name As String, ByVal value As Object)
    Try
      HttpContext.Current.Session.Add(name, value)
    Catch ex As Exception
      Throw New ApplicationException("Error adding data to session")
    End Try
  End Sub

  Friend Shared Function RetriveFromSession(ByVal name As String) As Object
    Try
      Return HttpContext.Current.Session(name)
    Catch ex As Exception
      Throw New ApplicationException("Error retriving session data")
    End Try
  End Function
#End Region

#Region "Constants"
  Friend Const CatalogManagerKey As String = "CatalogManager"
  Friend Const ContentManagerKey As String = "ContentManager"
  Friend Const AccountManagerKey As String = "AccountManager"
  Friend Const OrderManagerKey As String = "OrderManager"
	Friend Const SiteManagerKey As String = "SiteManager"
	Friend Const MyAccountRetUNameKey As String = "MyAccountRetUName"
#End Region

    Public Shared Sub LogException(ByVal ex As Exception, ByVal severity As CharterDotCom.CommonEntities.Library.Enumerations.ExceptionSeverity)
        Try
            '###########################################
            'LOGG THE ERROR MESSAGE TO THE ERROR QUEUE
            '###########################################
            Dim ErrorQueueLocation As String = Environment.MachineName & CType(HttpContext.Current.Application("ErrorQueueLocation"), String)
            Dim lMessageQComponent As New MessageQComponent
            lMessageQComponent.AddAMessage(ErrorQueueLocation, ex.Message)
        Catch ex2 As Exception
            '##########################################
            'IF THIS FAILS, JUST SKIP THE LOGGING PART
            '##########################################
        End Try
    End Sub

End Class
