Exemplo n.º 1
0
        public async Task Pair(CancellationToken cancellationToken = default)
        {
            try
            {
                await Observable.Create <PropertyChanges>(async observer =>
                {
                    var action         = new Action <PropertyChanges>(observer.OnNext);
                    var propertySignal = await _device1.WatchPropertiesAsync(action);

                    try
                    {
                        await _device1.PairAsync().ConfigureAwait(false);
                    }
                    catch
                    {
                        propertySignal.Dispose();
                        throw;
                    }

                    return(propertySignal);
                })
                .Where(x => x.GetStruct <bool>(nameof(Device1Properties.Paired)).GetValueOrDefault(false))
                .Take(1)
                .ToTask(cancellationToken)
                .ConfigureAwait(false);
            }
            catch (TaskCanceledException)
            {
                await _device1.CancelPairingAsync().ConfigureAwait(false);

                throw;
            }
        }
Exemplo n.º 2
0
        async Task <Device> InitAsync()
        {
            propertyWatcher = await proxy.WatchPropertiesAsync(x => UpdateProperties(x.Changed));

            UpdateProperties(await proxy.GetAllAsync());
            await proxy.ConnectAsync();

            return(this);
        }
Exemplo n.º 3
0
        internal static async Task <Device> CreateAsync(IDevice1 proxy)
        {
            var device = new Device
            {
                m_proxy = proxy,
            };

            device.m_propertyWatcher = await proxy.WatchPropertiesAsync(device.OnPropertyChanges);

            return(device);
        }