Example #1
0
 public JetAdvantageManager(PluginExecutionData executionData, DeviceWorkflowLogger workflowLogger, IDevice device, PrintDeviceInfo printDeviceInfo)
 {
     _pluginExecutionData = executionData;
     _activityData        = executionData.GetMetadata <JetAdvantageActivityData>();
     _device          = device;
     _printDeviceInfo = printDeviceInfo;
     WorkflowLogger   = workflowLogger;
 }
Example #2
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);
        }
        private void PrepareDevice(DeviceWorkflowLogger workflowLogger)
        {
            _preparationManager.InitializeDevice(_initMethod != InitiationMethod.DoNotSignIn);
            _preparationManager.WorkflowLogger = workflowLogger;

            OnHomeScreen      = true;
            IsUnAuthenticated = true;
            IsAuthenticated   = false;
        }
Example #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CollectDeviceSystemInfoEngine"/> class.
 /// </summary>
 /// <param name="executionData">The execution data.</param>
 /// <exception cref="ArgumentNullException">executionData</exception>
 public CollectDeviceSystemInfoEngine(PluginExecutionData executionData) : base()
 {
     if (executionData == null)
     {
         throw new ArgumentNullException(nameof(executionData));
     }
     ErrorMessage   = string.Empty;
     ProblemDevices = new ConcurrentBag <string>();
     _executionData = executionData;
     WorkflowLogger = new DeviceWorkflowLogger(executionData);
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="ContentionManager"/> class.
        /// </summary>
        /// <param name="executionData"></param>
        public ContentionManager(PluginExecutionData executionData)
        {
            if (executionData == null)
            {
                throw new ArgumentNullException(nameof(executionData));
            }

            _data          = executionData.GetMetadata <ContentionData>();
            ExecutionData  = executionData;
            WorkflowLogger = new DeviceWorkflowLogger(executionData);
        }
        protected LinkPrintActivityManager(PluginExecutionData executionData, LockTimeoutData lockTimeoutData)
        {
            if (executionData == null)
            {
                throw new ArgumentNullException(nameof(executionData));
            }

            ExecutionData    = executionData;
            WorkflowLogger   = new DeviceWorkflowLogger(executionData);
            ConnectorLog     = new ConnectorJobInputLog(executionData, LinkJobType);
            _lockTimeoutData = lockTimeoutData;
        }
Example #7
0
        /// <summary>
        /// Executes this plugin's workflow using the specified <see cref="PluginExecutionData" />.
        /// </summary>
        /// <param name="executionData">The execution data.</param>
        /// <returns>A <see cref="PluginExecutionResult" /> indicating the outcome of the execution.</returns>
        public PluginExecutionResult Execute(PluginExecutionData executionData)
        {
            _executionData     = executionData;
            _performanceLogger = new DeviceWorkflowLogger(_executionData);
            _activityData      = executionData.GetMetadata <EWSFirmwarePerformanceActivityData>();

            TimeSpan lockTimeout = TimeSpan.FromMinutes(10);
            TimeSpan holdTimeout = TimeSpan.FromMinutes(60);

            PluginExecutionResult result = new PluginExecutionResult(PluginResult.Failed, "Failed to Start Upgrade");


            ///Dictionary<string, PluginExecutionResult> results = new Dictionary<string, PluginExecutionResult>();
            if (_executionData.Assets.OfType <IDeviceInfo>().Count() == 0)
            {
                return(new PluginExecutionResult(PluginResult.Failed, $"There were no assets retrieved.  If this is a count-based run, your reservation in asset inventory may have expired.", "DeviceInfo Asset error"));
            }

            try
            {
                var assetTokens = _executionData.Assets.OfType <IDeviceInfo>().Select(n => new AssetLockToken(n, lockTimeout, holdTimeout));
                _performanceLogger.RecordEvent(DeviceWorkflowMarker.DeviceLockBegin);
                ExecutionServices.CriticalSection.Run(assetTokens, selectedToken =>
                {
                    _performanceLogger.RecordEvent(DeviceWorkflowMarker.ActivityBegin);

                    IDeviceInfo asset = (selectedToken as AssetLockToken).AssetInfo as IDeviceInfo;
                    ExecutionServices.DataLogger.Submit(new ActivityExecutionAssetUsageLog(_executionData, asset));

                    ExecutionServices.SystemTrace.LogDebug("Validating Firmware bundle for the selected asset");
                    result = ValidateFirmwareBundles(asset.AssetId, asset.AdminPassword, asset.Address);
                    if (result.Result == PluginResult.Failed)
                    {
                        throw new DeviceWorkflowException($"Failed to validate FW bundle for device {asset.AssetId}. Error: {result.Message}");
                    }
                    if (result.Result != PluginResult.Skipped)
                    {
                        ExecutionServices.SystemTrace.LogDebug($"Performing update on device {asset.AssetId} at address {asset.Address}");

                        result = UpgradeFirmware(asset);
                    }
                });
            }
            catch (Exception e)
            {
                ExecutionServices.SystemTrace.LogDebug(e);
                UpdateStatus(e.Message);
                result = new PluginExecutionResult(PluginResult.Failed, e.Message);
            }
            _performanceLogger.RecordEvent(DeviceWorkflowMarker.ActivityEnd);
            _performanceLogger.RecordEvent(DeviceWorkflowMarker.DeviceLockEnd);
            return(result);
        }
Example #8
0
        protected ScanActivityManager(PluginExecutionData executionData)
        {
            if (executionData == null)
            {
                throw new ArgumentNullException(nameof(executionData));
            }

            ExecutionData  = executionData;
            FilePrefix     = new ScanFilePrefix(executionData.SessionId, executionData.Credential.UserName, ScanType);
            ScanLog        = new DigitalSendJobInputLog(executionData, FilePrefix, ScanType);
            WorkflowLogger = new DeviceWorkflowLogger(executionData);
        }
Example #9
0
        protected LinkScanActivityManager(PluginExecutionData executionData, LockTimeoutData lockTimeoutData)
        {
            if (executionData == null)
            {
                throw new ArgumentNullException(nameof(executionData));
            }

            ExecutionData    = executionData;
            FilePrefix       = new ScanFilePrefix(executionData.SessionId, executionData.Credential.UserName, LinkJobType);
            WorkflowLogger   = new DeviceWorkflowLogger(executionData);
            ConnectorLog     = new ConnectorJobInputLog(executionData, LinkJobType);
            _lockTimeoutData = lockTimeoutData;
        }
Example #10
0
        public WindjammerAuthenticatorDriver(JediWindjammerDevice device, string solutionButton, DeviceWorkflowLogger workflowLogger)
        {
            _device             = device;
            _preparationManager = new JediWindjammerPreparationManager(_device);
            _workflowLogger     = workflowLogger;

            _controlPanel = _device.ControlPanel;


            _solutionButton = solutionButton;
            _initMethod     = AuthInitMethod.GetInitiationMethod(_solutionButton);

            PrepareDevice();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="OmniAuthenticatorDriver"/> class.
        /// </summary>
        /// <param name="device">The device.</param>
        /// <param name="solutionButton">The solution button.</param>
        public OmniAuthenticatorDriver(JediOmniDevice device, string solutionButton, DeviceWorkflowLogger workflowLogger)
        {
            _omniDevice   = device;
            _controlPanel = device.ControlPanel;
            _launchHelper = new JediOmniLaunchHelper(device);
            _launchHelper.WorkflowLogger = workflowLogger;

            _preparationManager = new JediOmniPreparationManager(_omniDevice);
            _preparationManager.WorkflowLogger = workflowLogger;

            _solutionButton = solutionButton;
            _workflowLogger = workflowLogger;

            _initMethod = AuthInitMethod.GetInitiationMethod(solutionButton);

            PrepareDevice();
        }
Example #12
0
        private void LogPerformance(int iterations)
        {
            try
            {
                PluginConfigurationData configData     = PluginConfigurationData.LoadFromFile("C:\\Work\\PluginConfig\\GFriendDataBlank.plugindata");
                PluginExecutionData     executionData  = CreateExecutionData(configData);
                DeviceWorkflowLogger    workflowLogger = new DeviceWorkflowLogger(executionData);

                for (int i = 0; i < iterations; i++)
                {
                    workflowLogger.RecordEvent(DeviceWorkflowMarker.DeviceLockBegin);
                }
            }
            catch (Exception ex)
            {
                TraceFactory.Logger.Error(ex);
            }
        }
Example #13
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);
        }
