private void SubscriptionSelectionChanged() { IntegrationAccountContext iaContext = new IntegrationAccountContext(); var authResult = this.ApplicationContext.GetProperty("IntegrationAccountAuthorization") as AuthenticationResult; statusBarViewModel.Clear(); try { HttpResponseMessage response = iaContext.SendSyncGetRequestToIA(UrlHelper.GetResourceGroupsUrl(SelectedSubscription.SubscriptionId), authResult); var reponseObj = JObject.Parse(response.Content.ReadAsStringAsync().Result); if (reponseObj.GetValue("value") != null) { UserResourceGroups = JsonConvert.DeserializeObject <ObservableCollection <ResourceGroup.RootObject> >(reponseObj["value"].ToString()); if (userResourceGroups.Count != 0) { IsLoginButttonEnabled = false; } else { TraceProvider.WriteLine("No Resource Groups are available for the user. Please login as different user or select different Subscription"); statusBarViewModel.ShowError("No Resource Groups are available for the user. Please login as different user or select different Subscription"); IsLoginButttonEnabled = true; } } else { TraceProvider.WriteLine("No Resource Groups are available for the user. Please login as different user or select different Subscription"); statusBarViewModel.ShowError("No Resource Groups are available for the user. Please login as different user or select different Subscription"); IsLoginButttonEnabled = true; } } catch (Exception ex) { TraceProvider.WriteLine(string.Format("Error reading user RG's from Portal. Reason: {0}{1}", ExceptionHelper.GetExceptionMessage(ex), "Please Login again or as different user.")); statusBarViewModel.ShowError(string.Format("Error reading user RG's from Portal. Reason: {0}{1}", ExceptionHelper.GetExceptionMessage(ex), "Please Login again or as different user.")); IsLoginButttonEnabled = true; } }
private void ResourceGroupSelectionChanged() { IntegrationAccountContext iaContext = new IntegrationAccountContext(); var authResult = this.ApplicationContext.GetProperty("IntegrationAccountAuthorization") as AuthenticationResult; statusBarViewModel.Clear(); try { HttpResponseMessage IAresponse = iaContext.SendSyncGetRequestToIA(UrlHelper.GetIntegrationAccountsUrl(SelectedSubscription.SubscriptionId, SelectedResourceGroup.Name), authResult); var IAreponseObj = JObject.Parse(IAresponse.Content.ReadAsStringAsync().Result); HttpResponseMessage KVresponse = iaContext.SendSyncGetRequestToIA(UrlHelper.GetKeyVaultsUrl(SelectedSubscription.SubscriptionId, SelectedResourceGroup.Name), authResult); var KVreponseObj = JObject.Parse(KVresponse.Content.ReadAsStringAsync().Result); if (IAreponseObj.GetValue("value") != null && KVreponseObj.GetValue("value") != null) { UserIntegrationAccounts = JsonConvert.DeserializeObject <ObservableCollection <IntegrationAccount.RootObject> >(IAreponseObj["value"].ToString()); UserKeyVaults = JsonConvert.DeserializeObject <ObservableCollection <KeyVault.RootObject> >(KVreponseObj["value"].ToString()); if (UserIntegrationAccounts.Count != 0) { IsLoginButttonEnabled = false; } else { TraceProvider.WriteLine("No Integration Accounts are available for the user. Please login as different user or select a different ResourceGroup/Subscription"); statusBarViewModel.ShowError("No Integration Accounts are available for the user. Please login as different user or select a different ResourceGroup/Subscription"); IsLoginButttonEnabled = true; } if (UserKeyVaults.Count == 0) { TraceProvider.WriteLine("No Key Vaults are available for the user in the current RG. If you wish to migrate any Private cerificate to IA, please login as different user or select a different ResourceGroup/Subscription"); statusBarViewModel.ShowError("No Key Vaults are available for the user in the current RG. If you wish to migrate any Private cerificate to IA, please login as different user or select a different ResourceGroup/Subscription"); IsLoginButttonEnabled = true; } } else { TraceProvider.WriteLine("No Integration Accounts are available for the user. Please login as different user or select a different ResourceGroup/Subscription"); statusBarViewModel.ShowError("No Integration Accounts are available for the user. Please login as different user or select a different ResourceGroup/Subscription"); IsLoginButttonEnabled = true; } } catch (Exception ex) { TraceProvider.WriteLine(string.Format("Error reading user IA's from Portal. Reason: {0}{1}", ExceptionHelper.GetExceptionMessage(ex), "Please Login again or as different user.")); statusBarViewModel.ShowError(string.Format("Error reading user IA's from Portal. Reason: {0}{1}", ExceptionHelper.GetExceptionMessage(ex), "Please Login again or as different user.")); IsLoginButttonEnabled = true; } }
private void AzureLoginButtonClick(object sender) { try { IntegrationAccountContext iaContext = new IntegrationAccountContext(); var authresult = iaContext.GetAccessTokenFromAAD(); AuthenticationResult integrationAccountResult = authresult[AuthenticationAccessToken.IntegrationAccount]; AuthenticationResult keyVaultResult = authresult[AuthenticationAccessToken.KeyVault]; this.ApplicationContext.SetProperty("IntegrationAccountAuthorization", integrationAccountResult); this.ApplicationContext.SetProperty("KeyVaultAuthorization", keyVaultResult); string iaToken = integrationAccountResult?.AccessToken; string kvToken = keyVaultResult?.AccessToken; statusBarViewModel.Clear(); try { HttpResponseMessage response = iaContext.SendSyncGetRequestToIA(UrlHelper.GetSubscriptionsUrl(), integrationAccountResult); var reponseObj = JObject.Parse(response.Content.ReadAsStringAsync().Result); if (reponseObj.GetValue("value") != null) { UserSubscriptions = JsonConvert.DeserializeObject <ObservableCollection <Subscription.RootObject> >(reponseObj["value"].ToString()); if (userSubscriptions.Count != 0) { SubscriptionVisible = true; IsLoginButttonEnabled = false; } else { TraceProvider.WriteLine("No Subscriptions are available for the user. Please login as different user"); statusBarViewModel.ShowError("No Subscriptions are available for the user. Please login as different user"); IsLoginButttonEnabled = true; SubscriptionVisible = false; } } else { TraceProvider.WriteLine("No Subscriptions are available for the user. Please login as different user"); statusBarViewModel.ShowError("No Subscriptions are available for the user. Please login as different user"); IsLoginButttonEnabled = true; SubscriptionVisible = false; } } catch (Exception ex) { TraceProvider.WriteLine(string.Format("Error reading user subscriptions from Portal. Reason: {0}{1}", ExceptionHelper.GetExceptionMessage(ex), "Please Login again or as different user.")); statusBarViewModel.ShowError(string.Format("Error reading user subscriptions from Portal. Reason: {0}{1}", ExceptionHelper.GetExceptionMessage(ex), "Please Login again or as different user.")); IsLoginButttonEnabled = true; SubscriptionVisible = false; } } catch (Exception ex) { TraceProvider.WriteLine(string.Format("Error getting the Access Tokens. Reason: {0}", ExceptionHelper.GetExceptionMessage(ex))); statusBarViewModel.ShowError(string.Format("Error getting the Access Tokens. Reason: {0}", ExceptionHelper.GetExceptionMessage(ex))); IsLoginButttonEnabled = true; SubscriptionVisible = false; } }