コード例 #1
0
        public SearchNotificationsResult SearchNotifications(SearchNotificationCriteria criteria)
        {
            var retVal = new SearchNotificationsResult();

            using (var repository = _repositoryFactory())
            {
                retVal.Notifications = new List <Core.Notifications.Notification>();

                var query = repository.Notifications;

                if (!string.IsNullOrEmpty(criteria.ObjectId))
                {
                    query = query.Where(n => n.ObjectId == criteria.ObjectId);
                }
                if (!string.IsNullOrEmpty(criteria.ObjectTypeId))
                {
                    query = query.Where(n => n.ObjectTypeId == criteria.ObjectTypeId);
                }

                if (criteria.IsActive)
                {
                    query = query.Where(n => n.IsActive && n.SentDate == null && (n.LastFailAttemptDate == null || DbFunctions.AddHours(n.LastFailAttemptDate, criteria.RepeatHoursIntervalForFail) < DateTime.UtcNow) &&
                                        (n.StartSendingDate == null || n.StartSendingDate < DateTime.UtcNow));
                }
                retVal.TotalCount    = query.Count();
                retVal.Notifications = query.OrderBy(n => n.CreatedDate)
                                       .Skip(criteria.Skip)
                                       .Take(criteria.Take)
                                       .ToArray()
                                       .Select(x => GetNotificationCoreModel(x))
                                       .ToList();
            }

            return(retVal);
        }
コード例 #2
0
        public SearchNotificationsResult SearchNotifications(SearchNotificationCriteria criteria)
        {
            var retVal = new SearchNotificationsResult();

            using (var repository = _repositoryFactory())
            {
                retVal.Notifications = new List <Core.Notification.Notification>();
                if (!criteria.IsActive)
                {
                    var notifications = repository.Notifications.Where(n => n.ObjectId == criteria.ObjectId && n.ObjectTypeId == criteria.ObjectTypeId).OrderBy(n => n.CreatedDate).Skip(criteria.Skip).Take(criteria.Take);
                    foreach (var notification in notifications)
                    {
                        retVal.Notifications.Add(GetNotificationCoreModel(notification));
                    }
                    retVal.TotalCount = repository.Notifications.Count(n => n.ObjectId == criteria.ObjectId && n.ObjectTypeId == criteria.ObjectTypeId);
                }
                else
                {
                    var notifications = repository.Notifications.Where(n => n.IsActive && !n.IsSuccessSend && !n.SentDate.HasValue && (!n.StartSendingDate.HasValue || (n.StartSendingDate.HasValue && n.StartSendingDate.Value < DateTime.UtcNow))).OrderBy(n => n.CreatedBy).Take(criteria.Take);
                    foreach (var notification in notifications)
                    {
                        retVal.Notifications.Add(GetNotificationCoreModel(notification));
                    }
                }
            }

            return(retVal);
        }
コード例 #3
0
        public void Process()
        {
            var criteria = new SearchNotificationCriteria()
            {
                IsActive = true, Take = _sendingBatchSize
            };

            var result = _notificationManager.SearchNotifications(criteria);

            if (result != null && result.Notifications != null && result.Notifications.Count > 0)
            {
                foreach (var notification in result.Notifications)
                {
                    notification.AttemptCount++;
                    SendNotificationResult sendResult = null;
                    try
                    {
                        sendResult = notification.SendNotification();
                    }
                    catch (Exception ex)
                    {
                        sendResult = new SendNotificationResult
                        {
                            IsSuccess    = false,
                            ErrorMessage = ex.ToString()
                        };
                    }

                    if (sendResult.IsSuccess)
                    {
                        notification.IsActive      = false;
                        notification.IsSuccessSend = true;
                        notification.SentDate      = DateTime.UtcNow;
                    }
                    else
                    {
                        if (notification.AttemptCount >= notification.MaxAttemptCount)
                        {
                            notification.IsActive = false;
                        }

                        notification.LastFailAttemptDate    = DateTime.UtcNow;
                        notification.LastFailAttemptMessage = sendResult.ErrorMessage;
                    }

                    _notificationManager.UpdateNotification(notification);
                }
            }
        }
コード例 #4
0
        public SearchNotificationsResult SearchNotifications(SearchNotificationCriteria criteria)
        {
            var retVal = new SearchNotificationsResult();

            using (var repository = _repositoryFactory())
            {
                retVal.Notifications = new List <Core.Notification.Notification>();
                var notifications = repository.Notifications.Take(criteria.Take).Skip(criteria.Skip);
                foreach (var notification in notifications)
                {
                    retVal.Notifications.Add(GetNotificationCoreModel(notification));
                }
                retVal.TotalCount = notifications.Count();
            }

            return(retVal);
        }
コード例 #5
0
        public SearchNotificationsResult SearchNotifications(SearchNotificationCriteria criteria)
        {
            var retVal = new SearchNotificationsResult();

            using (var repository = _repositoryFactory())
            {
                retVal.Notifications = new List <Notification>();

                var query = repository.Notifications;

                if (!string.IsNullOrEmpty(criteria.ObjectId))
                {
                    query = query.Where(n => n.ObjectId == criteria.ObjectId);
                }
                if (!string.IsNullOrEmpty(criteria.ObjectTypeId))
                {
                    query = query.Where(n => n.ObjectTypeId == criteria.ObjectTypeId);
                }

                if (criteria.IsActive)
                {
                    query = query.Where(n => n.IsActive && n.SentDate == null && (n.LastFailAttemptDate == null || DbFunctions.AddMinutes(n.LastFailAttemptDate, criteria.RepeatMinutesIntervalForFail) < DateTime.UtcNow) &&
                                        (n.StartSendingDate == null || n.StartSendingDate < DateTime.UtcNow));
                }
                retVal.TotalCount = query.Count();

                var sortInfos = criteria.SortInfos;
                if (sortInfos.IsNullOrEmpty())
                {
                    sortInfos = new[] { new SortInfo {
                                            SortColumn = "CreatedDate", SortDirection = SortDirection.Descending
                                        } };
                }
                query = query.OrderBySortInfos(sortInfos).ThenBy(x => x.Id);

                retVal.Notifications = query.Skip(criteria.Skip)
                                       .Take(criteria.Take)
                                       .ToArray()
                                       .Select(GetNotificationCoreModel)
                                       .ToList();
            }

            return(retVal);
        }
コード例 #6
0
        public void Process()
        {
            var criteria = new SearchNotificationCriteria()
            {
                IsActive = true, Take = _take
            };

            var result = _notificationManager.SearchNotifications(criteria);

            if (result != null && result.Notifications != null && result.Notifications.Count > 0)
            {
                foreach (var notification in result.Notifications)
                {
                    notification.AttemptCount++;
                    var sendResult = notification.SendNotification();
                    if (sendResult.IsSuccess)
                    {
                        notification.IsActive      = false;
                        notification.IsSuccessSend = true;
                        notification.SentDate      = DateTime.UtcNow;
                    }
                    else
                    {
                        if (notification.AttemptCount >= notification.MaxAttemptCount)
                        {
                            notification.IsActive = false;
                        }

                        notification.LastFailAttemptDate    = DateTime.UtcNow;
                        notification.LastFailAttemptMessage = sendResult.ErrorMessage;
                    }

                    _notificationManager.UpdateNotification(notification);
                }
            }
        }