Example #14
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);
        }
        /// <summary>
        /// Executes this plugin's workflow using the specified <see cref="PluginExecutionData" />.
        /// </summary>
        /// <param name="executionData">The execution data.</param>
        /// <returns>A <see cref="PluginExecutionResult" /> indicating the outcome of the execution.</returns>
        public PluginExecutionResult Execute(PluginExecutionData executionData)
        {
            _executionData     = executionData;
            _activityData      = executionData.GetMetadata <RebootActivityData>();
            _performanceLogger = new DeviceWorkflowLogger(_executionData);

            TimeSpan lockTimeout = TimeSpan.FromMinutes(10);
            TimeSpan holdTimeout = TimeSpan.FromMinutes(60);


            UpdateStatus("Starting activity.");
            if (_executionData.Assets.OfType <IDeviceInfo>().Count() == 0)
            {
                return(new PluginExecutionResult(PluginResult.Failed, $"There were no assets retrieved.  If this is a count-based run, your reservation in asset inventory may have expired.", "DeviceInfo Asset error"));
            }

            PluginExecutionResult result = new PluginExecutionResult(PluginResult.Failed, "Failed to Start Reboot");


            try
            {
                var assetTokens = _executionData.Assets.OfType <IDeviceInfo>().Select(n => new AssetLockToken(n, lockTimeout, holdTimeout));
                _performanceLogger.RecordEvent(DeviceWorkflowMarker.DeviceLockBegin);

                ExecutionServices.CriticalSection.Run(assetTokens, selectedToken =>
                {
                    _performanceLogger.RecordEvent(DeviceWorkflowMarker.ActivityBegin);

                    IDeviceInfo asset = (selectedToken as AssetLockToken).AssetInfo as IDeviceInfo;
                    ExecutionServices.DataLogger.Submit(new ActivityExecutionAssetUsageLog(_executionData, asset));
                    IDevice device = DeviceConstructor.Create(asset);


                    ExecutionServices.SystemTrace.LogInfo($@"Rebooting {asset.AssetId}");
                    UpdateStatus($@"Rebooting {asset.AssetId}");

                    result = RebootDevice(device);


                    //If we rebooted AND we want to set PJL, do so
                    if (_activityData.SetPaperless)
                    {
                        //Wait for WS* to come back up. It's one of the last services
                        WaitForService(device);

                        Thread.Sleep(60000);
                        EnablePJL(device);
                        Thread.Sleep(1000);
                        SetPaperlessPrintMode(true, device);
                    }
                });
            }
            catch (Exception e)
            {
                ExecutionServices.SystemTrace.LogInfo(e);
                UpdateStatus(e.Message);
                result = new PluginExecutionResult(PluginResult.Failed, e.Message);
            }


            UpdateStatus("Finished activity.");
            UpdateStatus($"Result = {result.Result}");

            return(result);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="CollectDeviceJobInfoEngine"/> class.
 /// </summary>
 /// <param name="executionData">The execution data.</param>
 /// <exception cref="ArgumentNullException">executionData</exception>
 public CollectDeviceJobInfoEngine(PluginExecutionData executionData) : base()
 {
     _executionData = executionData ?? throw new ArgumentNullException(nameof(executionData));
     ProblemDevices = new Dictionary <string, string>();
     WorkflowLogger = new DeviceWorkflowLogger(executionData);
 }
Example #17
0
        /// <summary>
        /// Executes this plug-in's workflow using the specified <see cref="PluginExecutionData"/>.
        /// </summary>
        /// <param name="executionData">The execution data.</param>
        /// <returns>A <see cref="PluginExecutionResult"/> indicating the outcome of the
        /// execution.</returns>
        public PluginExecutionResult Execute(PluginExecutionData executionData)
        {
            _executionData     = executionData;
            _performanceLogger = new DeviceWorkflowLogger(_executionData);
            _activityData      = _executionData.GetMetadata <DriverlessPrintingActivityData>();
            var printer = executionData.Assets.OfType <PrintDeviceInfo>().FirstOrDefault();

            if (printer == null)
            {
                return(new PluginExecutionResult(PluginResult.Skipped, "No assets available for execution."));
            }
            if (!printer.Attributes.HasFlag(AssetAttributes.Printer))
            {
                return(new PluginExecutionResult(PluginResult.Skipped, "The device has no print capability."));
            }
            var address = printer.Address;

            var iteratorMode = _activityData.ShuffleDocuments
                ? CollectionSelectorMode.ShuffledRoundRobin
                : CollectionSelectorMode.Random;
            var      documentIterator = new DocumentCollectionIterator(iteratorMode);
            var      document         = documentIterator.GetNext(executionData.Documents);
            FileInfo localFile        = ExecutionServices.FileRepository.GetFile(document);

            if (_activityData.PinProtected)
            {
                AddPinProtection(localFile, _activityData.Pin);
            }

            if (_activityData.PrintMethod == PrintMethod.Random)
            {
                Random newRandom = new Random(4);
                var    randomInt = newRandom.Next(0, 999) % 4;
                _activityData.PrintMethod = (PrintMethod)randomInt;
            }

            _performanceLogger.RecordEvent(DeviceWorkflowMarker.PrintJobBegin);
            UpdateStatus($"Printing {document.FileName} via {_activityData.PrintMethod}.");
            switch (_activityData.PrintMethod)
            {
            default:
                Print9100(address, localFile);
                break;

            case PrintMethod.Ftp:
                PrintFtp(address, "admin", printer.AdminPassword, localFile, true);
                break;

            case PrintMethod.Ipp:
                PrintIpp(address, localFile);
                break;

            case PrintMethod.Ews:
                PrintEws(address, printer.AdminPassword, localFile);
                break;
            }
            _performanceLogger.RecordEvent(DeviceWorkflowMarker.PrintJobEnd);
            _performanceLogger.RecordExecutionDetail(DeviceWorkflowMarker.PrintJobEnd, _activityData.PrintMethod.ToString());
            ActivityExecutionDocumentUsageLog documentLog = new ActivityExecutionDocumentUsageLog(executionData, document);

            ExecutionServices.DataLogger.Submit(documentLog);

            if (_activityData.PrintJobSeparator)
            {
                UpdateStatus("Printing Job Separator.");
                PrintJobSeparator(address);
            }
            localFile.Delete();
            return(_result);
        }
Example #18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PullPrintManager"/> class.
 /// </summary>
 /// <param name="pluginExecutionData">The plugin execution data.</param>
 protected PullPrintManager(PluginExecutionData pluginExecutionData)
 {
     ExecutionData  = pluginExecutionData;
     WorkflowLogger = new DeviceWorkflowLogger(pluginExecutionData);
 }
Example #19
0
 /// <summary>
 /// Initialize Print Activity manager
 /// </summary>
 /// <param name="executionData">Execution data</param>
 protected MobilePrintActivityManager(PluginExecutionData executionData)
 {
     ExecutionData  = executionData;
     WorkflowLogger = new DeviceWorkflowLogger(executionData);
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="OmniAuthenticatorDriver"/> class.
        /// </summary>
        /// <param name="device">The device.</param>
        /// <param name="solutionButton">The solution button.</param>
        /// <param name="maxWaitTime">The maximum wait time.</param>
        public SiriusUIv3AuthenticationDriver(SiriusUIv3Device device, string solutionButton, DeviceWorkflowLogger workflowLogger)
        {
            _device       = device;
            _controlPanel = device.ControlPanel;

            _preparationManager = new SiriusUIv3PreparationManager(_device);
            _solutionButton     = solutionButton;

            _initMethod = AuthInitMethod.GetInitiationMethod(solutionButton);

            PrepareDevice(workflowLogger);
        }
        /// <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.");
            }
        }
