void GetOnlineList() { List <OnlineInfoEntity> list = OnlineSqlHelper.GetOnlineList(OnlineConfig.TIMEOffLineMinutes, OnlineConfig.PROCBatchSize); if (list == null || list.Count == 0) { return; } for (int i = 0; i < list.Count; i++) { var item = list[i]; cacheActive[item.ManagerId] = item; } }
bool UpdateActive() { if (!syncTable) { syncUpdating = true; lockCache.EnterWriteLock(); syncUpdating = false; try { lock (lockWrite) { cacheTable.Clear(); bool flagCacheReset = syncCacheReset; List <Guid> removeList = new List <Guid>(); foreach (var kvp in cacheActive) { var actObj = kvp.Value; //if (actObj.ManagerId.ToString() == "") //{ // int a = 0; // string s = a.ToString(); //} DataRow row = cacheTable.NewRow(); int inactMinutes = (int)DateTime.Now.Subtract(actObj.ActiveTime).TotalMinutes; int actMinutes = (int)actObj.ActiveTime.Subtract(actObj.GuildInTime).TotalMinutes; if (actMinutes < 0) { actMinutes = 0; } bool isOnLine = (inactMinutes < OnlineConfig.TIMEOffLineMinutes); row[cacheTable.ManagerIdColumn.ColumnName] = actObj.ManagerId; row[cacheTable.LoginTimeColumn.ColumnName] = actObj.LoginTime; row[cacheTable.GuildInTimeColumn.ColumnName] = actObj.GuildInTime; row[cacheTable.ActiveTimeColumn.ColumnName] = actObj.ActiveTime; row[cacheTable.ActiveFlagColumn.ColumnName] = isOnLine; row[cacheTable.ResetFlagColumn.ColumnName] = 1; row[cacheTable.CntOnlineMinutesColumn.ColumnName] = isOnLine ? 0 : actMinutes; row[cacheTable.CurOnlineMinutesColumn.ColumnName] = isOnLine ? actMinutes : 0; row[cacheTable.StatusColumn.ColumnName] = 0; row[cacheTable.LoginIpColumn.ColumnName] = ""; row[cacheTable.RowTimeColumn.ColumnName] = DateTime.Now; row[cacheTable.TotalOnlineMinutesColumn.ColumnName] = actObj.TotalOnlineMinutes; cacheTable.Rows.Add(row); if (isOnLine) { if (flagCacheReset) { actObj.GuildInTime = DateTime.Now; actObj.ActiveTime = DateTime.Now; actObj.CntOnlineMinutes = 0; actObj.CurOnlineMinutes = 0; } } else { removeList.Add(kvp.Key); } } syncTable = true; if (flagCacheReset) { syncCacheReset = false; } for (int i = 0; i < removeList.Count; i++) { cacheActive.Remove(removeList[i]); } OnlineCore.LogoutOnline(removeList); } } catch (Exception ex) { SystemlogMgr.Error("GetCacheData", ex); } finally { lockCache.ExitWriteLock(); } } lock (lockWrite) { try { OnlineSqlHelper.UpdateActive(cacheTable); cacheTable.Clear(); syncTable = false; if (syncDBReset) { OnlineSqlHelper.ResetActive(OnlineConfig.PROCBatchSize); syncDBReset = false; } return(true); } catch (Exception ex) { SystemlogMgr.Error("UpdateActive", ex); return(false); } } }