コード例 #1
0
        protected async Task Save()
        {
            ValidationMessages.Clear();
            if (!Recipients.Any(x => x.IsChecked))
            {
                ValidationMessages.Add("Atleast one recipient should be selected.");
                return;
            }
            var selectedRecipients = Recipients.Where(x => x.IsChecked).Select(x => x.Data).ToList();
            var deletedRecipients  = _originalSelectedRecipients.Where(x => !selectedRecipients.Any(y => y.Id == x.Id));
            var addedRecipients    = selectedRecipients.Where(x => !_originalSelectedRecipients.Any(y => y.Id == x.Id));

            var parsedFolderId = Guid.Parse(FolderId);

            await Mediator.Send(new UpdateRecipientsForFolderCommand { FolderId = parsedFolderId, ToAddRecipients = addedRecipients.ToList(), ToDeleteRecipients = deletedRecipients.ToList() });

            foreach (var fwh in FolderWebhookViewModels.Where(x => x.IsChanged))
            {
                await Mediator.Send(new UpsertFolderWebhookCommand { FolderId = parsedFolderId, WebhookTypeId = fwh.WebhookTypeId, WebhookTypeName = fwh.WebHookTypeName, CallbackUrl = fwh.CallbackUrl });
            }

            foreach (var newRecipient in addedRecipients)
            {
                //todo notify. Start processing existing files for these recipients. should be done in de command
            }

            NavigationManager.NavigateTo($"/folder/{FolderId}");
        }
 private void AddRecipient(Message.Recipient recipient)
 {
     if (!Recipients.Any(x => x.EmailAddress.IsEqualTo(recipient.EmailAddress)))
     {
         Recipients.Add(recipient);
         OnPropertyChanged(() => SendCommand);
     }
 }
コード例 #3
0
 internal string[] SanitizeRecipients()
 {
     if (Recipients == null)
     {
         return(new string[0]);
     }
     if (Recipients.Any() == false)
     {
         return(new string[0]);
     }
     return(Recipients.Where(item => IsValid(item)).ToArray());
 }
コード例 #4
0
 /// <summary>
 /// Handles the SelectPerson event of the ppAddPerson control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
 protected void ppAddPerson_SelectPerson(object sender, EventArgs e)
 {
     if (ppAddPerson.PersonId.HasValue)
     {
         if (!Recipients.Any(r => r.PersonId == ppAddPerson.PersonId.Value))
         {
             var Person = new PersonService(new RockContext()).Get(ppAddPerson.PersonId.Value);
             if (Person != null)
             {
                 Recipients.Add(new Recipient(Person, CommunicationRecipientStatus.Pending));
                 ShowAllRecipients = true;
             }
         }
     }
 }
コード例 #5
0
 internal bool IsValid()
 {
     if (Recipients == null)
     {
         return(false);
     }
     if (Recipients.Any() == false)
     {
         return(false);
     }
     if (string.IsNullOrEmpty(SenderId))
     {
         return(false);
     }
     return(true);
 }
コード例 #6
0
        public IReportSender GetReportSender()
        {
            if (!string.IsNullOrEmpty(Username) && !UseWindowsCredentials && string.IsNullOrEmpty(Password))
            {
                throw new ArgumentException("Password cannot be empty when using username/password authentication");
            }
            if (string.IsNullOrEmpty(SenderAddress))
            {
                throw new ArgumentException("Sender address cannot be empty.");
            }
            if (!Recipients.Any())
            {
                throw new ArgumentException("A recipient must be specified.");
            }
            if (string.IsNullOrEmpty(SmtpServerName))
            {
                throw new ArgumentException("Smtp server has to be defined.");
            }

            SmtpSender smtp;

            if (string.IsNullOrEmpty(Username) || UseWindowsCredentials)
            {
                // In these two cases the username and password should not be given to the SmtpSender:
                // - if user name is empty -> use anonymous access (only if the UseWindowsCredentials is false)
                // - if UseWindowsCredentials is true -> use the windows credentials
                smtp = new SmtpSender(SmtpServerName, PortNumber, UseWindowsCredentials, MaxIdleTime, UseSsl);
            }
            else
            {
                smtp = new SmtpSender(SmtpServerName, PortNumber, UseWindowsCredentials, MaxIdleTime, Username, Password, UseSsl);
            }

            smtp.Sender     = new MailAddress(SenderAddress, SenderName);
            smtp.Recipients = Recipients.Select(m => new MailAddress(m)).ToList();

            return(smtp);
        }
