public static void SaveCredentialToLocker(MobileCredentials mobileCredentials) { // clean up var vault = new PasswordVault(); try { var credentialList = vault.FindAllByResource(ResourceName); foreach (var passwordCredential in credentialList) { vault.Remove(passwordCredential); } } // ReSharper disable once EmptyGeneralCatchClause catch (Exception) { } var credential = new PasswordCredential { Resource = ResourceName, UserName = mobileCredentials.MobileNumber, Password = mobileCredentials.Password }; vault.Add(credential); }
public async Task<Poraba> GetData(MobileCredentials mobileCredentials) { var stopwatch = new Stopwatch(); stopwatch.Start(); var serviceClient = new MDFServiceSoapClient(); var result = await serviceClient.MonitorAsync(mobileCredentials.MobileNumber, mobileCredentials.Password); var poraba = new Poraba(result.Body.MonitorResult); stopwatch.Stop(); _tc.TrackMetric("Background Task", stopwatch.ElapsedMilliseconds); return poraba; }
public static MobileCredentials GetCredentialFromLocker() { try { var vault = new PasswordVault(); var credentialList = vault.FindAllByResource(ResourceName); if (credentialList.Count <= 0) return null; var credential = credentialList[0]; var fullCredential = vault.Retrieve(credential.Resource, credential.UserName); var credentials = new MobileCredentials(fullCredential.UserName, fullCredential.Password); return credentials; } catch { return null; } }
private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) { // Ensure the user name and password fields aren't empty. If a required field // is empty, set args.Cancel = true to keep the dialog open. if (string.IsNullOrEmpty(UserNameTextBox.Text)) { args.Cancel = true; ErrorTextBlock.Text = "User name is required."; return; } else if (string.IsNullOrEmpty(PasswordTextBox.Password)) { args.Cancel = true; ErrorTextBlock.Text = "Password is required."; return; } // If you're performing async operations in the button click handler, // get a deferral before you await the operation. Then, complete the // deferral when the async operation is complete. var deferral = args.GetDeferral(); var mobileCredentials = new MobileCredentials(UserNameTextBox.Text, PasswordTextBox.Password); var resultTask = Task.Run(async () => await PorabaViewModel.TryLogin(mobileCredentials)); var result = resultTask.Result; if (result == LoginResult.Success) { this.Result = LoginResult.Success; Credentials.SaveCredentialToLocker(mobileCredentials); } else { Result = result; args.Cancel = true; } deferral.Complete(); }
private async Task RefreshData(MobileCredentials mobileCredentials, bool networkPresent) { try { if (networkPresent) { Poraba = await _dataService.GetData(mobileCredentials); CacheData(Poraba); } else // TODO // Really? Poraba = new Poraba(); TileUpdateBackgroundTask.UpdateTile(Poraba.QuotaPerc, Poraba.WorstQuotas, Poraba.ExtraSpent, Poraba.MonetaSpent, Poraba.QuotaDescription, Poraba.LastUpdated); } catch (Exception ex) { TelemetryClient.TrackException(ex); throw; } }
internal static async Task<LoginResult> TryLogin(MobileCredentials mobileCredentials) { var service = new MDFServiceSoapClient(); try { var result = await service.AuthenticateUserAsync(mobileCredentials.MobileNumber, mobileCredentials.Password); return result.Body.AuthenticateUserResult == 0 ? LoginResult.Success : LoginResult.LoginFailed; } catch (Exception) { // TODO: reason - network not present, host not found, etc return LoginResult.CallFailed; } }
private async Task Login() { if ((Username ?? "").Trim().Length > 0 && ((Password ?? "").Trim().Length > 0)) { ShowLoginSpinner = true; var mobileCredentils = new MobileCredentials(Username, Password); if (await TryLogin(mobileCredentils) == LoginResult.Success) { Credentials.SaveCredentialToLocker(mobileCredentils); // TODO: ShowLoginError = false; await Initialize(); } else { // TODO: ShowLoginError = true; } ShowLoginSpinner = false; } }
private async Task RefreshData(MobileCredentials mobileCredentials, bool networkPresent) { ShowAppBar = false; ShowLogin = Visibility.Collapsed; ShowData = Visibility.Collapsed; ShowProgress = Visibility.Visible; try { if (networkPresent) Poraba = await _dataService.GetData(mobileCredentials); else Poraba = new Poraba(); TileUpdateBackgroundTask.UpdateTile(Poraba.QuotaPerc, Poraba.WorstQuotas, Poraba.ExtraSpent, Poraba.MonetaSpent, Poraba.QuotaDescription, Poraba.LastUpdated); } catch (Exception ex) { _tc.TrackException(ex); throw; } finally { ShowProgress = Visibility.Collapsed; ShowData = Visibility.Visible; } }