async Task <bool> ExecuteLoadStorageAccountsAsync(bool force = false) { if (IsBusy) { return(false); } try { IsBusy = true; NoStorageAccountsFound = false; var realm = App.GetRealm(); if (force) { var subs = realm.All <Subscription>().AsRealmCollection(); foreach (var sub in subs.Where(sub => sub.IsSubOn == false)) { realm.Write(() => { var sas = realm.All <StorageAccountExt>().Where(sa => sa.SubscriptionName == sub.Name); realm.RemoveRange(sas); }); } foreach (var sub in subs.Where(sub => sub.IsSubOn)) { await AzureManagementHelper.GetStorageAccountsForSubscription( sub.Id, signOnClient.GetTokenForTenant(sub.TenantId), sub.Name, sub.TenantId); } } var storageAccounts = realm.All <StorageAccountExt>(); storageAccounts.SubscribeForNotifications((sender, changes, error) => { Console.WriteLine("Change to StorageAccount"); }); StorageAccounts.ReplaceRange(storageAccounts.OrderBy(sa => sa.Name)); StorageAccountsGrouped.ReplaceRange(StorageAccounts.FilterBySubscription()); if (StorageAccounts.Count == 0) { NoStorageAccountsFoundMessage = "No Storage Accounts Found"; NoStorageAccountsFound = true; } else { NoStorageAccountsFound = false; } } catch (Exception ex) { Logger.Report(ex, "Method", "ExecuteLoadStorageAccountsAsync"); MessagingService.Current.SendMessage(MessageKeys.Error, ex); } finally { IsBusy = false; } return(true); }
async Task ExecuteLoginAsync() { try { IsBusy = true; var result = await signOnClient.Authenticate(); Settings.Current.Email = result.UserInfo.DisplayableId; Settings.Current.FirstName = result.UserInfo.GivenName; Settings.Current.LastName = result.UserInfo.FamilyName; Message = "Sign in successful, fetching Subscriptions"; var tenants = await Services.AzureSubscriptionInfoService.GetTenants(result.AccessToken); foreach (var tenant in tenants.TenantCollection) { var subResult = await signOnClient.AuthenticateSilently(tenant.TenantId, result.UserInfo.UniqueId); var subs = await Services.AzureSubscriptionInfoService.GetSubscriptionsForTenant(tenant.TenantId, subResult.AccessToken); foreach (var sub in subs) { sub.tenantId = tenant.TenantId; } App.current.Subscriptions.AddRange(subs); } Message = "Subscriptions obtained, fetching Storage Accounts"; foreach (var sub in App.current.Subscriptions) { await AzureManagementHelper.GetStorageAccountsForSubscription(sub.SubscriptionId, sub.Token, sub.DisplayName, sub.tenantId); } //Send them to the navigation page var nav = Application.Current?.MainPage?.Navigation; if (nav == null) { return; } Settings.FirstRun = false; Settings.Current.ForceUserLogin = false; await Navigation.PopModalAsync(); MessagingService.Current.SendMessage(MessageKeys.NavigateToStorageAccounts); } catch (Exception ex) { Logger.Track(ASELoggerKeys.LoginFailure, "Reason", ex?.Message ?? string.Empty); MessagingService.Current.SendMessage <MessagingServiceAlert>(MessageKeys.Message, new MessagingServiceAlert { Title = "Unable to Sign in", Message = "There was an issue signing in.", Cancel = "OK" }); IsBusy = false; } finally { //IsBusy = false; } }