/// <summary> /// Build DAOs if we need to build DAOs /// </summary> /// <param name="connection">the current <see cref="MySqlConnection"/></param> /// <param name="playerDAO">DAO for <see cref="Player"/>s</param> /// <param name="missionDAO">DAO for <see cref="Mission"/>s</param> /// <param name="sessionDAO">DAO for <see cref="Session"/>s</param> private void BuildDAOsIfNeeded(ref MySqlConnection connection, ref PlayerDAO playerDAO, ref MissionDAO missionDAO, ref SessionDAO sessionDAO) { if (connection == null || connection.State == ConnectionState.Closed) { connection = DatabaseUtil.OpenDataSource(); playerDAO = new PlayerDAO(connection); missionDAO = new MissionDAO(connection); sessionDAO = new SessionDAO(connection); } }
public int CreerMission(string mission, out string msgerr) { int nbAjout = 0; msgerr = ""; Mission uneMission = new Mission(mission); try { nbAjout = MissionDAO.GetInstance().AjoutMission(uneMission); } catch (SqlException err) { msgerr = "ERREUR requête SQL : " + err.Message; } catch (Exception err) { msgerr = "ERREUR GRAVE : " + err.Message; } return(nbAjout); }
public List <Mission> GetMission() { return(MissionDAO.GetInstance().GetMission()); }
/// <summary> /// Begins reporting on a session, should handle DAOs here /// </summary> public void StartReporting() { // define DAO objects to interact with databases MySqlConnection connection = null; PlayerDAO playerDAO = null; MissionDAO missionDAO = null; SessionDAO sessionDAO = null; try { // create DAO objects to interact with databases BuildDAOsIfNeeded(ref connection, ref playerDAO, ref missionDAO, ref sessionDAO); ServerInfoService serverInfoService = new ServerInfoService(); // variables needed to track session playthough Session session = null; MissionSession currentMissionSession = null; ISet <PlayerMissionSession> currentPlayersToMissionSession = new HashSet <PlayerMissionSession>(); int missionCount = 0; bool inGame = false; Stopwatch runTime = new Stopwatch(); runTime.Start(); try { while (session == null && CheckTimeThreshold(runTime.ElapsedMilliseconds)) { try { _logger.Debug("Trying to set up session"); session = SetUpSession(serverInfoService, sessionDAO, Settings.Default.armaServerAddress, Settings.Default.armaServerPort, ref inGame); } catch (MySqlException e) { _logger.Error("Problem setting up session: ", e); BuildDAOsIfNeeded(ref connection, ref playerDAO, ref missionDAO, ref sessionDAO); } Thread.Sleep(Settings.Default.pollRate); } while (CheckMissionThreshold(missionCount, inGame) && CheckTimeThreshold(runTime.ElapsedMilliseconds)) { try { _logger.Debug("Trying to update session details"); ServerInfo serverInfo = serverInfoService.GetServerInfo(Settings.Default.armaServerAddress, Settings.Default.armaServerPort); inGame = CheckServerRunningState(serverInfo.ServerState); if (inGame) { if (session.MaxPing < serverInfo.Ping) { session.MaxPing = serverInfo.Ping; } else if (session.MinPing > serverInfo.Ping) { session.MinPing = serverInfo.Ping; } if (session.MaxPlayers < serverInfo.Players.Count) { session.MaxPlayers = serverInfo.Players.Count; } MissionSession missionSession = missionDAO.GetOrCreateMissionSession(serverInfo.MapName, serverInfo.Mission, session); if (currentMissionSession != null && currentMissionSession.Id != missionSession.Id) // handle case where missions changed between polls { sessionDAO.UpdateSession(session); missionDAO.UpdateMissionSession(currentMissionSession); playerDAO.UpdatePlayerMissionSessions(currentPlayersToMissionSession); currentPlayersToMissionSession.Clear(); } missionSession.Length += (Settings.Default.pollRate / 1000); if (missionSession.Played == false && CheckPlayedThreshold(missionSession.Length)) { missionSession.Played = true; missionCount++; } currentMissionSession = missionSession; ISet <PlayerMissionSession> playersToMissionSession = playerDAO.GetOrCreatePlayerMissionSessions(serverInfo.Players, missionSession); foreach (PlayerMissionSession playerToMissionSession in playersToMissionSession) { playerToMissionSession.Length += (Settings.Default.pollRate / 1000); if (playerToMissionSession.Played == false && CheckPlayedThreshold(playerToMissionSession.Length)) { playerToMissionSession.Played = true; } } currentPlayersToMissionSession.UnionWith(playersToMissionSession); } else if (currentMissionSession != null) { sessionDAO.UpdateSession(session); missionDAO.UpdateMissionSession(currentMissionSession); playerDAO.UpdatePlayerMissionSessions(currentPlayersToMissionSession); currentMissionSession = null; currentPlayersToMissionSession.Clear(); } } catch (MySqlException e) { _logger.Error("Problem updating session details: ", e); BuildDAOsIfNeeded(ref connection, ref playerDAO, ref missionDAO, ref sessionDAO); } Thread.Sleep(Settings.Default.pollRate); } } catch (NoServerInfoException nsie) { _logger.Error("Error reporting", nsie); } } finally { // Ensure disposable objects are disposed if (playerDAO != null) { playerDAO.Dispose(); } if (missionDAO != null) { missionDAO.Dispose(); } if (sessionDAO != null) { sessionDAO.Dispose(); } if (connection != null) { connection.Dispose(); } } }
/// <summary> /// Helper method to update the session info /// </summary> /// <param name="serverInfoService">service to get info from an A3 server</param> /// <param name="sessionDAO">DAO for <see cref="Session"/>s</param> /// <param name="playerDAO">DAO for <see cref="Player"/>s</param> /// <param name="missionDAO">DAO for <see cref="Mission"/>s</param> /// <param name="host">A3 server host</param> /// <param name="port">A3 server port</param> /// <param name="session">The current game <see cref="Session"/></param> /// <param name="missionCount">The number of missions played</param> /// <param name="inGame">Boolean to check if the server is currently in game</param> /// <returns>The current mission session</returns> private Session UpdateInfo(ServerInfoService serverInfoService, SessionDAO sessionDAO, PlayerDAO playerDAO, MissionDAO missionDAO, string host, int port, Session session, ref int missionCount, ref bool inGame) { return(session); }
/// <summary> /// Build DAOs if we need to build DAOs /// </summary> /// <param name="connection">the current <see cref="MySqlConnection"/></param> /// <param name="playerDAO">DAO for <see cref="Player"/>s</param> /// <param name="missionDAO">DAO for <see cref="Mission"/>s</param> /// <param name="sessionDAO">DAO for <see cref="Session"/>s</param> /// <param name="pstmsDAO">DAO for <see cref="PlayerSessionToMissionSession"/>s</param> private void BuildDAOsIfNeeded(ref MySqlConnection connection, ref PlayerDAO playerDAO, ref MissionDAO missionDAO, ref SessionDAO sessionDAO, ref PlayerSessionToMissionSessionDAO pstmsDAO) { if (connection == null || connection.State == ConnectionState.Closed) { connection = DatabaseUtil.OpenDataSource(); playerDAO = new PlayerDAO(connection); missionDAO = new MissionDAO(connection); sessionDAO = new SessionDAO(connection); pstmsDAO = new PlayerSessionToMissionSessionDAO(connection); } }
/// <summary> /// Helper method to update <see cref="Mission"/> data in the database /// </summary> /// <param name="missionDAO">DAO for <see cref="Mission"/>s</param> /// <param name="session">The current game <see cref="Session"/></param> /// <param name="serverInfo">The current <see cref="ServerInfo"/></param> /// <param name="missionCount">The number of missions played</param> /// <returns>The current <see cref="MissionSession"/></returns> private MissionSession UpdateMissionData(MissionDAO missionDAO, Session session, ServerInfo serverInfo, ref int missionCount) { MissionSession missionSession = missionDAO.GetOrCreateMissionSession(serverInfo.MapName, serverInfo.Mission, session); missionSession.Updated = true; missionSession.Length += (Settings.Default.pollRate / 1000); if (missionSession.Played == false && CheckPlayedThreshold(missionSession.Length)) { missionSession.Played = true; missionCount++; } missionDAO.UpdateMissionSession(missionSession); return missionSession; }
/// <summary> /// Helper method to update the session info /// </summary> /// <param name="serverInfoService">service to get info from an A3 server</param> /// <param name="sessionDAO">DAO for <see cref="Session"/>s</param> /// <param name="playerDAO">DAO for <see cref="Player"/>s</param> /// <param name="missionDAO">DAO for <see cref="Mission"/>s</param> /// <param name="pstmsDAO">DAO for <see cref="PlayerSessionToMissionSession"/>s</param> /// <param name="host">A3 server host</param> /// <param name="port">A3 server port</param> /// <param name="session">The current game <see cref="Session"/></param> /// <param name="missionCount">The number of missions played</param> /// <param name="inGame">Boolean to check if the server is currently in game</param> /// <returns>The current mission session</returns> private Session UpdateInfo(ServerInfoService serverInfoService, SessionDAO sessionDAO, PlayerDAO playerDAO, MissionDAO missionDAO, PlayerSessionToMissionSessionDAO pstmsDAO, string host, int port, Session session, ref int missionCount, ref bool inGame) { ServerInfo serverInfo = serverInfoService.GetServerInfo(host, port); inGame = CheckServerRunningState(serverInfo.ServerState); if (inGame) { UpdateSessionData(sessionDAO, session, serverInfo); MissionSession missionSession = UpdateMissionData(missionDAO, session, serverInfo, ref missionCount); ISet<PlayerSession> playerSessions = UpdatePlayerData(playerDAO, session, serverInfo, missionSession); UpdatePTSTMTSData(pstmsDAO, missionSession, playerSessions); } return session; }