예제 #1
0
        // TODO: Make this available to other generated interfaces too, not just IDevice1.
        // `dynamic obj` works, but it requires a Microsoft.* NuGet package and isn't type safe.
        public static async Task WaitForPropertyValueAsync <T>(this IDevice1 obj, string propertyName, T value,
                                                               TimeSpan timeout)
        {
            var(watchTask, watcher) = WaitForPropertyValueInternal <T>(obj, propertyName, value);
            var currentValue = await obj.GetAsync <T>(propertyName);

            // Console.WriteLine($"{propertyName}: {currentValue}");

            // https://stackoverflow.com/questions/390900/cant-operator-be-applied-to-generic-types-in-c
            if (EqualityComparer <T> .Default.Equals(currentValue, value))
            {
                watcher.Dispose();
                return;
            }

            await Task.WhenAny(new Task[] { watchTask, Task.Delay(timeout) });

            if (!watchTask.IsCompleted)
            {
                throw new TimeoutException($"Timed out waiting for '{propertyName}' to change to '{value}'.");
            }

            // propogate any exceptions.
            await watchTask;
        }
예제 #2
0
파일: DeviceApi.cs 프로젝트: twgraham/Blue
 public static Task <short> GetTxPowerAsync(this IDevice1 o) => o.GetAsync <short>(nameof(Device1Properties.TxPower));
예제 #3
0
파일: DeviceApi.cs 프로젝트: twgraham/Blue
 public static Task <IDictionary <string, object> > GetServiceDataAsync(this IDevice1 o) =>
 o.GetAsync <IDictionary <string, object> >(nameof(Device1Properties.ServiceData));
예제 #4
0
파일: DeviceApi.cs 프로젝트: twgraham/Blue
 public static Task <IDictionary <ushort, object> > GetManufacturerDataAsync(this IDevice1 o) =>
 o.GetAsync <IDictionary <ushort, object> >(nameof(Device1Properties.ManufacturerData));
예제 #5
0
파일: DeviceApi.cs 프로젝트: twgraham/Blue
 public static Task <IAdapter1> GetAdapterAsync(this IDevice1 o) => o.GetAsync <IAdapter1>(nameof(Device1Properties.Adapter));
예제 #6
0
파일: DeviceApi.cs 프로젝트: twgraham/Blue
 public static Task <string> GetModaliasAsync(this IDevice1 o) => o.GetAsync <string>(nameof(Device1Properties.Modalias));
예제 #7
0
파일: DeviceApi.cs 프로젝트: twgraham/Blue
 public static Task <string[]> GetUUIDsAsync(this IDevice1 o) => o.GetAsync <string[]>(nameof(Device1Properties.UUIDs));
예제 #8
0
파일: DeviceApi.cs 프로젝트: twgraham/Blue
 public static Task <string> GetNameAsync(this IDevice1 o) => o.GetAsync <string>(nameof(Device1Properties.Name));
예제 #9
0
파일: DeviceApi.cs 프로젝트: twgraham/Blue
 public static Task <short> GetRSSIAsync(this IDevice1 o) => o.GetAsync <short>(nameof(Device1Properties.RSSI));
예제 #10
0
파일: DeviceApi.cs 프로젝트: twgraham/Blue
 public static Task <bool> GetLegacyPairingAsync(this IDevice1 o) => o.GetAsync <bool>(nameof(Device1Properties.LegacyPairing));
예제 #11
0
파일: DeviceApi.cs 프로젝트: twgraham/Blue
 public static Task <bool> GetBlockedAsync(this IDevice1 o) => o.GetAsync <bool>(nameof(Device1Properties.Blocked));
예제 #12
0
파일: DeviceApi.cs 프로젝트: twgraham/Blue
 public static Task <string> GetIconAsync(this IDevice1 o) => o.GetAsync <string>(nameof(Device1Properties.Icon));
예제 #13
0
파일: DeviceApi.cs 프로젝트: twgraham/Blue
 public static Task <ushort> GetAppearanceAsync(this IDevice1 o) => o.GetAsync <ushort>(nameof(Device1Properties.Appearance));
예제 #14
0
파일: DeviceApi.cs 프로젝트: twgraham/Blue
 public static Task <uint> GetClassAsync(this IDevice1 o) => o.GetAsync <uint>("Class");
예제 #15
0
파일: DeviceApi.cs 프로젝트: twgraham/Blue
 public static Task <bool> GetServicesResolvedAsync(this IDevice1 o) => o.GetAsync <bool>(nameof(Device1Properties.ServicesResolved));
예제 #16
0
파일: DeviceApi.cs 프로젝트: twgraham/Blue
 public static Task <bool> GetConnectedAsync(this IDevice1 o) => o.GetAsync <bool>(nameof(Device1Properties.Connected));
예제 #17
0
파일: DeviceApi.cs 프로젝트: twgraham/Blue
 public static Task <string> GetAddressAsync(this IDevice1 o) => o.GetAsync <string>(nameof(Device1Properties.Address));