|
using System;
using System.Collections;
using System.Messaging;
using System.Windows.Forms;
using Message = System.Messaging.Message;
namespace MessageNotification
{
/// <summary>
/// Summary description for MessageDealer.
/// </summary>
public class MessageDealer
{
public MessageDealer()
{
//
// TODO: Add constructor logic here
//
}
#region send
public void SendObject(string ID,Object obj)
{
try
{
Configuration conf = new Configuration();
string machineName = conf.DBServerName();
MessageQueue mQ = new System.Messaging.MessageQueue(machineName + "\\" + ID);
mQ.Formatter = new BinaryMessageFormatter();
mQ.Send(obj);
}
catch(Exception e)
{
}
}
public void Send(string queuePath,object[] objs)
{
MessageQueue mQ = new System.Messaging.MessageQueue (queuePath);
mQ.Formatter = new BinaryMessageFormatter();
foreach(object obj in objs)
mQ.Send(obj);
}
#endregion
#region receive
public Hashtable ReceiveMessages(MessageQueue[] MQ)
{
Hashtable MessageVsID = null;
foreach(MessageQueue mq in MQ)
{
MessageQueue myQueue = new MessageQueue(mq.Path);
myQueue.Formatter = new BinaryMessageFormatter();
try
{
Message[] myMessages = myQueue.GetAllMessages();
MessageVsID.Add(myQueue.QueueName,myMessages);
}
catch (MessageQueueException)
{
return null;
}
catch (InvalidOperationException e)
{
return null;
}
}
return MessageVsID;
}
public System.Messaging.Message[] ReciveAllMessages(string ID)
{
Configuration conf = new Configuration();
string machineName = conf.DBServerName();
MessageQueue myQueue = new MessageQueue(machineName + "\\" + ID);
return myQueue.GetAllMessages();
}
public Message ReciveMessage(string ID)
{
Configuration conf = new Configuration();
string machineName = conf.DBServerName();
MessageQueue myQueue = new MessageQueue(machineName + "\\" + ID);
myQueue.MessageReadPropertyFilter.CorrelationId = true;
Message returnMessage = null;
myQueue.Formatter = new BinaryMessageFormatter();
try
{
Message myMessage = myQueue.Receive(new TimeSpan(0,0,3));
returnMessage = myMessage;
}
catch (MessageQueueException)
{
return null;
}
catch (InvalidOperationException e)
{
return null;
}
return returnMessage;
}
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.