Beispiel #1
0
        public PluginExecutionResult Execute(PluginExecutionData executionData)
        {
            try
            {
                ServerInfo exchangeServerInfo = executionData.Servers.First();

                if (!_controllerConfigured)
                {
                    // Alan Andrews 7/9/2010:
                    // For some reason, Autodiscover hangs when we do not have this VMLevelLock in place.
                    // Putting the lock in, then Autodiscover no longer hangs.  I don't quite understand why, but
                    // this is how automation goes sometimes.

                    var action = new Action(() =>
                    {
                        ExecutionServices.SystemTrace.LogDebug("Autodiscover lock acquired");
                        ExchangeConnectionSettings settings = new ExchangeConnectionSettings(exchangeServerInfo);
                        _emailController = new ExchangeEmailController(executionData.Credential, settings);
                    });

                    ExecutionServices.CriticalSection.Run(new ExchangeAutodiscoverLockToken(new TimeSpan(0, 5, 0), new TimeSpan(0, 5, 0)), action);

                    if (InvokeRequired)
                    {
                        ExecutionServices.SystemTrace.LogDebug("Invoking Load Inbox activity");
                        Invoke(new Action(LoadInbox));
                    }

                    _controllerConfigured = true;
                }

                LogUsageData(executionData, exchangeServerInfo);

                _sendActivity = executionData.GetMetadata <EmailActivityData>();
                ExecutionServices.SystemTrace.LogDebug("Activity deserialized, Preparing to send an email");

                var allRecipients = ExecutionServices.SessionRuntime.AsInternal().GetOfficeWorkerEmailAddresses(_sendActivity.ToRandomCount + _sendActivity.CCRandomCount);
                ExecutionServices.SystemTrace.LogDebug("Adding To: recipients");
                var toRecipients = allRecipients.Take(_sendActivity.ToRandomCount);
                ExecutionServices.SystemTrace.LogDebug("Adding CC: recipients");
                var ccRecipients = allRecipients.Skip(_sendActivity.ToRandomCount).Take(_sendActivity.CCRandomCount);

                PopulateControl(_sendActivity, executionData.Documents, toRecipients, ccRecipients);
                SendEmail();

                ExecutionServices.SystemTrace.LogDebug("Email sent, now sleeping 1 second");
                Thread.Sleep(TimeSpan.FromSeconds(1));
            }
            finally
            {
                // We want to attempt an email receive, even if something goes wrong with the send
                if (_exchangeInboxControl != null)
                {
                    _exchangeInboxControl.LoadInbox();
                }
            }

            return(new PluginExecutionResult(PluginResult.Passed));
        }
Beispiel #2
0
        /// <summary>
        /// Populate the email form.
        /// </summary>
        /// <param name="email">Email details to populate the form with.</param>
        private void PopulateControl(EmailActivityData email, DocumentCollection attachments, IEnumerable <MailAddress> toRecipients, IEnumerable <MailAddress> ccRecipients)
        {
            ExecutionServices.SystemTrace.LogDebug("Clearing form");
            ClearForm();

            ExecutionServices.SystemTrace.LogDebug("Populating fields");
            TypeText(emailToTextBox, string.Join(";", toRecipients), 10);
            TypeText(emailCcTextBox, string.Join(";", ccRecipients), 10);
            TypeText(emailSubjectTextBox, email.Subject, 75);
            TypeText(emailBodyTextBox, email.Body, 75);

            ExecutionServices.SystemTrace.LogDebug("Adding attachments");
            AddAttachmentsToList(attachments);
        }
        public void Initialize(PluginConfigurationData configuration, PluginEnvironment environment)
        {
            EmailActivityData emailData = configuration.GetMetadata <EmailActivityData>();

            attachments_DocumentSelectionControl.Initialize(configuration.Documents, GetDocumentFilter());
            exchange_ServerComboBox.Initialize(configuration.Servers.SelectedServers.FirstOrDefault(), "Exchange");

            toCount_NumericUpDown.Value       = emailData.ToRandomCount;
            ccCount_NumericUpDown.Value       = emailData.CCRandomCount;
            subject_TextBox.Text              = emailData.Subject;
            body_TextBox.Text                 = emailData.Body;
            attachAll_RadioButton.Checked     = emailData.SelectAllDocuments;
            attachSome_RadioButton.Checked    = !emailData.SelectAllDocuments;
            documentCount_NumericUpDown.Value = emailData.NumberOfDocuments;
        }
        public PluginConfigurationData GetConfiguration()
        {
            EmailActivityData emailData = new EmailActivityData()
            {
                ToRandomCount      = (int)toCount_NumericUpDown.Value,
                CCRandomCount      = (int)ccCount_NumericUpDown.Value,
                Subject            = subject_TextBox.Text,
                Body               = body_TextBox.Text,
                SelectAllDocuments = attachAll_RadioButton.Checked,
                NumberOfDocuments  = (int)documentCount_NumericUpDown.Value
            };

            return(new PluginConfigurationData(emailData, "1.0")
            {
                Documents = attachments_DocumentSelectionControl.DocumentSelectionData,
                Servers = new ServerSelectionData(exchange_ServerComboBox.SelectedServer)
            });
        }