コード例 #1
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;
            }
        }
コード例 #2
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);
        }