/// <summary> /// Enqueues a list of push notifications on the database to be pushed when the processor runs. /// </summary> /// <param name="databaseContext">The database context used for saving.</param> /// <param name="pushNotifications">The list of push notifications on the database to be pushed when the processor runs</param> /// <returns>True if all OK, false if not.</returns> public bool EnqueueNotificationsOnDatabase(PushSharpDatabaseContext databaseContext, List<PushNotification> pushNotifications) { try { foreach (var pushNotification in pushNotifications) if (!EnqueueNotificationOnDatabase(databaseContext, pushNotification, false)) throw new Exception("INTERNAL EX. ERROR: Error on adding a single notification in EnqueueNotificationsOnDatabase method!"); databaseContext.SaveChanges(); databaseContext.Dispose(); return true; } catch (Exception ex) { On(DisplayErrorMessage, "EX. ERROR: Enqueuing notification, DB save failed: " + ex.Message); SimpleErrorLogger.LogError(ex); return false; } }
private void DisposeContext(PushSharpDatabaseContext ctx, bool disposeContext) { if (disposeContext) { ctx.Dispose(); ctx = null; _databaseContext = null; On(DisplayMessage, "Database context sucessfully disposed."); } }
/// <summary> /// Enqueues a single notification on the database. /// </summary> /// <param name="databaseContext">The database context used for saving.</param> /// <param name="pushNotification">A push notification to be saved for later processing.</param> /// <param name="saveAndDisposeContext"></param> /// <returns>True if all OK, false if not.</returns> public bool EnqueueNotificationOnDatabase(PushSharpDatabaseContext databaseContext, PushNotification pushNotification, bool saveAndDisposeContext = true) { try { databaseContext.PushNotification.Add(pushNotification); if (saveAndDisposeContext) { databaseContext.SaveChanges(); databaseContext.Dispose(); } return true; } catch (Exception ex) { On(DisplayErrorMessage, "EX. ERROR: Enqueuing notification, DB save failed: " + ex.Message); SimpleErrorLogger.LogError(ex); return false; } }