Пример #1
0
        async Task StartCommandsSubscription()
        {
            if (CommandsObservable == null || filterCommandsEnd != null)
            {
                return;
            }
            await StopCommandsSubscription();

            Debug.WriteLine("CMD subscription START");
            try
            {
                commandsSubscription = await ClientService.Current.AddCommandSubscriptionAsync(new[] { deviceId }, null, async (commandReceived) =>
                {
                    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        lock (CommandsObservable)
                        {
                            if (!CommandsObservable.Any(c => c.Id == commandReceived.Command.Id))
                            {
                                CommandsObservable.Insert(0, commandReceived.Command);
                            }
                        }
                    });
                });
            }
            catch (Exception ex)
            {
                if (!wasSubscriptionError)
                {
                    new MessageDialog(ex.Message, "Can't subscribe to commands").ShowAsync();
                    wasSubscriptionError = true;
                }
            }
            Debug.WriteLine("CMD subscription END");
        }
Пример #2
0
        async void StartPollCommands()
        {
            if (CommandsObservable == null || filterCommandsEnd != null)
            {
                return;
            }
            StopPollCommands();
            commandsCancellationSource = new CancellationTokenSource();

            Debug.WriteLine("CMD POLL START");
            await ClientService.Current.PollCommands((commandsPolled) =>
            {
                foreach (Command command in commandsPolled)
                {
                    CommandsObservable.Insert(0, command);
                }
            }, deviceId, CommandsObservable.Any()?(DateTime?)CommandsObservable.Max(n => n.Timestamp.Value) : filterCommandsStart, commandsCancellationSource.Token);

            Debug.WriteLine("CMD POLL END");
        }