/// <summary>
        /// Initializes the device.
        /// </summary>
        protected override void InitializeDevice()
        {
            try
            {
                Device          = DeviceConstructor.Create(DeviceInfo);
                _geniusBytesApp = GeniusBytesAppFactory.Create(Device);
                var preparationManager = new GeniusBytesPreparationManager((JediOmniDevice)Device, _geniusBytesApp);
                preparationManager.InitializeDevice(false);
                _collectMemoryManager = new CollectMemoryManager(Device, DeviceInfo);
            }
            catch (Exception ex)
            {
                // Make sure the device is disposed, if necessary
                if (Device != null)
                {
                    Device.Dispose();
                    Device = null;
                }

                // Log the error and re-throw.
                ExecutionServices.SystemTrace.LogError(ex);
                throw;
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="JediOmniPreparationManager" /> class.
 /// </summary>
 /// <param name="device">The device.</param>
 /// <param name="geniusBytesApp">GeniusBytes solution app</param>
 public GeniusBytesPreparationManager(JediOmniDevice device, IGeniusBytesApp geniusBytesApp)
     : base(device)
 {
     _geniusBytesApp = geniusBytesApp;
 }
        /// <summary>
        /// Executes the scan job using the specified device.
        /// </summary>
        /// <param name="device">The device.</param>
        /// <param name="deviceInfo">The device information.</param>
        /// <returns>
        /// The result of execution.
        /// </returns>
        protected override PluginExecutionResult ExecuteScan(IDevice device, IDeviceInfo deviceInfo)
        {
            var result = new PluginExecutionResult(PluginResult.Failed, "Automation Failure", "Device workflow error.");

            try
            {
                _geniusBytesApp = GeniusBytesAppFactory.Create(device);
                var devicePrepManager = new GeniusBytesPreparationManager((JediOmniDevice)device, _geniusBytesApp);
                devicePrepManager.WorkflowLogger = WorkflowLogger;
                devicePrepManager.InitializeDevice(false);

                // Configure the device (apply settings, load simulator ADF, etc.)
                UpdateStatus("Configuring device...");
                ConfigureDevice(deviceInfo);
                ScanLog.PageCount = (short)ScanOptions.PageCount;
                ScanLog.Sender    = ExecutionData.Credential.UserName;

                // Set up the job (enter parameters, etc.)
                RecordEvent(DeviceWorkflowMarker.ActivityBegin);
                UpdateStatus("Setting up job...");
                SetupJob(device);
                UpdateStatus("Job setup complete.");

                // Finish the job (apply job build options, press start, wait for finish)
                UpdateStatus("Finishing job...");
                result = FinishJob(device);
                UpdateStatus("Job finished.");

                try
                {
                    SignOut();
                    RecordEvent(DeviceWorkflowMarker.ActivityEnd);
                }
                catch (Exception ex) when(ex is DeviceCommunicationException || ex is DeviceInvalidOperationException)
                {
                    // Don't fail the activity if there is an exception here.
                    UpdateStatus("Device could not return to home screen.");
                    //GatherTriageData(device, $"Device could not return to home screen: {ex.ToString()}");
                }

                // SignOut will be developed
                UpdateStatus("Activity finished.");
            }
            catch (DeviceCommunicationException ex)
            {
                result = new PluginExecutionResult(PluginResult.Failed, ex, "Device communication error.");
                GatherTriageData(device, ex.ToString());
            }
            catch (DeviceInvalidOperationException ex)
            {
                result = new PluginExecutionResult(PluginResult.Failed, ex, "Device automation error.");
                GatherTriageData(device, ex.ToString());
            }
            catch (DeviceWorkflowException ex)
            {
                result = new PluginExecutionResult(PluginResult.Failed, ex, "Device workflow error.");
                GatherTriageData(device, ex.ToString());
            }
            catch (Exception ex)
            {
                GatherTriageData(device, $"Unexpected exception, gathering triage data: {ex.ToString()}");
                throw;
            }
            return(result);
        }