private async Task InitializeSubscriptionComboBox()

in src/Forms/ProjectDetailsForm.cs [55:113]


        private async Task InitializeSubscriptionComboBox()
        {
            SubscriptionInfoLabel.Text = "";
            SubscriptionComboBox.Text = "Loading...";
            SubscriptionComboBox.Enabled = false;
            List<KeyValuePair<string, string>> Subscriptions = new List<KeyValuePair<string, string>>();

            HttpClientHelper httpClientHelperObj = new HttpClientHelper();

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

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

                    JToken jsonTokenResponse = await httpClientHelperObj.GetProjectDetailsHttpJsonResponse(nextLink);
                    if (jsonTokenResponse.HasValues)
                    {
                        foreach (var x in jsonTokenResponse["value"])
                            partialSubscriptionsList.Add(new KeyValuePair<string, string>(x["subscriptionId"].Value<string>(), x["displayName"].Value<string>() + " - " + x["subscriptionId"].Value<string>()));
                        Subscriptions.AddRange(partialSubscriptionsList);

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

            try
            {
                Subscriptions.Sort(CompareValue);
                if (Subscriptions.Count <= 0)
                    SubscriptionInfoLabel.Text = "No active subscriptions found. Please change the Tenant ID.";
                SubscriptionComboBox.DataSource = Subscriptions;
                SubscriptionComboBox.ValueMember = "Key";
                SubscriptionComboBox.DisplayMember = "Value";
                SubscriptionComboBox.SelectedItem = null;
            }
            catch (Exception exSubscriptionDataHandling)
            {
                MessageBox.Show($"Error handling subscription data: {exSubscriptionDataHandling.Message} Please log an issue.");
                mainFormObj.CloseForm();
            }

            SubscriptionComboBox.Enabled = true;
            if (Subscriptions.Count > 0)
                SubscriptionComboBox.Text = "Please select Subscription";
        }