C# Class Westwind.MessageQueueing.QueueMessageManager

An implementation of a SQL based multi-access Queue that provides random acccess to requests so they can be retrived for long running tasks where both client and server can interact with each message for processing. Great for long running tasks or even light workflow scenarios.
Inheritance: IDisposable
ファイルを表示 Open project: RickStrahl/Westwind.QueueMessageManager Class Usage Examples

Protected Properties

Property Type Description
_IsNew bool

Public Methods

Method Description
CancelRequest ( QueueMessageItem item = null, string messageText = null, bool autoSave = false ) : bool

Sets the Item record with the required settings to complete and cancel a request. Not saved to database call Save() explicitly.

ClearMessages ( System.TimeSpan messageTimeout = null ) : bool

Method used to clear out 'old' messages to keep database size down Removes messages that have been started but not completed in the specified timeout period.

CompleteRequest ( QueueMessageItem item = null, string messageText = null, bool autoSave = false ) : bool

Sets the Item record with the required settings to complete a request. Note record is not written to database - Call Save explicitly.

CreateDatastore ( ) : bool

Creates the DatabaseTable and stored procedure for the queue. Note this routine requires that a database exists already and uses the same connection string that is used for the main application.

CreateItem ( QueueMessageItem entity = null ) : QueueMessageItem

Creates a new item instance and properly initializes the instance's values.

DeleteMessage ( string id ) : bool
DeleteWaitingMessages ( string queueName = null ) : bool
Dispose ( ) : void

Clear data access component

GetCancelledMessages ( string queueName = null, int maxCount ) : IEnumerable

Returns all messages in a queue that are cancelled

GetCompleteQueueMessages ( string queueName = null, int maxCount ) : IEnumerable

Result Cursor: TCompleteMessages

GetNextQueueMessage ( string queueName = null ) : QueueMessageItem

Retrieves the next pending Message from the Queue based on a provided queueName

GetPendingQueueMessages ( string queueName = null, int maxCount ) : IEnumerable

Retrieves all messages that are pending, that have started but not completed yet.

GetProperty ( string key ) : object

Retrieves a value from the Properties collection safely. If the value doesn't exist null is returned.

GetRecentQueueItems ( string queueName = null, int itemCount = 25 ) : IEnumerable

Returns a list of recent queue items

GetTimedOutQueueMessages ( string queueName = null, int maxCount ) : IEnumerable

Returns a list of queue items that have timed out during processing. Not completed where started time is greater than the MessageTimeout.

GetWaitingQueueMessageCount ( string queueName = null ) : int

Returns a count of messages that are waiting to be processed - this is the queue backup.

GetWaitingQueueMessages ( string queueName = null, int maxCount ) : IEnumerable

Returns a count of messages that are waiting to be processed - this is the queue backup.

IsCompleted ( string id = null ) : bool

Determines if anqueue has been completed successfully or failed. Note this method returns true if the request has completed or cancelled/failed. It just checks completion.

Load ( string id ) : QueueMessageItem

Loads a Queue Item

QueueMessageManager ( ) : System
QueueMessageManager ( string connectionString ) : System
ResubmitMessage ( QueueMessageItem item = null ) : bool

Resubmits an existing message by clearing out all completion/date settings and then resubmitting the entry. This method calls Save() and actually saves the message to disk.

Save ( QueueMessageItem item = null ) : bool

Saves the passed item or the attached item to the database. Call this after updating properties or individual values.

SetError ( ) : void

Clear the error messages

SetError ( Exception ex, bool checkInner = false ) : void

Set from exception and optionally use inner exception

SetError ( string message ) : void

Set error to the error message

SubmitRequest ( QueueMessageItem item = null, string messageText = null, bool autoSave = false ) : bool

Sets the message properties for starting a new message request operation. Note the record is not written to the database use Save explicitly

UpdateQueueMessageStatus ( QueueMessageItem item = null, string status = null, string messageText = null, int percentComplete = -1, bool autoSave = false ) : bool

Updates the QueueMessageStatus and or messages

Protected Methods

Method Description
GetProperties ( string stringFieldNameToLoadFrom = "Properties", object entity = null ) : void

Loads the Properties dictionary with values from a Properties property of an item object. Once loaded you can access the dictionary to read and write values from it arbitrarily and use SetProperties to write the values back in serialized form to the underlying property for database storage.

SetProperties ( string stringFieldToSaveTo = "Properties", object entity = null ) : void

Saves the Properties Dictionary - in serialized string form - to a specified item field which in turn allows writing the data back to the database.

Method Details

CancelRequest() public method

Sets the Item record with the required settings to complete and cancel a request. Not saved to database call Save() explicitly.
public CancelRequest ( QueueMessageItem item = null, string messageText = null, bool autoSave = false ) : bool
item QueueMessageItem
messageText string
autoSave bool
return bool

ClearMessages() public abstract method

Method used to clear out 'old' messages to keep database size down Removes messages that have been started but not completed in the specified timeout period.
public abstract ClearMessages ( System.TimeSpan messageTimeout = null ) : bool
messageTimeout System.TimeSpan
return bool

CompleteRequest() public method

Sets the Item record with the required settings to complete a request. Note record is not written to database - Call Save explicitly.
public CompleteRequest ( QueueMessageItem item = null, string messageText = null, bool autoSave = false ) : bool
item QueueMessageItem
messageText string
autoSave bool
return bool

CreateDatastore() public abstract method

