Exemple #1
0
        public void onMessage(com.adaptiveMQ2.message.Message msg)
        {
            string stopic = msg.Destination.getName();

            if (stopic.Equals(ConstsMessage.TOPIC_ATS_LOGIN))
            {
                Dictionary <string, object> map = CedaObject.GetLoginResult(msg);
                if (map != null)
                {
                    foreach (string key in map.Keys)
                    {
                        switch (key.ToLower())
                        {
                        case "sid":
                            sid = map[key] + "";
                            if (clientInfo != null)
                            {
                                clientInfo.SID = sid;
                            }
                            break;
                        }
                    }
                }
            }

            if (OnCedaMessage != null)
            {
                OnCedaMessage(msg);
            }
        }
Exemple #2
0
        void _cedaSubscribe_OnCedaMessage(com.adaptiveMQ2.message.Message msg)
        {
            CedaObject co  = CedaObject.ToCedaObject(msg);
            string     str = string.Format("receive a msg,topic={0},MessageBody=\n{1}", co.Topic, co.MessageBody);

            logHelper.Info(str);
        }
Exemple #3
0
        private void ConnectionServer()
        {
            _cedaSubscribe = new CedaManager(logHelper);
            _cedaSubscribe.OnCedaMessage += new Action <com.adaptiveMQ2.message.Message>(_cedaSubscribe_OnCedaMessage);
            string host = txtHost.Text.Trim();
            int    port = 0;

            if (!Int32.TryParse(txtPort.Text.Trim(), out port))
            {
                logHelper.Warn("port is error!");
                return;
            }

            _clientInfo = new ClientInfo();

            if ("ACS".Equals(cbType.Text.Trim()))
            {
                if (!host.EndsWith(".httpMQTunnel"))
                {
                    host = string.Format("{0}/mq.httpMQTunnel", host);
                }
                _clientInfo.setAddress(host, port);
                if (ckSSL.Checked)
                {
                    _clientInfo.Protocol = ClientInfo.PROTOCOL_HTTPS;
                }
                else
                {
                    _clientInfo.Protocol = ClientInfo.PROTOCOL_HTTP;
                }
                if (cbVS.Checked)
                {
                    _clientInfo.LoginMessage = CedaObject.GetLoginMessage(txtUserName.Text, txtPwd.Text, txtRole.Text, null, encryption, clientType);
                }
            }
            else if ("CEDA".Equals(cbType.Text.Trim()))
            {
                _clientInfo.setAddress(host, port);
                _clientInfo.setUser("test", "test");
                if (ckSSL.Checked)
                {
                    _clientInfo.Protocol = ClientInfo.PROTOCOL_TCPS;
                }
                else
                {
                    _clientInfo.Protocol = ClientInfo.PROTOCOL_TCP;
                }
                if (cbVS.Checked)
                {
                    _clientInfo.LoginMessage = CedaObject.GetLoginMessage(txtUserName.Text, txtPwd.Text, txtRole.Text, null, encryption, clientType);
                }
            }

            string temp = string.Format("Address:{0}:{1},Topic:{2}", _clientInfo.AddressHost, _clientInfo.AddressPort,
                                        txtTopic.Text);

            logHelper.Info(temp);
            ThreadPool.QueueUserWorkItem(o => _cedaSubscribe.Connect(_clientInfo));
        }
Exemple #4
0
        void _cedaSubscribe_OnCedaMessage(com.adaptiveMQ2.message.Message msg)
        {
            TopicCount++;
            OneSCount++;

            //StopTime = DateTime.Now;
            //TimeSpan ts = StopTime - StartTime;
            //int hourTime = ts.Hours;
            //int minuteTime = ts.Minutes;
            //int secondTime = (hourTime * 3600) + (minuteTime * 60) + ts.Seconds;
            //labelTime.Text = secondTime.ToString() + "S";


            labelCount.Text = TopicCount.ToString();
            int clear = -1;

            if (!int.TryParse(txtClear.Text, out clear))
            {
                clear = int.MaxValue;
            }
            if (ClearCount >= clear)
            {
                if (ClearCount > 0)
                {
                    SetMsg(null);
                    ClearCount = 0;
                }
            }
            else
            {
                ClearCount++;
                CedaObject co  = CedaObject.ToCedaObject(msg);
                string     str = string.Format("receive a msg,topic={0},MessageBody=\n{1}", co.Topic, co.MessageBody);

                logHelper.Info(str);
            }
        }
