Example #1
0
 //通知核心将解析消息加入解析队列
 public void Notify_send(NSampleModel msg)
 {
     lock (_sync_send)
     {
         if (_enabled)
         {
             _queue_send.Enqueue(msg);
             log.Debug("发送消息添加到队列:" + msg.sampleModel.sampleNo);
         }
     }
 }
Example #2
0
        public void DataDecode(long instrumentId, string dbTypeof, string dbServer, string dbUser, string dbPwd)
        {
            try
            {
                SampleModel  sampleModel  = parseDb(dbTypeof, dbServer, dbUser, dbPwd, instrumentId.ToString());
                NSampleModel nSampleModel = new NSampleModel();

                nSampleModel.id          = Guid.NewGuid().ToString();
                nSampleModel.sampleModel = sampleModel;
                nSampleModel.status      = -1;
                Utils.kernel.Notify_send(nSampleModel);
            }
            catch (Exception e)
            {
                Console.Write(e.ToString());
            }
        }
Example #3
0
 public void DataDecode(long instrumentId, string dbTypeof, string dbServer, string dbUser, string dbPwd)
 {
     try
     {
         SampleModel  sampleModel  = parseDb(dbTypeof, dbServer, dbUser, dbPwd, instrumentId.ToString());
         NSampleModel nSampleModel = new NSampleModel();
         if (sampleModel != null)
         {
             nSampleModel.id          = sampleModel.sampleNo;
             nSampleModel.sampleModel = sampleModel;
             nSampleModel.status      = -1;
             //判断是否发送到发送线程处理
             //条件1:如果数据库里存在该样本数据,则进行条件2,否则发送到发送线程处理
             //条件2:如果发送数据库里的数据与解析的数据相同,则不再发送到发送线程处理,否则发送到发送线程
             //
             using (var odb = OdbFactory.Open("samplemodel.dat"))
             {
                 var query = odb.Query <NSampleModel>();
                 query.Descend("id").Constrain(nSampleModel.id).Equal();
                 var nSampleModel_query = query.Execute <NSampleModel>().GetFirst();
                 if (nSampleModel_query != null)
                 {
                     if (nSampleModel_query != nSampleModel)
                     {
                         nSampleModel_query.status      = nSampleModel.status;
                         nSampleModel_query.sampleModel = nSampleModel.sampleModel;
                         odb.Store <NSampleModel>(nSampleModel_query);
                         Utils.kernel.Notify_send(nSampleModel);
                     }
                 }
                 else
                 {
                     odb.Store <NSampleModel>(nSampleModel);
                     Utils.kernel.Notify_send(nSampleModel);
                 }
             }
         }
     }
     catch (Exception e)
     {
         Console.Write(e.ToString());
     }
 }
Example #4
0
        public void SendToServer(NSampleModel nsampleModel)
        {
            SampleModel sampleModel = nsampleModel.sampleModel;

            if (sampleModel != null)
            {
                String tmp = "0";
                //获取天气数据
                String weatherRes = Utils.HttpPost("https://free-api.heweather.net/s6/weather/now?location=auto_ip&key=12d41376e9e34bb18c54b95de9cfb85a", null, "");
                if (weatherRes != null && !weatherRes.Equals(""))
                {
                    JObject job    = JObject.Parse(weatherRes);
                    JArray  jArray = JArray.Parse(job["HeWeather6"].ToString());
                    job = (JObject)jArray[0];
                    job = JObject.Parse(job["now"].ToString());
                    tmp = job["tmp"].ToString();
                }
                //发送数据
                log.Debug("发送采集到的数据");
                Dictionary <String, Object> dict = new Dictionary <string, object>();
                dict.Add("jsonData", Utils.ObjToJson <SampleModel>(sampleModel));
                String response = Utils.HttpPostJson(ini.IniReadValue("配置", "ServerUrl") + "?tmp=" + tmp, dict, "");
                log.Debug("发送成功,准备更新界面");
                //通知界面更新,如果不在进度条显示
                if (!sampleModel.isProgressShow)
                {
                    OnTaskEndEvent(this, nsampleModel, response);
                }
                else
                {
                    //向progressbar发送消息
                    OnSendProgressEvent(response, nsampleModel);
                }
            }
            else
            {
                OnTaskEndEvent(this, nsampleModel, "null");
                log.Error("发送时sampleModel为null");
            }
        }
Example #5
0
        public Kernel(String serverUrl)
        {
            _serverUrl     = serverUrl;
            _enabled       = true;
            _exited_decode = new ManualResetEvent(initialState: false);
            _queue_decode  = new Queue <Message4Kernel>();
            _sync_decode   = ((ICollection)_queue_decode).SyncRoot;
            //解析线程
            ThreadPool.QueueUserWorkItem(delegate
            {
                while (_enabled || Count_decode > 0)
                {
                    Message4Kernel decodeMessage = dequeue_decode();
                    cureentMessage = decodeMessage;
                    if (decodeMessage != null)
                    {
                        log.Info("开始处理文件: " + decodeMessage.fileName);
                        try
                        {
                            DecodeFactory.Instance.Decode(decodeMessage);
                        }
                        catch (Exception exception)
                        {
                            log.Error("Decode ", exception);
                        }
                    }
                    else
                    {
                        Thread.Sleep(500);
                    }
                }

                _exited_decode.Set();
            });
            _exited_send = new ManualResetEvent(initialState: false);
            _queue_send  = new Queue <NSampleModel>();
            _sync_send   = ((ICollection)_queue_send).SyncRoot;
            //发送线程
            ThreadPool.QueueUserWorkItem(delegate
            {
                while (_enabled || Count_send > 0)
                {
                    NSampleModel sendMessage = dequeue_send();
                    if (sendMessage != null && sendMessage.sampleModel != null)
                    {
                        log.Info("开始发送样本号: " + sendMessage.sampleModel.sampleNo);
                        try
                        {
                            DecodeFactory.Instance.SendToServer(sendMessage);
                        }
                        catch (Exception exception)
                        {
                            log.Error("Send ", exception);
                        }
                    }
                    else
                    {
                        Thread.Sleep(500);
                    }
                }
                _exited_send.Set();
            });
        }