private async Task loadItems() { var collection = await NotificationClient.Get(); if ((collection != null) && (collection.Entries != null)) { if (NotificationItems == null) { NotificationItems = new ObservableCollection <Notification>(); } await NotificationItems.UpdateItems(collection.Entries.OrderByDescending(q => q.Created)); await NotificationItems.SortByDate(); OnPropertyChanged(nameof(NotificationItemsCount)); OnPropertyChanged(nameof(UnreadNotificationsCount)); } }
private async Task loadDetailsAsync(Notification item) { try { if (item != null) { var notification = await NotificationClient.Get(item.ID); if (notification != null) { item.RecordQueueItem = notification.RecordQueueItem; } } } catch (Exception ex) { //XXX : Handle error LoggerService.Instance.Log("ERROR: Notifications.loadDetailsAsync: " + ex); } }
private async void handleNotificationReceived(object sender, AppNotificationMessage message) { try { LoggerService.Instance.Log("Cloud.handleNotificationReceived: Start notification processing"); if (accountViewModel == null) { LoggerService.Instance.Log("Cloud.handleNotificationReceived: Account is null. Exiting"); return; } if (!accountViewModel.SignedIn) { LoggerService.Instance.Log("Cloud.handleNotificationReceived: Account not logged in. Trying to log in."); var stored = accountViewModel.LoadUserFromCredentials(); if (stored == null) { LoggerService.Instance.Log("Cloud.handleNotificationReceived: Account stored credits are null."); return; } if (string.IsNullOrEmpty(stored.AuthToken)) { LoggerService.Instance.Log("Cloud.handleNotificationReceived: Account AuthToken is null."); return; } var error = await accountViewModel.SignInWithTokenAsync(stored, false); if (!string.IsNullOrEmpty(error)) { LoggerService.Instance.Log("ERROR: Cloud.handleNotificationReceived: SignIn Error: " + error); } LoggerService.Instance.Log("Cloud.handleNotificationReceived: SignIn success"); } switch (message.Type) { case AppNotificationType.DownloadComplete: case AppNotificationType.RecordingReady: case AppNotificationType.DownloadFailed: await handleLocalRecordingsMessage(message); break; case AppNotificationType.RecordingFailed: case AppNotificationType.DownloadExpiring: await handleNotificationMessage(message); break; case AppNotificationType.RemoteNotification: LoggerService.Instance.Log("Cloud.handleNotificationReceived: Loading Notification item"); var notification = await NotificationClient.Get(message.ID, RemoteNotificationsService.Instance.GetTokenType(), RemoteNotificationsService.Instance.GetTokenValue()); if (notification == null) { LoggerService.Instance.Log("ERROR: Cloud.handleNotificationReceived: Cannot get notification " + message.ID + " from server"); return; } notification.LibraryItem = new LibraryItem() { ID = notification.RecordingID, Title = notification.RecordQueueItem != null ? notification.RecordQueueItem.Title : string.Empty, Series = notification.RecordQueueItem != null ? notification.RecordQueueItem.Series : string.Empty, }; await handleRemoteNotification(notification); break; } } catch (Exception ex) { LoggerService.Instance.Log("Error while processing notification: " + ex); } finally { message.WaitHandle?.SetResult(true); } }