Example #22
0
        /// <summary>
        /// Executes this plugin's workflow using the specified <see cref="PluginExecutionData" />.
        /// </summary>
        /// <param name="executionData">The execution data.</param>
        /// <returns>A <see cref="PluginExecutionResult" /> indicating the outcome of the execution.</returns>
        public PluginExecutionResult Execute(PluginExecutionData executionData)
        {
            _executionData     = executionData;
            _performanceLogger = new DeviceWorkflowLogger(_executionData);
            _activityData      = executionData.GetMetadata <USBFirmwarePerformanceActivityData>();

            TimeSpan lockTimeout = TimeSpan.FromMinutes(10);
            TimeSpan holdTimeout = TimeSpan.FromMinutes(60);

            PluginExecutionResult result = new PluginExecutionResult(PluginResult.Failed, "Failed to Start Upgrade");


            ///Dictionary<string, PluginExecutionResult> results = new Dictionary<string, PluginExecutionResult>();
            if (_executionData.Assets.OfType <IDeviceInfo>().Count() == 0)
            {
                return(new PluginExecutionResult(PluginResult.Failed, $"There were no assets retrieved.  If this is a count-based run, your reservation in asset inventory may have expired.", "DeviceInfo Asset error"));
            }

            try
            {
                var assetTokens = _executionData.Assets.OfType <IDeviceInfo>().Select(n => new AssetLockToken(n, lockTimeout, holdTimeout));
                _performanceLogger.RecordEvent(DeviceWorkflowMarker.DeviceLockBegin);
                ExecutionServices.CriticalSection.Run(assetTokens, selectedToken =>
                {
                    _performanceLogger.RecordEvent(DeviceWorkflowMarker.ActivityBegin);

                    IDeviceInfo asset = (selectedToken as AssetLockToken).AssetInfo as IDeviceInfo;
                    IDevice device    = DeviceConstructor.Create(asset);
                    ExecutionServices.DataLogger.Submit(new ActivityExecutionAssetUsageLog(_executionData, asset));

                    ExecutionServices.SystemTrace.LogDebug($"Performing update on device {asset.AssetId} at address {asset.Address}");

                    result = UpgradeFirmware(asset);


                    if (result.Result != PluginResult.Passed)
                    {
                        //the update process failed, just return
                        return;
                    }

                    if (!_activityData.ValidateFlash)
                    {
                        _performanceLogger.RecordExecutionDetail(DeviceWorkflowMarker.FirmwareUpdateEnd, device.GetDeviceInfo().FirmwareRevision);
                        return;
                    }

                    int maxRetries = (int)_activityData.ValidateTimeOut.TotalSeconds / 5;
                    if (Retry.UntilTrue(() => HasDeviceRebooted(device), maxRetries, TimeSpan.FromSeconds(5)))
                    {
                        _performanceLogger.RecordEvent(DeviceWorkflowMarker.DeviceRebootBegin);
                        UpdateStatus("Device has Rebooted. Waiting for device to boot up...");
                    }
                    else
                    {
                        result = new PluginExecutionResult(PluginResult.Failed, $"Device did not reboot after firmware was uploaded. Please check the device for pending jobs and try again.");
                        return;
                    }


                    ExecutionServices.SystemTrace.LogInfo($"FW Update Complete");

                    //Wait for device to finish rebooting or end
                    ExecutionServices.SystemTrace.LogInfo($"Starting Reboot");
                    UpdateStatus("Waiting for device to boot up...");
                    //_performanceLogger.RecordEvent(DeviceWorkflowMarker.DeviceRebootBegin);
                    //We're probably not up and running right away.
                    Thread.Sleep(TimeSpan.FromSeconds(30));


                    ExecutionServices.SystemTrace.LogDebug($"Max Retries: {maxRetries}");
                    int retry             = 0;
                    string fwRevision     = string.Empty;
                    bool controlPanelUp   = false; //Actually webservices, but close enough.
                    bool embeddedServerUp = false;
                    if (Retry.UntilTrue(() => IsDeviceRunning(device, retry++, ref controlPanelUp, ref embeddedServerUp), maxRetries, TimeSpan.FromSeconds(10)))
                    {
                        try
                        {
                            fwRevision = device.GetDeviceInfo().FirmwareRevision;
                            postRevision_textBox.InvokeIfRequired(c => { c.Text = fwRevision; });
                        }
                        catch
                        {
                            fwRevision = string.Empty;
                        }
                        //Validate update passed by comparing starting and ending FW
                        //result = startingFW != fwRevision ? new PluginExecutionResult(PluginResult.Passed, $"Firmware upgraded for device {device.Address}") : new PluginExecutionResult(PluginResult.Failed, "The device firmware upgrade validation failed");
                        result = new PluginExecutionResult(PluginResult.Passed);
                    }
                    else
                    {
                        result = new PluginExecutionResult(PluginResult.Failed,
                                                           $"Device firmware could not be validated for device:{device.Address} within {_activityData.ValidateTimeOut}");
                    }
                    _performanceLogger.RecordEvent(DeviceWorkflowMarker.DeviceRebootEnd);
                    _performanceLogger.RecordEvent(DeviceWorkflowMarker.FirmwareUpdateEnd);

                    ExecutionServices.SystemTrace.LogInfo($"Reboot End");

                    _activityExecutionDetailLog = new ActivityExecutionDetailLog(_executionData, "PostUpgradeFirmware", fwRevision);
                    ExecutionServices.DataLogger.Submit(_activityExecutionDetailLog);

                    //return result;
                });
            }
            catch (Exception e)
            {
                ExecutionServices.SystemTrace.LogDebug(e);
                UpdateStatus(e.Message);
                result = new PluginExecutionResult(PluginResult.Failed, e.Message);
            }
            _performanceLogger.RecordEvent(DeviceWorkflowMarker.ActivityEnd);
            _performanceLogger.RecordEvent(DeviceWorkflowMarker.DeviceLockEnd);
            return(result);
        }
