private async Task InitializeAzureMigrateProjectNameComboBox()

in src/Forms/ProjectDetailsForm.cs [183:260]


        private async Task InitializeAzureMigrateProjectNameComboBox()
        {
            KeyValuePair<string, string> selectedSubscription = GetSelectedSubscription();
            KeyValuePair<string, string> selectedResourceGroup = GetSelectedResourceGroupName();

            if (string.IsNullOrEmpty(selectedSubscription.Key) || string.IsNullOrEmpty(selectedSubscription.Value))
            {
                MessageBox.Show("Empty Subscription ID or name. Please Select Subscription again.");
                return;
            }

            if (string.IsNullOrEmpty(selectedResourceGroup.Key) || string.IsNullOrEmpty(selectedResourceGroup.Value))
            {
                MessageBox.Show("Empty Resource Group ID or name. Please select Resource Group again.");
                return;
            }

            AzureMigrateProjectNameInfoLabel.Text = "";
            AzureMigrateProjectNameComboBox.Text = "Loading...";
            AzureMigrateProjectNameComboBox.Enabled = false;

            List<KeyValuePair<string, string>> AzureMigrateProjects = 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.ForwardSlash + selectedResourceGroup.Value + Routes.ForwardSlash +
                              Routes.ProvidersPath + Routes.ForwardSlash + Routes.MigrateProvidersPath + Routes.ForwardSlash +
                              Routes.MigrateProjectsPath +
                              Routes.QueryStringQuestionMark + Routes.QueryParameterApiVersion + Routes.QueryStringEquals + Routes.ProjectDetailsApiVersion;

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

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

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

            try
            {
                AzureMigrateProjects.Sort(CompareValue);
                if (AzureMigrateProjects.Count <= 0)
                    AzureMigrateProjectNameInfoLabel.Text = "No Migrate projects found. Please select a different Resource group.";
                AzureMigrateProjectNameComboBox.DataSource = AzureMigrateProjects;
                AzureMigrateProjectNameComboBox.ValueMember = "Key";
                AzureMigrateProjectNameComboBox.DisplayMember = "Value";
                AzureMigrateProjectNameComboBox.SelectedItem = null;
            }
            catch (Exception exAzureMigrateProjectDataHandling)
            {
                MessageBox.Show($"Error handling Migrate project data: {exAzureMigrateProjectDataHandling.Message} Please log an issue.");
                mainFormObj.CloseForm();
            }

            AzureMigrateProjectNameComboBox.Enabled = true;
            if (AzureMigrateProjects.Count > 0)
                AzureMigrateProjectNameComboBox.Text = "Please select Migrate Project";
        }