/// <summary>
        /// Performs ScanToEmail job on Control Panel
        /// </summary>
        /// <param name="device"></param>
        /// <param name="emailScanData"></param>
        /// <returns></returns>
        private PluginExecutionResult ExecuteEmailActivity(IDevice device, ScanActivityData emailScanData, IAuthenticator authenticator)
        {
            var result = new PluginExecutionResult(PluginResult.Failed);

            // Make sure the device is in a good state
            UpdateStatus($"Setting up device at address {device.Address} for user {ExecutionData.Credential.UserName}");
            var devicePrepManager = DevicePreparationManagerFactory.Create(device);

            devicePrepManager.WorkflowLogger = WorkflowLogger;
            devicePrepManager.InitializeDevice(true);

            // Load the email application
            IEmailApp contentionEmailApp = EmailAppFactory.Create(device);

            //Launch the Scan to Email application
            UpdateStatus("ScanToEmail Activity: Launching the Scan To Email application...");
            contentionEmailApp.Launch(authenticator, AuthenticationMode.Lazy);

            //Enter subject and file name
            ScanFilePrefix FilePrefix = new ScanFilePrefix(ExecutionData.SessionId, ExecutionData.Credential.UserName, "Email");
            string         fileName   = FilePrefix.ToString().ToLowerInvariant();

            contentionEmailApp.EnterSubject(fileName);
            UpdateStatus("ScanToEmail Activity: Email subject entered...");
            contentionEmailApp.EnterFileName(fileName);
            UpdateStatus("ScanToEmail Activity: File name entered...");

            List <string> emailList = new List <string>();

            emailList.Add(emailScanData.EmailAddress);
            //Enter email address
            contentionEmailApp.EnterToAddress(emailList);
            UpdateStatus("ScanToEmail Activity: Email address entered...");

            try
            {
                ScanExecutionOptions options = new ScanExecutionOptions();
                options.ValidateJobExecution = false;
                if (emailScanData.PageCount > 1)
                {
                    options.JobBuildSegments = emailScanData.PageCount;
                }

                //Finish the job
                UpdateStatus("ScanToEmail Activity: Finishing the activity...");
                if (contentionEmailApp.ExecuteJob(options))
                {
                    result = new PluginExecutionResult(PluginResult.Passed);
                }

                // Clean up
                try
                {
                    devicePrepManager.NavigateHome();
                    if (devicePrepManager.SignOutRequired())
                    {
                        UpdateStatus("ScanToEmail Activity: Signing Out...");
                        devicePrepManager.SignOut();
                    }
                    UpdateStatus("ScanToEmail Activity: Activity finished");
                }
                catch (Exception ex) when(ex is DeviceCommunicationException || ex is DeviceInvalidOperationException)
                {
                    // Don't fail the activity if there is an exception here.
                    ExecutionServices.SystemTrace.LogWarn($"Device could not return to home screen: {ex.ToString()}");
                }
            }
            finally
            {
                // End of ScanToEmail activity
                ExecutionServices.SystemTrace.LogDebug("ScanToEmail activity completed");
            }

            return(result);
        }
        /// <summary>
        /// Emails via the lazy authentication.
        /// </summary>
        /// <param name="authenticator">The authenticator.</param>
        /// <param name="device">The device.</param>
        protected void EmailLazyAuth(IAuthenticator authenticator, IDevice device)
        {
            IEmailApp emailApp = EmailAppFactory.Create(device);

            emailApp.Launch(authenticator, AuthenticationMode.Lazy);
        }
示例#3
0
        /// <summary>
        /// Sets up the scan job.
        /// </summary>
        /// <param name="device">The device.</param>
        protected override void SetupJob(IDevice device)
        {
            ScanLog.JobEndStatus = "Failed";
            if (device == null)
            {
                throw new ArgumentNullException(nameof(device));
            }

            UpdateStatus($"Setting up device at address {device.Address} for user {ExecutionData.Credential.UserName}");

            InitializeAuthenticator(_data.AuthProvider, device, ExecutionData);

            // Load the email application
            _emailApp = EmailAppFactory.Create(device);

            // need to add the ability for user to set eager or lazy authentication
            AuthenticationMode am = (_data.ApplicationAuthentication == false) ? AuthenticationMode.Eager : AuthenticationMode.Lazy;

            // Special handling for Sirius/Phoenix
            var emailAppWithAddressSource = _emailApp as IEmailAppWithAddressSource;

            if (emailAppWithAddressSource != null)
            {
                emailAppWithAddressSource.AddressSource = _data.AddressSource;
                emailAppWithAddressSource.FromAddress   = ExecutionData.Credential.UserName;
            }

            _emailApp.WorkflowLogger = Authenticator.WorkflowLogger = WorkflowLogger;
            _emailApp.Pacekeeper     = Authenticator.Pacekeeper = new Pacekeeper(_data.AutomationPause);
            if (_data.UseQuickset)
            {
                if (!_data.LaunchQuicksetFromApp)
                {
                    _emailApp.LaunchFromQuickSet(Authenticator, am, _data.QuickSetName);
                }
                else
                {
                    _emailApp.Launch(Authenticator, am);
                    _emailApp.SelectQuickset(_data.QuickSetName);
                }
                EnterFileName();
            }
            else
            {
                _emailApp.Launch(Authenticator, am);

                // Apply settings from the configuration
                List <string> emailAddresses = new List <string>();
                string        emailAddress   = string.Empty;
                string[]      emailsList     = _data.EmailAddress.Split(';');
                foreach (string email in emailsList)
                {
                    emailAddress = email;
                    if (emailAddress != string.Empty)
                    {
                        if (!IsValidEmail(emailAddress))
                        {
                            emailAddress = new EmailBuilder(emailAddress, ExecutionData).ToString();
                        }

                        emailAddresses.Add(emailAddress);
                    }
                }

                _emailApp.EnterToAddress(emailAddresses);
                EnterFileName();

                // Select the appropriate file type
                // emailApp.Options.SelectFileType(_data.UseOcr ? "Searchable PDF (OCR)" : "PDF");
                //Sets the scan job options
                SetOptions(_data.ScanOptions, _emailApp.Options.GetType(), _emailApp.GetType(), device);
            }

            ScanLog.Ocr = _data.UseOcr;

            // Set job build
            _emailApp.Options.SetJobBuildState(UseJobBuild);
        }