コード例 #1
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);
        }
コード例 #2
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);
        }