Esempio n. 1
0
        public async Task <List <AzureResource> > GetResourceGroups(AzureSubscription subscription)
        {
            subscriptionId = subscription.ID;

            try
            {
                List <AzureResource> resourceGroups = new List <AzureResource>();

                JsonDocument result = await CallARM($"https://management.azure.com/subscriptions/{subscriptionId}/resourcegroups?api-version=2020-06-01");

                var e = result.RootElement.GetProperty("value").EnumerateArray();
                while (e.MoveNext())
                {
                    resourceGroups.Add(ResourceGroup.FromJsonElement(e.Current));
                }

                resourceGroups.Sort((i1, i2) => { return(i1.Name.CompareTo(i2.Name)); });

                return(resourceGroups);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return(null);
            }
        }