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 void Reset() { if (m_platform != null) { Logger.Instance.LogMessage("Shutting down platform"); await m_platform.ShutdownAsync(); m_platform = null; m_feed = null; m_newNotifications.Clear(); m_historicalNotifications.Clear(); } CacheUpdated?.Invoke(this, new EventArgs()); }
// This is a singleton object which holds onto the app's ConnectedDevicesPlatform and // handles account management. This is accessed via App.Current.ConnectedDevicesManager public ConnectedDevicesManager() { // Construct and initialize a platform. All we are doing here is hooking up event handlers before // calling ConnectedDevicesPlatform.Start(). After Start() is called events may begin to fire. m_platform = new ConnectedDevicesPlatform(); m_platform.AccountManager.AccessTokenRequested += AccountManager_AccessTokenRequestedAsync; m_platform.AccountManager.AccessTokenInvalidated += AccountManager_AccessTokenInvalidated; m_platform.NotificationRegistrationManager.NotificationRegistrationStateChanged += NotificationRegistrationManager_NotificationRegistrationStateChanged; m_platform.Start(); // Pull the accounts from our app's cache and synchronize the list with the apps cached by // ConnectedDevicesPlatform.AccountManager. DeserializeAccounts(); // Finally initialize the accounts. This will refresh registrations when needed, add missing accounts, // and remove stale accounts from the ConnectedDevicesPlatform.AccountManager. Task.Run(() => InitializeAccountsAsync()); }
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; } } } }); } }
public Account(ConnectedDevicesPlatform platform, String id, ConnectedDevicesAccountType type, String token, AccountRegistrationState registrationState) { m_platform = platform; Id = id; Type = type; Token = token; RegistrationState = registrationState; // Accounts can be in 3 different scenarios: // 1: cached account in good standing (initialized in the SDK and our token cache). // 2: account missing from the SDK but present in our cache: Add and initialize account. // 3: account missing from our cache but present in the SDK. Log the account out async // Subcomponents (e.g. UserDataFeed) can only be initialized when an account is in both the app cache // and the SDK cache. // For scenario 1, immediately initialize our subcomponents. // For scenario 2, subcomponents will be initialized after InitializeAccountAsync registers the account with the SDK. // For scenario 3, InitializeAccountAsync will unregister the account and subcomponents will never be initialized. if (RegistrationState == AccountRegistrationState.InAppCacheAndSdkCache) { InitializeSubcomponents(); } }