示例#1
0
        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);
            }
        }
示例#2
0
        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();
            }
        }
示例#3
0
        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();
            }
        }
示例#4
0
        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();
     }
 }
示例#6
0
 private void Save()
 {
     using (var context = new DataHandler())
     {
         context.Events.InsertOnSubmit(this);
         context.SubmitChanges();
     }
 }
示例#7
0
        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();
                }
            }
        }
示例#8
0
        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();
                }
            }
        }
示例#9
0
 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");
 }
示例#10
0
        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");
        }
示例#11
0
 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();
     }
 }
示例#12
0
        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();
            }
        }
示例#13
0
        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();
            }
        }
示例#14
0
        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();
                }
        }
示例#15
0
        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;
            }
        }
示例#16
0
        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();
                }
            }
        }
示例#17
0
 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;
     }
 }
示例#18
0
 private void Save()
 {
     using (var context = new DataHandler())
     {
         context.Events.InsertOnSubmit(this);
         context.SubmitChanges();
     }
 }
示例#19
0
        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();
                }
            }
        }
示例#20
0
        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();
                }
            }
        }
示例#21
0
        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();
            }
        }
示例#22
0
        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");
        }
示例#23
0
        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");
        }
示例#24
0
        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;
            }
        }
示例#25
0
 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();
     }
 }