public static async Task <List <serverInstance> > GetServerInstanceList(List <string> instanceNoList)
        {
            try
            {
                DataManager           dataManager     = DataManager.Instance;
                List <serverInstance> serverInstances = new List <serverInstance>();

                string endpoint = dataManager.GetValue(DataManager.Category.ApiGateway, DataManager.Key.Endpoint);
                string action   = @"/server/v2/getServerInstanceList";
                List <KeyValuePair <string, string> > parameters = new List <KeyValuePair <string, string> >();
                parameters.Add(new KeyValuePair <string, string>("responseFormatType", "json"));

                int i = 0;
                foreach (var instanceNo in instanceNoList)
                {
                    i++;
                    string serverInstanceNoListKey   = "serverInstanceNoList." + i;
                    string serverInstanceNoListValue = instanceNo;
                    parameters.Add(new KeyValuePair <string, string>(serverInstanceNoListKey, serverInstanceNoListValue));
                }

                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
                {
                    getServerInstanceList getServerInstanceList = JsonConvert.DeserializeObject <getServerInstanceList>(response, options);
                    if (getServerInstanceList.getServerInstanceListResponse.returnCode.Equals("0"))
                    {
                        serverInstances.Clear();
                        foreach (var a in getServerInstanceList.getServerInstanceListResponse.serverInstanceList)
                        {
                            serverInstances.Add(a);
                        }
                        if (getServerInstanceList.getServerInstanceListResponse.totalRows == 0)
                        {
                            throw new Exception("server not founds");
                        }
                    }
                    return(serverInstances);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Example #2
0
        private async Task CreateLoginKeyAndFileSave(string path, string loginKeyName)
        {
            try
            {
                string privateKey = string.Empty;
                if (loginKeyName.Length < 3)
                {
                    throw new Exception("The minimum length of the login key is three characters.");
                }

                string endpoint = dataManager.GetValue(DataManager.Category.ApiGateway, DataManager.Key.Endpoint);
                string action   = @"/server/v2/createLoginKey";
                List <KeyValuePair <string, string> > parameters = new List <KeyValuePair <string, string> >();
                parameters.Add(new KeyValuePair <string, string>("responseFormatType", "json"));
                parameters.Add(new KeyValuePair <string, string>("keyName", loginKeyName));
                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
                {
                    createLoginKey createLoginKey = JsonConvert.DeserializeObject <createLoginKey>(response, options);
                    if (createLoginKey.createLoginKeyResponse.returnCode.Equals("0"))
                    {
                        privateKey = createLoginKey.createLoginKeyResponse.privateKey;
                    }

                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }

                    File.WriteAllText(Path.Combine(path, loginKeyName + ".pem"), privateKey);
                }
            }
            catch (Exception)
            {
                var menuItem = mConfigListDesignModel.Items.Single(x => x.Number == "C2");
                menuItem.ProfilePictureRGB = "5c5c5c";
                throw;
            }
        }
Example #3
0
        private async Task LoginAsync(object parameter)
        {
            await RunCommandAsync(() => LoginIsRunning, async() =>
            {
                try
                {
                    var SecretKey = (parameter as IHavePassword).SecurePassword.Unsecure();
                    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, @"/server/v2/getRegionList", parameters, AccessKey, 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);
                    }

                    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"))
                    {
                        throw new Exception(response);
                    }

                    if (IsSave)
                    {
                        dataManager.SetValue(DataManager.Category.Login, DataManager.Key.IsSaveKeyYn, "Y");
                        logClientConfig.SetValue(LogClient.Category.Api, LogClient.Key.AccessKey, AccessKey.Trim());
                        logClientConfig.SetValue(LogClient.Category.Api, LogClient.Key.SecretKey, SecretKey.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, AccessKey.Trim());
                        logClientConfig.SetValue(LogClient.Category.Api, LogClient.Key.SecretKey, SecretKey.Trim());
                        dataManager.SaveUserData();
                    }
                    IoC.Get <ApplicationViewModel>().GoToPage(ApplicationPage.ObjectStorage);
                }
                catch (Exception ex)
                {
                    await IoC.UI.ShowMessage(new MessageBoxDialogViewModel
                    {
                        Title   = "ERROR",
                        Message = ex.Message,
                        OkText  = "OK"
                    });
                }
            });
        }