/// <summary> /// Checks if it is time to activate the snooze mode. /// </summary> /// <param name="options">The snooze options.</param> /// <returns>True, if the snooze mode should be activated, else false.</returns> /// <remarks>Documented by Dev02, 2008-05-06</remarks> internal bool CheckSnooze(ISnoozeOptions options) { if (CheckOptionsChanged(options)) { ResetSnoozeValues(); } if (options.SnoozeMode == ESnoozeMode.SendToTray || options.SnoozeMode == ESnoozeMode.QuitProgram) { //calculate differential values since last snooze TimeSpan time = new TimeSpan(); int cards = 0; int rights = 0; foreach (StackCard card in this) { if (lastSnoozeCard != null && card == lastSnoozeCard) { break; } time += card.Duration; cards++; if (card.Promoted) { rights += card.CardPoints; } } //compare with settings if ((options.IsTimeEnabled.GetValueOrDefault() && time.Minutes >= options.SnoozeTime.GetValueOrDefault()) || (options.IsCardsEnabled.GetValueOrDefault() && cards >= options.SnoozeCards.GetValueOrDefault()) || (options.IsRightsEnabled.GetValueOrDefault() && rights >= options.SnoozeRights.GetValueOrDefault())) { lastSnoozeCard = this.Peek(); //set snooze card return(true); } } return(false); }
/// <summary> /// Checks the options changed. /// </summary> /// <param name="options">The options.</param> /// <returns></returns> /// <remarks>Documented by Dev02, 2009-04-09</remarks> private bool CheckOptionsChanged(ISnoozeOptions options) { bool changed = false; if (previousOptions != null) { if (!Methods.IsEqual <bool?>(options.IsCardsEnabled, previousOptions.IsCardsEnabled) || !Methods.IsEqual <bool?>(options.IsRightsEnabled, previousOptions.IsRightsEnabled) || !Methods.IsEqual <bool?>(options.IsTimeEnabled, previousOptions.IsTimeEnabled)) { changed = true; } if (!Methods.IsEqual <int?>(options.SnoozeCards, previousOptions.SnoozeCards) || !Methods.IsEqual <int?>(options.SnoozeHigh, previousOptions.SnoozeHigh) || !Methods.IsEqual <int?>(options.SnoozeLow, previousOptions.SnoozeLow) || !Methods.IsEqual <ESnoozeMode?>(options.SnoozeMode, previousOptions.SnoozeMode) || !Methods.IsEqual <int?>(options.SnoozeRights, previousOptions.SnoozeRights) || !Methods.IsEqual <int?>(options.SnoozeTime, previousOptions.SnoozeTime)) { changed = true; } } foreach (PropertyInfo property in typeof(ISnoozeOptions).GetProperties()) { if (property.CanRead && property.CanWrite) { object obj = property.GetValue(options, null); if (obj != null) { property.SetValue(previousOptions, obj, null); } } } return(changed); }
public SnoozeOptions(ISnoozeOptions defaultSettings, ISnoozeOptions userSettings) { this.defaultSettings = defaultSettings; this.userSettings = userSettings; }
/// <summary> /// Sets the snooze options. /// </summary> /// <param name="id">The id.</param> /// <param name="SnoozeOptions">The snooze options.</param> /// <remarks>Documented by Dev11, 2008-08-14</remarks> public void SetSnoozeOptions(int id, ISnoozeOptions SnoozeOptions) { using (NpgsqlConnection con = PostgreSQLConn.CreateConnection(Parent.CurrentUser)) { using (NpgsqlCommand cmd = con.CreateCommand()) { cmd.CommandText = "SELECT snooze_options FROM \"Settings\" WHERE id=:id"; cmd.Parameters.Add("id", id); int soid = Convert.ToInt32(PostgreSQLConn.ExecuteScalar(cmd, Parent.CurrentUser)); if (soid > 0) { using (NpgsqlCommand cmd2 = con.CreateCommand()) { cmd2.CommandText = "UPDATE \"SnoozeOptions\" SET " + "cards_enabled=:c_e, rights_enabled=:r_e, time_enabled=:t_e, snooze_cards=:s_c, snooze_hight=:s_h, snooze_low=:s_l, " + "snooze_mode=:s_m, snooze_rights=:s_r, snooze_time=:s_t WHERE id=:id"; cmd2.Parameters.Add("id", soid); cmd2.Parameters.Add("c_e", SnoozeOptions.IsCardsEnabled); cmd2.Parameters.Add("r_e", SnoozeOptions.IsRightsEnabled); cmd2.Parameters.Add("t_e", SnoozeOptions.IsTimeEnabled); cmd2.Parameters.Add("s_c", SnoozeOptions.SnoozeCards); cmd2.Parameters.Add("s_h", SnoozeOptions.SnoozeHigh); cmd2.Parameters.Add("s_l", SnoozeOptions.SnoozeLow); cmd2.Parameters.Add("s_m", SnoozeOptions.SnoozeMode); cmd2.Parameters.Add("s_r", SnoozeOptions.SnoozeRights); cmd2.Parameters.Add("s_t", SnoozeOptions.SnoozeTime); PostgreSQLConn.ExecuteNonQuery(cmd2, Parent.CurrentUser); //Save to Cache Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsSnoozeOptionsFk, id, Cache.DefaultSettingsValidationTime)] = soid; Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsSnoozeCardsEnabled, soid, Cache.DefaultSettingsValidationTime)] = SnoozeOptions.IsCardsEnabled; Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsSnoozeRightsEnabled, soid, Cache.DefaultSettingsValidationTime)] = SnoozeOptions.IsRightsEnabled; Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsSnoozeTimeEnabled, soid, Cache.DefaultSettingsValidationTime)] = SnoozeOptions.IsTimeEnabled; Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsSnoozeCards, soid, Cache.DefaultSettingsValidationTime)] = SnoozeOptions.SnoozeCards; Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsSnoozeHigh, soid, Cache.DefaultSettingsValidationTime)] = SnoozeOptions.SnoozeHigh; Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsSnoozeLow, soid, Cache.DefaultSettingsValidationTime)] = SnoozeOptions.SnoozeLow; Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsSnoozeMode, soid, Cache.DefaultSettingsValidationTime)] = SnoozeOptions.SnoozeMode; Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsSnoozeRights, soid, Cache.DefaultSettingsValidationTime)] = SnoozeOptions.SnoozeRights; Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsSnoozeTime, soid, Cache.DefaultSettingsValidationTime)] = SnoozeOptions.SnoozeTime; } } else { using (NpgsqlCommand cmd3 = con.CreateCommand()) { cmd3.CommandText = "INSERT INTO \"SnoozeOptions\" " + "(cards_enabled, rights_enabled, time_enabled, snooze_cards, snooze_hight, snooze_low, snooze_mode, snooze_rights, snooze_time) VALUES " + "(:c_e, :r_e, :t_e, :s_c, :s_h, :s_l, :s_m, :s_r, :s_t); UPDATE \"Settings\" SET snooze_options=currval('\"SnoozeOptions_id_seq\"') WHERE id=:id; " + "SELECT snooze_options FROM \"Settings\" WHERE id=:id"; cmd3.Parameters.Add("id", id); cmd3.Parameters.Add("c_e", SnoozeOptions.IsCardsEnabled); cmd3.Parameters.Add("r_e", SnoozeOptions.IsRightsEnabled); cmd3.Parameters.Add("t_e", SnoozeOptions.IsTimeEnabled); cmd3.Parameters.Add("s_c", SnoozeOptions.SnoozeCards); cmd3.Parameters.Add("s_h", SnoozeOptions.SnoozeHigh); cmd3.Parameters.Add("s_l", SnoozeOptions.SnoozeLow); cmd3.Parameters.Add("s_m", SnoozeOptions.SnoozeMode); cmd3.Parameters.Add("s_r", SnoozeOptions.SnoozeRights); cmd3.Parameters.Add("s_t", SnoozeOptions.SnoozeTime); //PostgreSQLConn.ExecuteNonQuery(cmd3); int? snoozeOptionsId = PostgreSQLConn.ExecuteScalar<int>(cmd3, Parent.CurrentUser); //Save to Cache Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsSnoozeOptionsFk, id, Cache.DefaultSettingsValidationTime)] = snoozeOptionsId.Value; Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsSnoozeCardsEnabled, snoozeOptionsId.Value, Cache.DefaultSettingsValidationTime)] = SnoozeOptions.IsCardsEnabled; Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsSnoozeRightsEnabled, snoozeOptionsId.Value, Cache.DefaultSettingsValidationTime)] = SnoozeOptions.IsRightsEnabled; Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsSnoozeTimeEnabled, snoozeOptionsId.Value, Cache.DefaultSettingsValidationTime)] = SnoozeOptions.IsTimeEnabled; Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsSnoozeCards, snoozeOptionsId.Value, Cache.DefaultSettingsValidationTime)] = SnoozeOptions.SnoozeCards; Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsSnoozeHigh, snoozeOptionsId.Value, Cache.DefaultSettingsValidationTime)] = SnoozeOptions.SnoozeHigh; Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsSnoozeLow, snoozeOptionsId.Value, Cache.DefaultSettingsValidationTime)] = SnoozeOptions.SnoozeLow; Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsSnoozeMode, snoozeOptionsId.Value, Cache.DefaultSettingsValidationTime)] = SnoozeOptions.SnoozeMode; Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsSnoozeRights, snoozeOptionsId.Value, Cache.DefaultSettingsValidationTime)] = SnoozeOptions.SnoozeRights; Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsSnoozeTime, snoozeOptionsId.Value, Cache.DefaultSettingsValidationTime)] = SnoozeOptions.SnoozeTime; } } } } }
public SnoozeOptions(ISnoozeOptions defaultSettings, ISnoozeOptions userSettings) { this.defaultSettings = defaultSettings; this.userSettings = userSettings; }
/// <summary> /// Sets the snooze options. /// </summary> /// <param name="id">The id.</param> /// <param name="SnoozeOptions">The snooze options.</param> /// <remarks>Documented by Dev05, 2009-01-15</remarks> public void SetSnoozeOptions(int id, ISnoozeOptions SnoozeOptions) { SqlCeCommand cmd = MSSQLCEConn.CreateCommand(Parent.CurrentUser); cmd.CommandText = "SELECT snooze_options FROM \"Settings\" WHERE id=@id"; cmd.Parameters.Add("@id", id); int soid = Convert.ToInt32(MSSQLCEConn.ExecuteScalar(cmd)); if (soid > 0) { SqlCeCommand cmd2 = MSSQLCEConn.CreateCommand(Parent.CurrentUser); cmd2.CommandText = "UPDATE \"SnoozeOptions\" SET " + "cards_enabled=@c_e, rights_enabled=@r_e, time_enabled=@t_e, snooze_cards=@s_c, snooze_hight=@s_h, snooze_low=@s_l, " + "snooze_mode=@s_m, snooze_rights=@s_r, snooze_time=@s_t WHERE id=@id"; cmd2.Parameters.Add("@id", soid); cmd2.Parameters.Add("@c_e", SnoozeOptions.IsCardsEnabled); cmd2.Parameters.Add("@r_e", SnoozeOptions.IsRightsEnabled); cmd2.Parameters.Add("@t_e", SnoozeOptions.IsTimeEnabled); cmd2.Parameters.Add("@s_c", SnoozeOptions.SnoozeCards); cmd2.Parameters.Add("@s_h", SnoozeOptions.SnoozeHigh); cmd2.Parameters.Add("@s_l", SnoozeOptions.SnoozeLow); cmd2.Parameters.Add("@s_m", SnoozeOptions.SnoozeMode); cmd2.Parameters.Add("@s_r", SnoozeOptions.SnoozeRights); cmd2.Parameters.Add("@s_t", SnoozeOptions.SnoozeTime); MSSQLCEConn.ExecuteNonQuery(cmd2); //Save to Cache Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsSnoozeOptionsFk, id, Cache.DefaultSettingsValidationTime)] = soid; Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsSnoozeCardsEnabled, soid, Cache.DefaultSettingsValidationTime)] = SnoozeOptions.IsCardsEnabled; Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsSnoozeRightsEnabled, soid, Cache.DefaultSettingsValidationTime)] = SnoozeOptions.IsRightsEnabled; Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsSnoozeTimeEnabled, soid, Cache.DefaultSettingsValidationTime)] = SnoozeOptions.IsTimeEnabled; Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsSnoozeCards, soid, Cache.DefaultSettingsValidationTime)] = SnoozeOptions.SnoozeCards; Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsSnoozeHigh, soid, Cache.DefaultSettingsValidationTime)] = SnoozeOptions.SnoozeHigh; Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsSnoozeLow, soid, Cache.DefaultSettingsValidationTime)] = SnoozeOptions.SnoozeLow; Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsSnoozeMode, soid, Cache.DefaultSettingsValidationTime)] = SnoozeOptions.SnoozeMode; Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsSnoozeRights, soid, Cache.DefaultSettingsValidationTime)] = SnoozeOptions.SnoozeRights; Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsSnoozeTime, soid, Cache.DefaultSettingsValidationTime)] = SnoozeOptions.SnoozeTime; } else { SqlCeCommand cmd3 = MSSQLCEConn.CreateCommand(Parent.CurrentUser); cmd3.CommandText = "INSERT INTO \"SnoozeOptions\" " + "(cards_enabled, rights_enabled, time_enabled, snooze_cards, snooze_hight, snooze_low, snooze_mode, snooze_rights, snooze_time) VALUES " + "(@c_e, @r_e, @t_e, @s_c, @s_h, @s_l, @s_m, @s_r, @s_t); UPDATE \"Settings\" SET snooze_options=@@IDENTITY WHERE id=@id; " + "SELECT snooze_options FROM \"Settings\" WHERE id=@id"; cmd3.Parameters.Add("@id", id); cmd3.Parameters.Add("@c_e", SnoozeOptions.IsCardsEnabled); cmd3.Parameters.Add("@r_e", SnoozeOptions.IsRightsEnabled); cmd3.Parameters.Add("@t_e", SnoozeOptions.IsTimeEnabled); cmd3.Parameters.Add("@s_c", SnoozeOptions.SnoozeCards); cmd3.Parameters.Add("@s_h", SnoozeOptions.SnoozeHigh); cmd3.Parameters.Add("@s_l", SnoozeOptions.SnoozeLow); cmd3.Parameters.Add("@s_m", SnoozeOptions.SnoozeMode); cmd3.Parameters.Add("@s_r", SnoozeOptions.SnoozeRights); cmd3.Parameters.Add("@s_t", SnoozeOptions.SnoozeTime); //MSSQLCEConn.ExecuteNonQuery(cmd3); int? snoozeOptionsId = MSSQLCEConn.ExecuteScalar<int>(cmd3); //Save to Cache Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsSnoozeOptionsFk, id, Cache.DefaultSettingsValidationTime)] = snoozeOptionsId.Value; Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsSnoozeCardsEnabled, snoozeOptionsId.Value, Cache.DefaultSettingsValidationTime)] = SnoozeOptions.IsCardsEnabled; Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsSnoozeRightsEnabled, snoozeOptionsId.Value, Cache.DefaultSettingsValidationTime)] = SnoozeOptions.IsRightsEnabled; Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsSnoozeTimeEnabled, snoozeOptionsId.Value, Cache.DefaultSettingsValidationTime)] = SnoozeOptions.IsTimeEnabled; Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsSnoozeCards, snoozeOptionsId.Value, Cache.DefaultSettingsValidationTime)] = SnoozeOptions.SnoozeCards; Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsSnoozeHigh, snoozeOptionsId.Value, Cache.DefaultSettingsValidationTime)] = SnoozeOptions.SnoozeHigh; Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsSnoozeLow, snoozeOptionsId.Value, Cache.DefaultSettingsValidationTime)] = SnoozeOptions.SnoozeLow; Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsSnoozeMode, snoozeOptionsId.Value, Cache.DefaultSettingsValidationTime)] = SnoozeOptions.SnoozeMode; Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsSnoozeRights, snoozeOptionsId.Value, Cache.DefaultSettingsValidationTime)] = SnoozeOptions.SnoozeRights; Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsSnoozeTime, snoozeOptionsId.Value, Cache.DefaultSettingsValidationTime)] = SnoozeOptions.SnoozeTime; } }