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.Now.AddMinutes(timeframe), LockId = AppDomainId }; try { context.Synchronizations.InsertOnSubmit(notifLock); context.SubmitChanges(); success = true; } catch (Exception ex) { Logger.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 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(); } }
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 static void ClearMessages() { using (var context = new DataHandler()) { context.Messages.DeleteAllOnSubmit(context.Messages); context.SubmitChanges(); } }
private void Save() { using (var context = new DataHandler()) { context.Events.InsertOnSubmit(this); 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.Count() > 0) { 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 ReleaseLock() { using (var context = new DataHandler()) { var notificationLock = context.Synchronizations.SingleOrDefault(lockItem => lockItem.LockName == NOTIFICATIONLOCKNAME); if (notificationLock == null) { throw new Exception(); //TODO: #notifB: ?? what is this? } notificationLock.Locked = false; context.SubmitChanges(); } Debug.WriteLine("#Notification> ** lock released"); }
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.Now.AddMinutes(timeframe); context.SubmitChanges(); } Debug.WriteLine("#Notification> ** lock refreshed"); }
private static void SetActivation(User subscriber, Node target, bool value) { using (var context = new DataHandler()) { var subscription = context.Subscriptions.Where(x => x.UserPath == subscriber.Path && x.ContentPath == target.Path && x.Active == (byte)(value ? 0 : 1)).FirstOrDefault(); if (subscription == null) { return; } subscription.IsActive = value; context.SubmitChanges(); } }
private static void InsertMessages(int from, int to) { using (var context = new DataHandler()) { for (int i = from; i < to; i++) { var message = new Message { Address = "*****@*****.**", Body = i.ToString(), Subject = i.ToString() }; context.Messages.InsertOnSubmit(message); } 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); Logger.WriteException(exception); } finally { ProcessQueuedMessagesFinished(); } }
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); Logger.WriteException(exception); } finally { ProcessQueuedMessagesFinished(); } }
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; } }
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; } }
private void Save() { using (var context = new DataHandler()) { context.Events.InsertOnSubmit(this); 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(); } } }
public static void UnSubscribeAll(User subscriber) { using (var context = new DataHandler()) { var existing = context.Subscriptions.Where( x => x.UserPath == subscriber.Path); if (existing.Count() > 0) { context.Subscriptions.DeleteAllOnSubmit(existing); context.SubmitChanges(); } } }
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(); } }
internal static void ReleaseLock() { using (var context = new DataHandler()) { var notificationLock = context.Synchronizations.SingleOrDefault(lockItem => lockItem.LockName == NOTIFICATIONLOCKNAME); if (notificationLock == null) throw new Exception(); //TODO: #notifB: ?? what is this? notificationLock.Locked = false; context.SubmitChanges(); } Debug.WriteLine("#Notification> ** lock released"); }
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.Now.AddMinutes(timeframe); context.SubmitChanges(); } Debug.WriteLine("#Notification> ** lock refreshed"); }
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.Now.AddMinutes(timeframe), LockId = AppDomainId }; try { context.Synchronizations.InsertOnSubmit(notifLock); context.SubmitChanges(); success = true; } catch (Exception ex) { Logger.WriteException(ex); } return success; } }
private static void SetActivation(User subscriber, Node target, bool value) { using (var context = new DataHandler()) { var subscription = context.Subscriptions.Where(x => x.UserPath == subscriber.Path && x.ContentPath == target.Path && x.Active == (byte)(value ? 0 : 1)).FirstOrDefault(); if (subscription == null) return; subscription.IsActive = value; context.SubmitChanges(); } }