Beispiel #1
0
#pragma warning disable 4014
        public async Task SubscribeEventsAsync(string deviceId)
        {
            if (string.IsNullOrEmpty(deviceId))
            {
                throw new ArgumentNullException("deviceId");
            }

            using (var client = _httpClientHelper.GetAuthorizedClient())
            {
                client.Timeout = TimeSpan.FromMilliseconds(Timeout.Infinite);
                var stream = await client.GetStreamAsync(string.Format("/v1/devices/{0}/events", deviceId));

                _cancellationTokenSource = new CancellationTokenSource();

                var processor = new EventStreamProcessor(stream, _cancellationTokenSource);

                Task.Factory.StartNew(() => { processor.ProcessEvents(); },
                    _cancellationTokenSource.Token).ConfigureAwait(false);
            }
        }
#pragma warning disable 4014
        public async Task SubscribeAllDevicesEventsAsync()
        {
            using (var client = _httpClientHelper.GetAuthorizedClient())
            {
                client.Timeout = TimeSpan.FromMilliseconds(Timeout.Infinite);
                var stream = await client.GetStreamAsync("/v1/devices/events");

                _cancellationTokenSource = new CancellationTokenSource();

                var processor = new EventStreamProcessor(stream, _cancellationTokenSource);

                Task.Factory.StartNew(() => { processor.ProcessEvents(); },
                    _cancellationTokenSource.Token).ConfigureAwait(false);
            }
        }