/// <summary>
        /// Sets up the copy job.
        /// </summary>
        /// <param name="device">The device.</param>
        protected override void SetupJob(IDevice device)
        {
            FilePrefix.MaxLength = maxLength;
            if (device == null)
            {
                throw new ArgumentNullException(nameof(device));
            }

            InitializeAuthenticator(_data.AuthProvider, device, ExecutionData);

            // Load the Job storage application
            _jobStorageScanApp = ScanJobStorageAppFactory.Create(device);

            _jobStorageScanApp.WorkflowLogger = Authenticator.WorkflowLogger = WorkflowLogger;
            _jobStorageScanApp.Pacekeeper     = Authenticator.Pacekeeper = new Pacekeeper(_data.AutomationPause);
            _jobStorageScanApp.Launch(Authenticator, !_data.ApplicationAuthentication ? AuthenticationMode.Eager : AuthenticationMode.Lazy);
            // Enter the job name
            if (_data.IsPinRequired)
            {
                _jobStorageScanApp.AddJobName(FilePrefix.ToString().ToLowerInvariant(), _data.Pin);
            }
            else
            {
                _jobStorageScanApp.AddJobName(FilePrefix.ToString().ToLowerInvariant());
            }
            //Sets the scan job options
            SetOptions(_data.ScanOptions, _jobStorageScanApp.Options.GetType(), _jobStorageScanApp.GetType(), device);

            // Set job build
            _jobStorageScanApp.Options.SetJobBuildState(UseJobBuild);
        }
Esempio n. 2
0
        /// <summary>
        /// Performs ScanToJobStorage job on Control Panel
        /// </summary>
        /// <param name="device"></param>
        /// <param name="jobStorageScanData"></param>
        /// <returns></returns>
        private PluginExecutionResult ExecuteJobStorageActivity(IDevice device, ScanActivityData jobStorageScanData, 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 Job storage application
            IJobStorageScanApp contentionJobStorageApp = ScanJobStorageAppFactory.Create(device);

            //Launch the Scan To Job Storage application
            UpdateStatus("ScanToJobStorage Activity: Launching the Scan To Job Storage application...");
            contentionJobStorageApp.Launch(authenticator, AuthenticationMode.Lazy);

            //Enter the job name
            ScanFilePrefix FilePrefix = new ScanFilePrefix(ExecutionData.SessionId, ExecutionData.Credential.UserName, "Job Storage");

            FilePrefix.MaxLength = 16;
            UpdateStatus("ScanToJobStorage Activity: Entering job name...");
            contentionJobStorageApp.AddJobName(FilePrefix.ToString().ToLowerInvariant());

            // Set job build
            contentionJobStorageApp.Options.SetJobBuildState((jobStorageScanData.PageCount > 1) ? true : false);

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

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

                // Clean up
                try
                {
                    devicePrepManager.NavigateHome();
                    if (devicePrepManager.SignOutRequired())
                    {
                        UpdateStatus("ScanToJobStorage Activity: Signing Out...");
                        devicePrepManager.SignOut();
                    }
                    UpdateStatus("ScanToJobStorage 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 ScanToJobStorage activity
                ExecutionServices.SystemTrace.LogDebug("ScanToJobStorage activity completed");
            }

            return(result);
        }