Ejemplo n.º 1
0
        async void StartPollNotifications()
        {
            if (NotificationsObservable == null || filterNotificationsEnd != null)
            {
                return;
            }
            StopPollNotifications();
            notificationsCancellationSource = new CancellationTokenSource();

            Debug.WriteLine("NTF POLL START");
            await ClientService.Current.PollNotifications((notificationsPolled) =>
            {
                foreach (Notification notification in notificationsPolled)
                {
                    NotificationsObservable.Insert(0, notification);
                }
            }, deviceId, NotificationsObservable.Any()?(DateTime?)NotificationsObservable.Max(n => n.Timestamp.Value) : filterNotificationsStart, notificationsCancellationSource.Token);

            Debug.WriteLine("NTF POLL END");
        }
Ejemplo n.º 2
0
        async Task StartNotificationsSubscription()
        {
            // TODO check that already started
            if (filterNotificationsEnd != null)
            {
                return;
            }
            await StopNotificationsSubscription();

            Debug.WriteLine("NTF subscription START");
            try
            {
                notificationsSubscription = await ClientService.Current.AddNotificationSubscriptionAsync(new[] { deviceId }, null, async (notificationReceived) =>
                {
                    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        lock (NotificationsObservable)
                        {
                            if (!NotificationsObservable.Any(c => c.Id == notificationReceived.Notification.Id))
                            {
                                NotificationsObservable.Insert(0, notificationReceived.Notification);
                            }
                        }
                    });
                });

                Debug.WriteLine("NTF subscription END");
            }
            catch (Exception ex)
            {
                Debug.WriteLine("NTF subscription FAILED: " + ex.Message);
                if (!wasSubscriptionError)
                {
                    new MessageDialog(ex.Message, "Can't subscribe to notifications").ShowAsync();
                    wasSubscriptionError = true;
                }
            }
        }