/// <summary> /// Closes the user learning session. /// </summary> /// <param name="last_entry">The last_entry.</param> /// <remarks>Documented by Dev08, 2008-09-05</remarks> public void CloseUserSession(int last_entry) { using (NpgsqlConnection con = PostgreSQLConn.CreateConnection(Parent.CurrentUser)) { using (NpgsqlCommand cmd = con.CreateCommand()) { cmd.CommandText = "UPDATE \"LearningSessions\" SET endtime=CURRENT_TIMESTAMP WHERE id=:id"; cmd.Parameters.Add("id", last_entry); PostgreSQLConn.ExecuteNonQuery(cmd, Parent.CurrentUser, false); //Following Statement does add the "RunningSession" = false to the current Statistic. PgSqlStatisticConnector connector = PgSqlStatisticConnector.GetInstance(Parent); connector.RunningSession = -1; } } }
/// <summary> /// Opens the user learning session. /// </summary> /// <param name="lm_id">The lm_id.</param> /// <remarks>Documented by Dev08, 2008-09-05</remarks> public int OpenUserSession(int lm_id) { using (NpgsqlConnection con = PostgreSQLConn.CreateConnection(Parent.CurrentUser)) { using (NpgsqlCommand cmd = con.CreateCommand()) { cmd.CommandText = "SELECT \"StartLearningSession\"(:usrid, :lmid, :pool, :b1, :b2, :b3, :b4, :b5, :b6, :b7, :b8, :b9, :b10)"; cmd.Parameters.Add("usrid", Parent.CurrentUser.Id); cmd.Parameters.Add("lmid", lm_id); int counter = 0; int cardsInBoxes = 0; BoxSizes boxContent = GetCurrentBoxContent(); foreach (int box in boxContent.Sizes) { if (counter == 0) { cmd.Parameters.Add("pool", box); ++counter; continue; } cmd.Parameters.Add("b" + Convert.ToString(counter++), box); cardsInBoxes += box; } int newSessionId = PostgreSQLConn.ExecuteScalar <int>(cmd, Parent.CurrentUser).Value; //Following Statement does add the "RunningSession" = true to the current Statistic. PgSqlStatisticConnector connector = PgSqlStatisticConnector.GetInstance(Parent); connector.RunningSession = newSessionId; return(newSessionId); } } }
/// <summary> /// Gets all learn sessions from a LM. /// </summary> /// <param name="lmId">The lm id.</param> /// <returns></returns> /// <remarks>Documented by Dev08, 2008-11-13</remarks> public List <int> GetLearnSessions(int lmId) { object learnSessionsCache = parent.CurrentUser.Cache[ObjectLifetimeIdentifier.GetIdentifier(CacheObject.StatisticsLearnSessions, lmId)]; PgSqlStatisticConnector c = PgSqlStatisticConnector.GetInstance(parent); //The data of GetLearnSession can be cached until a new session was created. if (runningSessionCopy == c.RunningSession && learnSessionsCache != null) { return(learnSessionsCache as List <int>); } //if cache is empty or the RunningSession has changed... using (NpgsqlConnection con = PostgreSQLConn.CreateConnection(parent.CurrentUser)) { using (NpgsqlCommand cmd = con.CreateCommand()) { cmd.CommandText = "SELECT id FROM \"LearningSessions\" WHERE lm_id = :lmId AND user_id=:uid ORDER BY endtime ASC"; cmd.Parameters.Add("lmId", lmId); cmd.Parameters.Add("uid", parent.CurrentUser.Id); List <int> output = new List <int>(); NpgsqlDataReader reader = PostgreSQLConn.ExecuteReader(cmd, parent.CurrentUser); while (reader.Read()) { object id = reader["id"]; int id_converted = Convert.ToInt32(id); output.Add(id_converted); } runningSessionCopy = c.RunningSession; //Save to Cache parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.StatisticsLearnSessions, lmId, Cache.DefaultStatisticValidationTime)] = output; return(output); } } }