Ejemplo n.º 1
0
        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();
            }
        }
Ejemplo n.º 2
0
        private long GetSystemSeconds()
        {
            OsState os = _fsServer.Hos.Os;

            Tick     tick     = os.GetSystemTick();
            TimeSpan timeSpan = os.ConvertToTimeSpan(tick);

            return(timeSpan.GetSeconds());
        }
Ejemplo n.º 3
0
        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));
        }
Ejemplo n.º 4
0
        internal static string ToSerializedValue(this OsState value)
        {
            switch (value)
            {
            case OsState.Generalized:
                return("Generalized");

            case OsState.Specialized:
                return("Specialized");
            }
            return(null);
        }
Ejemplo n.º 5
0
        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();
 }
Ejemplo n.º 7
0
 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();
 }
Ejemplo n.º 8
0
        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));
            }
        }
Ejemplo n.º 9
0
        /// <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;
            }
        }
Ejemplo n.º 10
0
 public static Tick ConvertToTick(this OsState os, TimeSpan ts) => os.GetTickManager().ConvertToTick(ts);
Ejemplo n.º 11
0
 public static TimeSpan ConvertToTimeSpan(this OsState os, Tick tick) => os.GetTickManager().ConvertToTimespan(tick);
Ejemplo n.º 12
0
 public static long GetSystemTickFrequency(this OsState os) => os.GetTickManager().GetTickFrequency();
Ejemplo n.º 13
0
 public static Tick GetSystemTick(this OsState os) => os.GetTickManager().GetTick();
Ejemplo n.º 14
0
 public static void CloseNativeHandle(this OsState os, object handle)
 {
 }
Ejemplo n.º 15
0
 public static Tick GetCurrentTick(this OsState os) => os.GetTickManager().GetTick();
Ejemplo n.º 16
0
 public NativeHandle(OsState os, Handle handle)
 {
     Os     = os;
     Handle = handle;
 }
Ejemplo n.º 17
0
 public static void Sleep(OsState os, TimeSpan timeout)
 {
     TimeoutHelperImpl.Sleep(os, timeout);
 }
Ejemplo n.º 18
0
 public NativeHandle(OsState os, Handle handle, bool isManaged)
 {
     Handle    = handle;
     IsManaged = isManaged;
 }
Ejemplo n.º 19
0
 public GameCardEventSimulator(OsState os) : base(os, 2000)
 {
 }
Ejemplo n.º 20
0
 public static TickManager GetTickManager(this OsState os) => os.GetOsResourceManager().TickManager;
Ejemplo n.º 21
0
 public IDeviceEventSimulator(OsState os, int timeoutMs)
 {
     _os = os;
     _timeoutLengthMs = timeoutMs;
     _mutex           = new SdkRecursiveMutex();
 }
Ejemplo n.º 22
0
 public static Tick GetCurrentTickOrdered(this OsState os) => os.GetTickManager().GetSystemTickOrdered();
Ejemplo n.º 23
0
 public static OsResourceManager GetOsResourceManager(this OsState os)
 {
     return(os.ResourceManager);
 }