Ejemplo n.º 1
0
        private async void GetApiAppsInSubscription()
        {
            if (Wizard.Pages.Any(x => x.Legend == Resources.Page1Legend && x.IsSelected))
            {
                using (Context.StartBusyIndicator(Resources.WaitMessageGettingApiApps))
                {
                    IAzureRMUserAccountSubscriptionContext sub = _selectedSubscription;
                    if (sub == null)
                    {
                        ApiApps = new List <ApiAppResource>();
                        return;
                    }

                    Token = await sub.GetAuthenticationHeaderAsync(true);

                    Token = Token.Substring("Bearer ".Length);

                    var apiApps = new List <ApiAppResource>();

                    using (var httpClient = new HttpClient())
                    {
                        httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Token);
                        var url  = string.Format(Constants.URL_APP_SERVICES_WITH_METADATA_DEFINITION, sub.Subscription.SubscriptionId);
                        var json = httpClient.GetStringAsync(new Uri(url)).Result;
                        var job  = JObject.Parse(json);
                        var apps = (JArray)job["value"];

                        foreach (var app in apps)
                        {
                            try
                            {
                                apiApps.Add(new ApiAppResource
                                {
                                    Name          = app["name"].Value <string>(),
                                    ResourceGroup = Utility.ResourceUtilities.GetResourceGroupFromResourceId(
                                        app["id"].Value <string>()
                                        ),
                                    ResourceId = app["id"].Value <string>(),
                                    SwaggerUrl = app["properties"]["siteConfig"]["apiDefinition"]["url"].Value <string>()
                                });
                            }
                            catch
                            {
                            }
                        }
                    }

                    _dispatcher.Invoke(() => ApiApps = apiApps);
                }

                if (ApiApps.Any())
                {
                    Wizard.IsNextEnabled = true;
                }
            }
        }
        private async Task GetApiManagementProducts()
        {
            if (Wizard.Pages.First(x => x.Legend == Resources.Page2Legend).IsSelected)
            {
                using (Context.StartBusyIndicator(Resources.WaitMessageRetrievingProductList))
                {
                    IAzureRMUserAccountSubscriptionContext sub = _selectedSubscription;
                    if (sub == null)
                    {
                        return;
                    }

                    Token = await sub.GetAuthenticationHeaderAsync(true);

                    Token = Token.Substring("Bearer ".Length);

                    ApiManagementClient = new ApiManagementClient(
                        new TokenCloudCredentials(SelectedSubscription.Subscription.SubscriptionId, Token)
                        );

                    var productResponse = await ApiManagementClient.Products.ListAsync(
                        ResourceUtilities.GetResourceGroupFromResourceId(SelectedApiManagementInstance.ResourceId),
                        SelectedApiManagementInstance.Name,
                        new QueryParameters()
                        );

                    var products = new List <ApiManagementProduct>();

                    foreach (var product in productResponse.Result.Values)
                    {
                        products.Add(new ApiManagementProduct
                        {
                            Name = product.Name,
                            Id   = product.Id
                        });
                    }

                    _dispatcher.Invoke(() =>
                    {
                        Products.Clear();
                        products.ForEach(p => Products.Add(p));
                    });
                }
            }
        }
        private async Task GetApiManagementResources()
        {
            if (Wizard.Pages.First(x => x.Legend == Resources.Page2Legend).IsSelected)
            {
                using (Context.StartBusyIndicator(Resources.WaitMessageGettingApimList))
                {
                    IAzureRMUserAccountSubscriptionContext sub = _selectedSubscription;
                    if (sub == null)
                    {
                        return;
                    }

                    Token = await sub.GetAuthenticationHeaderAsync(true);

                    Token = Token.Substring("Bearer ".Length);

                    ResourceManagementClient = new ResourceManagementClient(
                        new TokenCloudCredentials(SelectedSubscription.Subscription.SubscriptionId, Token)
                        );

                    var resources = await ResourceManagementClient.Resources.ListAsync(new ResourceListParameters
                    {
                        ResourceType = Constants.APIM_RESOURCE_TYPE
                    });

                    var apims = new List <ApiManagementInstance>();

                    foreach (var resource in resources.Resources)
                    {
                        apims.Add(new ApiManagementInstance
                        {
                            Name       = resource.Name,
                            ResourceId = resource.Id
                        });
                    }

                    _dispatcher.Invoke(() => ApiManagementInstances = apims);
                }
            }
        }