Exemplo n.º 1
0
        /// <summary>
        /// Performs ScanToUsb job on Control Panel
        /// </summary>
        /// <param name="device"></param>
        /// <param name="usbScanData"></param>
        /// <returns></returns>
        private PluginExecutionResult ExecuteUsbActivity(IDevice device, ScanActivityData usbScanData, 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 network folder application
            IUsbApp contentionUsbApp = UsbAppFactory.Create(device);

            //Launch the Scan To Job Storage application
            UpdateStatus("ScanToUSB Activity: Launching the Scan To USB application...");
            contentionUsbApp.LaunchScanToUsb(authenticator, AuthenticationMode.Lazy);

            //Select the USB device
            UpdateStatus("ScanToUSB Activity: Selecting the USB device...");
            contentionUsbApp.SelectUsbDevice(usbScanData.UsbName);

            // Enter the file name
            ScanFilePrefix FilePrefix = new ScanFilePrefix(ExecutionData.SessionId, ExecutionData.Credential.UserName, "USB");

            UpdateStatus("ScanToUSB Activity: Entering file name...");
            contentionUsbApp.AddJobName(FilePrefix.ToString().ToLowerInvariant());

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

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

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

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

            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Sets up the scan job.
        /// </summary>
        /// <param name="device">The device.</param>
        protected override void SetupJob(IDevice device)
        {
            if (device == null)
            {
                throw new ArgumentNullException("device");
            }

            InitializeAuthenticator(_data.AuthProvider, device, ExecutionData);

            // Update the destination type
            ScanLog.ScanType = _data.UsbName;

            UpdateStatus(string.Format("Setting up device at address {0} for user {1}", device.Address, ExecutionData.Credential.UserName));

            // Load the network folder application

            _usbApp = UsbAppFactory.Create(device);

            _usbApp.WorkflowLogger = Authenticator.WorkflowLogger = WorkflowLogger;
            _usbApp.Pacekeeper     = Authenticator.Pacekeeper = new Pacekeeper(_data.AutomationPause);

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

            if (device is JediOmniDevice)
            {
                _usbApp.LaunchScanToUsb(Authenticator, am);

                // Apply settings from the configuration
                if (_data.UseQuickset)
                {
                    _usbApp.SelectQuickset(_data.QuickSetName);
                }
                else
                {
                    _usbApp.SelectUsbDevice(_data.UsbName);
                }
            }
            else if (device is JediWindjammerDevice)
            {
                if (!_data.UseQuickset)
                {
                    _usbApp.LaunchScanToUsb(Authenticator, am);
                    _usbApp.SelectUsbDevice(_data.UsbName);
                }
                else
                {
                    _usbApp.LaunchScanToUsbByQuickSet(Authenticator, am, _data.QuickSetName);
                }
            }


            // Enter the file name
            _usbApp.AddJobName(FilePrefix.ToString().ToLowerInvariant());

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

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