/// <summary> /// Determines whether the simulator is up and ready. /// </summary> /// <param name="hostAddress">The machine name.</param> /// <returns><c>true</c> if the simulator is ready; otherwise, <c>false</c>.</returns> public static bool IsSimulatorReady(string hostAddress) { JediDevice simulator = new JediDevice(hostAddress); return(simulator.GetDeviceStatus() == DeviceStatus.Running && simulator.GetPrinterStatus() >= PrinterStatus.Idle); }
public void WaitForReady() { TimeSpan waitBetweenChecks = TimeSpan.FromSeconds(5); OnUpdateStatus("Waiting for device to come to ready..."); PowerState[] rejectedPowerStates = new PowerState[] { PowerState.Off, PowerState.None }; OnUpdateStatus($" Waiting for device to return a responsive power state..."); int powerCheckCount = 0; bool success = Wait.ForTrue( () => { var state = _device.PowerManagement.GetPowerState(); OnUpdateStatus($" Device Power State: {state}"); bool ok = !rejectedPowerStates.Contains(state); if (ok) { ++powerCheckCount; } return(ok); } , TimeSpan.FromSeconds(240) , waitBetweenChecks); if (!success) { throw new DeviceInvalidOperationException($"Device did not come to an acceptable power state. ({_device.Address})"); } DeviceStatus[] acceptedDeviceStatus = new DeviceStatus[] { DeviceStatus.Running, DeviceStatus.Warning }; OnUpdateStatus($" Waiting for device status reflecting readiness..."); success = Wait.ForTrue( () => { var state = _device.GetDeviceStatus(); OnUpdateStatus($" Device Status: {state}"); return(acceptedDeviceStatus.Contains(state)); } , TimeSpan.FromSeconds(240) , waitBetweenChecks); if (!success) { throw new DeviceInvalidOperationException($"Device did not return an acceptable status. ({_device.Address})"); } OnUpdateStatus($" Waiting for device web services and OXP services to come online..."); const int MaxCreateCreateDeviceAttempts = 10; int createDeviceAttempts = 0; const int ConsecutiveSuccessfulDeviceInfoCallsRequired = 2; int consecutiveSuccessfulDeviceInfoCalls = 0; StringBuilder statusMessages = new StringBuilder(); do { JediDevice tempDevice = null; try { using (tempDevice = (JediDevice)DeviceConstructor.Create(_deviceInfo)) { var deviceInfo = tempDevice.GetDeviceInfo(); if (++consecutiveSuccessfulDeviceInfoCalls >= ConsecutiveSuccessfulDeviceInfoCallsRequired) { string message = $"Device is ready. (FirmwareRevision {deviceInfo.FirmwareRevision}; FirmwareDateCode: {deviceInfo.FirmwareDateCode})"; OnUpdateStatus($" {message}"); break; } else { string message = $"Device is responding. (ModelName {deviceInfo.ModelName}; ModelNumber: {deviceInfo.ModelNumber}; SerialNumber: {deviceInfo.SerialNumber})"; OnUpdateStatus($" {message}"); statusMessages.AppendLine(message); waitBetweenChecks = TimeSpan.FromSeconds(3); } } } catch (InvalidCastException castX) { // Might encounter exception: Unable to cast object of type 'HP.DeviceAutomation.Phoenix.PhoenixDevice' to type 'HP.DeviceAutomation.Jedi.JediDevice'. // Device is still initializing operate a different web service which looks like a Phoenix device. OnUpdateStatus($" Device is still initializing and hosting a rudimentary EWS landing page on a Phoenix-y web server. ({castX.Message})"); statusMessages.AppendLine(castX.ToString()); } catch (DeviceCommunicationException comX) { // HP.DeviceAutomation.DeviceCommunicationException: OXP UI Configuration service could not be found at 15.86.229.141 // HP.DeviceAutomation.DeviceCommunicationException: OXP UI Configuration service at 15.86.229.141 did not respond. OnUpdateStatus($" Device OXP services not yet ready. ({comX.Message})"); statusMessages.AppendLine(comX.ToString()); } catch (Exception x) { OnUpdateStatus($" {x.Message}"); statusMessages.AppendLine(x.ToString()); } Thread.Sleep(waitBetweenChecks); } while (++createDeviceAttempts <= MaxCreateCreateDeviceAttempts); if (createDeviceAttempts >= MaxCreateCreateDeviceAttempts) { OnUpdateStatus(statusMessages.ToString()); throw new DeviceInvalidOperationException($"Device web services and/or OXP services did not respond as expected after {MaxCreateCreateDeviceAttempts} attempts."); } }