Creates the DatabaseTable and stored procedure for the queue. Note this routine requires that a database exists already and uses the same connection string that is used for the main application.
public abstract CreateDatastore ( ) : bool
return bool

CreateItem() public method

Creates a new item instance and properly initializes the instance's values.
public CreateItem ( QueueMessageItem entity = null ) : QueueMessageItem
entity QueueMessageItem
return QueueMessageItem

DeleteMessage() public abstract method

public abstract DeleteMessage ( string id ) : bool
id string
return bool

DeleteWaitingMessages() public abstract method

public abstract DeleteWaitingMessages ( string queueName = null ) : bool
queueName string
return bool

Dispose() public method

Clear data access component
public Dispose ( ) : void
return void

GetCancelledMessages() public abstract method

Returns all messages in a queue that are cancelled
public abstract GetCancelledMessages ( string queueName = null, int maxCount ) : IEnumerable
queueName string
maxCount int
return IEnumerable

GetCompleteQueueMessages() public abstract method

Result Cursor: TCompleteMessages
public abstract GetCompleteQueueMessages ( string queueName = null, int maxCount ) : IEnumerable
queueName string
maxCount int
return IEnumerable

GetNextQueueMessage() public abstract method

Retrieves the next pending Message from the Queue based on a provided queueName
public abstract GetNextQueueMessage ( string queueName = null ) : QueueMessageItem
queueName string
return QueueMessageItem

GetPendingQueueMessages() public abstract method

Retrieves all messages that are pending, that have started but not completed yet.
public abstract GetPendingQueueMessages ( string queueName = null, int maxCount ) : IEnumerable
queueName string Name of the queue to return items for
maxCount int Optional - max number of items to return
return IEnumerable

GetProperties() protected method

Loads the Properties dictionary with values from a Properties property of an item object. Once loaded you can access the dictionary to read and write values from it arbitrarily and use SetProperties to write the values back in serialized form to the underlying property for database storage.
protected GetProperties ( string stringFieldNameToLoadFrom = "Properties", object entity = null ) : void
stringFieldNameToLoadFrom string The name of the field to load the XML properties from.
entity object
return void

GetProperty() public method

Retrieves a value from the Properties collection safely. If the value doesn't exist null is returned.
public GetProperty ( string key ) : object
key string
return object

GetRecentQueueItems() public abstract method

Returns a list of recent queue items
public abstract GetRecentQueueItems ( string queueName = null, int itemCount = 25 ) : IEnumerable
queueName string
itemCount int
return IEnumerable

GetTimedOutQueueMessages() public abstract method

Returns a list of queue items that have timed out during processing. Not completed where started time is greater than the MessageTimeout.
public abstract GetTimedOutQueueMessages ( string queueName = null, int maxCount ) : IEnumerable
queueName string
maxCount int
return IEnumerable

GetWaitingQueueMessageCount() public abstract method

Returns a count of messages that are waiting to be processed - this is the queue backup.
public abstract GetWaitingQueueMessageCount ( string queueName = null ) : int
queueName string
return int

GetWaitingQueueMessages() public abstract method

Returns a count of messages that are waiting to be processed - this is the queue backup.
public abstract GetWaitingQueueMessages ( string queueName = null, int maxCount ) : IEnumerable
queueName string
maxCount int
return IEnumerable

IsCompleted() public abstract method

Determines if anqueue has been completed successfully or failed. Note this method returns true if the request has completed or cancelled/failed. It just checks completion.
public abstract IsCompleted ( string id = null ) : bool
id string
return bool

Load() public abstract method

Loads a Queue Item
public abstract Load ( string id ) : QueueMessageItem
id string
return QueueMessageItem

QueueMessageManager() public method

public QueueMessageManager ( ) : System
return System

QueueMessageManager() public method

public QueueMessageManager ( string connectionString ) : System
connectionString string
return System

ResubmitMessage() public method

Resubmits an existing message by clearing out all completion/date settings and then resubmitting the entry. This method calls Save() and actually saves the message to disk.
public ResubmitMessage ( QueueMessageItem item = null ) : bool
item QueueMessageItem
return bool

Save() public abstract method

Saves the passed item or the attached item to the database. Call this after updating properties or individual values.
public abstract Save ( QueueMessageItem item = null ) : bool
item QueueMessageItem
return bool

SetError() public method

Clear the error messages
public SetError ( ) : void
return void

SetError() public method

Set from exception and optionally use inner exception
public SetError ( Exception ex, bool checkInner = false ) : void
ex System.Exception
checkInner bool
return void

SetError() public method

Set error to the error message
public SetError ( string message ) : void
message string
return void

SetProperties() protected method

Saves the Properties Dictionary - in serialized string form - to a specified item field which in turn allows writing the data back to the database.
protected SetProperties ( string stringFieldToSaveTo = "Properties", object entity = null ) : void
stringFieldToSaveTo string
entity object
return void

SubmitRequest() public method

Sets the message properties for starting a new message request operation. Note the record is not written to the database use Save explicitly
public SubmitRequest ( QueueMessageItem item = null, string messageText = null, bool autoSave = false ) : bool
item QueueMessageItem An existing item instance
messageText string
autoSave bool
return bool

UpdateQueueMessageStatus() public method

Updates the QueueMessageStatus and or messages
public UpdateQueueMessageStatus ( QueueMessageItem item = null, string status = null, string messageText = null, int percentComplete = -1, bool autoSave = false ) : bool
item QueueMessageItem
status string
messageText string
percentComplete int
autoSave bool
return bool

Property Details

_IsNew protected_oe property

protected bool _IsNew
return bool