Exemplo n.º 1
0
        // 重新更新配置
        private void GetProcessOfConfig()
        {
            if (NCSys.Reset == true)
            {
                NCSys.Pro.Clear();
                NCSys.Result.Clear();
                NCSys.Reset       = false;
                NCSys.ResetSiTime = false;
                //addBaseValTime = null;
                //updatePayEstTime = null;

                //Helper.LoadTime = DateTime.Now;
                //Helper.RangeUse = CommFunc.ConvertDBNullToString(IniHepler.GetConfig(Config.lpFileName, "Alarm", "RangeUse"));

                #region 获取基本配置信息
                DataTable dtInfo = sysBll.GetSyscont();
                foreach (DataRow drInfo in dtInfo.Rows)
                {
                    SysPro pro    = new SysPro();
                    int    ledger = CommFunc.ConvertDBNullToInt32(drInfo["Ledger"]);
                    pro.ProjectKey = CommFunc.ConvertDBNullToString(drInfo["Project"]) + "->" + CommFunc.ConvertDBNullToInt32(drInfo["Ledger"]) + "->";
                    pro.Project    = CommFunc.ConvertDBNullToString(drInfo["Project"]);
                    pro.FrMd       = CommFunc.ConvertDBNullToInt32(drInfo["FrMd"]);
                    pro.MaxVal     = CommFunc.ConvertDBNullToInt32(drInfo["MaxVal"]);
                    pro.Auto       = CommFunc.ConvertDBNullToInt32(drInfo["Auto"]);
                    pro.FrMd       = pro.FrMd == 0 ? 15 : pro.FrMd;
                    NCSys.Pro.Add(ledger, pro);
                    /////
                    #region 获取各种参数配置信息
                    //DataProcessBLL bll = new DataProcessBLL(ledger, Config.Uid);
                    //DataTable dtConfig = bll.GetSysConfig("");
                    //AliSmsConfig sms = new AliSmsConfig();
                    //ComSmsConfig comConfig = new ComSmsConfig();
                    //WxConfig wx = new WxConfig();
                    //EmailConfig em = new EmailConfig();
                    //System.Reflection.PropertyInfo[] smsInfo = sms.GetType().GetProperties();
                    //System.Reflection.PropertyInfo[] comInfo = comConfig.GetType().GetProperties();
                    //System.Reflection.PropertyInfo[] wxInfo = wx.GetType().GetProperties();
                    //System.Reflection.PropertyInfo[] emInfo = em.GetType().GetProperties();
                    //foreach (DataRow dr in dtConfig.Rows)
                    //{
                    //    foreach (System.Reflection.PropertyInfo f_key in smsInfo)
                    //    {
                    //        if (CommFunc.ConvertDBNullToString(dr["CfKey"]).Equals(f_key.Name))
                    //            f_key.SetValue(sms, dr["CfValue"], null);
                    //    }
                    //    foreach (System.Reflection.PropertyInfo f_key in wxInfo)
                    //    {
                    //        if (CommFunc.ConvertDBNullToString(dr["CfKey"]).Equals(f_key.Name))
                    //            f_key.SetValue(wx, dr["CfValue"], null);
                    //    }
                    //    foreach (System.Reflection.PropertyInfo f_key in emInfo)
                    //    {
                    //        if (CommFunc.ConvertDBNullToString(dr["CfKey"]).Equals(f_key.Name))
                    //            f_key.SetValue(em, dr["CfValue"], null);
                    //    }
                    //    foreach (System.Reflection.PropertyInfo f_key in comInfo)
                    //    {
                    //        if (CommFunc.ConvertDBNullToString(dr["CfKey"]).Equals(f_key.Name))
                    //            f_key.SetValue(comConfig, dr["CfValue"], null);
                    //    }
                    //}
                    //SmsFun.AliSmsConfig = sms;
                    //pro.Wx.WxConfig = wx;
                    //pro.Sms.ComSmsConfig = comConfig;
                    //EmailUtilities.EmConfig = em;
                    //dtConfig.Dispose();
                    #endregion

                    #region 更新配置
                    //lock (wholeObj)
                    //{/*操作datatable线程非安全*/
                    //    DataTable dtTmp = bll.GetMapInfo("");
                    //    if (DtMap == null)
                    //        DtMap = dtTmp;
                    //    else
                    //        DtMap.Merge(dtTmp.Copy(), true, MissingSchemaAction.Ignore);
                    //    dtTmp.Dispose();
                    //}
                    #endregion
                }
                //Helper.FrMd = Helper.FrMd == 0 ? 15 : Helper.FrMd;
                //Helper.SendSpan = Helper.SendSpan == 0 ? 15 : Helper.SendSpan;
                #endregion

                #region 获取IOService变量
                System.Data.DataTable dtSource          = sysBll.GetMapInfo();
                Dictionary <string, List <string> > dic = new Dictionary <string, List <string> >();
                foreach (System.Data.DataRow dr in dtSource.Rows)
                {
                    int    ledger    = CommFunc.ConvertDBNullToInt32(dr["Ledger"]);
                    int    action    = CommFunc.ConvertDBNullToInt32(dr["Action"]);
                    string handledBY = CommFunc.ConvertDBNullToString(dr["HandledBY"]);
                    string nKey      = CommFunc.ConvertDBNullToString(dr["NKey"]);
                    string tagName   = CommFunc.ConvertDBNullToString(dr["TagName"]);
                    if (!string.IsNullOrEmpty(Config.IOHandledBY))
                    {
                        handledBY = Config.IOHandledBY;
                    }
                    List <string> tag = null;
                    if (dic.TryGetValue(handledBY, out tag) == false)
                    {
                        tag = new List <string>();
                        dic.Add(handledBY, tag);
                    }
                    if (action == 0 || action == 1)
                    {
                        tag.Add(tagName);
                    }
                    #region 更新内存
                    SysPro pro = null;
                    NCSys.Pro.TryGetValue(ledger, out pro);
                    if (pro == null)
                    {
                        FileLog.Error("KEY:" + nKey + "没有此账目: " + ledger);
                        continue;
                    }
                    CollectVModel collect = ModelHandler <CollectVModel> .FillModel(dr);

                    collect.CachedKey = pro.ProjectKey + collect.CachedKey;
                    NCSys.Result.TryAdd(pro.ProjectKey + nKey, collect);
                    #endregion
                }
                foreach (var kk in dic)
                {
                    DataProcess.IOService.Collection.CollectionHelper.Instance(kk.Key, kk.Value);
                }
                dtSource.Dispose();
                #endregion

                FileLog.WriteLog("更新配置成功");
            }
        }
