コード例 #1
0
ファイル: vhmsg.cs プロジェクト: USC-ICT/elsender
        /// <summary>
        /// Sends a message to the server using 2 arguments.  The first argument is the first word in the message, the second argument is the rest of the message.
        /// </summary>
        /// <param name="op">The first word in the message</param>
        /// <param name="arg">The rest of the message</param>
        public void SendMessage(string op, string arg)
        {
            op  = op.Trim();
            arg = arg.Trim();

            if (string.IsNullOrEmpty(op))
            {
                return;
            }


            string arg_encoded = HttpUtility.UrlEncode(arg, Encoding.UTF8);

            string mess = op + " " + arg_encoded;

            Apache.NMS.ActiveMQ.Commands.ActiveMQTextMessage message = (Apache.NMS.ActiveMQ.Commands.ActiveMQTextMessage)m_session.CreateTextMessage(mess);
            message.SetObjectProperty("ELVISH_SCOPE", m_scope);
            message.SetObjectProperty("MESSAGE_PREFIX", op);
            message.SetObjectProperty("VHMSG_VERSION", VHMSG_VERSION);
            message.SetObjectProperty("VHMSG", "VHMSG");
            message.SetObjectProperty("MESSAGE_TYPE_VHMSG", "VHMSG");
            //message.SetObjectProperty( op, arg );

            m_Producer.Send(message);
        }
コード例 #2
0
 public void OnMessage(IMessage message)
 {
     count++;
     Apache.NMS.ActiveMQ.Commands.ActiveMQTextMessage outputMsg = (Apache.NMS.ActiveMQ.Commands.ActiveMQTextMessage)message;
     mcontent = "No: " + count + " ::message: " + outputMsg.Text;
     Console.WriteLine(mcontent);
     writeLog(mcontent);
 }
コード例 #3
0
 private void OnMessage(IMessage message)
 {
     ReceivedNumber++;
     Apache.NMS.ActiveMQ.Commands.ActiveMQTextMessage outputMsg = (Apache.NMS.ActiveMQ.Commands.ActiveMQTextMessage)message;
     Console.WriteLine("Message Content:" + outputMsg.Text);
     if (stopWithMessage != null && stopWithMessage == outputMsg.Text)
     {
         session.Close();
         connection.Close();
         isFinished = true;
     }
     else
     {
         ReceivedMessages.Add(outputMsg.Text);
     }
     //mcontent = "No: " + ReceivedNumber + " ::message: " + outputMsg.Text;
     //Console.WriteLine(mcontent);
 }
コード例 #4
0
ファイル: vhmsg.cs プロジェクト: USC-ICT/elsender
        /// <summary>
        /// This function is a callback function received whenever an ActiveMQ message is received from the server.  It processes the message and passes it on to the client via
        /// the MessageEvent handler.
        /// </summary>
        /// <param name="msg">ActiveMQ message received from the server</param>
        protected void OnMessage(Apache.NMS.IMessage msg)
        {
            string message = "";
            //string elements  = null ;
            string temp = null;
            //string holder = null ;
            //StringTokenizer st = null;
            //int index = 0 ;

            //System.out.println("onMessage(): " + ((TextMessage)msg).getText() );

            //if ( msg instanceof TextMessage )
            {
                Apache.NMS.ActiveMQ.Commands.ActiveMQTextMessage txtMsg = (Apache.NMS.ActiveMQ.Commands.ActiveMQTextMessage)msg;
                temp = txtMsg.Text;

                temp = HttpUtility.UrlDecode(temp);

                temp = temp.Trim();

                /*
                 * // Strip off first char of args if it is a "
                 * if( temp.substring(0,1).compareToIgnoreCase("\"") == 0 )
                 * {
                 * temp = (temp.substring( 1, temp.length())).trim() ;
                 * if( temp.substring(0,1).compareToIgnoreCase("\"") == 0 )
                 * {
                 *    // if 2 double quotes at end, take one double quote off
                 *    message += temp.substring( 0, temp.length()-1 );
                 * }
                 * else
                 * {
                 *    message += "\"" + temp ;
                 * }
                 * }
                 * else
                 * {
                 * message += temp ;
                 * }
                 */
                message = temp;

                Dictionary <string, string> properties = new Dictionary <string, string>();
                foreach (string key in txtMsg.Properties.Keys)
                {
                    object data  = txtMsg.Properties[key];
                    string sData = data as string;
                    if (sData != null)
                    {
                        properties[key] = HttpUtility.UrlDecode(sData).Trim();
                    }
                }

                Message args = new Message(message, properties);

                if (m_immediateMethod)
                {
                    MessageEvent(this, args);
                }
                else
                {
                    lock (m_messageLock)
                    {
                        m_messages.Add(args);
                    }

                    // signal the other thread that we've received a message (only used in WaitAndPoll() )
                    lock (m_waitLock)
                    {
                        m_waitCondition.Set();
                    }
                }
            }
        }