internal void Exercise(DirtyDeviceActivityData activityData, NetworkCredential userCredential, PluginEnvironment environment, AssetAttributes deviceAttribute) { _activityData = activityData; _userCredential = userCredential; _environment = environment; StartEws(deviceAttribute); }
private void Initialize(DirtyDeviceActivityData activityData) { // Copy plugin task-specific settings from activity data to control here... dirtyDeviceSettings.Value = activityData; // Plugin behavior lockTimeoutControl.Initialize(activityData.LockTimeouts); }
public DirtyDeviceManager(Framework.Assets.IDeviceInfo deviceInfo, NetworkCredential userCredential, DirtyDeviceActivityData activityData, PluginEnvironment environment) { _deviceInfo = deviceInfo; _userCredential = userCredential; _environment = environment; _activityData = activityData; InitializeDevice(); }
/// <summary> /// Validates the given metadata against the DirtyDevice Activity data. /// </summary> /// <param name="configurationData">The configuration data.</param> /// <returns>true if valid</returns> public bool ValidateMetadata(ref PluginConfigurationData configurationData) { bool validData = true; DirtyDeviceActivityData activityData = null; try { activityData = configurationData.GetMetadata <DirtyDeviceActivityData>(new[] { new DirtyDeviceDataConverter1_1() }); } catch { activityData = new DirtyDeviceActivityData(); validData = false; } configurationData = new PluginConfigurationData(activityData, DirtyDeviceConfigurationControl.Version); return(validData); }
internal void Exercise(DirtyDeviceActivityData activityData) { const string AppButtonFilter = "-homescreen-button"; var controls = _controlPanel.GetIds("div", OmniIdCollectionType.Children).Where(id => id.EndsWith(AppButtonFilter)).ToArray(); _owner.OnUpdateStatus(this, $"Found {controls.Length} app buttons..."); for (int controlIndex = 0; controlIndex < controls.Length; controlIndex++) { string controlSelector = "#" + controls[controlIndex]; string innerText = _controlPanel.GetValue(controlSelector, "innerText", OmniPropertyType.Property).Trim(); _controlPanel.ScrollToItem(controlSelector); if (_controlPanel.WaitForState(controlSelector, OmniElementState.Useable, TimeSpan.FromSeconds(10))) { _owner.OnUpdateStatus(this, $" Pressing {innerText} ({controlIndex + 1:##}/{controls.Length:##})"); _controlPanel.Press(controlSelector); } else { _owner.OnUpdateStatus(this, $" Skipping {innerText}. App is not available currently. ({controlIndex + 1:##}/{controls.Length:##})"); continue; } System.Threading.Thread.Sleep(5000); try { _preparationManager.Reset(); } catch (Exception x) { _owner.OnUpdateStatus(this, x.ToString()); _owner.OnUpdateStatus(this, $" Pressing 'Home' button did not exit {innerText}. Consider filing a bug report against the app."); _owner.OnUpdateStatus(this, $" Attempting to return to home screen by waiting for timeout."); UnauthenticateByTimeout(); } } }
internal void Exercise(DirtyDeviceActivityData activityData) { for (int seed1 = 0; seed1 <= 2; seed1++) { for (int seed2 = 0; seed2 < 40; seed2++) { string seed = $"{seed1}.{seed2}"; // HP devices only seem to respond to the following seeds but we will try them all: 1.0, 1.2, 1.3 try { _device.Snmp.Walk(seed); } catch (Exception x) { string message = $"Snmp walk failed with seed {seed}."; _owner.OnUpdateStatus(this, message + " ({x.ToString()})"); throw new SnmpException(message, x); } } } }
public void Exercise(DirtyDeviceActivityData activityData, int jobCountGoal) { for (int jobCount = 0; jobCount < jobCountGoal; jobCount++) { var progressMessage = $"{jobCount + 1,3}/{jobCountGoal}"; var helloBytes = Encoding.ASCII.GetBytes($"Hello world! (print job {progressMessage})" + Environment.NewLine); try { using (var tcpClient = new TcpClient(_device.Address, 9100)) using (var stream = tcpClient.GetStream()) { stream.Write(helloBytes, 0, helloBytes.Length); } } catch (Exception) { _owner.OnUpdateStatus(this, $"Exception sending print job {progressMessage}"); throw; } Thread.Sleep(1000); } }
internal void Exercise(DirtyDeviceActivityData activityData, AssetAttributes deviceAttributes) { WebServiceTicket webTicket; var callList = new[] { new { EndPoint = "device", Uri = "urn:hp:imaging:con:service:device:DeviceService", GetOrSet = "get", }, }.ToList(); if (deviceAttributes.HasFlag(AssetAttributes.Scanner)) { callList = new[] { new { EndPoint = "device", Uri = "urn:hp:imaging:con:service:device:DeviceService", GetOrSet = "get", }, new { EndPoint = "email", Uri = "urn:hp:imaging:con:service:email:EmailService", GetOrSet = "get;set", }, new { EndPoint = "copy", Uri = "urn:hp:imaging:con:service:copy:CopyService", GetOrSet = "get;set", }, }.ToList(); } foreach (var call in callList) { for (var attempt = 1; attempt <= MaxRetryCount; attempt++) { try { _owner.OnUpdateStatus(this, $" Performing web service GET. (EndPoint: {call.EndPoint}; Uri: {call.Uri})"); webTicket = GetUrn(call.EndPoint, call.Uri); _owner.OnUpdateStatus(this, $" Device response was {webTicket.ToString().Length} characters."); } catch (Exception x) { _owner.OnUpdateStatus(this, $" Could not perform web service GET. (Device: {_device.Address}; EndPoint: {call.EndPoint}; Uri: {call.Uri}; Error: {x.Message})"); if (attempt >= MaxRetryCount) { throw; } _owner.OnUpdateStatus(this, $" Will attempt {MaxRetryCount - attempt} more times."); // Cannot proceed to set that which we did not successfully get. continue; } if (call.GetOrSet.Contains("set")) { try { _owner.OnUpdateStatus(this, $" Performing web service SET. (EndPoint: {call.EndPoint}; Uri: {call.Uri})"); SetUrn(call.EndPoint, call.Uri, webTicket); // If we got this far successfully, we are done. We do not need to retry. break; } catch (Exception x) { _owner.OnUpdateStatus(this, $" Could not perform web service SET. (Device: {_device.Address}; EndPoint: {call.EndPoint}; Uri: {call.Uri}; Error: {x.Message})"); if (attempt >= MaxRetryCount) { throw; } _owner.OnUpdateStatus(this, $" Will attempt {MaxRetryCount - attempt} more times."); } } else { // If we got this far successfully, we are done. We do not need to retry. break; } } } }
/// <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."); } }
internal void Exercise(DirtyDeviceActivityData activityData, NetworkCredential userCredential, PluginEnvironment environment) { _activityData = activityData; _userCredential = userCredential; string localMachineName = NetUtil.GetFQDN(); string fileShareServerName = $"{activityData.DigitalSend.OutputFolder.ServerHostName}.{environment.UserDnsDomain}"; var externalFacingProtocolSpecificPath = activityData.DigitalSend.OutputFolder.MonitorLocation; var correspondingSharePath = $@"\\{fileShareServerName}\{externalFacingProtocolSpecificPath.Replace("/", @"\")}"; EndpointPath fileSharePath = new EndpointPath( DestinationType.NetworkFolder, fileShareServerName, null, externalFacingProtocolSpecificPath, correspondingSharePath); EndpointPath ftpPath = new EndpointPath( DestinationType.Ftp, localMachineName, null, externalFacingProtocolSpecificPath, correspondingSharePath); EndpointPath httpPath = new EndpointPath( DestinationType.Http, localMachineName, EndpointManager.HttpPort, externalFacingProtocolSpecificPath, correspondingSharePath); var pathManager = new PathManager(fileSharePath, ftpPath, httpPath); _endpointManager = new EndpointManager(pathManager, environment); _endpointManager.UpdateStatus += (s, e) => _owner.OnUpdateStatus(s, e.StatusMessage); // eschew "all inspectable pages are in use" exception foreach (var protocol in new[] { DestinationType.Ftp, DestinationType.Http, DestinationType.NetworkFolder }) { for (var attempt = 1; attempt <= MaxRetryCount; attempt++) { _owner.OnUpdateStatus(this, $""); _preparationManager.InitializeDevice(true); try { ExecuteScanToDestination(protocol); // If we got this far successfully, we are done. We do not need to retry. break; } catch (Exception x) { _owner.OnUpdateStatus(this, $" Digital send failed. (Device: {_deviceDat.Address}; Protocol: {protocol}; Error: {x.Message})"); if (attempt >= MaxRetryCount) { throw; } _owner.OnUpdateStatus(this, $" Will attempt {MaxRetryCount - attempt} more times."); } } } _owner.OnUpdateStatus(this, string.Empty); _preparationManager.InitializeDevice(true); }
internal void Exercise(DirtyDeviceActivityData activityData) { Exercise(activityData, PrintJobCount); }