private async Task InitializeResourceGroupNameComboBox()

in src/Forms/ProjectDetailsForm.cs [115:181]


        private async Task InitializeResourceGroupNameComboBox()
        {
            KeyValuePair<string, string> selectedSubscription = GetSelectedSubscription();
            if (string.IsNullOrEmpty(selectedSubscription.Key) || string.IsNullOrEmpty(selectedSubscription.Value))
            {
                MessageBox.Show("Empty Subscription ID or name. Please select Subscription again.");
                return;
            }
            ResourceGroupNameInfoLabel.Text = "";
            ResourceGroupNameComboBox.Text = "Loading...";
            ResourceGroupNameComboBox.Enabled = false;

            List<KeyValuePair<string, string>> ResourceGroups = new List<KeyValuePair<string, string>>();

            HttpClientHelper httpClientHelperObj = new HttpClientHelper();

            string nextLink = Routes.ProtocolScheme + Routes.AzureManagementApiHostname + Routes.ForwardSlash +
                              Routes.SubscriptionPath + Routes.ForwardSlash + selectedSubscription.Key + Routes.ForwardSlash +
                              Routes.ResourceGroupPath +
                              Routes.QueryStringQuestionMark + Routes.QueryParameterApiVersion + Routes.QueryStringEquals + Routes.ProjectDetailsApiVersion;

            try
            {
                while (!string.IsNullOrEmpty(nextLink))
                {
                    List<KeyValuePair<string, string>> partialResourceGroupList = new List<KeyValuePair<string, string>>();

                    JToken jsonTokenResponse = await httpClientHelperObj.GetProjectDetailsHttpJsonResponse(nextLink);
                    if (jsonTokenResponse.HasValues)
                    {
                        foreach (var x in jsonTokenResponse["value"])
                            partialResourceGroupList.Add(new KeyValuePair<string, string>(x["id"].Value<string>(), x["name"].Value<string>()));
                        ResourceGroups.AddRange(partialResourceGroupList);

                        if (jsonTokenResponse["nextLink"] != null)
                            nextLink = jsonTokenResponse["nextLink"].Value<string>();
                        else
                            nextLink = null;
                    }
                }
            }
            catch (Exception exResourceGroups)
            {
                MessageBox.Show($"Could not retrieve Resource Group data: {exResourceGroups.Message} Please re-login");
                mainFormObj.CloseForm();
            }

            try
            {
                ResourceGroups.Sort(CompareValue);
                if (ResourceGroups.Count <= 0)
                    ResourceGroupNameInfoLabel.Text = "No Resource Groups found. Please select a different Subscription ID";
                ResourceGroupNameComboBox.DataSource = ResourceGroups;
                ResourceGroupNameComboBox.ValueMember = "Key";
                ResourceGroupNameComboBox.DisplayMember = "Value";
                ResourceGroupNameComboBox.SelectedItem = null;
            }
            catch (Exception exResourceGroupDataHandling)
            {
                MessageBox.Show($"Error handling Resource Group data: {exResourceGroupDataHandling.Message} Please log an issue.");
                mainFormObj.CloseForm();
            }

            ResourceGroupNameComboBox.Enabled = true;
            if (ResourceGroups.Count > 0)
                ResourceGroupNameComboBox.Text = "Please select Resource Group";
        }