Beispiel #1
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));
        }
Beispiel #2
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");
        }
Beispiel #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}/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");
        }