Example #1
0
 public void sendASyncResponse(TaskSocketMessage msg)
 {
     msg.request = false;
     msg.async   = true;
     send(msg);
     log.Info("sendASyncResponse:" + JsonConvert.SerializeObject(msg));
 }
Example #2
0
        public TaskSocketMessage sendSyncRequest(TaskSocketMessage msg)
        {
            log.Info("request:" + JsonConvert.SerializeObject(msg));
            msg.request          = true;
            msg.async            = false;
            reqReturnMap[msg.id] = null;
            send(msg);
            //循环次数
            int cycleIndex = 0;
            //休眠毫秒数
            int sleepTimeUnitMil = 5;
            //休眠总时间
            int waitTime = 10 * 1000;

            while (reqReturnMap[msg.id] == null)
            {
                cycleIndex++;
                if (cycleIndex >= (waitTime / sleepTimeUnitMil))
                {
                    break;
                }
                Thread.Sleep(sleepTimeUnitMil);
            }
            TaskSocketMessage returnMsg = reqReturnMap[msg.id];

            lock (reqReturnMap)
            {
                reqReturnMap.Remove(msg.id);
            }
            log.Info("response:" + JsonConvert.SerializeObject(returnMsg));
            return(returnMsg);
        }
Example #3
0
        private void websocket_Opened(object sender, EventArgs e)
        {
            TaskSocketMessage tsm = new TaskSocketMessage();

            tsm.type       = "initDevice";
            tsm.request    = true;
            tsm.createTime = DateTimeUtil.getSystemTimestampMilli();

            Login _login = new Login();

            _login.GUID        = ConfigManager.Instance.Config.license;
            _login.CompanyName = "";
            _login.ACTION      = "1";
            _login.TaxCodeList = new List <string>();

            XPathDocument     doc          = new XPathDocument("USBData.xml");
            XPathNavigator    xPathNav     = doc.CreateNavigator();
            XPathNodeIterator nodeIterator = xPathNav.Select("/Root/Item");

            while (nodeIterator.MoveNext())
            {
                XPathNavigator itemNav = nodeIterator.Current;
                _login.TaxCodeList.Add(itemNav.SelectSingleNode("TaxCode").Value);
            }
            _login.TIME = DateTime.Now.ToString();              // "2017-06-30 09:09:09";
            tsm.content = JsonConvert.SerializeObject(_login);
            log.Info("ydz:" + JsonConvert.SerializeObject(tsm));
            send(tsm);
            log.Info("taskserver 已打开");
            instance.connected = true;
        }
Example #4
0
        private void websocket_Opened(object sender, EventArgs e)
        {
            TaskSocketMessage tsm = new TaskSocketMessage();

            tsm.type       = "initDevice";
            tsm.request    = true;
            tsm.createTime = DateTimeUtil.getSystemTimestampMilli();

            Login _login = new Login();

            _login.GUID        = ConfigManager.Instance.Config.license;
            _login.CompanyName = "";
            _login.ACTION      = "1";
            _login.TaxCodeList = new List <string>();
            _login.TaxCodeList.Add(ConfigManager.Instance.Config.sh);
            tsm.content = JsonConvert.SerializeObject(_login);
            send(tsm);
            log.Info("taskserver 已打开");
            instance.connected = true;
        }
Example #5
0
        private void handleMessage(TaskSocketMessage msg)
        {
            log.Info("当前执行线程名称:" + Thread.CurrentThread.GetHashCode());
            if (!msg.request && !msg.async)
            {
                lock (reqReturnMap)
                {
                    reqReturnMap[msg.id] = msg;
                }
                return;
            }

            try
            {
                TaskHandle.handle(msg);
            }
            catch (Exception exp)
            {
                log.Error("处理TaskSocketMessage 失败" + JsonConvert.SerializeObject(msg), exp);
            }
        }
Example #6
0
        private void websocket_MessageReceived(object sender, MessageReceivedEventArgs e)
        {
            log.Info("接收消息:" + e.Message);
            TaskSocketMessage msg = null;

            try
            {
                msg = JsonConvert.DeserializeObject <TaskSocketMessage>(e.Message);
                log.Info("content:" + msg.content);
            }
            catch (Exception exp)
            {
                log.Error("处理TaskSocketMessage 失败" + e.Message, exp);
            }
            if (msg == null)
            {
                return;
            }
            Thread thread = new Thread(delegate(){ handleMessage(msg); });

            thread.Name = "MessageReceived:" + thread.GetHashCode();
            thread.Start();
        }
Example #7
0
 private void send(TaskSocketMessage tsm)
 {
     websocket.Send(JsonConvert.SerializeObject(tsm));
 }
Example #8
0
 public void sendASyncRequest(TaskSocketMessage msg)
 {
     msg.request = true;
     msg.async   = true;
     send(msg);
 }