public static void Sleep(OsState os, TimeSpan time) { if (time == new TimeSpan(0)) { return; } TickManager tickManager = os.GetTickManager(); // Attempt to avoid overflow by doing the addition unsigned ulong currentTick = (ulong)tickManager.GetTick().GetInt64Value(); ulong timeoutTick = (ulong)tickManager.ConvertToTick(time).GetInt64Value(); ulong absoluteEndTick = currentTick + timeoutTick + 1; var endTick = new Tick((long)Math.Min(long.MaxValue, absoluteEndTick)); Tick curTick = tickManager.GetTick(); // Sleep in a loop until the requested time has past. while (curTick < endTick) { Tick remaining = endTick - curTick; int sleepTimeMs = (int)ConvertToImplTime(os, remaining).GetMilliSeconds(); System.Threading.Thread.Sleep(sleepTimeMs); curTick = tickManager.GetTick(); } }
private long GetSystemSeconds() { OsState os = _fsServer.Hos.Os; Tick tick = os.GetSystemTick(); TimeSpan timeSpan = os.ConvertToTimeSpan(tick); return(timeSpan.GetSeconds()); }
public static TimeSpan ConvertToImplTime(OsState os, Tick tick) { TickManager tickManager = os.GetTickManager(); TimeSpan ts = tickManager.ConvertToTimespan(tick); // .NET allows sleeping up to int.MaxValue milliseconds at a time. long timeMs = Math.Min(int.MaxValue, ts.GetMilliSeconds()); return(TimeSpan.FromMilliSeconds(timeMs)); }
internal static string ToSerializedValue(this OsState value) { switch (value) { case OsState.Generalized: return("Generalized"); case OsState.Specialized: return("Specialized"); } return(null); }
internal HorizonClient(Horizon horizon, ProcessId processId) { Horizon = horizon; ProcessId = processId; Fs = new FileSystemClient(this); Sm = new ServiceManagerClient(Horizon.ServiceManager); Os = new OsState(this, horizon.TickGenerator); Diag = new DiagClient(this); Lr = new LrClient(this); ArpLazy = new Lazy <ArpClient>(InitArpClient, true); }
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) { writer.WriteStartObject(); writer.WritePropertyName("osType"); writer.WriteStringValue(OsType.ToSerialString()); writer.WritePropertyName("osState"); writer.WriteStringValue(OsState.ToSerialString()); if (Snapshot != null) { writer.WritePropertyName("snapshot"); writer.WriteObjectValue(Snapshot); } if (ManagedDisk != null) { writer.WritePropertyName("managedDisk"); writer.WriteObjectValue(ManagedDisk); } if (BlobUri != null) { writer.WritePropertyName("blobUri"); writer.WriteStringValue(BlobUri); } if (Caching != null) { writer.WritePropertyName("caching"); writer.WriteStringValue(Caching.Value.ToSerialString()); } if (DiskSizeGB != null) { writer.WritePropertyName("diskSizeGB"); writer.WriteNumberValue(DiskSizeGB.Value); } if (StorageAccountType != null) { writer.WritePropertyName("storageAccountType"); writer.WriteStringValue(StorageAccountType.Value.ToString()); } if (DiskEncryptionSet != null) { writer.WritePropertyName("diskEncryptionSet"); writer.WriteObjectValue(DiskEncryptionSet); } writer.WriteEndObject(); }
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) { writer.WriteStartObject(); writer.WritePropertyName("osType"); writer.WriteStringValue(OsType.ToSerialString()); writer.WritePropertyName("osState"); writer.WriteStringValue(OsState.ToSerialString()); if (Optional.IsDefined(Snapshot)) { writer.WritePropertyName("snapshot"); JsonSerializer.Serialize(writer, Snapshot); } if (Optional.IsDefined(ManagedDisk)) { writer.WritePropertyName("managedDisk"); JsonSerializer.Serialize(writer, ManagedDisk); } if (Optional.IsDefined(BlobUri)) { writer.WritePropertyName("blobUri"); writer.WriteStringValue(BlobUri); } if (Optional.IsDefined(Caching)) { writer.WritePropertyName("caching"); writer.WriteStringValue(Caching.Value.ToSerialString()); } if (Optional.IsDefined(DiskSizeGB)) { writer.WritePropertyName("diskSizeGB"); writer.WriteNumberValue(DiskSizeGB.Value); } if (Optional.IsDefined(StorageAccountType)) { writer.WritePropertyName("storageAccountType"); writer.WriteStringValue(StorageAccountType.Value.ToString()); } if (Optional.IsDefined(DiskEncryptionSet)) { writer.WritePropertyName("diskEncryptionSet"); JsonSerializer.Serialize(writer, DiskEncryptionSet); } writer.WriteEndObject(); }
public TimeoutHelper(OsState os, TimeSpan timeout) { _os = os; if (timeout == new TimeSpan(0)) { // If timeout is zero, don't do relative tick calculations. _endTick = new Tick(0); } else { TickManager tickManager = os.GetTickManager(); // Attempt to avoid overflow by doing the addition unsigned ulong currentTick = (ulong)tickManager.GetTick().GetInt64Value(); ulong timeoutTick = (ulong)tickManager.ConvertToTick(timeout).GetInt64Value(); ulong absoluteEndTick = currentTick + timeoutTick + 1; _endTick = new Tick((long)Math.Min(long.MaxValue, absoluteEndTick)); } }
/// <summary> /// Event fired by the OS each time its state has changed, so that the UI is updated. /// </summary> private void OnOsStateChanged(object sender, EventArgs e) { OsState state = (OsState)sender; switch (state) { case OsState.Busy: OsStateLabel.Content = "OS: Busy"; OsStateBorder.Background = new SolidColorBrush(Color.FromRgb(214, 40, 40)); break; case OsState.Idle: OsStateLabel.Content = "OS: Idle"; OsStateBorder.Background = new SolidColorBrush(Color.FromRgb(252, 163, 17)); break; default: OsStateLabel.Content = "OS: Free"; OsStateBorder.Background = new SolidColorBrush(Color.FromRgb(6, 214, 160)); break; } }
public static Tick ConvertToTick(this OsState os, TimeSpan ts) => os.GetTickManager().ConvertToTick(ts);
public static TimeSpan ConvertToTimeSpan(this OsState os, Tick tick) => os.GetTickManager().ConvertToTimespan(tick);
public static long GetSystemTickFrequency(this OsState os) => os.GetTickManager().GetTickFrequency();
public static Tick GetSystemTick(this OsState os) => os.GetTickManager().GetTick();
public static void CloseNativeHandle(this OsState os, object handle) { }
public static Tick GetCurrentTick(this OsState os) => os.GetTickManager().GetTick();
public NativeHandle(OsState os, Handle handle) { Os = os; Handle = handle; }
public static void Sleep(OsState os, TimeSpan timeout) { TimeoutHelperImpl.Sleep(os, timeout); }
public NativeHandle(OsState os, Handle handle, bool isManaged) { Handle = handle; IsManaged = isManaged; }
public GameCardEventSimulator(OsState os) : base(os, 2000) { }
public static TickManager GetTickManager(this OsState os) => os.GetOsResourceManager().TickManager;
public IDeviceEventSimulator(OsState os, int timeoutMs) { _os = os; _timeoutLengthMs = timeoutMs; _mutex = new SdkRecursiveMutex(); }
public static Tick GetCurrentTickOrdered(this OsState os) => os.GetTickManager().GetSystemTickOrdered();
public static OsResourceManager GetOsResourceManager(this OsState os) { return(os.ResourceManager); }