Beispiel #1
0
        private void Process()
        {
            while (true)
            {
                Thread.Sleep(1000);/*每一秒*/
                if (NCSys.IsRun == false)
                {
                    continue;
                }

                try
                {
                    this.GetProcessOfConfig();
                }
                catch (Exception ex)
                {
                    FileLog.Error("读取采集配置数据错误:" + ex.Message + ex.StackTrace);
                }
                try
                {
                    foreach (var s0 in NCSys.Result)
                    {
                        CollectVModel s1 = s0.Value;
                        if (DateTime.Now < s1.UpTime.AddMinutes(Helper.FrMd))
                        {
                            continue;
                        }

                        RstVar rst = s1.RstVar;
                        if (rst == null)
                        {
                            continue;
                        }
                        try
                        {
                            string msg;
                            int    errcode = processBll.DataProcess(s1.Module_id, s1.ModuleAddr, s1.Fun_id, rst.lpszVal, rst.lpszdateTime, out msg);
                            if (errcode < 0)
                            {
                                FileLog.Error("KEY:" + s0.Key + "值:" + rst.lpszVal + "数据处理结果错误:" + msg);
                            }
                            FileLog.Debug("KEY:" + s0.Key + "值:" + rst.lpszVal + "保存成功");
                        }
                        catch (Exception ex)
                        {
                            FileLog.Error("KEY:" + s0.Key + "值:" + rst.lpszVal + "采集时间:" + rst.lpszdateTime.ToString() + "数据处理结果错误:" + ex.Message);
                        }
                        s1.UpTime = DateTime.Now;/*入库时间*/
                    }
                }
                catch (Exception ex)
                {
                    FileLog.Error("数据处理错误:" + ex.Message + ex.StackTrace);
                }
            }
        }
Beispiel #2
0
        private void DbProcess()
        {
            while (true)
            {
                Thread.Sleep(1000);/*每一秒*/
                if (NCSys.IsRun == false)
                {
                    continue;
                }

                #region 配置信息
                try
                {
                    this.GetProcessOfConfig();
                }
                catch (Exception ex)
                {
                    FileLog.Error("读取采集配置数据错误:" + ex.Message + ex.StackTrace);
                }
                #endregion

                #region 先入库存储
                try
                {
                    bool bIsNext = true;
                    var  enumer  = NCSys.Result.GetEnumerator();
                    while (bIsNext == true)
                    {
                        bIsNext = enumer.MoveNext();
                        if (bIsNext == false)
                        {
                            break;
                        }
                        var           s0  = enumer.Current;
                        CollectVModel s1  = s0.Value;
                        SysPro        pro = null;
                        NCSys.Pro.TryGetValue(s1.Ledger, out pro);
                        if (pro == null)
                        {
                            FileLog.Error("KEY:" + s0.Key + "没有此账目: " + s1.Ledger);
                            continue;
                        }
                        RstVar rst = MemcachedMgr.GetVal <RstVar>(s1.CachedKey);
                        if (rst == null)
                        {
                            //FileLog.Error("KEY:" + s0.Key + "没有缓存值");
                            continue;
                        }
                        if (s1.Module_id == 0 || s1.Action != 0)
                        {
                            continue;
                        }
                        if (s1.IsDb == false)
                        {
                            if (s1.UpTime.AddMinutes(pro.FrMd) > rst.lpszdateTime)
                            {
                                continue;
                            }
                        }
                        try
                        {
                            string         msg;
                            DataProcessBLL bll     = new DataProcessBLL(s1.Ledger, Config.Uid);
                            int            errcode = bll.DataProcess(s1.Module_id, s1.ModuleAddr, s1.Fun_id, rst.lpszVal, rst.lpszdateTime, out msg, 90);
                            if (errcode < 0)
                            {
                                FileLog.Error("KEY:" + s0.Key + "值:" + rst.lpszVal + "数据处理结果错误:" + msg);
                            }
                            else
                            {
                                FileLog.Debug("KEY:" + s0.Key + "值:" + rst.lpszVal + "保存成功");
                            }
                        }
                        catch (Exception ex)
                        {
                            FileLog.Error("KEY:" + s0.Key + "值:" + rst.lpszVal + "采集时间:" + rst.lpszdateTime.ToString() + "数据处理结果错误:" + ex.Message);
                        }
                        s1.UpTime = DateTime.Now; /*入库时间*/
                        s1.IsDb   = false;
                        Thread.Sleep(20);         /*每20毫秒*/
                    }
                }
                catch (Exception ex)
                {
                    FileLog.Error("数据处理错误:" + ex.Message + ex.StackTrace);
                }
                #endregion
            }
        }