Example #23
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>Initializes a new instance of the <see cref="RoamAndroidAppManager"/> class.</summary>
 /// <param name="pluginExecutionData">The plugin execution data.</param>
 /// <param name="activityData">The activity data.</param>
 public RoamAndroidAppManager(PluginExecutionData pluginExecutionData, HpRoamActivityData activityData)
     : base(pluginExecutionData, activityData)
 {
     WorkflowLogger = new DeviceWorkflowLogger(pluginExecutionData);
 }
Example #25
0
        /// <summary>
        /// Executes this plugin's workflow using the specified <see cref="PluginExecutionData" />.
        /// </summary>
        /// <param name="executionData">The execution data.</param>
        /// <returns>A <see cref="PluginExecutionResult" /> indicating the outcome of the execution.</returns>
        public PluginExecutionResult Execute(PluginExecutionData executionData)
        {
            UpdateStatus("Starting activity.");
            UpdateLabel(sessionId_value_label, executionData.SessionId);

            _workflowLogger = new DeviceWorkflowLogger(executionData);
            GFriendExecutionActivityData data = executionData.GetMetadata <GFriendExecutionActivityData>();

            UpdateStatus("Prepare Files.");
            string scriptPath;

            if (executionData.Environment.PluginSettings.ContainsKey("GFScriptPath"))
            {
                scriptPath = executionData.Environment.PluginSettings["GFScriptPath"];
            }
            else
            {
                scriptPath = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "scripts", executionData.SessionId);
            }
            UpdateStatus($"GFriend files will be saved to {scriptPath}");

            GFriendPreparationManager.PrepareFiles(data.GFriendFiles, scriptPath);

            string scriptToRun = data.GFriendFiles.Where(s => s.FileType.Equals(GFFileTypes.GFScript)).FirstOrDefault()?.FileName ?? string.Empty;

            if (string.IsNullOrEmpty(scriptToRun))
            {
                UpdateStatus("GF Script file does not exist. Please check activity data");
                return(new PluginExecutionResult(PluginResult.Failed, "Invalid activity data (No Script File)"));
            }

            scriptToRun = Path.Combine(scriptPath, scriptToRun);
            UpdateStatus($"GFriend test script {scriptToRun} will be exeucted.");

            // Run GFriend
            _consoleWriter = new OutputWriter(output_RichTextBox);
            Console.SetOut(_consoleWriter);

            IDeviceInfo           deviceInfo;
            PluginExecutionResult executionResult = new PluginExecutionResult(PluginResult.Passed);

            if (executionData.Assets.Count > 0)
            {
                var devices     = executionData.Assets.OfType <IDeviceInfo>();
                var assetTokens = devices.Select(n => new AssetLockToken(n, data.LockTimeouts));
                _workflowLogger.RecordEvent(DeviceWorkflowMarker.DeviceLockBegin);
                ExecutionServices.CriticalSection.Run(assetTokens, selectedToken =>
                {
                    deviceInfo = (selectedToken as AssetLockToken).AssetInfo as IDeviceInfo;
                    UpdateLabel(dut_value_label, deviceInfo.AssetId);
                    ExecutionServices.DataLogger.Submit(new ActivityExecutionAssetUsageLog(executionData, deviceInfo));
                    executionResult = RunGFriendScript(executionData, scriptToRun, deviceInfo);
                });
                _workflowLogger.RecordEvent(DeviceWorkflowMarker.DeviceLockEnd);
            }
            else
            {
                executionResult = RunGFriendScript(executionData, scriptToRun, null);
            }

            var standardOutput = new StreamWriter(Console.OpenStandardOutput());

            standardOutput.AutoFlush = true;
            Console.SetOut(standardOutput);

            UpdateStatus("Finished activity.");
            UpdateStatus($"Result = {executionResult.Result}");

            return(executionResult);
        }
 public static IAuthenticationDriver Create(IDevice device, string solutionButton, DeviceWorkflowLogger workflowLogger) => _instance.FactoryCreate(device, solutionButton, workflowLogger);