Ejemplo n.º 1
0
        private async void LoadData(object sender, EventArgs e)
        {
            try
            {
                dataManager.LoadUserData();
                templateManager = new TemplateManager(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Tools", "TemplatesSql.txt"));
                templateManager.LoadTemplate();
                InitComboBoxScriptTemplates();
                comboBoxScriptTemplates.SelectedIndex = 0;

                await fileDb.ReadTable(FileDb.TableName.TBL_CLUSTER);

                await fileDb.ReadTable(FileDb.TableName.TBL_SERVER);

                await fileDb.ReadTable(FileDb.TableName.TBL_CLUSTER_SERVER);

                comboBoxloadBalancerName.Items.Clear();
                foreach (var a in fileDb.TBL_CLUSTER.Data)
                {
                    comboBoxloadBalancerName.Items.Add(a.Key.clusterName);
                }
                ComboBoxDefaultValueSetting();
                radioButtonDomain.Checked    = true;
                checkBoxUsePrivateIp.Checked = false;
                FillConnectionInfo(comboBoxloadBalancerName.Text, "DOMAIN", checkBoxUsePrivateIp.Checked);
                DbListUpdate();
            }
            catch (Exception)
            {
            }
        }
Ejemplo n.º 2
0
        public async Task HeartBeatWrite()
        {
            string filePath = @"heartBeat/" + config.GetServerName();
            List <TBL_HEALTH_INFO> purgeTarget = new List <TBL_HEALTH_INFO>();
            long cutTime = long.Parse(DateTime.Now.Add(new TimeSpan(0, 0, -60)).ToString("yyyyMMddHHmmss"));
            await fileDb.ReadTable(FileDb.TableName.TBL_HEALTH_INFO, filePath);

            foreach (var a in fileDb.TBL_HEALTH_INFO.Data)
            {
                if (!long.TryParse(a.Key.time, out long storedTime))
                {
                    storedTime = long.Parse(DateTime.Now.ToString("yyyyMMddHHmmss"));
                }
                if (storedTime < cutTime)
                {
                    purgeTarget.Add(new TBL_HEALTH_INFO
                    {
                        serverName = a.Key.serverName,
                        time       = a.Key.time,
                        healthInfo = a.Value.healthInfo
                    });
                }
            }

            foreach (var a in purgeTarget)
            {
                var dp = new List <KeyValuePair <string, string> >();
                dp.Add(new KeyValuePair <string, string>("serverName", a.serverName));
                dp.Add(new KeyValuePair <string, string>("time", a.time));
                await fileDb.DeleteTable(FileDb.TableName.TBL_HEALTH_INFO, dp, filePath);
            }

            string healthStatus = GetHealthStatus();
            string serverName   = config.GetServerName();
            var    p            = new List <KeyValuePair <string, string> >();

            p.Add(new KeyValuePair <string, string>("serverName", serverName));
            p.Add(new KeyValuePair <string, string>("time", DateTime.Now.ToString("yyyyMMddHHmmss")));
            p.Add(new KeyValuePair <string, string>("healthInfo", healthStatus));

            await fileDb.UpSertTable(FileDb.TableName.TBL_HEALTH_INFO, p, filePath);
        }
Ejemplo n.º 3
0
        private async void LoadData(object sender, EventArgs e)
        {
            try
            {
                dataManager.LoadUserData();
                await fileDb.ReadTable(FileDb.TableName.TBL_CLUSTER);

                await fileDb.ReadTable(FileDb.TableName.TBL_SERVER);

                await fileDb.ReadTable(FileDb.TableName.TBL_CLUSTER_SERVER);

                comboBoxloadBalancerName.Items.Clear();
                foreach (var a in fileDb.TBL_CLUSTER.Data)
                {
                    comboBoxloadBalancerName.Items.Add(a.Key.clusterName);
                }
                ComboBoxDefaultValueSetting();

                checkBoxUsePrivateIp.Checked = false;
                FillConnectionInfo(comboBoxloadBalancerName.Text, "MASTER", checkBoxUsePrivateIp.Checked);
                templateManager = new TemplateManager(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Tools", "TemplatesSql.txt"));
                templateManager.LoadTemplate();
                InitComboBoxScriptTemplates();
                comboBoxScriptTemplates.SelectedIndex = 0;

                comboBoxCmd.Items.Add("ExecuterRest");
                comboBoxCmd.Items.Add("ExecuterPs");
                comboBoxCmd.Items.Add("ExecuterSql");
                comboBoxCmd.SelectedItem = "ExecuterPs";

                comboBoxCmdType.Items.Add("OUT-STRING");
                comboBoxCmdType.Items.Add("OBJECT");
                comboBoxCmdType.SelectedItem = "OUT-STRING";
                //
                textBoxAccessKey.Text = LogClient.Config.Instance.GetValue(Category.Api, Key.AccessKey);
                textBoxSecretKey.Text = LogClient.Config.Instance.GetValue(Category.Api, Key.SecretKey);

                radioButtonMaster.Checked = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 4
0
        private async Task ServerListLoad()
        {
            try
            {
                ControlHelpers.ButtonStatusChange(buttonServerListReload, "Requested");
                await fileDb.ReadTable(FileDb.TableName.TBL_SERVER);

                List <string> instanceNoList       = new List <string>();
                List <string> deleteServerNameList = new List <string>();

                foreach (var a in fileDb.TBL_SERVER.Data)
                {
                    if (a.Value.serverInstanceNo != "NULL")
                    {
                        instanceNoList.Add(a.Value.serverInstanceNo);
                    }
                }


                List <serverInstance> serverInstances = new List <serverInstance>();

                try
                {
                    serverInstances = await ServerOperation.GetServerInstanceList(instanceNoList);
                }
                catch (Exception ex)
                {
                    if (ex.Message.Contains("server not found"))
                    {
                        //
                    }
                    else
                    {
                        throw new Exception(ex.Message);
                    }
                }

                dgvServerList.InvokeIfRequired(async s =>
                {
                    try
                    {
                        s.Rows.Clear();
                        foreach (var a in fileDb.TBL_SERVER.Data)
                        {
                            var serverInstance = serverInstances.Find(x => x.serverName == a.Key.serverName);

                            if (serverInstance != null)
                            {
                                int n = s.Rows.Add();
                                s.Rows[n].Cells["CheckBox"].Value   = false;
                                s.Rows[n].Cells["Name"].Value       = a.Key.serverName;
                                s.Rows[n].Cells["ZoneNo"].Value     = a.Value.zoneNo + "(" + serverInstance.zone.zoneCode + ")";
                                s.Rows[n].Cells["InstanceNo"].Value = a.Value.serverInstanceNo;
                                s.Rows[n].Cells["PublicIp"].Value   = a.Value.serverPublicIp;
                                s.Rows[n].Cells["PrivateIp"].Value  = a.Value.serverPrivateIp;
                                s.Rows[n].Cells["Status"].Value     = serverInstance.serverInstanceStatus.code;
                                s.Rows[n].Cells["Operation"].Value  = serverInstance.serverInstanceOperation.code;
                            }
                            else
                            {
                                deleteServerNameList.Add(a.Key.serverName);
                            }
                        }

                        foreach (var a in deleteServerNameList)
                        {
                            var p = new List <KeyValuePair <string, string> >();
                            p.Add(new KeyValuePair <string, string>("serverName", a));
                            await fileDb.DeleteTable(FileDb.TableName.TBL_SERVER, p);
                        }
                    }
                    catch (Exception ex)
                    {
                        throw;
                    }
                });
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                ControlHelpers.ButtonStatusChange(buttonServerListReload, "Reload");
            }
        }
Ejemplo n.º 5
0
        private SqlServerLicenseData GetSqlServerLicenseData(string serverName)
        {
            string batchRequestsPerSec = "";
            string onlineDbCnt         = "";
            string cpuCnt           = "";
            string hyperthreadRatio = "";
            string physicalMemoryKb = "";

            SqlServerLicenseData sld = new SqlServerLicenseData();

            try
            {
                AsyncHelpers.RunSync(() => fileDb.ReadTable(FileDb.TableName.TBL_SERVER));
                TBL_SERVER_VALUE tbl_server_value = new TBL_SERVER_VALUE();
                if (fileDb.TBL_SERVER.Data.ContainsKey(new TBL_SERVER_KEY {
                    serverName = serverName
                }))
                {
                    tbl_server_value = fileDb.TBL_SERVER.Data[new TBL_SERVER_KEY {
                                                                  serverName = serverName
                                                              }];
                }

                string connString = string.Empty;

                if (tbl_server_value != null)
                {
                    try
                    {
                        string decryptedPassword = TranString.DecodeRijndael(
                            tbl_server_value.serverPassword,
                            LogClient.Config.Instance.GetCryptionKey());

                        connString = new SqlConnectionStringBuilder
                        {
                            DataSource     = tbl_server_value.serverPublicIp + "," + tbl_server_value.serverPort,
                            UserID         = tbl_server_value.serverUserId,
                            Password       = decryptedPassword,
                            InitialCatalog = "master",
                            ConnectTimeout = 5,
                        }.ConnectionString;

                        using (SqlConnection conn = new SqlConnection(connString))
                        {
                            conn.Open();
                            using (SqlCommand cmd = conn.CreateCommand())
                            {
                                cmd.CommandType = System.Data.CommandType.Text;
                                cmd.CommandText =
                                    @"
set nocount on 
set transaction isolation level read uncommitted 
declare @pre int, @post int, @BatchRequestsPerSec int, @OnlineDbCnt int, @CpuCnt int, @HyperthreadRatio int, @PhysicalMemoryKb int
begin try 
    select @CpuCnt = cpu_count, @HyperthreadRatio = hyperthread_ratio, @PhysicalMemoryKb = physical_memory_kb from [sys].[dm_os_sys_info]
    select @OnlineDbCnt = count(*) from sys.databases where name not in ('master', 'tempdb', 'model', 'msdb', 'LazyLog') and state_desc = 'ONLINE'
    select @pre = cntr_value from sys.dm_os_performance_counters WHERE counter_name  ='Batch Requests/sec'
    waitfor delay '00:00:01.000'
    select @post = cntr_value from sys.dm_os_performance_counters WHERE counter_name  ='Batch Requests/sec'
    select @BatchRequestsPerSec = (@post - @pre)
end try 
begin catch 
end catch 
select 
    cast(@BatchRequestsPerSec as varchar(100)) batchRequestsPerSec 
    , cast(@OnlineDbCnt as varchar(100)) onlineDbCnt
    , cast(@CpuCnt as varchar(100)) cpuCnt
    , cast(@HyperthreadRatio as varchar(100)) hyperthreadRatio
    , cast(@PhysicalMemoryKb as varchar(100)) physicalMemoryKb
";
                                cmd.CommandTimeout = 5;
                                SqlDataReader reader = cmd.ExecuteReader();
                                while (reader.Read())
                                {
                                    batchRequestsPerSec = config.DatabaseValue <string>(reader["batchRequestsPerSec"]);
                                    onlineDbCnt         = config.DatabaseValue <string>(reader["onlineDbCnt"]);
                                    cpuCnt           = config.DatabaseValue <string>(reader["cpuCnt"]);
                                    hyperthreadRatio = config.DatabaseValue <string>(reader["hyperthreadRatio"]);
                                    physicalMemoryKb = config.DatabaseValue <string>(reader["physicalMemoryKb"]);
                                }
                                reader.Close();
                            }
                            conn.Close();
                        }

                        GetClusterInfo(GetServerName(), out string loadBalancerInstanceNo, out string serverInstanceNo, out string clusterName, out string publicIp, out string privateIp, out string serverRole);

                        sld.loadBalancerInstanceNo   = loadBalancerInstanceNo;
                        sld.loadBalancerInstanceName = clusterName;
                        sld.serverName          = serverName;
                        sld.serverInstanceNo    = serverInstanceNo;
                        sld.privateIp           = privateIp;
                        sld.serverRole          = serverRole;
                        sld.batchRequestsPerSec = batchRequestsPerSec;
                        sld.onlineDbCnt         = onlineDbCnt;
                        sld.cpuCnt           = cpuCnt;
                        sld.hyperthreadRatio = hyperthreadRatio;
                        sld.physicalMemoryKb = physicalMemoryKb;
                    }
                    catch (Exception ex)
                    {
                        log.Error(string.Format("get licensedata error {0}, {1}", ex.Message, ex.StackTrace));
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(string.Format("{0}, {1}", ex.Message, ex.StackTrace));
            }
            return(sld);
        }