public async Task DoAuthenticationAsync() { if (App.Authenticator != null) { var authenticationResult = await App.Authenticator.Authenticate(mobileServiceAuthenticationProvider); if (authenticationResult.Success) { PmdAppSetting.UserProviderAuthentication = JsonConvert.SerializeObject(dataStore.CurrentClient.CurrentUser); PmdAppSetting.IsProviderAuthenticated = true; } /* * - Sync with the server * - Register User+Provider */ if (PmdAppSetting.IsProviderAuthenticated && string.IsNullOrEmpty(PmdAppSetting.RegistrationId)) { // Step 1 RegistrationStarted?.Invoke(this, new EventArgs()); var deviceId = GetDeviceRegistrationId(); var userDeviceRegistrationModel = new { Email = "*****@*****.**", DeviceId = deviceId, ProviderUserId = authenticationResult.UserId, Provider = mobileServiceAuthenticationProvider.ToString(), Idiom = Plugin.DeviceInfo.CrossDeviceInfo.Current.Idiom.ToString(), Model = Plugin.DeviceInfo.CrossDeviceInfo.Current.Model, Platform = Plugin.DeviceInfo.CrossDeviceInfo.Current.Platform.ToString(), Version = Plugin.DeviceInfo.CrossDeviceInfo.Current.Version, }; try { var registrationContent = Newtonsoft.Json.Linq.JToken.FromObject(userDeviceRegistrationModel); var postResult = await dataStore.CurrentClient.InvokeApiAsync("/api/users", registrationContent); var responseModel = postResult.ToObject <Models.Auth.AuthResult>(); if (responseModel.Succeeded) { // Step 2 PmdAppSetting.RegistrationId = responseModel.UserId; await dataStore.EntitiesRegistrationCheckAsync(); var resultCode = await dataStore.SyncAsync(); RegistrationCompleted?.Invoke(this, resultCode); } } catch (Exception) { RegistrationCompleted?.Invoke(this, DataStoreSyncCode.ErrorInServer); } } } }
void OnRegistrationCompleted(bool isSuccess) { OnPropertyChanged(nameof(IsRegisteredForPushNotifications)); OnPropertyChanged(nameof(RegisterForPushNotificationButtonLabel)); RegistrationCompleted?.Invoke(this, new PushNotifEventArgs { IsSuccessful = isSuccess }); }
void OnRegistrationCompleted(bool isSuccess) => RegistrationCompleted?.Invoke(this, new PushNotifEventArgs { IsSuccessful = isSuccess });