public List<GameSessionMeta> QueryRunningGameSessions() { List<GameSessionMeta> SessionList = new List<GameSessionMeta>(); DataTable GameSessionsTable = DBManager.Instance.Query(Datastore.General, GetGameSessionsQueryStr()); if (GameSessionsTable.Rows.Count > 0) { foreach (DataRow row in GameSessionsTable.Rows) { GameSessionMeta GameSessionMetaRow = new GameSessionMeta() { RecordCreated = DateTime.UtcNow, RecordLastUpdateTime = DateTime.UtcNow, GameSessionId = row["Id"].ToString(), IP = row["IP"].ToString(), Port = Convert.ToInt32(row["Port"].ToString()), CreationTime = DateTime.Parse(row["CreationTime"].ToString()), SessionStarted = Convert.ToBoolean(row["SessionStarted"]), GameId = row["GameId"].ToString(), IsLocallyEmulated = Convert.ToBoolean(row["IsLocallyEmulated"]), LastUpdateTime = DateTime.Parse(row["LastUpdateTime"].ToString()), Major = Convert.ToInt32(row["Major"]), Minor = Convert.ToInt32(row["Minor"]), UsersCount = Convert.ToInt32(row["UsersCount"]), SessionTypeId = row["SessionTypeId"].ToString(), SessionTypeFriendly = row["SessionTypeFriendly"].ToString(), Status = Convert.ToInt32(row["Status"]), CurrentRanking = Convert.ToInt32(row["CurrentRanking"]), IsPartySession = Convert.ToBoolean(row["IsPartySession"]), InitiatorUserId = row["InitiatorUserId"].ToString(), IsHosted = Convert.ToBoolean(row["IsHosted"]), SessionMetadata = row["SessionMetadata"].ToString() }; SessionList.Add(GameSessionMetaRow); } } return SessionList; }
public void UpdateGameSessionMeta(List<GameSessionMeta> CurrentGameSessions, DateTime ProcessDate) { List<GameMonitoringConfig> games = Games.Instance.GetMonitoredGames(); //Logger.Instance.Info(String.Format("Beginning {0}", game.Title)); int RunningGameCounter = 0; //List<GameSessionUpdateInfo> CurrentRecords = QueryGameSessionMeta(ProcessDate); string query = String.Format("SELECT * FROM {0} WHERE DATE(recordCreated) = '{1}' AND Status <> 2;", GAME_SESSION_META_TABLE, ProcessDate.ToString("yyyy-MM-dd")); Logger.Instance.Info(query); //#if DEBUG // Debugger.Launch(); //#endif List<GameSessionMeta> GameSessionList = new List<GameSessionMeta>(); DataTable GameSessionMetaTable = DBManager.Instance.Query(Datastore.Monitoring, query); if (GameSessionMetaTable.Rows.Count > 0) { List<string> statements = new List<string>(); foreach (DataRow row in GameSessionMetaTable.Rows) { GameSessionMeta GameSessionMetaRow = new GameSessionMeta() { RecordCreated = DateTime.Parse(row["RecordCreated"].ToString()), RecordLastUpdateTime = DateTime.Parse(row["RecordLastUpdateTime"].ToString()), GameSessionId = row["GameSessionId"].ToString(), IP = row["IP"].ToString(), Port = Convert.ToInt32(row["Port"]), CreationTime = DateTime.Parse(row["CreationTime"].ToString()), SessionStarted = Convert.ToBoolean(row["SessionStarted"]), GameId = row["GameId"].ToString(), IsLocallyEmulated = Convert.ToBoolean(row["IsLocallyEmulated"]), LastUpdateTime = DateTime.Parse(row["LastUpdateTime"].ToString()), Major = Convert.ToInt32(row["Major"]), Minor = Convert.ToInt32(row["Minor"]), UsersCount = Convert.ToInt32(row["UsersCount"]), SessionTypeId = row["SessionTypeId"].ToString(), SessionTypeFriendly = row["SessionTypeFriendly"].ToString(), Status = Convert.ToInt32(row["Status"]), CurrentRanking = Convert.ToInt32(row["CurrentRanking"]), IsPartySession = Convert.ToBoolean(row["IsPartySession"]), InitiatorUserId = row["InitiatorUserId"].ToString(), IsHosted = Convert.ToBoolean(row["IsHosted"]), SessionMetadata = row["SessionMetadata"].ToString() }; string UpdateStatement = String.Format("UPDATE {0} SET RecordLastUpdateTime = '{1}', Status = {2}, IP = '{4}', Port = {5}, LastUpdateTime = '{6}', SessionStarted = {7} WHERE GameSessionId = '{3}'; ", GAME_SESSION_META_TABLE, DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"), GameSessionMetaRow.Status, GameSessionMetaRow.GameSessionId, GameSessionMetaRow.IP, GameSessionMetaRow.Port, GameSessionMetaRow.LastUpdateTime.ToString("yyyy-MM-dd HH:mm:ss"), (GameSessionMetaRow.SessionStarted == true) ? 1 : 0, GameSessionMetaRow.GameId); //Logger.Instance.Info(UpdateStatement); statements.Add(UpdateStatement); CurrentGameSessions.Remove(GameSessionMetaRow); RunningGameCounter++; } try { Logger.Instance.Info(String.Format("updating {0} statements in {1} batches", statements.Count, statements.Count / 100)); foreach (List<string> updateBatch in statements.Batch<string>(1000)) { MoniverseResponse response = new MoniverseResponse() { Status = "unsent", TimeStamp = DateTime.UtcNow }; lock (MoniverseBase.ConsoleWriterLock) { Console.ForegroundColor = ConsoleColor.Cyan; Logger.Instance.Info("-----------------------------------------------"); Logger.Instance.Info("Beginning Update of Active Sessions (All Games)"); Logger.Instance.Info("-----------------------------------------------"); Logger.Instance.Info(""); } GameSessions.Service(Service => { Service.Update(new UpdateRequest() { TaskName = "UpdateGameSessionMeta Update", Task = updateBatch, TimeStamp = DateTime.UtcNow }); }); //int result = DBManager.Instance.Update(Datastore.Monitoring, statements); lock (MoniverseBase.ConsoleWriterLock) { Console.ForegroundColor = ConsoleColor.Green; Logger.Instance.Info("--------------------------------------"); Logger.Instance.Info("Active Game Session Update Batch Success"); Logger.Instance.Info("--------------------------------------"); Console.ResetColor(); } } } catch (Exception e) { Console.ForegroundColor = ConsoleColor.Red; Logger.Instance.Info(e.Message); Console.ResetColor(); } } }
public List<GameSessionMeta> QueryGameSessionMeta(DateTime ProcessDate) { string query = String.Format("SELECT * FROM {0} WHERE recordCreated = '{1}';", GAME_SESSION_META_TABLE, ProcessDate.ToString("yyyy-MM-dd HH:mm:ss")); List<GameSessionMeta> GameSessionList = new List<GameSessionMeta>(); DataTable GameSessionMetaTable = new DataTable(); try { GameSessionMetaTable = DBManager.Instance.Query(Datastore.Monitoring, query); } catch (Exception ex) { Logger.Instance.Exception(ex.Message, ex.StackTrace); //throw; } if (GameSessionMetaTable.Rows.Count > 0) { foreach (DataRow row in GameSessionMetaTable.Rows) { GameSessionMeta GameSessionMetaRow = new GameSessionMeta() { RecordCreated = DateTime.Parse(row["RecordCreated"].ToString()), RecordLastUpdateTime = DateTime.Parse(row["RecordLastUpdateTime"].ToString()), GameSessionId = row["Id"].ToString(), IP = row["IP"].ToString(), Port = Convert.ToInt32(row["Port"]), CreationTime = DateTime.Parse(row["CreationTime"].ToString()), SessionStarted = (bool)row["SessionStarted"], GameId = row["GameId"].ToString(), IsLocallyEmulated = (bool)row["IsLocallyEmulated"], LastUpdateTime = DateTime.Parse(row["LastUpdateTime"].ToString()), Major = Convert.ToInt32(row["Major"]), Minor = Convert.ToInt32(row["Minor"]), UsersCount = Convert.ToInt32(row["UsersCount"]), SessionTypeId = row["SessionTypeId"].ToString(), SessionTypeFriendly = row["SessionTypeFriendly"].ToString(), Status = Convert.ToInt32(row["Status"]), CurrentRanking = Convert.ToInt32(row["CurrentRanking"]), IsPartySession = (bool)row["IsPartySession"], InitiatorUserId = row["InitiatorUserId"].ToString(), IsHosted = (bool)row["IsHosted"], SessionMetadata = row["SessionMetadata"].ToString() }; GameSessionList.Add(GameSessionMetaRow); } } return GameSessionList; }