/// <summary> /// Helper method to create a new session /// </summary> /// <param name="serverInfoService">service to get info from an A3 server</param> /// <param name="sessionDAO">DAO for sessions</param> /// <param name="host">A3 server host</param> /// <param name="port">A3 server port</param> /// <param name="inGame">Boolean to check if the server is currently in game</param> /// <returns>The new session</returns> private Session SetUpSession(ServerInfoService serverInfoService, SessionDAO sessionDAO, string host, int port, ref bool inGame) { Session returnSession = null; // initial info grab ServerInfo serverInfo = serverInfoService.GetServerInfo(host, port); inGame = CheckServerRunningState(serverInfo.ServerState); if (inGame) { // create a session Session session = new Session(); session.HostName = serverInfo.HostName; session.Version = serverInfo.GameVersion; session.MaxPing = serverInfo.Ping; session.MinPing = serverInfo.Ping; session.MaxPlayers = serverInfo.NumPlayers; session = sessionDAO.CreateSession(session); returnSession = session; } return(returnSession); }
public ActionResult insertSchedule(FormCollection formCollection) { foreach (string key in formCollection.AllKeys) { Response.Write("Key + " + key + " "); Response.Write(formCollection[key] + "</br>"); } DateTime StartTime = Convert.ToDateTime(formCollection["StartTime"]); DateTime EndTime = Convert.ToDateTime(formCollection["EndTime"]); DateTime Sche_Date = Convert.ToDateTime(formCollection["Sche_Date"]); SessionDAO sesDAO = new SessionDAO(); Session session = sesDAO.getSessionByTime(StartTime, EndTime); int id_Ses = -1; if (session == null) { id_Ses = sesDAO.createSession(StartTime, EndTime); } else { id_Ses = session.id_Ses; } int id_F = Convert.ToInt32(formCollection["id_F"]); ScheduleDAO scheDAO = new ScheduleDAO(); scheDAO.createSchedule(id_Ses, Sche_Date, id_F); return(View()); }
/// <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 async Task <IActionResult> Session(string sessionId) { using (var sessionDAO = new SessionDAO()) { var result = await sessionDAO.Context.Session .Include(x => x.UsernameNavigation) .FirstOrDefaultAsync(x => x.SessionId == sessionId); if (result == null) { return(Json(null)); } return(await Index(result.UsernameNavigation.Username, result.UsernameNavigation.Password)); } }
public async Task <IActionResult> UserProductOrder() { //find username with session Id using (var sessionDAO = new SessionDAO()) { var foundUsername = (await sessionDAO.Read(this.SessionId(), false)).Username; using (var onlineOrderDAO = new OnlineOrderProductDAO(sessionDAO.Context)) { var result = onlineOrderDAO.Context.OnlineOrder .Include(x => x.Status) .Include(x => x.OnlineOrderProduct) .Where(x => x.Username == foundUsername) .Select(x => new { onlineOrderId = x.OnlineOrderId, lastName = x.LastName, firstName = x.FirstName, address = x.Address, postCode = x.PostCode, city = x.City, phoneNo = x.PhoneNo, email = x.Email, date = x.Date, statusId = x.StatusId, statusName = x.Status.Name, statusDescription = x.Status.Description, products = x.OnlineOrderProduct.Select(y => new { productId = y.ProductId, quantity = y.Quantity }) }) .ToArray(); return(Json(result)); } } }
/// <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> Retrieves Entity rows in a datatable which match the specified filter. It will always create a new connection to the database.</summary> /// <param name="selectFilter">A predicate or predicate expression which should be used as filter for the entities to retrieve.</param> /// <param name="maxNumberOfItemsToReturn"> The maximum number of items to return with this retrieval query.</param> /// <param name="sortClauses">The order by specifications for the sorting of the resultset. When not specified, no sorting is applied.</param> /// <param name="relations">The set of relations to walk to construct to total query.</param> /// <param name="pageNumber">The page number to retrieve.</param> /// <param name="pageSize">The page size of the page to retrieve.</param> /// <returns>DataTable with the rows requested.</returns> public static DataTable GetMultiAsDataTable(IPredicate selectFilter, long maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relations, int pageNumber, int pageSize) { SessionDAO dao = DAOFactory.CreateSessionDAO(); return(dao.GetMultiAsDataTable(maxNumberOfItemsToReturn, sortClauses, selectFilter, relations, pageNumber, pageSize)); }