Exemplo n.º 1
0
        public Router(System.ComponentModel.IContainer container)
        {
            ///
            /// Required for Windows.Forms Class Composition Designer support
            ///
            container.Add(this);
            InitializeComponent();

            messageQueueVehiclesToAssemble.BeginReceive();
        }
Exemplo n.º 2
0
        public Router(System.ComponentModel.IContainer container)
        {
            ///
            /// Required for Windows.Forms Class Composition Designer support
            ///
            container.Add(this);
            InitializeComponent();

            // start waiting for the first incoming message
            messageQueueOrders.BeginReceive();
        }
Exemplo n.º 3
0
        protected override void OnStart(string[] args) 
        { 
            // Create directories if needed 
            if (!System.IO.Directory.Exists(MessageDirectory)) 
                System.IO.Directory.CreateDirectory(MessageDirectory); 
            
            // Create new message queue instance 
            messageQueue = new System.Messaging.MessageQueue(MessageQueue); 
 
            try 
            {    
                // Set formatter to allow ASCII text 
                messageQueue.Formatter = new System.Messaging.ActiveXMessageFormatter(); 
                // Assign event handler when message is received 
                messageQueue.ReceiveCompleted += 
                    new System.Messaging.ReceiveCompletedEventHandler(messageQueue_ReceiveCompleted); 
                // Start listening 
                
                messageQueue.BeginReceive(); 
            } 
            catch (Exception e) 
            { 
                
            } 
        } 
Exemplo n.º 4
0
        public void Subscribe()
        {
            if (System.Threading.Interlocked.Exchange(ref _subscribed, 1) == 0)
            {
                try
                {
                    if (string.IsNullOrEmpty(this.QueuePath))
                    {
                        return;
                    }

                    Utilities.CreateIfNotExist(new MessageQueueRequest
                    {
                        QueuePath = this.QueuePath
                    });

                    if (this.Logger != null)
                    {
                        this.Logger.Debug(string.Format("Begin subscribing to event '{1}' via Message Queue '{0}' using type '{2}'",
                                                        this.QueuePath, typeof(TEvnt).Name, this.GetType().Name));
                    }

                    _mq                   = new System.Messaging.MessageQueue(this.QueuePath);
                    _mq.Formatter         = _formatter;
                    _mq.ReceiveCompleted += OnMQReceiveCompleted;

                    _mq.BeginReceive();
                }
                catch (Exception ex)
                {
                    this.Logger.Error(string.Format("Error during {0}.Subscribe()", this.GetType().Name), ex);
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// For Asynchroneous Reporting...
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e">     </param>
        protected internal static void client_SendCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
        {
            string result = "Message sent at " + DateTime.Now.ToString();
            Type   tipo   = e.UserState.GetType();

            if (tipo.Equals(typeof(object[])))
            {
                object[] pkg = e.UserState as object[];

                System.Messaging.MessageQueue qu     = pkg[0] as System.Messaging.MessageQueue;
                System.Net.Mail.MailMessage   mail   = pkg[1] as System.Net.Mail.MailMessage;
                System.Net.Mail.SmtpClient    client = sender as System.Net.Mail.SmtpClient;

                System.Messaging.Message m = new System.Messaging.Message();
                if (e.Error != null)
                {
                    m.Body  = new Exception(e.Error.Message);
                    m.Label = "AsyncEmail FAILED";
                }
                else
                {
                    if (mail.Attachments.Count > 0)
                    {
                        Attachment           at     = mail.Attachments[0];
                        System.IO.FileStream stream = (System.IO.FileStream)at.ContentStream;
                        m.Body = stream.Name;
                        // stream.Unlock(0, stream.Length);
                        stream.Close();
                        stream.Dispose();
                        ///NOT USED BUT COULD BE

                        /*
                         * byte[] array = new byte[stream.Length];
                         * stream.Read(array, 0, (int)stream.Length);
                         * stream.Close();
                         * stream.Dispose();
                         * m.Extension = array;
                         */
                    }
                    m.Label = "AsyncEmail OK";
                }
                m.Formatter   = new System.Messaging.BinaryMessageFormatter();
                m.AppSpecific = 1;
                System.Messaging.MessageQueueTransaction mqt = new System.Messaging.MessageQueueTransaction();
                mqt.Begin();
                qu.Send(m, mqt);
                mqt.Commit();
                mqt.Dispose();
                mqt = null;
                m.Dispose();
                m = null;

                Dispose(ref client, ref mail);

                qu.BeginReceive();
            }
            else
            {
                if (e.Cancelled)
                {
                    System.Windows.Forms.MessageBox.Show(e.Error.Message, "Email Cancelled", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
                }
                if (e.Error != null)
                {
                    System.Windows.Forms.MessageBox.Show(e.Error.Message, "Email NOT Sent!", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                }
                else if (!e.Cancelled)
                {
                    System.Windows.Forms.MessageBox.Show(result, "Email Sent!", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
                }
            }
        }