コード例 #1
0
        /// <summary>
        /// Adds dummy notifications for testing.
        /// </summary>
        /// <param name="who">The who.</param>
        public static bool AddDummyNotifications(string who)
        {
            var repository = new NotificationsRepository();

            if (!repository.Init())
            {
                return(false);
            }

            var dummyNotifications = new List <NotificationModel>();
            var notification1      = new NotificationModel(who, Guid.NewGuid().ToString())
            {
                Title      = "Lorem ipsum dolor",
                Message    = "Duis aute irure dolor in reprehenderit in voluptate",
                NotifyType = NotificationType.Warning
            };

            var notification2 = new NotificationModel(who, Guid.NewGuid().ToString())
            {
                Title   = "Excepteur sint occaecat",
                Message = "Excepteur sint occaecat cupidatat non proident," +
                          "sunt in culpa qui officia deserunt mollit",
                NotifyType = NotificationType.Warning
            };

            var notification3 = new NotificationModel(who, Guid.NewGuid().ToString())
            {
                Title      = "Mauris ipsum arcu",
                Message    = "Mauris ipsum arcu, feugiat non tempor tincidunt sit amet turpis",
                Url        = "/Home/Contact",
                LinkText   = "ipsum arcu!",
                NotifyType = NotificationType.Info
            };

            var notification4 = new NotificationModel(who, Guid.NewGuid().ToString())
            {
                Title      = "Ut a diam magna",
                Message    = "Nulla convallis, orci in sodales blandit",
                NotifyType = NotificationType.Success
            };

            var notification5 = new NotificationModel(who, Guid.NewGuid().ToString())
            {
                Title   = "lorem augue feugiat",
                Message = "vitae dapibus mi ligula quis ligula." +
                          "Aenean mattis pulvinar est quis bibendum.",
                NotifyType = NotificationType.Success
            };

            var notification6 = new NotificationModel(who, Guid.NewGuid().ToString())
            {
                Title      = "Donec posuere pulvinar",
                Message    = "nec sagittis lacus pharetra ac",
                NotifyType = NotificationType.Failure
            };

            var notification7 = new NotificationModel(who, Guid.NewGuid().ToString())
            {
                Title      = "Pellentesque et magna",
                Message    = "Donec velit vulputate nec tristique vitae",
                NotifyType = NotificationType.Info
            };

            dummyNotifications.Add(notification1);
            dummyNotifications.Add(notification2);
            dummyNotifications.Add(notification3);
            dummyNotifications.Add(notification4);
            dummyNotifications.Add(notification5);
            dummyNotifications.Add(notification6);
            dummyNotifications.Add(notification7);


            foreach (var notification in dummyNotifications)
            {
                repository.AddNotification(notification);
            }

            return(true);
            //var notifications = repository.GetNotificationsByUserId(who);
        }
コード例 #2
0
        /// <summary>
        /// Removes the old sent notifications.
        /// </summary>
        /// <param name="userEmail">The user email.</param>
        /// <param name="sentNotifications">The sent notifications.</param>
        public static void RemoveOldSentNotifications(string userEmail,
                                                      List <NotificationModel> sentNotifications, NotificationsRepository sentNotifyRepo)
        {
            int daysOld  = 30;
            var timeSpan = TimeSpan.FromDays(daysOld);

            var dateTimeOffset = DateTime.Now.Subtract(timeSpan);

            foreach (var sentNotification in sentNotifications)
            {
                // Remove connection if older that 'dateTimeOffset'
                if (sentNotification.Timestamp.DateTime <= dateTimeOffset)
                {
                    sentNotifyRepo.RemoveNotification(sentNotification.PartitionKey, sentNotification.RowKey);
                }
            }
        }