Exemple #5
0
        private void ConnectionServer()
        {
            _cedaSubscribe = new CedaManager(logHelper);
            _cedaSubscribe.OnCedaMessage += new Action <com.adaptiveMQ2.message.Message>(_cedaSubscribe_OnCedaMessage);
            string host = txtHost.Text.Trim();
            int    port = 0;

            if (!Int32.TryParse(txtPort.Text.Trim(), out port))
            {
                logHelper.Warn("port is error!");
                return;
            }

            _clientInfo = new ClientInfo();

            if ("ACS".Equals(cbType.Text.Trim()))
            {
                if (!host.EndsWith(".httpMQTunnel"))
                {
                    host = string.Format("{0}/mq.httpMQTunnel", host);
                }
                _clientInfo.setAddress(host, port);
                if (ckSSL.Checked)
                {
                    _clientInfo.Protocol = ClientInfo.PROTOCOL_HTTPS;
                }
                else
                {
                    _clientInfo.Protocol = ClientInfo.PROTOCOL_HTTP;
                }
                if (cbVS.Checked)
                {
                    _clientInfo.LoginMessage = CedaObject.GetLoginMessage(txtUserName.Text, txtPwd.Text, txtRole.Text, null, encryption, clientType);
                }
            }
            else if ("CEDA".Equals(cbType.Text.Trim()))
            {
                _clientInfo.setAddress(host, port);
                _clientInfo.setUser("test", "test");
                if (ckSSL.Checked)
                {
                    _clientInfo.Protocol = ClientInfo.PROTOCOL_TCPS;
                }
                else
                {
                    _clientInfo.Protocol = ClientInfo.PROTOCOL_TCP;
                }
                if (cbVS.Checked)
                {
                    _clientInfo.LoginMessage = CedaObject.GetLoginMessage(txtUserName.Text, txtPwd.Text, txtRole.Text, null, encryption, clientType);
                }
            }

            string temp = string.Format("Address:{0}:{1},Topic:{2}", _clientInfo.AddressHost, _clientInfo.AddressPort,
                                        txtTopic.Text);

            logHelper.Info(temp);

            request             = new Message();
            request.Destination = new Destination(txtTopic.Text.Trim());
            request.SvrID       = cbServiceName.Text;
            request.MessageBody.addString((short)3, txtRequest.Text.Trim());
            request.MessageBody.addString((short)4, "JSON");
            request.MessageBody.addInt((short)5, 0);
            request.MessageBody.addString(7, DateTime.Now.ToString("yyyyMMdd HH:mm:ss"));
            ThreadPool.QueueUserWorkItem(o =>
            {
                _cedaSubscribe.Connect(_clientInfo);
                //if (false)
                //{
                //    if (_cedaSubscribe != null)
                //    {
                //        _cedaSubscribe.Disconnect();
                //        _cedaSubscribe.OnCedaMessage -= new Action<com.adaptiveMQ2.message.Message>(_cedaSubscribe_OnCedaMessage);
                //        _cedaSubscribe = null;
                //    }
                //}

                if (_cedaSubscribe != null && _cedaSubscribe.IsConnected)
                {
                    _cedaSubscribe.isStopRequest = false;
                    while (_cedaSubscribe != null && !_cedaSubscribe.isStopRequest)
                    {
                        if (_cedaSubscribe.IsConnected)
                        {
                            Message reply = _cedaSubscribe.Request(request);

                            CedaObject co = CedaObject.ToCedaObject(reply);
                            if (co != null)
                            {
                                logHelper.Info(co.Topic + ":" + co.MessageBody);
                            }
                            else
                            {
                                logHelper.Error("reply is null");
                            }
                        }
                        Thread.Sleep(1000);
                    }
                }
            });
            SetButtonEnable("0111");
        }
