Example #1
0
        static CheckLoginStatusService()
        {
            Task.Factory.StartNew(() => {
                try
                {
                    var redisSubHelp = new RedisSubHelp((a, b) =>
                    {
                        if (b.StartsWith(CacheKeyString.UserLoginAllKeyPre))
                        {
                            LogWrite.Write("redisLog.txt", "redis key:" + b);
                            try
                            {
                                string[] strArray = b.Split("#");
                                string ID         = strArray[3];
                                int companyID     = Convert.ToInt32(strArray[2]);
                                string userID     = strArray[1].ToString();
                                LoginLog loginLog = MongoDbUtil.GetDoc <LoginLog>(p => p.LoginID == ID, null).FirstOrDefault();

                                DateTime now       = DateTime.Now;
                                TimeSpan spendSpan = now.Subtract(loginLog.LoginTime);
                                if (loginLog != null)
                                {
                                    UpdateDefinition <LoginLog> update = Builders <LoginLog> .
                                                                         Update.Set(y => y.Seconds, spendSpan.TotalSeconds).Set(y => y.TimeSpan, DateUtil.parseTimeSeconds(spendSpan.TotalSeconds, 0))
                                                                         .Set(y => y.Status, LoginStatusEum.LogOut);
                                    MongoDbUtil.UpdateOne <LoginLog>(p => p.LoginID == ID, update);
                                }

                                var redis       = CacheFactory.Instance(CacheType.Redis) as RedisCache;
                                string thisWeek = DateUtil.GetThisWeekString();
                                string strV     = string.Format(CacheKeyString.StaOnlineUser, companyID, thisWeek);

                                string strTimeV = string.Format(CacheKeyString.StaOnlineTimes, companyID, thisWeek);

                                //累加登陆时长
                                redis.IncrementItemInSortedSet(strV, userID, spendSpan.TotalSeconds);
                                redis.Client.ExpireAt(strV, DateUtil.ToUnixEpochDate(DateTime.Now.AddDays(15)));

                                redis.IncrementItemInSortedSet(strTimeV, userID, 1);
                                redis.Client.ExpireAt(strV, DateUtil.ToUnixEpochDate(DateTime.Now.AddDays(15)));
                            }
                            catch (Exception ex) {
                                LogWrite.Write("redisLog", "错误:" + ex.Message);
                            }
                        }
                    });
                    redisSubHelp.SubscribeToChannels("__keyevent@0__:expired");
                }
                catch (Exception ex) {
                    LogWrite.Write("redisLog.txt", "最外层线程:" + ex.Message);
                }
            });
        }
 public void FillFilterList(ComboBox cbFilter, List <TextBox> tbList)
 {
     try
     {
         int index = 0;
         cbFilter.Items.Insert(index, "No Filter");
         foreach (TextBox tb in tbList)
         {
             if (tb.Name != "tbID")
             {
                 index++;
                 cbFilter.Items.Insert(index, tb.Name.Substring(2));
             }
         }
         cbFilter.SelectedIndex = 0;
     }
     catch (Exception ex)
     {
         log.Write(ex.ToString());
     }
 }