public async Task <ActionResult> GetNotification() { var notifications = await UserNotificationReader.GetUserNotifications(User.Identity.GetUserId()); return(PartialView("_Notification", new UserNotificationModel { Notifications = new List <UserNotificationItemModel>(notifications) })); }
public UserNotificationsManager(ConnectedDevicesPlatform platform, ConnectedDevicesAccount account) { m_feed = UserDataFeed.GetForAccount(account, platform, Secrets.APP_HOST_NAME); m_feed.SyncStatusChanged += Feed_SyncStatusChanged; m_channel = new UserNotificationChannel(m_feed); m_reader = m_channel.CreateReader(); m_reader.DataChanged += Reader_DataChanged; Logger.Instance.LogMessage($"Setup feed for {account.Id} {account.Type}"); }
public async Task <ActionResult> GetNotificationCount() { var toolBarInfo = await UserNotificationReader.GetUserToolbarInfo(User.Identity.GetUserId()); if (toolBarInfo != null) { return(Json(toolBarInfo, JsonRequestBehavior.AllowGet)); } return(Json(new UserToolbarInfoModel(), JsonRequestBehavior.AllowGet)); }
private async Task SetupChannel() { var account = m_accoutProvider.SignedInAccount; if (account != null && m_platform == null) { m_platform = new ConnectedDevicesPlatform(m_accoutProvider, this); } if (m_feed == null) { // Need to run UserDataFeed creation on a background thread // because MSA/AAD token request might need to show UI. await Task.Run(() => { lock (this) { if (account != null && m_feed == null) { try { m_feed = new UserDataFeed(account, m_platform, "graphnotifications.sample.windows.com"); m_feed.SyncStatusChanged += Feed_SyncStatusChanged; m_feed.AddSyncScopes(new List <IUserDataFeedSyncScope> { UserNotificationChannel.SyncScope }); m_channel = new UserNotificationChannel(m_feed); m_reader = m_channel.CreateReader(); m_reader.DataChanged += Reader_DataChanged; Logger.Instance.LogMessage($"Setup feed for {account.Id} {account.Type}"); } catch (Exception ex) { Logger.Instance.LogMessage($"Failed to setup UserNotificationChannel {ex.Message}"); m_feed = null; } } } }); } }
private async void ReadNotifications(UserNotificationReader reader) { var notifications = await reader.ReadBatchAsync(UInt32.MaxValue); Logger.Instance.LogMessage($"Read {notifications.Count} notifications"); foreach (var notification in notifications) { //Logger.Instance.LogMessage($"UserNotification: {notification.Id} Status: {notification.Status} ReadState: {notification.ReadState} UserActionState: {notification.UserActionState}"); if (notification.Status == UserNotificationStatus.Active) { m_newNotifications.RemoveAll((n) => { return(n.Id == notification.Id); }); if (notification.UserActionState == UserNotificationUserActionState.NoInteraction) { // Brand new notification, add to new m_newNotifications.Add(notification); Logger.Instance.LogMessage($"UserNotification not interacted: {notification.Id}"); if (!string.IsNullOrEmpty(notification.Content) && notification.ReadState != UserNotificationReadState.Read) { RemoveToastNotification(notification.Id); ShowToastNotification(BuildToastNotification(notification.Id, notification.Content)); } } else { RemoveToastNotification(notification.Id); } m_historicalNotifications.RemoveAll((n) => { return(n.Id == notification.Id); }); m_historicalNotifications.Insert(0, notification); } else { // Historical notification is marked as deleted, remove from display m_newNotifications.RemoveAll((n) => { return(n.Id == notification.Id); }); m_historicalNotifications.RemoveAll((n) => { return(n.Id == notification.Id); }); RemoveToastNotification(notification.Id); } } CacheUpdated?.Invoke(this, new EventArgs()); }
private async void Reader_DataChanged(UserNotificationReader sender, object args) { Logger.Instance.LogMessage("New notification available"); await ReadNotificationsAsync(sender); }
public async Task <ActionResult> GetNotificationMenu() { var notifications = await UserNotificationReader.GetUserUnreadNotifications(User.Identity.GetUserId()); return(Json(notifications, JsonRequestBehavior.AllowGet)); }