Exemplo n.º 2
0
        private static void SaveCollectCache(int ledger, string lpszDbVarName, string lpszVal, DateTime lpszdateTime, UInt32 dwUserData)
        {
            SysPro pro = null;

            NCSys.Pro.TryGetValue(ledger, out pro);
            if (pro == null)
            {
                FileLog.Debug("获取账目数据错误");
                return;
            }
            string        mkey    = pro.ProjectKey + lpszDbVarName;
            CollectVModel collect = null;

            if (NCSys.Result.TryGetValue(mkey, out collect) == false)
            {
                //collect = new CollectVModel() { Ledger = ledger, Module_id = 0 };
                //return null;
            }
            if (collect == null || collect.Module_id == 0)
            {/*正常不出现此错误,除非上面数据库或逻辑错误*/
                FileLog.Debug("获取采集数据错误");
                return;
            }
            RstVar rstVar = MemcachedMgr.GetVal <RstVar>(collect.CachedKey);

            if (rstVar == null)
            {
                rstVar = new RstVar()
                {
                    lpszVal = lpszVal, lpszdateTime = lpszdateTime, dwUserData = dwUserData
                };
            }
            /////////////////////////////////////////////////////////////////
            bool isUpCached = true; // 是否更新内存

            if ((collect.FunType.Equals("E")) && pro.Auto == 0)
            {
                decimal curLpszVal = CommFunc.ConvertDBNullToDecimal(lpszVal);
                decimal chdLpszVal = CommFunc.ConvertDBNullToDecimal(rstVar.lpszVal);
                //if (decimal.TryParse(lpszVal, out curLpszVal) == false)
                //{
                //    string[] arr = lpszVal.Split(new char[] { ':', ',' }, StringSplitOptions.RemoveEmptyEntries);
                //    if (arr.Count() < 2)
                //    {
                //        FileLog.Debug("KEY:" + lpszDbVarName + "采集数据" + lpszVal + "格式异常");
                //    }
                //    else
                //    {
                //        curLpszVal = CommFunc.ConvertDBNullToDecimal(arr[1]);
                //    }
                //    if (!string.IsNullOrEmpty(collect.RstVar.lpszVal))
                //    {
                //        arr = collect.RstVar.lpszVal.Split(new char[] { ':', ',' }, StringSplitOptions.RemoveEmptyEntries);
                //        if (arr.Count() < 2)
                //        {
                //            FileLog.Debug("KEY:" + lpszDbVarName + "缓存的数据" + collect.RstVar.lpszVal + "格式异常");
                //        }
                //        else
                //        {
                //            chdLpszVal = CommFunc.ConvertDBNullToDecimal(arr[1]);
                //        }
                //    }
                //}
                if (chdLpszVal > curLpszVal)
                {
                    //collectInfo.errCode = AlarmType.Ez_1;
                    //collectInfo.errTxt = "上期采集值:" + CommFunc.ConvertDBNullToDecimal(collect.RstVar.lpszVal) + "本次采集值:" + CommFunc.ConvertDBNullToDecimal(lpszVal);
                    //collectInfo.isSend = 0;
                    //NCSys.AlarmCollect.Enqueue(collectInfo); /*更新数据库*/
                    isUpCached = false;
                    FileLog.Debug("KEY:" + lpszDbVarName + "采集数据反转" + " 上期采集值:" + chdLpszVal + "本次采集值:" + curLpszVal);
                }
                else
                {
                    if (pro.MaxVal != 0)
                    {
                        decimal useVal    = curLpszVal - chdLpszVal;/*当前使用量*/
                        decimal maxUseVal = (decimal)((lpszdateTime - rstVar.lpszdateTime).TotalMinutes / pro.FrMd) * pro.MaxVal;
                        if (useVal > maxUseVal)
                        {
                            //collectInfo.errCode = AlarmType.Err_OFlow;
                            //collectInfo.errTxt = "上期采集值:" + CommFunc.ConvertDBNullToDecimal(collect.RstVar.lpszVal) + "时间" + collect.RstVar.lpszdateTime.ToString("yyyy-MM-dd HH:mm:ss") + "本次采集值:" + CommFunc.ConvertDBNullToDecimal(lpszVal) + "时间" + lpszdateTime.ToString("yyyy-MM-dd HH:mm:ss");
                            //collectInfo.isSend = 0;
                            //NCSys.AlarmCollect.Enqueue(collectInfo); /*更新数据库*/
                            isUpCached = false;
                            FileLog.Debug("KEY:" + lpszDbVarName + "采集数据越限" + "上期采集值:" + chdLpszVal + "时间" + rstVar.lpszdateTime.ToString("yyyy-MM-dd HH:mm:ss") + "本次采集值:" + curLpszVal + "时间" + lpszdateTime.ToString("yyyy-MM-dd HH:mm:ss"));
                        }
                    }
                }
            }

            if (CommFunc.ConvertDBNullToDateTime(rstVar.lpszdateTime) > lpszdateTime)
            {
                //collectInfo.errCode = AlarmType.Ez_2;
                //collectInfo.errTxt = "上期采集值:" + collect.RstVar.lpszdateTime + "本次采集值:" + lpszVal;
                //collectInfo.isSend = 0;
                //NCSys.AlarmCollect.Enqueue(collectInfo); /*更新数据库*/
                isUpCached = false;
                FileLog.Debug("KEY:" + lpszDbVarName + "值采集时间反转");
            }

            if (isUpCached == true)
            {
                bool isDb = false;
                if (collect.FunType.ToLower().Equals("ssr") && !rstVar.lpszVal.Equals(lpszVal))
                {
                    isDb = true;/*更新存储入库标记*/
                }
                DateTime lastTime = rstVar.lpszdateTime;
                rstVar.lpszVal      = lpszVal;
                rstVar.lpszdateTime = lpszdateTime;
                rstVar.dwUserData   = dwUserData;
                if (collect.Action == 0)
                {                                                               /*事件的数据不缓存*/
                    bool last = MemcachedMgr.SetVal(collect.CachedKey, rstVar); /*加入memcached*/
                    if (last == false)
                    {
                        if (lpszdateTime > lastTime.AddMinutes(15))
                        {/*相隔15分钟入队列*/
                         //collectInfo.errCode = AlarmType.Err_Nd;
                         //collectInfo.errTxt = "更新Memcahed错误";
                         //collectInfo.isSend = 0;
                         //NCSys.AlarmCollect.Enqueue(collectInfo); /*更新数据库*/
                        }
                        /////////////////////////////////////////
                        FileLog.WriteLog("变量" + collect.CachedKey + "更新Memcahed错误");
                    }
                    else
                    {
                        if (isDb == true)
                        {
                            collect.IsDb = true;
                        }
                        FileLog.Debug("KEY:" + collect.CachedKey + " 保存缓存成功值:" + rstVar.lpszVal);
                    }
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 更新缓存信息
        /// </summary>
        /// <param name="command"></param>
        /// <param name="errCode"></param>
        /// <param name="errTxt"></param>
        private static void RefreshCached(CommandVModel command, string lpszVal, AlarmType errCode)
        {
            if (errCode != AlarmType.Sue)
            {
                return;                          /*不成功则返回;成功则继续往下操作*/
            }
            if (command.Action == 1 && command.Fun_id != 0)
            {/*记录写的值*/
                new DataProcessBLL(command.Ledger, Config.Uid).UpdataMap(command.Module_id, command.Fun_id, lpszVal);
            }
            SysPro pro = null;

            NCSys.Pro.TryGetValue(command.Ledger, out pro);
            if (pro == null)
            {
                return;
            }
            string ss1 = pro.ProjectKey + command.Module_id.ToString() + "." + command.ModuleAddr + ".";

            if (command.FunType.Equals(V0Fun.Ssr.ToString()) && !string.IsNullOrEmpty(command.DataValue))
            { // 立刻更新拉合闸
                string key = ss1 + V0Fun.Ssr.ToString();
                RstVar rst = MemcachedMgr.GetVal <RstVar>(key);
                if (rst == null)
                {
                    return;
                }
                rst.lpszVal      = command.DataValue;
                rst.lpszdateTime = command.CollectTime.Value;
                rst.dwUserData   = 0;
                ///////////////
                CollectVModel collect = null;
                if (NCSys.Result.TryGetValue(key, out collect) == true)
                {
                    //collect.RstVar = rst;
                    //collect.IsDb = true;
                    //collect.IsRn = command.IsRn;
                }
                ///////////////
                MemcachedMgr.SetVal(key, rst);
            }
            if (command.FunType.Equals(V0Fun.Pay.ToString()) || command.FunType.Equals(V0Fun.Refund.ToString()))
            { // 充值;退费
                string key = ss1 + V0Fun.RdVal.ToString();
                RstVar rst = MemcachedMgr.GetVal <RstVar>(key);
                if (rst == null)
                {
                    return;
                }
                decimal lpszPay = CommFunc.ConvertDBNullToDecimal(rst.lpszVal);
                if (command.FunType.Equals(V0Fun.Pay.ToString()))
                {
                    lpszPay = lpszPay + CommFunc.ConvertDBNullToDecimal(command.DataValue);
                }
                else if (command.FunType.Equals(V0Fun.Refund.ToString()))
                {
                    lpszPay = lpszPay - CommFunc.ConvertDBNullToDecimal(command.DataValue);
                }
                rst.lpszVal      = lpszPay.ToString();
                rst.lpszdateTime = command.CollectTime.Value;
                rst.dwUserData   = 0;
                ///////////////
                CollectVModel collect = null;
                if (NCSys.Result.TryGetValue(key, out collect) == true)
                {
                    //collect.RstVar = rst;
                    //collect.IsDb = true;
                }
                ///////////////
                MemcachedMgr.SetVal(key, rst);
                #region 2018.07.02
                //if (command.ModuleType.Equals("YD-ZB20-4PL2-SB"))
                //{
                //    key = ss1 + V0Fun.E.ToString();
                //    collect = null;
                //    if (NCSys.Result.TryGetValue(key, out collect) == true)
                //        collect.IsDb = true;
                //}
                #endregion
            }
        }
Exemplo n.º 4
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
            }
        }