Beispiel #1
0
        private void UpdateGroupStatusAndFireEvent(NotificationGroupModel group)
        {
            this.unitOfWork.NotificationGroupRepository.Update(group);
            this.unitOfWork.Save();

            this.eventAggregator.Publish <NotificationGroupStatusChangedEvent>();
        }
Beispiel #2
0
        private void SetProcessedStatusForGroup(NotificationGroupModel group)
        {
            group.Status        = (int)NotificationGroupStatus.Processed;
            group.CompletedDate = DateTime.Now;

            this.UpdateGroupStatusAndFireEvent(group);
        }
Beispiel #3
0
        private void ProcessGroupWithoutReceivers(NotificationGroupModel group)
        {
            group.Status = (int)NotificationGroupStatus.Processed;
            this.unitOfWork.NotificationGroupRepository.Update(group);
            this.unitOfWork.Save();

            this.eventAggregator.Publish <NotificationGroupStatusChangedEvent>();

            Log.Debug("There are no active e-mail receivers. Group delivery has been processed.");
        }
        private List <NotificationListModel> GetReceivers(NotificationGroupModel group)
        {
            var receivers = this.unitOfWork.NotificationListRepository.GetAllExceptDeletedByGroupId(group.Id)
                            .Where(a => a.Status == (int)NotificationListStatus.NotSent)
                            .ToList();

            Log.Debug("There was(were) found {0} not handled receiver(s) in {1} group.", Log.Args(receivers.Count, group.Description));

            return(receivers);
        }
        public NotificationGroup(NotificationGroupModel model)
        {
            InitializeComponent();

            if (model.Type == NotifIcationType.Guild)
            {
                SocketGuild guild = App.DiscordWindow.Client.GetGuild((model.Channel as IGuildChannel).Guild.Id);
                sourceTitle.Text = guild.Name;
                if (guild.IconUrl != null)
                {
                    sourceImage.ImageSource = Images.GetImage(guild.IconUrl);
                }
            }

            foreach (IMessage msg in model.Messages)
            {
                MessageViewer viewer = new MessageViewer(msg, model.Channel);
                messageViewer.Items.Add(viewer);
            }
        }
Beispiel #6
0
        /// <summary>
        /// Send e-mails.
        /// </summary>
        /// <param name="receivers">List of the receiver to send e-mail notification.</param>
        /// <param name="group">Notification group.</param>
        public void SendEmail(IList <NotificationListModel> receivers, NotificationGroupModel group)
        {
            this.settings.Refresh();

            if (receivers.Count == 0)
            {
                this.ProcessGroupWithoutReceivers(group);
                return;
            }

            this.SetProcessingStatusForGroup(group);

            try
            {
                Log.Debug("Start sending emails to receivers with {0} (id is {1}) template.", Log.Args(group.Template, group.TemplateId));

                var mailMessage = this.CreateAndFillMailMessage(group.TemplateId);
                var smtpClient  = this.InitializeSmtpClient();

                foreach (var receiver in receivers)
                {
                    if (this.EmailDeliveryService.IsCancellationRequested)
                    {
                        return;
                    }

                    if (receiver.SendDate != null)
                    {
                        continue;
                    }

                    var addressToSend = new MailAddress(receiver.PatientEmail);
                    mailMessage.To.Add(addressToSend);

                    try
                    {
                        receiver.StartDate = DateTime.Now;

                        smtpClient.Send(mailMessage);

                        this.SetSuccessStatusForReceiver(receiver);

                        this.LogSuccessfulResult(receiver);
                    }
                    catch (Exception ex)
                    {
                        Log.Exception(ex);
                        this.SetErrorStatusForReceiver(receiver, ex.Message);
                    }
                    finally
                    {
                        mailMessage.To.Remove(addressToSend);

                        this.UpdateReceiverStatusAndFireEvent(receiver);
                    }

                    Thread.Sleep(TimeSpan.FromSeconds(this.settings.SendingDelayInSeconds));
                }

                this.SetProcessedStatusForGroup(group);
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
            }
        }
Beispiel #7
0
        private void SetProcessingStatusForGroup(NotificationGroupModel group)
        {
            group.Status = (int)NotificationGroupStatus.Processing;

            this.UpdateGroupStatusAndFireEvent(group);
        }
 private bool IsGroupNotProcessingOrNotProcessed(NotificationGroupModel group)
 {
     return(group.Status != (int)NotificationGroupStatus.Processing ||
            group.Status != (int)NotificationGroupStatus.Processed);
 }