Пример #1
0
        private async Task ServerNameCheck(bool message = true)
        {
            try
            {
                if (textBoxServerName.Text.Length < 3)
                {
                    throw new Exception("check server name first");
                }

                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"));
                parameters.Add(new KeyValuePair <string, string>("searchFilterName", "serverName"));
                parameters.Add(new KeyValuePair <string, string>("searchFilterValue", textBoxServerName.Text.Trim()));
                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)
                        {
                            var item = new serverInstance
                            {
                                serverInstanceNo     = a.serverInstanceNo,
                                serverName           = a.serverName,
                                publicIp             = a.publicIp,
                                privateIp            = a.privateIp,
                                serverInstanceStatus = new codeCodeName
                                {
                                    code     = a.serverInstanceStatus.code,
                                    codeName = a.serverInstanceStatus.codeName
                                },
                                serverInstanceOperation = new codeCodeName
                                {
                                    code     = a.serverInstanceOperation.code,
                                    codeName = a.serverInstanceOperation.codeName
                                }
                            };
                            serverInstances.Add(item);
                        }
                        if (getServerInstanceList.getServerInstanceListResponse.totalRows == 0)
                        {
                            CheckedServer = new serverInstance();
                            if (message)
                            {
                                MessageBox.Show("You can use the name as the server name.");
                            }
                        }
                        else
                        {
                            bool matched = false;
                            foreach (var a in serverInstances)
                            {
                                if (a.serverName.Equals(textBoxServerName.Text.Trim(), StringComparison.OrdinalIgnoreCase))
                                {
                                    matched       = true;
                                    CheckedServer = a;
                                    if (message)
                                    {
                                        MessageBox.Show($"You have a server with that name. serverInstanceNo : {CheckedServer.serverInstanceNo}");
                                    }
                                }
                            }
                            if (!matched)
                            {
                                if (message)
                                {
                                    MessageBox.Show("You can use the name as the server name.");
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #2
0
        private async Task GetServerInstanceList(List <string> instanceNoList)
        {
            try
            {
                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)
                        {
                            var item = new serverInstance
                            {
                                serverInstanceNo        = a.serverInstanceNo,
                                serverName              = a.serverName,
                                publicIp                = a.publicIp,
                                privateIp               = a.privateIp,
                                serverInstanceStatus    = a.serverInstanceStatus,
                                serverInstanceOperation = a.serverInstanceOperation
                            };
                            serverInstances.Add(item);
                        }
                        if (getServerInstanceList.getServerInstanceListResponse.totalRows == 0)
                        {
                            MessageBox.Show("server not founds");
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }