Beispiel #1
0
        //实时数据项包含的类型
        public string GetMenuInfoJson(int userID)
        {
            string   key     = "user_" + userID;
            IDBCache dbCache = (_dbCacheFactory == null)?null:_dbCacheFactory.DefautCache;

            try
            {
                MenuInfAdapter menuAdp = null;
                try
                {
                    if (null != dbCache && dbCache.HashExists(MenuKey, key))
                    {
                        menuAdp = dbCache.HashGet <MenuInfAdapter>(MenuKey, key);
                    }
                }
                catch //(Exception)
                {
                    // throw;
                }
                if (null != menuAdp)
                {
                    userQueryMenuInf.BeginInvoke(userID, menuAdp.dateTime, null, null);
                    return(menuAdp.menuInfJson);
                }
                else
                {
                    return(userQueryMenuInf(userID, null));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #2
0
        //实时数据项包含的类型
        public int GetAlarmCount(string pdrList)
        {
            IDBCache dbCache = (null == _dbCacheFactory)?null:_dbCacheFactory.DefautCache;

            try
            {
                int total = 0;
                if (null != dbCache)
                {
                    userQueryAlarmCountInf.BeginInvoke(null, null);//放前面防止出错后被跳过
                    //if (dbCache.KeyExists(FirstKey))
                    //{
                    string[] pids = pdrList.Split(',');
                    //IList<string> fields = dbCache.HashKeys<string>(FirstKey);
                    //var fks = fields.Where(t => pids.Contains(t));
                    //IList<string> alarmCount1 = null;
                    //lock (_redisLoker)
                    //{
                    //    alarmCount1 = dbCache.HashGet<string>(FirstKey, pids.ToList<string>());
                    //}
                    //IList<int> alarmCount = alarmCount1.Where(t => !string.IsNullOrEmpty(t)).Select(t => Convert.ToInt32(t)).ToList();
                    //total = alarmCount.Sum();
                    string json = dbCache.StringGet(FirstKey);
                    Dictionary <int, int> result     = JsonConvert.DeserializeObject <Dictionary <int, int> >(json);
                    IList <int>           alarmCount = result.Where(t => pids.Contains(t.Key.ToString())).Select(t => t.Value).ToList <int>();
                    total = alarmCount.Sum();
                    //foreach (var v in pids)
                    //{
                    //    if (dbCache.HashExists(FirstKey, v))
                    //        total += dbCache.HashGet<int>(FirstKey, v);
                    //}
                    //}
                    //else
                    //{
                    //    System.Diagnostics.Debug.WriteLine("dbCache.KeyExists(FirstKey)");
                    //}
                }
                else
                {
                    total = userQueryAlarmCountInf();
                }

                return(total);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #3
0
        public IList <t_SM_HisData> GetDatas(int pid)
        {
            IDBCache             dbCache = _dbCacheFactory.DefautCache;
            IList <t_SM_HisData> data    = new List <t_SM_HisData>();

            try
            {
                string key = string.Format(FirstKeyFormat, pid);
                if (dbCache.KeyExists(key))
                {
                    string json = dbCache.StringGet(key);
                    if (!string.IsNullOrEmpty(json))
                    {
                        data = JsonConvert.DeserializeObject(json) as List <t_SM_HisData>;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(data);
        }
Beispiel #4
0
        private string queryMenuInf(int userID, DateTime?lastTime)
        {
            string   retValue = "unknown process.";
            IDBCache dbCache  = (null == _dbCacheFactory)?null:_dbCacheFactory.DefautCache;

            if (null != dbCache && null != lastTime && DateTime.Now.Subtract((DateTime)lastTime).TotalSeconds < 3)
            {
                return(string.Empty);
            }
            MenuInfAdapter menuAdp = new MenuInfAdapter();

            List <MenuInf>         listMenu  = new List <MenuInf>();
            IList <t_CM_RoleRight> roleRight = RoleRightDAL.getInstance().GetRoles(userID);

            if (null == roleRight || roleRight.Count() < 1)
            {
                return(JsonConvert.SerializeObject(listMenu));
            }
            string moduleIDS         = string.Join(",", roleRight.Select(c => c.ModuleID));
            IList <t_CM_Module> data = new List <t_CM_Module>();//

            try
            {
                //string query = "select * from  t_CM_Module  where ModuleID in(" + moduleIDS + ");";
                //using (IModule _hisDataDao = new ModuleDBContext())
                //{
                //    data = (_hisDataDao as IDAOBase).SQLQuery<t_CM_Module>(query);
                //}
                data = _dbFactory.module.GetModules(moduleIDS);
                var menu1 = from s in data where s.ParentID == 0 orderby s.SN select s;
                foreach (t_CM_Module model in menu1)
                {
                    MenuInf menu = new MenuInf();
                    listMenu.Add(menu);
                    menu.moduleParent = model;
                    int mid = (int)model.ModuleID;

                    List <t_CM_Module> list2 = (from s in data where s.ParentID == model.ModuleID orderby s.SN select s).ToList <t_CM_Module>();
                    //ViewData["list" + mid] = list2;
                    menu.childern        = list2;
                    menu.disenableModule = (from s in roleRight where s.Disenable select s).ToList <t_CM_RoleRight>();
                    //隐藏链接
                    var right = from c in menu.disenableModule where c.ModuleID == model.ModuleID && c.Disenable select c;
                    if (right.Count() > 0)
                    {
                        model.Location = "#";
                    }
                    foreach (var m in menu.childern)
                    {
                        right = from c in menu.disenableModule where c.ModuleID == m.ModuleID && c.Disenable select c;
                        if (right.Count() > 0)
                        {
                            m.Location = "#";
                        }
                    }
                }
                retValue = JsonConvert.SerializeObject(listMenu);
                //redis.StringSet(key + "_" + DateTime.Now.ToString(), retValue);
                menuAdp.dateTime    = DateTime.Now;
                menuAdp.menuInfJson = retValue;
                if (null != dbCache)
                {
                    string key = "user_" + userID;
                    dbCache.HashSet(MenuKey, key, menuAdp);
                }
                data.Clear();
                data = null;
                roleRight.Clear();
                roleRight = null;
                menuAdp   = null;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(retValue);
        }
Beispiel #5
0
        //object _redisLoker = new object();
        private int queryAlarmCountInf(/*string pdrlist*/)
        {
            IDBCache dbCache = (null == _dbCacheFactory) ? null : _dbCacheFactory.DefautCache;

            if (null != dbCache)
            {
                if (null != m_dtAlarmCount && (DateTime.Now - m_dtAlarmCount).TotalSeconds < 1)
                {
                    return(0);
                }
                if (m_queryed)
                {
                    return(0);
                }
                m_queryed      = true;
                m_dtAlarmCount = DateTime.Now;
            }
            //Loger.LogHelper.Info("queryAlarmCountInf: begin");
            int total = 0;

            //List<int> pdrIDS = new List<int>();
            //if(!string.IsNullOrEmpty(pdrlist))
            //    pdrIDS=pdrlist.Split(',').Select<string, int>(x => Convert.ToInt32(x)).ToList();
            try
            {
                IList <AlarmCount> data;
                //string query = "select COUNT(*) Count, pid from t_AlarmTable_en where AlarmState>0  group by pid ;";//全部更新
                //using (IAlarmTable_en _hisDataDao = new AlarmTable_enDBContext())
                //{
                //    data = (_hisDataDao as IDAOBase).SQLQuery<AlarmCount>(query);
                //}
                data = _dbFactory.alarmTable_en.GetAlarmCount();
                if (data.Count > 0)
                {
                    //List<int> listPid = null;
                    //lock (_redisLoker)
                    //{
                    //   listPid = dbCache.HashKeys<int>(FirstKey);

                    //}
                    Dictionary <object, object> fields = new Dictionary <object, object>();
                    //bool containted = false;
                    //foreach (var kPid in listPid)//删除没有报警的
                    //{
                    //    containted = false;
                    //    foreach (AlarmCount model in data)
                    //    {
                    //        if (model.PID == kPid)
                    //        {
                    //            containted = true;
                    //            break;
                    //        }
                    //    }
                    //    if (containted)
                    //    {
                    //        continue;
                    //    }
                    //    else
                    //    {
                    //        //dbCache.HashDelete(FirstKey, kPid.ToString());
                    //        //dbCache.HashSet(FirstKey, kPid.ToString(), 0);//不删除,防止读取异常
                    //        fields.Add(kPid, 0);
                    //    }

                    //}
                    foreach (AlarmCount model in data)
                    {
                        //dbCache.HashSet(FirstKey, model.PID.ToString(), model.Count);
                        //if (pdrIDS.Contains(model.PID))
                        total += model.Count;
                        fields.Add(model.PID, model.Count);
                    }
                    if (null != dbCache && fields.Count > 0)
                    {
                        //lock (_redisLoker)
                        {
                            //dbCache.HashSet(FirstKey, fields);
                            string json = JsonConvert.SerializeObject(fields);
                            dbCache.StringSet(FirstKey, json);
                        }
                    }
                }
                else
                {
                    //dbCache.KeyDelete(FirstKey);
                    if (null != dbCache)
                    {
                        dbCache.StringSet(FirstKey, "{}");
                    }
                    Loger.LogHelper.Debug("GetAlarmCount() data.Count():" + data.Count());
                }

                dbCache = null;

                data.Clear();
                data = null;
            }
            catch (Exception ex)
            {
                //throw ex;
                Loger.LogHelper.Error(ex);
            }
            finally
            {
                m_queryed = false;
            }
            return(total);
        }