private async Task GetRegionList() { try { string endpoint = dataManager.GetValue(DataManager.Category.ApiGateway, DataManager.Key.Endpoint); string action = @"/server/v2/getRegionList"; List <KeyValuePair <string, string> > parameters = new List <KeyValuePair <string, string> >(); parameters.Add(new KeyValuePair <string, string>("responseFormatType", "json")); SoaCall soaCall = new SoaCall(); var task = soaCall.WebApiCall(endpoint, RequestType.POST, action, parameters, LogClient.Config.Instance.GetValue(Category.Api, Key.AccessKey), LogClient.Config.Instance.GetValue(Category.Api, Key.SecretKey)); string response = await task; JsonSerializerSettings options = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, MissingMemberHandling = MissingMemberHandling.Ignore }; if (response.Contains("responseError")) { hasError hasError = JsonConvert.DeserializeObject <hasError>(response, options); throw new Exception(hasError.responseError.returnMessage); } else { getRegionList getRegionList = JsonConvert.DeserializeObject <getRegionList>(response, options); if (getRegionList.getRegionListResponse.returnCode.Equals("0")) { comboBoxRegion.Items.Clear(); foreach (var a in getRegionList.getRegionListResponse.regionList) { var item = new region { regionNo = a.regionNo, regionCode = a.regionCode, regionName = a.regionName }; // regionNo 1 Korea comboBoxRegion.Items.Add(item); } } } } catch (Exception) { throw; } comboBoxRegion.SelectedIndex = 0; //MessageBox.Show((comboBoxRegion.SelectedItem as region).regionCode); }
private async void buttonLogin_Click(object sender, EventArgs e) { try { buttonLogin.Enabled = false; List <KeyValuePair <string, string> > parameters = new List <KeyValuePair <string, string> >(); parameters.Add(new KeyValuePair <string, string>("responseFormatType", "json")); SoaCall soaCall = new SoaCall(); var task = soaCall.WebApiCall(textBoxApiGatewayEndpoint.Text, RequestType.POST, @"/server/v2/getRegionList", parameters, textBoxAccessKey.Text, textBoxSecretKey.Text); string response = await task; JsonSerializerSettings options = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, MissingMemberHandling = MissingMemberHandling.Ignore }; if (response.Contains("responseError")) { hasError hasError = JsonConvert.DeserializeObject <hasError>(response, options); throw new Exception(hasError.responseError.returnMessage); } if (response.Contains("error")) { authError authError = JsonConvert.DeserializeObject <authError>(response, options); throw new Exception(authError.error.message); } getRegionList getRegionList = JsonConvert.DeserializeObject <getRegionList>(response, options); if (!getRegionList.getRegionListResponse.returnCode.Equals("0")) { MessageBox.Show(response); } if (checkBoxSave.Checked) { dataManager.SetValue(DataManager.Category.Login, DataManager.Key.IsSaveKeyYn, "Y"); logClientConfig.SetValue(LogClient.Category.Api, LogClient.Key.AccessKey, textBoxAccessKey.Text.Trim()); logClientConfig.SetValue(LogClient.Category.Api, LogClient.Key.SecretKey, textBoxSecretKey.Text.Trim()); dataManager.SaveUserData(); logClientConfig.SaveLogClientData(); } else { dataManager.SetValue(DataManager.Category.Login, DataManager.Key.IsSaveKeyYn, "N"); logClientConfig.SetValue(LogClient.Category.Api, LogClient.Key.AccessKey, ""); logClientConfig.SetValue(LogClient.Category.Api, LogClient.Key.SecretKey, ""); logClientConfig.SaveLogClientData(); logClientConfig.SetValue(LogClient.Category.Api, LogClient.Key.AccessKey, textBoxAccessKey.Text.Trim()); logClientConfig.SetValue(LogClient.Category.Api, LogClient.Key.SecretKey, textBoxSecretKey.Text.Trim()); dataManager.SaveUserData(); } Hide(); FormMain formMain = new FormMain(); formMain.FormClosed += (s, args) => this.Close(); formMain.Show(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { buttonLogin.Enabled = true; } }