コード例 #7
0
 protected internal void SaveButton_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         using (ConfigurationServiceClient client = new ConfigurationServiceClient())
         {
             if (_OldRecipients.Any(x => !Recipients.Contains(x)) || Recipients.Any(x => !_OldRecipients.Contains(x)))
             {
                 client.UpdateRecipients(Recipients.ToList());
                 _OldRecipients = Recipients;
             }
             if (_OldWatcherPath != WatcherPath)
             {
                 client.UpdateWatcherPath(WatcherPath);
                 _OldWatcherPath = WatcherPath;
             }
             if (_OldUriWatchPath != UriToWatchPath)
             {
                 client.UpdateUriToWatchPath(UriToWatchPath);
                 _OldUriWatchPath = UriToWatchPath;
             }
         }
         if (service != null && !service.ServiceHandle.IsInvalid)
         {
             service.Stop();
             service.WaitForStatus(ServiceControllerStatus.Stopped);
             service.Start();
         }
     }
     catch (Exception ex)
     {
         _log.Error(ex);
         //_EventLog.WriteEntry(String.Format("Error occurred during initiation {0}{1}{0}{2}{0}{3}", Environment.NewLine, ex.Message, ex.InnerException != null ? ex.InnerException.Message : String.Empty, ex.StackTrace), EventLogEntryType.Error);
         throw ex;
     }
 }
コード例 #8
0
 /// <summary>
 /// Handles the ServerValidate event of the valRecipients control.
 /// </summary>
 /// <param name="source">The source of the event.</param>
 /// <param name="args">The <see cref="ServerValidateEventArgs" /> instance containing the event data.</param>
 protected void valRecipients_ServerValidate(object source, ServerValidateEventArgs args)
 {
     args.IsValid = Recipients.Any();
 }
コード例 #9
0
        /// <summary>
        /// Updates a communication model with the user-entered values
        /// </summary>
        /// <param name="communicationService">The service.</param>
        /// <returns></returns>
        private Rock.Model.Communication UpdateCommunication(RockContext rockContext)
        {
            var communicationService = new CommunicationService(rockContext);
            var recipientService     = new CommunicationRecipientService(rockContext);

            Rock.Model.Communication communication = null;
            if (CommunicationId.HasValue)
            {
                communication = communicationService.Get(CommunicationId.Value);

                // Remove any deleted recipients
                foreach (var recipient in recipientService.GetByCommunicationId(CommunicationId.Value))
                {
                    if (!Recipients.Any(r => recipient.PersonAlias != null && r.PersonId == recipient.PersonAlias.PersonId))
                    {
                        recipientService.Delete(recipient);
                        communication.Recipients.Remove(recipient);
                    }
                }
            }

            if (communication == null)
            {
                communication        = new Rock.Model.Communication();
                communication.Status = CommunicationStatus.Transient;
                communication.SenderPersonAliasId = CurrentPersonAliasId;
                communicationService.Add(communication);
            }

            // Add any new recipients
            foreach (var recipient in Recipients)
            {
                if (!communication.Recipients.Any(r => r.PersonAlias != null && r.PersonAlias.PersonId == recipient.PersonId))
                {
                    var person = new PersonService(rockContext).Get(recipient.PersonId);
                    if (person != null)
                    {
                        var communicationRecipient = new CommunicationRecipient();
                        communicationRecipient.PersonAlias = person.PrimaryAlias;
                        communication.Recipients.Add(communicationRecipient);
                    }
                }
            }

            communication.IsBulkCommunication = cbBulk.Checked;

            communication.MediumEntityTypeId = MediumEntityTypeId;
            communication.MediumData.Clear();
            GetMediumData();
            foreach (var keyVal in MediumData)
            {
                if (!string.IsNullOrEmpty(keyVal.Value))
                {
                    communication.MediumData.Add(keyVal.Key, keyVal.Value);
                }
            }

            if (communication.MediumData.ContainsKey("Subject"))
            {
                communication.Subject = communication.MediumData["Subject"];
                communication.MediumData.Remove("Subject");
            }

            DateTime?futureSendDate = dtpFutureSend.SelectedDateTime;

            if (futureSendDate.HasValue && futureSendDate.Value.CompareTo(RockDateTime.Now) > 0)
            {
                communication.FutureSendDateTime = futureSendDate;
            }
            else
            {
                communication.FutureSendDateTime = null;
            }

            return(communication);
        }