public override void HandleError(ServerUnreachableException exception) { IAuthDataService authDataService = (IAuthDataService)Mvx.get_IoCProvider().Resolve <IAuthDataService>(); IProfileDataService profileDataService = (IProfileDataService)Mvx.get_IoCProvider().Resolve <IProfileDataService>(); M0 m0 = Mvx.get_IoCProvider().Resolve <IConnectivity>(); ICredentialsDataService credentialsDataService = (ICredentialsDataService)Mvx.get_IoCProvider().Resolve <ICredentialsDataService>(); if (((IConnectivity)m0).get_IsConnected()) { Profile profile = profileDataService.GetActiveProfile(); try { if (profile == null) { this.DisplayServerUnreachableErrorMessage(exception); } else { Credentials credentials = credentialsDataService.GetCredentials(profile?.Id); if (credentials != null) { Task.Run <Profile>((Func <Task <Profile> >)(() => authDataService.Login(profile.Institute, credentials.UserName, credentials.Password))).Wait(); } else { Task.Run <TokenData>((Func <Task <TokenData> >)(() => authDataService.RefreshToken(profile))).Wait(); } } } catch (AggregateException ex) { foreach (Exception innerException in ex.Flatten().InnerExceptions) { if (innerException is ServerUnreachableException exception1) { this.DisplayServerUnreachableErrorMessage(exception1); ErrorHandler.Current.HandleError((Exception) new RefreshTokenException("Sikertelen relogin vagy token refresh", profile).SetErrorCode <RefreshTokenException>("/Users/admin/myagent/macMiniBlack3/_work/2/s/eKreta.Mobile/eKreta.Mobile.Core.Standard/Helpers/ErrorHandlers/ServerUnreachableErrorHandler.cs", 58)); } else { ErrorHandler.Current.HandleError(innerException); } } } } else { ErrorHandler.Current.HandleError((Exception) new NoInternetConnectionException().SetErrorCode <NoInternetConnectionException>("/Users/admin/myagent/macMiniBlack3/_work/2/s/eKreta.Mobile/eKreta.Mobile.Core.Standard/Helpers/ErrorHandlers/ServerUnreachableErrorHandler.cs", 69)); } }
private static void AddAccessTokenToHttpHeader <T>( HttpRequestMessage httpMessage, string profileId) where T : class { ISecureStore secureStore = (ISecureStore)Mvx.get_IoCProvider().Resolve <ISecureStore>(); IProfileDataService profileDataService = (IProfileDataService)Mvx.get_IoCProvider().Resolve <IProfileDataService>(); Profile profile = profileId != null?profileDataService.GetProfile(profileId) : profileDataService.GetActiveProfile(); if (profile == null) { return; } TokenData tokenData = secureStore.GetTokenData(profile.Id); if (tokenData == null) { return; } httpMessage.Headers.Add("Authorization", "bearer " + tokenData.AccessToken); }