Beispiel #1
0
        /// <summary>
        /// Initializes this configuration control with the specified <see cref="PluginConfigurationData" />.
        /// </summary>
        /// <param name="configuration">The configuration data.</param>
        /// <param name="environment">Information about the plugin environment.</param>
        public void Initialize(PluginConfigurationData configuration, PluginEnvironment environment)
        {
            _data = configuration.GetMetadata <USBFirmwarePerformanceActivityData>();
            assetSelectionControl.Initialize(configuration.Assets, AssetAttributes.None);

            checkBoxValidate.Checked      = _data.ValidateFlash;
            validatetimeSpanControl.Value = _data.ValidateTimeOut == TimeSpan.FromMinutes(0) ? TimeSpan.FromMinutes(1) : _data.ValidateTimeOut;
        }
Beispiel #2
0
 /// <summary>
 /// Initializes this configuration control to default values.
 /// </summary>
 /// <param name="environment">Information about the plugin environment.</param>
 public void Initialize(PluginEnvironment environment)
 {
     _data = new USBFirmwarePerformanceActivityData();
     validatetimeSpanControl.Value = TimeSpan.FromMinutes(30.0);
 }
Beispiel #3
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);
        }