/// <summary>
        /// Performs Fax job on Control Panel
        /// </summary>
        /// <param name="device"></param>
        /// <param name="controlPanelData"></param>
        /// <returns></returns>
        private PluginExecutionResult ExecuteFax(IDevice device, object controlPanelData, IAuthenticator authenticator)
        {
            var result = new PluginExecutionResult(PluginResult.Failed);

            FaxActivityData faxData = controlPanelData as FaxActivityData;

            // 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 fax application
            IFaxApp contentionFaxApp = FaxAppFactory.Create(device);

            //Launch the Fax application
            UpdateStatus("Fax Activity: Launching the Fax application...");
            contentionFaxApp.Launch(authenticator, AuthenticationMode.Lazy);

            ScanFilePrefix FilePrefix = new ScanFilePrefix(ExecutionData.SessionId, ExecutionData.Credential.UserName, "Fax");

            UpdateStatus("Fax Activity: Entering recipient fax number...");
            if (string.IsNullOrEmpty(faxData.FaxNumber) || string.IsNullOrWhiteSpace(faxData.FaxNumber))
            {
                // Apply settings from configuration
                contentionFaxApp.AddRecipient(FilePrefix.ToFaxCode());
            }
            else
            {
                contentionFaxApp.AddRecipient(faxData.FaxNumber);
            }

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

            try
            {
                // Start the job
                ScanExecutionOptions options = new ScanExecutionOptions();
                options.ValidateJobExecution = false;
                if (faxData.PageCount > 1)
                {
                    options.JobBuildSegments = faxData.PageCount;
                }

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

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

            return(result);
        }
        /// <summary>
        /// Faxes via the lazy authentication.
        /// </summary>
        /// <param name="authenticator">The authenticator.</param>
        /// <param name="device">The device.</param>
        protected void FaxLazyAuth(IAuthenticator authenticator, IDevice device)
        {
            IFaxApp faxApp = FaxAppFactory.Create(device);

            faxApp.Launch(authenticator, AuthenticationMode.Lazy);
        }
示例#3
0
        /// <summary>
        /// Sets up the Fax job.
        /// </summary>
        /// <param name="device">The device.</param>
        private void SendFaxSetupJob(IDevice device)
        {
            UpdateStatus("Setting up Fax Send job...");
            ScanLog.JobEndStatus = "Failed";
            if (device == null)
            {
                throw new ArgumentNullException(nameof(device));
            }

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

            InitializeAuthenticator(_data.AuthProvider, device, ExecutionData);
            // Load the fax application
            _faxApp = FaxAppFactory.Create(device);

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

            _faxApp.WorkflowLogger = Authenticator.WorkflowLogger = WorkflowLogger;
            _faxApp.Pacekeeper     = Authenticator.Pacekeeper = new Pacekeeper(_data.AutomationPause);
            _faxApp.Launch(Authenticator, am);

            if (!_data.UseSpeedDial)
            {
                if (string.IsNullOrEmpty(_data.FaxNumber) || string.IsNullOrWhiteSpace(_data.FaxNumber))
                {
                    // Apply settings from configuration
                    _faxApp.AddRecipient(FilePrefix.ToFaxCode());
                }
                else
                {
                    _faxApp.AddRecipient(_data.FaxNumber);
                }
            }
            else
            {
                Dictionary <string, string> recipients = new Dictionary <string, string>();
                string[] FaxNums;
                if (_data.FaxNumber == null || string.IsNullOrWhiteSpace(_data.FaxNumber))
                {
                    // Apply settings from configuration
                    FaxNums = FilePrefix.ToFaxCode().Split(',');
                    foreach (string FaxNum in FaxNums)
                    {
                        recipients[FaxNum] = string.Empty;
                    }
                    _faxApp.AddRecipients(recipients, false);
                }
                else
                {
                    FaxNums = _data.FaxNumber.Split(',');
                    string[] PINs = new string[FaxNums.Length];
                    _data.PIN.Split(',', (char)StringSplitOptions.None).CopyTo(PINs, 0);
                    for (int i = 0; i < FaxNums.Count(); i++)
                    {
                        recipients[FaxNums[i]] = PINs[i];
                    }

                    _faxApp.AddRecipients(recipients, _data.UseSpeedDial);
                }
            }

            if (_data.EnableNotification)
            {
                EmailBuilder emailAddress = new EmailBuilder(_data.NotificationEmail, ExecutionData);
                //sending false parameter for thumbNail as it is unchecked bydefault
                _faxApp.Options.EnableEmailNotification(NotifyCondition.Always, emailAddress.ToString(), false);
            }

            //Sets the scan job options
            SetOptions(_data.ScanOptions, _faxApp.Options.GetType(), _faxApp.GetType(), device);
            _faxApp.Options.SetJobBuildState(this.UseJobBuild);

            // OCR is not applicable for fax jobs
            ScanLog.Ocr = false;
            UpdateStatus("Job setup complete");
            _pacekeeper.Pause();
        }