private static void GenerateMessages(IEnumerable <Subscription> subscriptions) { var configs = new Dictionary <string, NotificationConfig>(); using (var context = new DataHandler()) { foreach (var subscription in subscriptions) { // gather notification configs (handler: NotificationConfig.cs) for all related content of subscriptions GatherConfigsForSubscription(subscription, configs); // generate messges for content whose notification are controlled by a notification config var msgs = GenerateMessagesForConfig(subscription, configs); foreach (var message in msgs) { context.Messages.InsertOnSubmit(message); } // generate messages for content whose notification are NOT controlled by a notification config (send a generic notification message) var msg = GenerateMessage(subscription, configs); if (msg != null) { context.Messages.InsertOnSubmit(msg); } } context.SubmitChanges(); } }
private static bool InsertLock(double timeframe) { using (var context = new DataHandler()) { var success = false; var notifLock = new Synchronization { LockName = NOTIFICATIONLOCKNAME, Locked = true, ComputerName = Environment.MachineName, LockedUntil = DateTime.UtcNow.AddMinutes(timeframe), LockId = AppDomainId }; try { context.Synchronizations.InsertOnSubmit(notifLock); context.SubmitChanges(); success = true; } catch (Exception ex) { SnLog.WriteException(ex); } return(success); } }
public void Save() { using (var context = new DataHandler()) { var existing = context.Subscriptions.Where(x => x.ContentPath == this.ContentPath && x.UserPath == this.UserPath); var count = existing.Count(); if (count == 1) { // update var item = existing.First(); item.Active = this.Active; item.ContentPath = this.ContentPath; item.Frequency = this.Frequency; item.IsActive = this.IsActive; item.UserEmail = this.UserEmail; item.UserId = this.UserId; item.UserName = this.UserName; item.UserPath = this.UserPath; item.Language = this.Language; } else { if (count > 1) { context.Subscriptions.DeleteAllOnSubmit(existing); } context.Subscriptions.InsertOnSubmit(this); } context.SubmitChanges(); } }
private void Save() { using (var context = new DataHandler()) { context.Events.InsertOnSubmit(this); context.SubmitChanges(); } }
/// <summary> /// Inactivate all subscriptions of a user. /// </summary> /// <param name="subscriber">Subscriber user.</param> public static void InactivateSubscriptions(User subscriber) { using (var context = new DataHandler()) { foreach (var subscription in context.Subscriptions.Where(x => x.UserPath == subscriber.Path && x.Active == 1)) { subscription.IsActive = false; } context.SubmitChanges(); } }
/// <summary> /// Deletes all subscriptions that belong to users that reside in the provided subtree. /// </summary> /// <param name="path">Content Repository path of a container (Organizational unit or folder).</param> public static void UnSubscribeBySubscriberSubtree(string path) { using (var context = new DataHandler()) { var existing = context.Subscriptions.Where(x => x.UserPath.StartsWith(path + RepositoryPath.PathSeparator)); if (existing.Any()) { context.Subscriptions.DeleteAllOnSubmit(existing); context.SubmitChanges(); } } }
public static void UnSubscribeAll(User subscriber) { using (var context = new DataHandler()) { var existing = context.Subscriptions.Where(x => x.UserPath == subscriber.Path); if (existing.Any()) { context.Subscriptions.DeleteAllOnSubmit(existing); context.SubmitChanges(); } } }
public static void UnSubscribeFrom(Node target) { using (var context = new DataHandler()) { var existing = context.Subscriptions.Where( x => x.ContentPath == target.Path); if (existing.Count() > 0) { context.Subscriptions.DeleteAllOnSubmit(existing); context.SubmitChanges(); } } }
internal static void RefreshLock(double timeframe) { using (var context = new DataHandler()) { var notificationLock = context.Synchronizations.SingleOrDefault(lockItem => lockItem.LockName == NOTIFICATIONLOCKNAME); if (notificationLock == null) { throw new InvalidOperationException("Could not update the Notification lock, because it doesn't exist. (the lock must be present when RefreshLock is called.)"); } notificationLock.LockedUntil = DateTime.UtcNow.AddMinutes(timeframe); context.SubmitChanges(); } Debug.WriteLine("#Notification> ** lock refreshed"); }
internal static void ReleaseLock() { using (var context = new DataHandler()) { var notificationLock = context.Synchronizations.SingleOrDefault(lockItem => lockItem.LockName == NOTIFICATIONLOCKNAME); if (notificationLock == null) { //TODO: #notifB: ?? what is this? throw new Exception(); } notificationLock.Locked = false; context.SubmitChanges(); } Debug.WriteLine("#Notification> ** lock released"); }
private static void SetActivation(User subscriber, Node target, bool value) { using (var context = new DataHandler()) { var subscription = context.Subscriptions.FirstOrDefault(x => x.UserPath == subscriber.Path && x.ContentPath == target.Path && x.Active == (byte)(value ? 0 : 1)); if (subscription == null) { return; } subscription.IsActive = value; context.SubmitChanges(); } }
public static void ChangeSubscriberEmail(User subscriber) { if (subscriber == null) { throw new ArgumentNullException("subscriber"); } using (var context = new DataHandler()) { // collect all subscriptions for this user where the email is different foreach (var subscription in context.Subscriptions.Where(x => x.UserPath == subscriber.Path && x.UserEmail != subscriber.Email)) { subscription.UserEmail = subscriber.Email ?? string.Empty; } context.SubmitChanges(); } }
private static void ProcessQueuedMessages() { try { while (true) { using (var context = new DataHandler()) { try { var messages = GetMessagesToSend(context); if (messages.Count() == 0) { break; } foreach (var message in messages) { ProcessMessage(message, context); } } finally { context.SubmitChanges(); } } Debug.WriteLine("#Notification> End of iteration"); } } catch (Exception exception) { Debug.WriteLine("#Notification> Rootlevel Exception:" + exception.Message); SnLog.WriteException(exception); } finally { ProcessQueuedMessagesFinished(); } }
private static void GenerateMessages(Dictionary <int, List <Subscription> > groupedSubscriptions) { var configs = new Dictionary <string, NotificationConfig>(); using (var context = new DataHandler()) { foreach (var item in groupedSubscriptions) { foreach (var subscription in item.Value) { // gather notification configs (handler: NotificationConfig.cs) for all related content of subscriptions GatherConfigsForSubscription(subscription, configs); } var msg = GenerateMessage(item.Value, configs); if (msg != null) { context.Messages.InsertOnSubmit(msg); } context.SubmitChanges(); } } }
internal static void SetLastProcessTime(NotificationFrequency freq, DateTime lastTime) { using (var context = new DataHandler()) { var existingEntry = context.LastProcessTimes.FirstOrDefault(); if (existingEntry == null) { context.LastProcessTimes.InsertOnSubmit(GetDefaultInstance(freq, lastTime)); } else { SetValue(existingEntry, freq, lastTime); } context.SubmitChanges(); } switch (freq) { case NotificationFrequency.Daily: _nextDaily = null; break; case NotificationFrequency.Weekly: _nextWeekly = null; break; case NotificationFrequency.Monthly: _nextMonthly = null; break; } }