Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Tcp
Imports System.Configuration
'''
''' Provides easy access to the batch queue functionality.
'''
'''
''' Client code should create an instance of this class to
''' interact with a batch queue. A BatchQueue object can
''' be used to interact with either the default batch queue
''' server or with a specific batch queue server.
'''
Public Class BatchQueue
Private mQueueURL As String
Private mServer As Server.BatchQueue
#Region " Constructors and Initialization "
'''
''' Creates an instance of the object that allows interaction
''' with the default batch queue server as specified in the
''' application configuration file.
'''
Public Sub New()
mQueueURL = ConfigurationSettings.AppSettings("DefaultBatchQueueServer")
End Sub
'''
''' Creates an instance of the object that allows interaction
''' with a specific batch queue server as specified by
''' the URL passed as a parameter.
'''
''' A URL referencing the batch queue server.
Public Sub New(ByVal QueueServerURL As String)
mQueueURL = QueueServerURL
End Sub
Private Function QueueServer() As Server.BatchQueue
If mServer Is Nothing Then
mServer = _
CType(Activator.GetObject(GetType(Server.BatchQueue), _
mQueueURL), _
Server.BatchQueue)
End If
Return mServer
End Function
#End Region
#Region " Submitting jobs "
'''
''' Submits an entry to the batch queue.
'''
''' A reference to your worker object.
Public Sub Submit(ByVal Entry As IBatchEntry)
QueueServer.Submit(New Server.BatchEntry(Entry))
End Sub
'''
''' Submits an entry to the batch queue with extra state data.
'''
''' A reference to your worker object.
''' A reference to a serializable object containing state data.
Public Sub Submit(ByVal Entry As IBatchEntry, ByVal State As Object)
QueueServer.Submit(New Server.BatchEntry(Entry, State))
End Sub
'''
''' Submits an entry to the batch queue with a specific priority.
'''
''' A reference to your worker object.
''' The priority of the entry.
Public Sub Submit(ByVal Entry As IBatchEntry, _
ByVal Priority As Messaging.MessagePriority)
Dim job As Server.BatchEntry = New Server.BatchEntry(Entry)
job.Info.Priority = Priority
QueueServer.Submit(job)
End Sub
'''
''' Submits an entry to the batch queue with extra state data and
''' a specific priority.
'''
''' A reference to your worker object.
''' A reference to a serializable object containing state data.
''' The priority of the entry.
Public Sub Submit(ByVal Entry As IBatchEntry, _
ByVal State As Object, _
ByVal Priority As Messaging.MessagePriority)
Dim job As Server.BatchEntry = New Server.BatchEntry(Entry, State)
job.Info.Priority = Priority
QueueServer.Submit(job)
End Sub
'''
''' Submits an entry to the batch queue to be held until a specific date/time.
'''
''' A reference to your worker object.
''' The date/time until which the entry should be held.
Public Sub Submit(ByVal Entry As IBatchEntry, ByVal HoldUntil As Date)
Dim job As Server.BatchEntry = New Server.BatchEntry(Entry)
job.Info.HoldUntil = HoldUntil
QueueServer.Submit(job)
End Sub
'''
''' Submits an entry to the batch queue with extra state data
''' and to be held until a specific date/time.
'''
''' A reference to your worker object.
''' A reference to a serializable object containing state data.
''' The date/time until which the entry should be held.
Public Sub Submit(ByVal Entry As IBatchEntry, _
ByVal State As Object, _
ByVal HoldUntil As Date)
Dim job As Server.BatchEntry = New Server.BatchEntry(Entry, State)
job.Info.HoldUntil = HoldUntil
QueueServer.Submit(job)
End Sub
'''
''' Submits an entry to the batch queue to be held until
''' a specific date/time and at a specific priority.
'''
''' A reference to your worker object.
''' The date/time until which the entry should be held.
''' The priority of the entry.
Public Sub Submit(ByVal Entry As IBatchEntry, _
ByVal HoldUntil As Date, ByVal Priority As Messaging.MessagePriority)
Dim job As Server.BatchEntry = New Server.BatchEntry(Entry)
job.Info.HoldUntil = HoldUntil
job.Info.Priority = Priority
QueueServer.Submit(job)
End Sub
'''
''' Submits an entry to the batch queue specifying all details.
'''
''' A reference to your worker object.
''' A reference to a serializable object containing state data.
''' The date/time until which the entry should be held.
''' The priority of the entry.
Public Sub Submit(ByVal Entry As IBatchEntry, _
ByVal State As Object, _
ByVal HoldUntil As Date, _
ByVal Priority As Messaging.MessagePriority)
Dim job As Server.BatchEntry = New Server.BatchEntry(Entry, State)
job.Info.HoldUntil = HoldUntil
job.Info.Priority = Priority
QueueServer.Submit(job)
End Sub
#End Region
#Region " Public methods "
'''
''' Removes a holding or pending entry from the
''' batch queue.
'''
''' A reference to the entry to be removed.
Public Sub Remove(ByVal Entry As BatchEntryInfo)
QueueServer.Remove(Entry)
End Sub
'''
''' Returns the URL which identifies the batch
''' queue server to which this object is attached.
'''
Public ReadOnly Property BatchQueueURL() As String
Get
Return mQueueURL
End Get
End Property
'''
''' Returns a collection of the batch entries currently
''' in the batch queue.
'''
Public ReadOnly Property Entries() As BatchEntries
Get
Return QueueServer.GetEntries(GetPrincipal)
End Get
End Property
#End Region
#Region " System.Object overrides "
Public Overrides Function ToString() As String
Return mQueueURL
End Function
Public Overloads Function Equals(ByVal Queue As BatchQueue) As Boolean
Return mQueueURL = Queue.BatchQueueURL
End Function
Public Overrides Function GetHashCode() As Integer
Return mQueueURL.GetHashCode
End Function
#End Region
#Region " Security "
Private Function AUTHENTICATION() As String
Return ConfigurationSettings.AppSettings("Authentication")
End Function
Private Function GetPrincipal() As System.Security.Principal.IPrincipal
If AUTHENTICATION() = "Windows" Then
' Windows integrated security
Return Nothing
Else
' we assume using the CSLA framework security
Return System.Threading.Thread.CurrentPrincipal
End If
End Function
#End Region
End Class