public async Task RegisterAccountWithSdkAsync() { if (RegistrationState != AccountRegistrationState.InAppCacheAndSdkCache) { throw new Exception("Account must be in both SDK and App cache before it can be registered"); } var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync(); ConnectedDevicesNotificationRegistration registration = new ConnectedDevicesNotificationRegistration(); registration.Type = ConnectedDevicesNotificationType.WNS; registration.Token = channel.Uri; var account = new ConnectedDevicesAccount(Id, Type); var registerResult = await m_platform.NotificationRegistrationManager.RegisterAsync(account, registration); // It would be a good idea for apps to take a look at the different statuses here and perhaps attempt some sort of remediation. // For example, web failure may indicate that a web service was temporarily in a bad state and retries may be successful. // // NOTE: this approach was chosen rather than using exceptions to help separate "expected" / "retry-able" errors from real // exceptions and keep the error-channel logic clean and simple. if (registerResult.Status == ConnectedDevicesNotificationRegistrationStatus.Success) { await UserNotifications.RegisterAccountWithSdkAsync(); } }
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}"); }
private void InitializeSubcomponents() { if (RegistrationState != AccountRegistrationState.InAppCacheAndSdkCache) { throw new Exception("Account must be in both SDK and App cache before subcomponents can be initialized"); } var account = new ConnectedDevicesAccount(Id, Type); UserNotifications = new UserNotificationsManager(m_platform, account); }
public async Task RegisterAccountWithSdkAsync() { if (RegistrationState != AccountRegistrationState.InAppCacheAndSdkCache) { throw new Exception("Account must be in both SDK and App cache before it can be registered"); } var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync(); ConnectedDevicesNotificationRegistration registration = new ConnectedDevicesNotificationRegistration(); registration.Type = ConnectedDevicesNotificationType.WNS; registration.Token = channel.Uri; var account = new ConnectedDevicesAccount(Id, Type); await m_platform.NotificationRegistrationManager.RegisterForAccountAsync(account, registration); await UserNotifications.RegisterAccountWithSdkAsync(); }
public async Task InitializeAccountAsync() { if (RegistrationState == AccountRegistrationState.InAppCacheOnly) { // Scenario 2, add the account to the SDK var account = new ConnectedDevicesAccount(Id, Type); await m_platform.AccountManager.AddAccountAsync(account); RegistrationState = AccountRegistrationState.InAppCacheAndSdkCache; InitializeSubcomponents(); await RegisterAccountWithSdkAsync(); } else if (RegistrationState == AccountRegistrationState.InSdkCacheOnly) { // Scenario 3, remove the account from the SDK var account = new ConnectedDevicesAccount(Id, Type); await m_platform.AccountManager.RemoveAccountAsync(account); } }
public bool EqualsTo(ConnectedDevicesAccount other) { return((other.Id == Id) && (other.Type == Type)); }