Public class QueueManage
{
///
/// Send the object to the queue
///
/// Queue name, because the queue name should not be changed in an application, it is best to write it in the configuration file.
/// The object to be sent out
Public static void SendQueue (string QueuePath, MyBase. SmsQueue sq)
{
System. Messaging. MessageQueue mqSend = new System. Messaging. MessageQueue (QueuePath, false );
EnsureQueueExists (QueuePath );
MqSend. Send (sq );
}
///
/// Check the queue. If the queue does not exist, create
///
/// Queue name
Private static void EnsureQueueExists (string path)
{
If (! MessageQueue. Exists (path ))
{
If (! MessageQueue. Exists (path ))
{
MessageQueue. Create (path );
MessageQueue mqTemp = new MessageQueue (path );
MqTemp. SetPermissions ("Everyone", System. Messaging. MessageQueueAccessRights. FullControl );
/// I don't know what permissions should I give, so I gave all the permissions to Everone. Of course, you 'd better control them by yourself.
}
}
}
///
/// Retrieve the object list from the queue
///
/// Queue name
Public static System. Collections. ArrayList GetMessage (string QueuePath)
{
MyBase. SmsQueue sq = new MyBase. SmsQueue ();
System. Messaging. MessageQueue mq = new System. Messaging. MessageQueue (QueuePath, false );
Mq. Formatter = new XmlMessageFormatter (new Type [] {typeof (MyBase. SmsQueue )});
System. Messaging. Message [] arrM = mq. GetAllMessages ();
Mq. Close ();
System. Collections. ArrayList al = new System. Collections. ArrayList ();
Foreach (System. Messaging. Message m in arrM)
{
Sq = (TimeFound. SmsGate. Base. SmsQueue) m. Body;
Al. Add (sq );
}
Return al;
}
}