Пример #1
0
        private async Task ResponseFileDbSave(string response)
        {
            try
            {
                List <serverInstance>  serverInstances = new List <serverInstance>();
                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
                {
                    createServerInstances createServerInstances = JsonConvert.DeserializeObject <createServerInstances>(response, options);
                    if (createServerInstances.createServerInstancesResponse.returnCode.Equals("0"))
                    {
                        serverInstances.Clear();
                        foreach (var a in createServerInstances.createServerInstancesResponse.serverInstanceList)
                        {
                            var item = new serverInstance
                            {
                                serverName       = a.serverName,
                                serverInstanceNo = a.serverInstanceNo,
                                publicIp         = a.publicIp,
                                privateIp        = a.privateIp,
                                region           = new region
                                {
                                    regionNo   = a.region.regionNo,
                                    regionCode = a.region.regionCode,
                                    regionName = a.region.regionName
                                },
                                zone = new zone
                                {
                                    zoneNo          = a.zone.zoneNo,
                                    zoneName        = a.zone.zoneName,
                                    zoneCode        = a.zone.zoneCode,
                                    zoneDescription = a.zone.zoneDescription,
                                    regionNo        = a.zone.regionNo
                                },
                                serverImageProductCode = a.serverImageProductCode,
                                serverProductCode      = a.serverProductCode,
                                feeSystemTypeCode      = "FXSUM",
                                loginKeyName           = a.loginKeyName,
                                // where is acg list ?
                            };
                            serverInstances.Add(item);
                        }
                        if (createServerInstances.createServerInstancesResponse.totalRows == 0)
                        {
                            CheckedServer = new serverInstance();
                            new Exception("createServerInstances response error.");
                        }
                        else
                        {
                            foreach (var a in serverInstances)
                            {
                                var p = new List <KeyValuePair <string, string> >();
                                p.Add(new KeyValuePair <string, string>("serverName", a.serverName));
                                p.Add(new KeyValuePair <string, string>("serverInstanceNo", a.serverInstanceNo));
                                p.Add(new KeyValuePair <string, string>("serverPublicIp", a.publicIp));
                                p.Add(new KeyValuePair <string, string>("serverPrivateIp", a.privateIp));
                                p.Add(new KeyValuePair <string, string>("regionNo", a.region.regionNo));
                                p.Add(new KeyValuePair <string, string>("zoneNo", a.zone.zoneNo));
                                p.Add(new KeyValuePair <string, string>("serverImageProductCode", a.serverImageProductCode));
                                p.Add(new KeyValuePair <string, string>("serverProductCode", a.serverProductCode));
                                p.Add(new KeyValuePair <string, string>("feeSystemTypeCode", a.feeSystemTypeCode));
                                p.Add(new KeyValuePair <string, string>("loginKeyName", a.loginKeyName));

                                if (comboBoxACG1.Text.Equals(""))
                                {
                                    p.Add(new KeyValuePair <string, string>("accessControlGroupConfigurationNoList_1", "NULL"));
                                }
                                else
                                {
                                    p.Add(new KeyValuePair <string, string>("accessControlGroupConfigurationNoList_1", (comboBoxACG1.SelectedItem as accessControlGroup).accessControlGroupConfigurationNo));
                                }

                                if (comboBoxACG2.Text.Equals(""))
                                {
                                    p.Add(new KeyValuePair <string, string>("accessControlGroupConfigurationNoList_2", "NULL"));
                                }
                                else
                                {
                                    p.Add(new KeyValuePair <string, string>("accessControlGroupConfigurationNoList_2", (comboBoxACG2.SelectedItem as accessControlGroup).accessControlGroupConfigurationNo));
                                }

                                if (comboBoxACG3.Text.Equals(""))
                                {
                                    p.Add(new KeyValuePair <string, string>("accessControlGroupConfigurationNoList_3", "NULL"));
                                }
                                else
                                {
                                    p.Add(new KeyValuePair <string, string>("accessControlGroupConfigurationNoList_3", (comboBoxACG3.SelectedItem as accessControlGroup).accessControlGroupConfigurationNo));
                                }

                                if (comboBoxACG4.Text.Equals(""))
                                {
                                    p.Add(new KeyValuePair <string, string>("accessControlGroupConfigurationNoList_4", "NULL"));
                                }
                                else
                                {
                                    p.Add(new KeyValuePair <string, string>("accessControlGroupConfigurationNoList_4", (comboBoxACG4.SelectedItem as accessControlGroup).accessControlGroupConfigurationNo));
                                }

                                if (comboBoxACG5.Text.Equals(""))
                                {
                                    p.Add(new KeyValuePair <string, string>("accessControlGroupConfigurationNoList_5", "NULL"));
                                }
                                else
                                {
                                    p.Add(new KeyValuePair <string, string>("accessControlGroupConfigurationNoList_5", (comboBoxACG5.SelectedItem as accessControlGroup).accessControlGroupConfigurationNo));
                                }

                                await fileDb.UpSertTable(FileDb.TableName.TBL_SERVER, p);
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #2
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;
            }
        }
Пример #3
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;
            }
        }