Ejemplo n.º 1
0
        public void SendMessage(string sQueueType, string FormatType, string MSMQServer, string QueueName,
            string MsgLabel, string MsgBody, bool IsTransaction, string Priority, bool IsJournal, bool IsRemote)
        {
            try
            {
             string MQPath=null;
            if (string.IsNullOrEmpty(sQueueType))
                    MQPath = MSMQServer + "\\" + QueueName;
                else
                    MQPath = FormatType+MSMQServer + "\\" + QueueName;
                MessageQueue oMQueue = new MessageQueue(MQPath);
                try
                {
                    System.Messaging.Message oMsg = new System.Messaging.Message(MsgBody, new ActiveXMessageFormatter());
                    if (Priority.ToLower() == "lowest")
                    { oMsg.Priority = MessagePriority.Lowest; }
                    else if (Priority.ToLower() == "verylow")
                    { oMsg.Priority = MessagePriority.VeryLow; }
                    else if (Priority.ToLower() == "low")
                    { oMsg.Priority = MessagePriority.Low; }
                    else if (Priority.ToLower() == "normal")
                    { oMsg.Priority = MessagePriority.Normal; }
                    else if (Priority.ToLower() == "abovenormal")
                    { oMsg.Priority = MessagePriority.AboveNormal; }
                    else if (Priority.ToLower() == "high")
                    { oMsg.Priority = MessagePriority.High; }
                    else if (Priority.ToLower() == "veryhigh")
                    { oMsg.Priority = MessagePriority.VeryHigh; }
                    else if (Priority.ToLower() == "highest")
                    { oMsg.Priority = MessagePriority.Highest; }

                    if (IsJournal)
                        oMsg.UseJournalQueue = true;

                    if (!(IsRemote))
                    {

                            if (!oMQueue.Transactional == IsTransaction)
                                MessageBox.Show("Transaction not match",
                                    "Message Queuing Admin", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    }
                    oMsg.Label = MsgLabel;
                    if (IsTransaction == false)
                        oMQueue.Send(oMsg);
                    else
                        oMQueue.Send(oMsg, MessageQueueTransactionType.Single);

                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message + "\r\n Please check " + QueueName + " if you have permission or the queue is exist",
                              "Message Queuing Admin", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }

                oMQueue.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\r\n Please check " + QueueName + " if you have permission or the queue is exist",
                          "Message Queuing Admin", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
        }
Ejemplo n.º 2
0
        public void SendMessage(string sQueueType, string FormatType, string MSMQServer, string QueueName,
                                string MsgLabel, string MsgBody, bool IsTransaction, string Priority, bool IsJournal, bool IsRemote)
        {
            try
            {
                string MQPath = null;
                if (string.IsNullOrEmpty(sQueueType))
                {
                    MQPath = MSMQServer + "\\" + QueueName;
                }
                else
                {
                    MQPath = FormatType + MSMQServer + "\\" + QueueName;
                }
                MessageQueue oMQueue = new MessageQueue(MQPath);
                try
                {
                    System.Messaging.Message oMsg = new System.Messaging.Message(MsgBody, new ActiveXMessageFormatter());
                    if (Priority.ToLower() == "lowest")
                    {
                        oMsg.Priority = MessagePriority.Lowest;
                    }
                    else if (Priority.ToLower() == "verylow")
                    {
                        oMsg.Priority = MessagePriority.VeryLow;
                    }
                    else if (Priority.ToLower() == "low")
                    {
                        oMsg.Priority = MessagePriority.Low;
                    }
                    else if (Priority.ToLower() == "normal")
                    {
                        oMsg.Priority = MessagePriority.Normal;
                    }
                    else if (Priority.ToLower() == "abovenormal")
                    {
                        oMsg.Priority = MessagePriority.AboveNormal;
                    }
                    else if (Priority.ToLower() == "high")
                    {
                        oMsg.Priority = MessagePriority.High;
                    }
                    else if (Priority.ToLower() == "veryhigh")
                    {
                        oMsg.Priority = MessagePriority.VeryHigh;
                    }
                    else if (Priority.ToLower() == "highest")
                    {
                        oMsg.Priority = MessagePriority.Highest;
                    }

                    if (IsJournal)
                    {
                        oMsg.UseJournalQueue = true;
                    }

                    if (!(IsRemote))
                    {
                        if (!oMQueue.Transactional == IsTransaction)
                        {
                            MessageBox.Show("Transaction not match",
                                            "Message Queuing Admin", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                    oMsg.Label = MsgLabel;
                    if (IsTransaction == false)
                    {
                        oMQueue.Send(oMsg);
                    }
                    else
                    {
                        oMQueue.Send(oMsg, MessageQueueTransactionType.Single);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message + "\r\n Please check " + QueueName + " if you have permission or the queue is exist",
                                    "Message Queuing Admin", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

                oMQueue.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\r\n Please check " + QueueName + " if you have permission or the queue is exist",
                                "Message Queuing Admin", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }