Esempio n. 1
0
        /// <summary>
        /// Performs the Control Panel activity if lock is acquired on the device, otherwise performs the Contention Activity.
        /// </summary>
        /// <returns></returns>
        public PluginExecutionResult RunContentionJob()
        {
            var result = new PluginExecutionResult(PluginResult.Failed);

            try
            {
                IEnumerable <IDeviceInfo>    devices     = ExecutionData.Assets.OfType <IDeviceInfo>();
                IEnumerable <AssetLockToken> assetTokens = devices.Select(n => new AssetLockToken(n, _data.LockTimeouts));

                RecordEvent(DeviceWorkflowMarker.DeviceLockBegin);
                ExecutionServices.CriticalSection.Run(assetTokens, selectedToken =>
                {
                    IDeviceInfo deviceInfo = (selectedToken as AssetLockToken).AssetInfo as IDeviceInfo;
                    using (IDevice device = DeviceConstructor.Create(deviceInfo))
                    {
                        var retryManager = new PluginRetryManager(ExecutionData, UpdateStatus);
                        result           = retryManager.Run(() => RunControlPanelActivity(device));
                    }
                }
                                                      );
                RecordEvent(DeviceWorkflowMarker.DeviceLockEnd);
            }
            catch (AcquireLockTimeoutException)
            {
                //If the user is unable to acquire the lock on device, run the contention activity.
                result = RunContentionActivity();
            }
            catch (HoldLockTimeoutException)
            {
                result = new PluginExecutionResult(PluginResult.Error, $"Automation did not complete within {_data.LockTimeouts.HoldTimeout}.", "Automation timeout exceeded.");
            }
            return(result);
        }
Esempio n. 2
0
        public PluginExecutionResult Execute(PluginExecutionData executionData)
        {
            _engine.Initialize();
            var retryManager = new PluginRetryManager(executionData, UpdateStatus);

            return(retryManager.Run(() => _engine.ProcessActivity(executionData)));
        }
Esempio n. 3
0
        public PluginExecutionResult Execute(PluginExecutionData executionData)
        {
            ActivityOutcomeData activityData = executionData.GetMetadata <ActivityOutcomeData>();
            var retryManager = new PluginRetryManager(executionData, UpdateStatus);

            return(retryManager.Run(() => DoActivity(executionData, activityData)));
        }
Esempio n. 4
0
        public PluginExecutionResult Execute(PluginExecutionData executionData)
        {
            var                  result          = new PluginExecutionResult(PluginResult.Passed);
            IAssetInfo           printAsset      = (IAssetInfo)executionData.Assets.First();;
            DeviceWorkflowLogger workflowLogger  = new DeviceWorkflowLogger(executionData);
            PrintDeviceInfo      printDeviceInfo = (PrintDeviceInfo)executionData.Assets.First();

            var activityData = executionData.GetMetadata <JetAdvantageActivityData>();

            try
            {
                using (_device = GetDevice(printDeviceInfo))
                {
                    FillFormWithActivityData(activityData);
                    workflowLogger.RecordEvent(DeviceWorkflowMarker.DeviceLockBegin);
                    UpdateStatus("Starting JetAdvantage Pull Printing Application");

                    _manager = new JetAdvantageManager(executionData, workflowLogger, _device, printDeviceInfo);
                    _manager.StatusUpdate += _manager_StatusUpdate;

                    var token = new AssetLockToken(printAsset, TimeSpan.FromHours(1), TimeSpan.FromHours(1));

                    ExecutionServices.CriticalSection.Run(token, () =>
                    {
                        var retryManager = new PluginRetryManager(executionData, UpdateStatus);
                        result           = retryManager.Run(() => _manager.RunJetAdvantage());
                    });
                }
                workflowLogger.RecordEvent(DeviceWorkflowMarker.DeviceLockEnd);
            }
            catch (DeviceCommunicationException ex)
            {
                return(new PluginExecutionResult(PluginResult.Failed, ex.Message, "Device communication error."));
            }
            catch (DeviceInvalidOperationException ex)
            {
                return(new PluginExecutionResult(PluginResult.Failed, ex.Message, "Device automation error."));
            }
            catch (DeviceWorkflowException ex)
            {
                result = new PluginExecutionResult(PluginResult.Failed, ex, "Device workflow error.");
            }
            catch (ScalableTest.Framework.Synchronization.AcquireLockTimeoutException)
            {
                return(new PluginExecutionResult(PluginResult.Skipped, "Could not obtain lock on specified device(s).", "Device unavailable."));
            }
            catch (ScalableTest.Framework.Synchronization.HoldLockTimeoutException)
            {
                return(new PluginExecutionResult(PluginResult.Error, $"Automation did not complete within {TimeSpan.FromHours(1)}.", "Automation timeout exceeded."));
            }
            finally
            {
                UpdateStatus($"Finished JetAdvantage Printing activity");
            }


            return(result);
        }
        public PluginExecutionResult Execute(PluginExecutionData executionData)
        {
            _pluginExecutionData = executionData;
            _activityData        = executionData.GetMetadata <HpcrSimulationData>();

            _hpcrClient = new HpcrExecutionProxyClient(executionData.Environment.PluginSettings["HpcrProxy"]);

            var retryManager             = new PluginRetryManager(executionData, UpdateStatus);
            PluginExecutionResult result = retryManager.Run(PerformActivity);

            return(result);
        }
Esempio n. 6
0
        /// <summary>
        /// Executes the pull print operation.
        /// </summary>
        /// <returns></returns>
        public virtual PluginExecutionResult ExecutePullPrintOperation()
        {
            PluginExecutionResult result = new PluginExecutionResult(PluginResult.Failed, "Automation Failure", "Device workflow error.");

            try
            {
                var devices     = ExecutionData.Assets.OfType <IDeviceInfo>();
                var assetTokens = devices.Select(n => new AssetLockToken(n, LockTimeouts));

                //If there is no device to run
                if (assetTokens.Count() == 0)
                {
                    //Skip when there are no device to execute on.
                    return(new PluginExecutionResult(PluginResult.Skipped, "No Asset available to run."));
                }

                RecordEvent(DeviceWorkflowMarker.DeviceLockBegin);

                ExecutionServices.CriticalSection.Run(assetTokens, selectedToken =>
                {
                    DeviceInfo = (selectedToken as AssetLockToken).AssetInfo as IDeviceInfo;
                    InitializeDevice();
                    InitializeAuthenticator(AuthProvider);

                    OnDeviceSelected(DeviceInfo.AssetId);
                    //OnDocumentProcessSelected(_activityData.DocumentProcessAction.GetDescription());
                    OnSessionIdUpdate(ExecutionData.SessionId);
                    LogDevice(DeviceInfo);

                    using (Device)
                    {
                        PluginRetryManager retryManager = new PluginRetryManager(ExecutionData, this.OnStatusUpdate);
                        result = retryManager.Run(() => LaunchAndPull());
                    }
                });
            }
            catch (AcquireLockTimeoutException)
            {
                result = new PluginExecutionResult(PluginResult.Skipped, "Could not obtain lock on specified device(s).", "Device unavailable.");
            }
            catch (HoldLockTimeoutException)
            {
                result = new PluginExecutionResult(PluginResult.Error, $"Automation did not complete within {LockTimeouts.HoldTimeout}.", "Automation timeout exceeded.");
            }
            finally
            {
                OnStatusUpdate($"Finished {PullPrintSolution} activity");

                WorkflowLogger.RecordEvent(DeviceWorkflowMarker.DeviceLockEnd);
            }
            return(result);
        }
Esempio n. 7
0
        /// <summary>
        /// Runs the scan activity.
        /// </summary>
        /// <returns>The result of the activity.</returns>
        public PluginExecutionResult RunScanActivity()
        {
            PluginExecutionResult result = new PluginExecutionResult(PluginResult.Failed, "Automation Execution Failure", "Device workflow error.");

            try
            {
                var devices     = ExecutionData.Assets.OfType <IDeviceInfo>();
                var assetTokens = devices.Select(n => new AssetLockToken(n, ScanOptions.LockTimeouts));

                //If there is no device to run
                if (assetTokens.Count() == 0)
                {
                    //Skip When there are no device to execute on.
                    return(new PluginExecutionResult(PluginResult.Skipped, "No Asset available to run."));
                }

                RecordEvent(DeviceWorkflowMarker.DeviceLockBegin);
                ExecutionServices.CriticalSection.Run(assetTokens, selectedToken =>
                {
                    IDeviceInfo deviceInfo = (selectedToken as AssetLockToken).AssetInfo as IDeviceInfo;
                    DeviceSelected?.Invoke(this, new StatusChangedEventArgs(deviceInfo.AssetId));

                    // Log the device and server used for this activity
                    ScanLog.DeviceId = deviceInfo.AssetId;
                    ExecutionServices.DataLogger.Submit(new ActivityExecutionAssetUsageLog(ExecutionData, deviceInfo));
                    if (_serverName != null)
                    {
                        ExecutionServices.DataLogger.Submit(new ActivityExecutionServerUsageLog(ExecutionData, _serverName));
                    }

                    using (IDevice device = CreateAutomationDevice(deviceInfo))
                    {
                        var retryManager = new PluginRetryManager(ExecutionData, this.UpdateStatus);
                        result           = retryManager.Run(() => ExecuteScan(device, deviceInfo));
                    }
                }
                                                      );

                RecordEvent(DeviceWorkflowMarker.DeviceLockEnd);
            }
            catch (AcquireLockTimeoutException)
            {
                result = new PluginExecutionResult(PluginResult.Skipped, "Could not obtain lock on specified device(s).", "Device unavailable.");
            }
            catch (HoldLockTimeoutException)
            {
                result = new PluginExecutionResult(PluginResult.Error, $"Automation did not complete within {ScanOptions.LockTimeouts.HoldTimeout}.", "Automation timeout exceeded.");
            }
            LogDebug("Scan activity complete.");
            return(result);
        }
        /// <summary>
        /// Processes the activity given to the plugin.
        /// </summary>
        /// <param name="executionData"></param>
        public PluginExecutionResult Execute(PluginExecutionData executionData)
        {
            _executionData = executionData;
            HpacServerConfigurationActivityData activityData = _executionData.GetMetadata <HpacServerConfigurationActivityData>();

            if (executionData.Assets.Count > 0)
            {
                activityData.DeviceData.Asset = (IDeviceInfo)executionData.Assets.FirstOrDefault();
            }

            PluginExecutionResult result = new PluginExecutionResult(PluginResult.Passed);



            try
            {
                _hpacServer = _executionData.Servers.First();
                _hostName   = _hpacServer.HostName;
                if (!_hostName.Contains(executionData.Environment.UserDnsDomain))
                {
                    _hostName += "." + executionData.Environment.UserDnsDomain;
                }
                LogUsageData(_hpacServer);
            }
            catch (ArgumentNullException ex)
            {
                return(new PluginExecutionResult(PluginResult.Error, ex));
            }
            catch (InvalidOperationException ex)
            {
                return(new PluginExecutionResult(PluginResult.Error, ex));
            }

            if (_hpacController == null)
            {
                _hpacController = new HpacServerConfigurationController(_executionData.Environment.UserDnsDomain, _hostName, _hpacServer.Address, _executionData.Credential);
            }

            UpdateUI(_hostName, activityData.HpacConfigTile.ToString());
            UpdateStatus("Starting HPAC Server Configuring  Activity...");

            var retryManager = new PluginRetryManager(executionData, UpdateStatus);

            result = retryManager.Run(() => ExecuteTask(activityData));

            return(result);
        }
Esempio n. 9
0
        /// <summary>
        /// Execute the task of the PrintFromUsb activity.
        /// </summary>
        /// <param name="executionData"></param>
        /// <returns></returns>
        public PluginExecutionResult Execute(PluginExecutionData executionData)
        {
            PluginExecutionResult result = new PluginExecutionResult(PluginResult.Failed);

            var acquireTimeout = TimeSpan.FromMinutes(10);
            var holdTimeout    = TimeSpan.FromMinutes(10);

            _executionData = executionData;
            _deviceAssets  = executionData.Assets.OfType <IDeviceInfo>().ToList();

            //If there is no device to run
            if (_deviceAssets.Count() == 0)
            {
                //Skip When there are no device to execute on.
                return(new PluginExecutionResult(PluginResult.Skipped, "No Asset available to run."));
            }

            _workflowLogger = new DeviceWorkflowLogger(executionData);
            UpdateStatus("Starting task engine");
            List <AssetLockToken> tokens = _deviceAssets.Select(n => new AssetLockToken(n, acquireTimeout, holdTimeout)).ToList();

            _workflowLogger.RecordEvent(DeviceWorkflowMarker.DeviceLockBegin);
            ExecutionServices.CriticalSection.Run(tokens, selectedToken =>
            {
                IDeviceInfo deviceInfo = (selectedToken as AssetLockToken).AssetInfo as IDeviceInfo;
                if (!deviceInfo.Attributes.HasFlag(AssetAttributes.Printer))
                {
                    result = new PluginExecutionResult(PluginResult.Skipped, "Device does not have print capability.");
                    return;
                }

                UpdateStatus($"Using device {deviceInfo.AssetId} ({deviceInfo.Address})");
                ExecutionServices.DataLogger.Submit(new ActivityExecutionAssetUsageLog(executionData, deviceInfo));
                using (IDevice device = IDeviceCreate(deviceInfo))
                {
                    var retryManager = new PluginRetryManager(executionData, UpdateStatus);
                    result           = retryManager.Run(() => RunApp(device));
                }
            });

            _workflowLogger.RecordEvent(DeviceWorkflowMarker.DeviceLockEnd);

            return(result);
        }
        /// <summary>
        /// Executes the pull print operation as specified by the Plugin Activity Data.
        /// </summary>
        /// <returns>PluginExecutionResult</returns>
        public PluginExecutionResult ExecutePullPrintOperation()
        {
            PluginExecutionResult result = null;

            try
            {
                IEnumerable <IDeviceInfo>    devices     = _executionData.Assets.OfType <IDeviceInfo>();
                IEnumerable <AssetLockToken> assetTokens = devices.Select(n => new AssetLockToken(n, _activityData.LockTimeouts));

                //If there is no device to run
                if (assetTokens.Count() == 0)
                {
                    //Skip when there are no device to execute on.
                    return(new PluginExecutionResult(PluginResult.Skipped, "No Asset available to run."));
                }

                OnStatusUpdate("Waiting for device lock.");
                RecordEvent(DeviceWorkflowMarker.DeviceLockBegin);
                ExecutionServices.CriticalSection.Run(assetTokens, selectedToken =>
                {
                    IDeviceInfo deviceInfo = (selectedToken as AssetLockToken).AssetInfo as IDeviceInfo;
                    LogDevice(deviceInfo);

                    PluginRetryManager retryManager = new PluginRetryManager(_executionData, this.OnStatusUpdate);
                    result = retryManager.Run(() => LaunchAndPull(deviceInfo));
                });
            }
            catch (AcquireLockTimeoutException)
            {
                result = new PluginExecutionResult(PluginResult.Skipped, "Could not obtain lock on specified device(s).", "Device unavailable.");
            }
            catch (HoldLockTimeoutException)
            {
                result = new PluginExecutionResult(PluginResult.Error, $"Automation did not complete within {_activityData.LockTimeouts.HoldTimeout}.", "Automation timeout exceeded.");
            }
            finally
            {
                OnStatusUpdate("Finished HP Roam Android Pull Print activity.");
                RecordEvent(DeviceWorkflowMarker.DeviceLockEnd);
            }

            return(result);
        }
Esempio n. 11
0
        /// <summary>
        /// Entrypoint for the Plugin Task Execution for TwainDriverConfiguration Plugin
        /// </summary>
        /// <param name="executionData"></param>
        /// <returns></returns>
        public PluginExecutionResult Execute(PluginExecutionData executionData)
        {
            PluginExecutionResult result = new PluginExecutionResult(PluginResult.Passed);
            var acquireTimeout           = TimeSpan.FromMinutes(5);
            var holdTimeout = TimeSpan.FromMinutes(5);

            _executionData = executionData;
            _deviceAssets  = executionData.Assets.OfType <IDeviceInfo>().ToList();
            try
            {
                _workflowLogger = new DeviceWorkflowLogger(executionData);
                UpdateStatus("Starting task engine");
                List <AssetLockToken> tokens = _deviceAssets.Select(n => new AssetLockToken(n, acquireTimeout, holdTimeout)).ToList();
                _workflowLogger.RecordEvent(DeviceWorkflowMarker.DeviceLockBegin);
                ExecutionServices.CriticalSection.Run(tokens, selectedToken =>
                {
                    IDeviceInfo deviceInfo = (selectedToken as AssetLockToken).AssetInfo as IDeviceInfo;

                    UpdateStatus($"Using device {deviceInfo.AssetId} ({deviceInfo.Address})");
                    using (IDevice device = DeviceConstructor.Create(deviceInfo))
                    {
                        var retryManager = new PluginRetryManager(executionData, UpdateStatus);
                        result           = retryManager.Run(() => RunTwain(device, executionData));
                    }
                });

                _workflowLogger.RecordEvent(DeviceWorkflowMarker.DeviceLockEnd);
            }
            catch (DeviceCommunicationException ex)
            {
                return(new PluginExecutionResult(PluginResult.Failed, ex.Message, "Device communication error."));
            }
            catch (DeviceInvalidOperationException ex)
            {
                return(new PluginExecutionResult(PluginResult.Failed, ex.Message, "Device automation error."));
            }
            catch (DeviceWorkflowException ex)
            {
                return(new PluginExecutionResult(PluginResult.Failed, ex, "Device workflow error."));
            }

            return(result);
        }
        public PluginExecutionResult Execute(PluginExecutionData executionData)
        {
            _executionData = executionData;
            SafeComSimulationActivityData activityData = _executionData.GetMetadata <SafeComSimulationActivityData>();
            PluginExecutionResult         result       = new PluginExecutionResult(PluginResult.Passed);

            DeviceInfo assetInfo     = null;
            ServerInfo safecomServer = null;

            try
            {
                assetInfo     = (DeviceInfo)_executionData.Assets.GetRandom();
                safecomServer = _executionData.Servers.First();
                LogUsageData(assetInfo, safecomServer);
            }
            catch (ArgumentNullException ex)
            {
                return(new PluginExecutionResult(PluginResult.Error, ex));
            }
            catch (InvalidOperationException ex)
            {
                return(new PluginExecutionResult(PluginResult.Error, ex));
            }

            if (_safecomController == null)
            {
                _safecomController = new SafeComSimulationController(_executionData.Credential, activityData.SafeComAuthenticationMode, assetInfo.Address, activityData.AssetMacAddress, safecomServer.HostName);
            }

            UpdateUI(safecomServer.HostName, assetInfo.Address);
            UpdateStatus("Starting SafeCom Pull Activity...");

            AssetLockToken lockToken = new AssetLockToken(assetInfo, TimeSpan.FromHours(12), TimeSpan.FromHours(12));

            //On error, Implement Retries before relinquishing the lock.
            ExecutionServices.CriticalSection.Run(lockToken, () =>
            {
                PluginRetryManager retryManager = new PluginRetryManager(_executionData, UpdateStatus);
                result = retryManager.Run(() => ExecuteTask(activityData, assetInfo));
            });

            return(result);
        }
        public PluginExecutionResult Execute(PluginExecutionData executionData)
        {
            _executionData = executionData;
            HpacSimulationActivityData activityData = _executionData.GetMetadata <HpacSimulationActivityData>();
            PluginExecutionResult      result       = new PluginExecutionResult(PluginResult.Passed);

            IPrinterInfo assetInfo  = null;
            ServerInfo   hpacServer = null;

            try
            {
                assetInfo  = (IPrinterInfo)_executionData.Assets.GetRandom();
                hpacServer = _executionData.Servers.First();
                LogUsageData(assetInfo, hpacServer);
            }
            catch (ArgumentNullException ex)
            {
                return(new PluginExecutionResult(PluginResult.Error, ex));
            }
            catch (InvalidOperationException ex)
            {
                return(new PluginExecutionResult(PluginResult.Error, ex));
            }

            if (_hpacController == null)
            {
                _hpacController = new HpacSimulationController(_executionData.Environment.UserDnsDomain, hpacServer.HostName, _executionData.Credential);
            }

            UpdateUI(hpacServer.HostName, assetInfo.AssetId, activityData.PullAllDocuments);
            UpdateStatus("Starting HPAC Pull Activity...");

            //On error or skip, Implement Retries
            PluginRetryManager retryManager = new PluginRetryManager(_executionData, UpdateStatus);

            result = retryManager.Run(() => ExecuteHandler(activityData, assetInfo));

            return(result);
        }
Esempio n. 14
0
        private PluginExecutionResult ProcessActivity()
        {
            PluginRetryManager    retryManager = new PluginRetryManager(_executionData, TraceFactory.Logger.Debug);
            PluginExecutionResult finalResult  = retryManager.Run(() =>
            {
                PluginExecutionResult result = null;
                try
                {
                    result = _plugin.Execute(_executionData);
                }
                catch (WorkerHaltedException)
                {
                    // This exception must be explicitly re-thrown so it isn't eaten by the general catch
                    throw;
                }
                catch (ThreadAbortException ex)
                {
                    Thread.ResetAbort();

                    // Log the whole exception, including stack trace
                    TraceFactory.Logger.Error("Unhandled exception in plugin execution.", ex);
                    result = new PluginExecutionResult(PluginResult.Error, ex.ToString(), "Unhandled exception.");
                }
                catch (Exception ex)
                {
                    // Log the whole exception, including stack trace
                    TraceFactory.Logger.Error("Unhandled exception in plugin execution.", ex);
                    result = new PluginExecutionResult(PluginResult.Error, ex.ToString(), "Unhandled exception.");
                }
                return(result);
            });

            if (finalResult.RetryStatus == PluginRetryStatus.Halt)
            {
                throw new WorkerHaltedException("Retry limit reached");
            }
            return(finalResult);
        }
        /// <summary>
        /// Executes this plugin's workflow using the specified <see cref="T:HP.ScalableTest.Framework.Plugin.PluginExecutionData" />.
        /// </summary>
        /// <param name="executionData">The execution data.</param>
        /// <returns>A <see cref="T:HP.ScalableTest.Framework.Plugin.PluginExecutionResult" /> indicating the outcome of the execution.</returns>
        public PluginExecutionResult Execute(PluginExecutionData executionData)
        {
            // reset current user as it may have changed since control load.
            _executionData = executionData;
            _currentUser   = _executionData.Credential;
            _activityData  = _executionData.GetMetadata <DirtyDeviceActivityData>(new[] { new DirtyDeviceDataConverter1_1() });

            UpdateExecutionStatus(this, "Starting activity...");

            _currentDevice  = _executionData.Assets.GetRandom <Framework.Assets.IDeviceInfo>();
            _workflowLogger = new DeviceWorkflowLogger(_executionData);

            InitializeControlWithActivityData();

            try
            {
                // Wrap in using to release any connections to the device.  This is critical for Omni operations.
                using (DirtyDeviceManager pluginActivityManager = new DirtyDeviceManager(_currentDevice, _currentUser, _activityData, executionData.Environment))
                {
                    pluginActivityManager.UpdateStatus += (s, e) => UpdateExecutionStatus(s, e);

                    if (_currentDevice == null)
                    {
                        return(new PluginExecutionResult(PluginResult.Error, $"{typeof(IDeviceInfo).Name} retrieved is null.  If this is a count-based run, your reservation in asset inventory may have expired.", "DeviceInfo Asset error"));
                    }
                    else if (_currentDevice.AssetId == null)
                    {
                        return(new PluginExecutionResult(PluginResult.Error, $"{typeof(IDeviceInfo).Name}.AssetId property is null.", "DeviceInfo Asset error"));
                    }
                    else if (_currentDevice.AssetType == null)
                    {
                        return(new PluginExecutionResult(PluginResult.Error, $"{typeof(IDeviceInfo).Name}.AssetType property is null.", "DeviceInfo Asset error"));
                    }
                    else if (pluginActivityManager.Device == null)
                    {
                        return(new PluginExecutionResult(PluginResult.Error, $"{nameof(pluginActivityManager)}.Device property is null.", $"Could not create IDevice (AssetId: {_currentDevice.AssetId})"));
                    }

                    PluginExecutionResult pluginExecutionResult = new PluginExecutionResult(PluginResult.Error, new Exception($"The {typeof(PluginExecutionResult)} was never set by the activity."));
                    try
                    {
                        UpdateExecutionStatus(this, $"Waiting for access to {_currentDevice.AssetId} ({_currentDevice.Address})");
                        var token = new AssetLockToken(_currentDevice, _activityData.LockTimeouts.AcquireTimeout, _activityData.LockTimeouts.HoldTimeout);
                        _workflowLogger.RecordEvent(DeviceWorkflowMarker.DeviceLockBegin);
                        ExecutionServices.CriticalSection.Run(token, () =>
                        {
                            var retryManager      = new PluginRetryManager(executionData, (e) => UpdateExecutionStatus(this, e));
                            pluginExecutionResult = retryManager.Run(() =>
                            {
                                ExecutionServices.DataLogger.Submit(new ActivityExecutionAssetUsageLog(_executionData, _currentDevice.AssetId));

                                try
                                {
                                    pluginActivityManager.ExecuteDirty();
                                    return(new PluginExecutionResult(PluginResult.Passed));
                                }
                                catch (DeviceCommunicationException ex)
                                {
                                    GatherTriageData(ex.ToString(), pluginActivityManager);
                                    return(new PluginExecutionResult(PluginResult.Failed, ex, "Device communication error."));
                                }
                                catch (DeviceInvalidOperationException ex)
                                {
                                    GatherTriageData(ex.ToString(), pluginActivityManager);
                                    return(new PluginExecutionResult(PluginResult.Failed, ex, "Device automation error."));
                                }
                                catch (DeviceWorkflowException ex)
                                {
                                    GatherTriageData(ex.ToString(), pluginActivityManager);
                                    return(new PluginExecutionResult(PluginResult.Failed, ex, "Device workflow error."));
                                }
                                catch (Exception ex)
                                {
                                    GatherTriageData(ex.ToString(), pluginActivityManager);
                                    return(new PluginExecutionResult(PluginResult.Error, new Exception($"The plugin activity threw an unexpected exception: {ex.ToString()}", ex)));
                                }
                            });
                        });
                        _workflowLogger.RecordEvent(DeviceWorkflowMarker.DeviceLockEnd);
                    }
                    catch (AcquireLockTimeoutException ex)
                    {
                        GatherTriageData(ex.ToString(), pluginActivityManager);
                        return(new PluginExecutionResult(PluginResult.Skipped, string.Format("Could not obtain lock on device {0}.", (_currentDevice != null ? _currentDevice.AssetId : "null")), "Device unavailable."));
                    }
                    catch (HoldLockTimeoutException ex)
                    {
                        GatherTriageData(ex.ToString(), pluginActivityManager);
                        return(new PluginExecutionResult(PluginResult.Error, $"Automation did not complete within {_activityData.LockTimeouts.HoldTimeout}.", "Automation timeout exceeded."));
                    }
                    catch (Exception ex)
                    {
                        GatherTriageData(ex.ToString(), pluginActivityManager);
                        return(new PluginExecutionResult(PluginResult.Error, new Exception($"The {typeof(PluginRetryManager).Name} threw an unexpected exception.", ex)));
                    }

                    return(pluginExecutionResult);
                }
            }
            catch (Exception x)
            {
                return(new PluginExecutionResult(PluginResult.Error, x, "Plugin error during activity setup."));
            }
            finally
            {
                UpdateExecutionStatus(this, $"Finished activity.");
            }
        }
Esempio n. 16
0
        /// <summary>
        /// Executes this plugin's workflow using the specified <see cref="T:HP.ScalableTest.Framework.Plugin.PluginExecutionData" />.
        /// </summary>
        /// <param name="executionData">The execution data.</param>
        /// <returns>A <see cref="T:HP.ScalableTest.Framework.Plugin.PluginExecutionResult" /> indicating the outcome of the execution.</returns>
        public PluginExecutionResult Execute(PluginExecutionData executionData)
        {
            PluginExecutionResult result = new PluginExecutionResult(PluginResult.Passed);

            _executionData = executionData;

            _deviceAssets = executionData.Assets.OfType <IDeviceInfo>().ToList();
            ExecutionServices.SystemTrace.LogDebug($"# of assets in ExecutionData: {executionData.Assets.Count}");

            try
            {
                UpdateStatus("Starting activity...");
                _activityData = executionData.GetMetadata <AuthenticationData>(ConverterProvider.GetMetadataConverters());

                _workflowLogger = new DeviceWorkflowLogger(executionData);
                TimeSpan acquireTimeout = _activityData.LockTimeouts.AcquireTimeout;
                TimeSpan holdTimeout    = _activityData.LockTimeouts.HoldTimeout;

                string msg = string.Empty;

                List <AssetLockToken> tokens = _deviceAssets.Select(n => new AssetLockToken(n, acquireTimeout, holdTimeout)).ToList();
                _workflowLogger.RecordEvent(DeviceWorkflowMarker.DeviceLockBegin);
                ExecutionServices.CriticalSection.Run(tokens, selectedToken =>
                {
                    IDeviceInfo deviceInfo = (selectedToken as AssetLockToken).AssetInfo as IDeviceInfo;
                    LogDevice(deviceInfo);

                    using (IDevice device = SetDevice(deviceInfo))
                    {
                        var retryManager = new PluginRetryManager(executionData, UpdateStatus);
                        result           = retryManager.Run(() => LaunchApp(device, deviceInfo));
                    }
                });

                _workflowLogger.RecordEvent(DeviceWorkflowMarker.DeviceLockEnd);
            }
            catch (DeviceCommunicationException ex)
            {
                return(new PluginExecutionResult(PluginResult.Failed, ex.Message, "Device communication error."));
            }
            catch (DeviceInvalidOperationException ex)
            {
                return(new PluginExecutionResult(PluginResult.Failed, ex.Message, "Device automation error."));
            }
            catch (DeviceWorkflowException ex)
            {
                result = new PluginExecutionResult(PluginResult.Failed, ex, "Device workflow error.");
            }
            catch (AcquireLockTimeoutException)
            {
                return(new PluginExecutionResult(PluginResult.Skipped, "Could not obtain lock on specified devices(s).", "Device unavailable."));
            }
            catch (HoldLockTimeoutException)
            {
                return(new PluginExecutionResult(PluginResult.Error, $"Automation did not complete within {_activityData.LockTimeouts.HoldTimeout}.", "Automation timeout exceeded."));
            }
            finally
            {
                UpdateStatus("Finished activity");
            }
            return(result);
        }
        /// <summary>
        /// Runs the scan activity.
        /// </summary>
        /// <returns>The result of the activity.</returns>
        public PluginExecutionResult RunLinkPrintActivity()
        {
            PluginExecutionResult result = new PluginExecutionResult(PluginResult.Failed, "Automation Execution Failure", "Device workflow error.");

            try
            {
                var devices     = ExecutionData.Assets.OfType <IDeviceInfo>();
                var assetTokens = devices.Select(n => new AssetLockToken(n, _lockTimeoutData));

                RecordEvent(DeviceWorkflowMarker.DeviceLockBegin);
                ExecutionServices.CriticalSection.Run(assetTokens, selectedToken =>
                {
                    IDeviceInfo deviceInfo = (selectedToken as AssetLockToken).AssetInfo as IDeviceInfo;
                    DeviceSelected?.Invoke(this, new StatusChangedEventArgs(deviceInfo.AssetId));

                    if (_linkPrintOptions != null)
                    {
                        AppNameSelected?.Invoke(this, new StatusChangedEventArgs(_linkPrintOptions.AppName));
                    }
                    else
                    {
                        AppNameSelected?.Invoke(this, new StatusChangedEventArgs(LinkJobType));
                    }

                    ConnectorLog.DeviceId = deviceInfo.AssetId;

                    ExecutionServices.DataLogger.Submit(new ActivityExecutionAssetUsageLog(ExecutionData, deviceInfo));

                    if (_serverName != null)
                    {
                        ExecutionServices.DataLogger.Submit(new ActivityExecutionServerUsageLog(ExecutionData, _serverName));
                    }

                    using (IDevice device = CreateAutomationDevice(deviceInfo))
                    {
                        var retryManager = new PluginRetryManager(ExecutionData, this.UpdateStatus);
                        result           = retryManager.Run(() => ExecuteLinkPrint(device, deviceInfo));
                    }
                }
                                                      );

                RecordEvent(DeviceWorkflowMarker.DeviceLockEnd);
            }
            catch (ArgumentException ex)
            {
                result = new PluginExecutionResult(PluginResult.Skipped, ex.Message, "Device automation error.");
            }
            catch (InvalidOperationException ex)
            {
                result = new PluginExecutionResult(PluginResult.Skipped, ex.Message, "Device automation error.");
            }
            catch (AcquireLockTimeoutException)
            {
                result = new PluginExecutionResult(PluginResult.Skipped, "Could not obtain lock on specified device(s).", "Device unavailable.");
            }
            catch (HoldLockTimeoutException)
            {
                result = new PluginExecutionResult(PluginResult.Error, $"Automation did not complete within {_lockTimeoutData.HoldTimeout}.", "Automation timeout exceeded.");
            }
            LogDebug($"Print activity complete. Result is {result.Result.ToString()}: {result.Message}");

            return(result);
        }