Exemple #6
0
        public static CedaObject ToCedaObject(Message msg)
        {
            if (msg == null)
            {
                return(null);
            }
            CedaObject cedaObject = new CedaObject();

            cedaObject.SvrID = msg.SvrID;
            cedaObject.Topic = msg.Destination.getName();

            MessageBody body = msg.MessageBody;

            if (body == null)
            {
                return(cedaObject);
            }

            if (body.haseField((short)5) != 0)
            {
                try
                {
                    cedaObject.ZipType = body.getInt((short)5);
                }
                catch (Exception ex)
                {
                    LogHelper.Error(ex);
                    cedaObject.ZipType = 0;
                }
            }
            else
            {
                cedaObject.ZipType = 0;
            }

            if (body.haseField((short)4) != 0)
            {
                try
                {
                    cedaObject.MessageType = body.getString((short)4);
                }
                catch (Exception ex)
                {
                    LogHelper.Error(ex);
                }
            }

            if (body.haseField((short)3) != 0)
            {
                string strMsg = "";
                try
                {
                    switch (cedaObject.ZipType)
                    {
                    case 0:
                        strMsg = body.getString((short)3);
                        break;

                    case 1:
                        strMsg = body.getGZIPString((short)3);
                        break;

                    case 3:
                        //strMsg=
                        if (body.haseField((short)1) != 0)
                        {
                            strMsg = com.adaptiveMQ2.utils.Utils.ungzipByte(body.getBlobField());
                        }
                        break;
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.Error(ex);
                }
                finally
                {
                    cedaObject.MessageBody = strMsg;
                }
            }

            if (body.haseField((short)6) != 0)
            {
                try
                {
                    cedaObject.MessageSize = body.getInt((short)6);
                }
                catch (Exception ex)
                {
                    LogHelper.Error(ex);
                }
            }

            if (body.haseField((short)7) != 0)
            {
                try
                {
                    cedaObject.SendTime = body.getString((short)7);
                }
                catch (Exception ex)
                {
                    LogHelper.Error(ex);
                }
            }

            if (body.haseField((short)10) != 0)
            {
                try
                {
                    cedaObject.ResultCode = body.getString((short)10);
                }
                catch (Exception ex)
                {
                    LogHelper.Error(ex);
                }
            }

            if (body.haseField((short)11) != 0)
            {
                try
                {
                    cedaObject.Result = body.getInt((short)11);
                }
                catch (MessageBodyException e)
                {
                    LogHelper.Error(e);
                }
            }

            if (body.haseField((short)1) != 0)
            {
                if (cedaObject.ZipType == 3)
                {
                    cedaObject.BigMessage = body.getBlobField();
                }
            }

            return(cedaObject);
        }
Exemple #7
0
        private void ConnectionServer()
        {
            _cedaSubscribe = new CedaManager(logHelper);
            _cedaSubscribe.OnCedaMessage += new Action <com.adaptiveMQ2.message.Message>(_cedaSubscribe_OnCedaMessage);
            string host = txtHost.Text.Trim();
            int    port = 0;

            if (!Int32.TryParse(txtPort.Text.Trim(), out port))
            {
                logHelper.Warn("port is error!");
                return;
            }

            _clientInfo = new ClientInfo();


            if ("ACS".Equals(cbType.Text.Trim()))
            {
                if (!host.EndsWith(".httpMQTunnel"))
                {
                    host = string.Format("{0}/ceda.httpMQTunnel", host);
                }
                _clientInfo.setAddress(host, port);
                if (ckSSL.Checked)
                {
                    _clientInfo.Protocol = ClientInfo.PROTOCOL_HTTPS;
                }
                else
                {
                    _clientInfo.Protocol = ClientInfo.PROTOCOL_HTTP;
                }
                if (cbVS.Checked)
                {
                    _clientInfo.LoginMessage = CedaObject.GetLoginMessage(txtUserName.Text, txtPwd.Text, txtRole.Text, null, encryption, clientType);
                }
            }
            else if ("CEDA".Equals(cbType.Text.Trim()))
            {
                _clientInfo.setAddress(host, port);
                _clientInfo.setUser("test", "test");
                if (ckSSL.Checked)
                {
                    _clientInfo.Protocol = ClientInfo.PROTOCOL_TCPS;
                }
                else
                {
                    _clientInfo.Protocol = ClientInfo.PROTOCOL_TCP;
                }
                if (cbVS.Checked)
                {
                    _clientInfo.LoginMessage = CedaObject.GetLoginMessage(txtUserName.Text, txtPwd.Text, txtRole.Text, null, encryption, clientType);
                }
            }

            ThreadPool.QueueUserWorkItem(o =>
            {
                _cedaSubscribe.Connect(_clientInfo);
                if (_cedaSubscribe == null)
                {
                    return;
                }
                if (_cedaSubscribe.IsConnected)
                {
                    if (rbtnSub.Checked)
                    {
                        _cedaSubscribe.Subscribe(txtTopic.Text.Trim());
                    }
                    else if (rbtnSubImage.Checked)
                    {
                        _cedaSubscribe.SubscribeWithImage(txtTopic.Text.Trim(), cbServiceName.Text.Trim());
                    }
                }
            });
            SetButtonEnable("0111");
        }