public UserMessageFilter(IUserBll userBll, IUpdateInfoBll updateInfoBll, IHangUpTimeBll hangUpTimeBll) { _userBll = userBll; _updateInfoBll = updateInfoBll; _hangUpTimeBll = hangUpTimeBll; _updateInfoCtreator = clientType => _updateInfoBll.Get(clientType); }
public GoldCalculator(IUserSubAccountBll subAccountBll, IUserBll userBll, IHangUpTimeBll hangUpTimeBll) { _subAccountBll = subAccountBll; _userBll = userBll; _hangUpTimeBll = hangUpTimeBll; _creator = userId => { return(_subAccountBll.Count(userId)); }; _timer = new Timer(obj => { if (InterlockedEx.IfThen(ref _isExecuted, 1, 1)) { return; } Interlocked.Increment(ref _isExecuted); try { foreach (var sessionId in Global.GetConnectedClientUserId()) { if (sessionId.LastCalcTime.Value.AddMinutes(10) <= DateTime.Now) { _hangUpTimeBll.Add(new HangUpTime { UserId = sessionId.Id, Minutes = 10 }); var count = CacheManager.GetSubAccountCount(sessionId.Id, _creator); int gold = 0; if (count == 1) { gold = 5; } else if (count == 2) { gold = 8; } else if (count >= 3) { gold = 13; } if (gold != 0) { _userBll.UpdateGold(sessionId.Id, gold); } sessionId.LastCalcTime = sessionId.LastCalcTime.Value.AddMinutes(10); } } } catch (Exception ex) { Global.Resolve <ILoggerFactory>() .GetCurrentClassLogger() .ErrorException("GoldCalculator Timer Callback.", ex); } finally { Interlocked.Decrement(ref _isExecuted); } }, null, Timeout.Infinite, CalculatePeriod); }