protected override PluginExecutionResult FinishJob(IDevice device) { PluginExecutionResult result = new PluginExecutionResult(PluginResult.Failed, "Error occurred After Login and Job Configuration.", "Device automation error."); // Start the job try { ScanExecutionOptions options = new ScanExecutionOptions(); if (UseJobBuild) { options.JobBuildSegments = _data.ScanOptions.PageCount; } options.ImagePreview = (ImagePreviewOption)_data.ImagePreviewOptions; _emailApp = EmailAppFactory.Create(device); // Special handling for Sirius/Phoenix var emailAppWithAddressSource = _emailApp as IEmailAppWithAddressSource; if (emailAppWithAddressSource != null) { emailAppWithAddressSource.AddressSource = _data.AddressSource; emailAppWithAddressSource.FromAddress = ExecutionData.Credential.UserName; } _emailApp.WorkflowLogger = WorkflowLogger; _emailApp.Pacekeeper = new Pacekeeper(_data.AutomationPause); if (_emailApp.ExecuteJob(options)) { result = new PluginExecutionResult(PluginResult.Passed); ScanLog.JobEndStatus = "Success"; } } finally { // We got far enough to start the scan job, so submit the log ExecutionServices.DataLogger.Submit(ScanLog); } return(result); }
/// <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); }