private async void buttonSavePolicy_Click(object sender, EventArgs e) { try { ControlHelpers.ButtonStatusChange(buttonSavePolicy, "Requested"); if (ControlHelpers.CheckBoxCheckedCnt(dgvServerList) != 1) { throw new Exception("select one server"); } string ip = string.Empty; foreach (DataGridViewRow item in dgvServerList.Rows) { if (bool.Parse(item.Cells["CheckBox"].Value.ToString())) { ip = item.Cells["PublicIp"].Value.ToString(); if ( !( item.Cells["Status"].Value.ToString().Equals("RUN", StringComparison.OrdinalIgnoreCase) && item.Cells["Operation"].Value.ToString().Equals("NULL", StringComparison.OrdinalIgnoreCase) ) ) { throw new Exception("The server is not running. Please use after changing the server running state."); } } } if (ip.Length == 0) { throw new Exception("check public ip"); } if (!long.TryParse(textBoxHeartBeatIntervalSec.Text, out long x2)) { throw new Exception("Error HeartBeatTimeLimitSec is not numeric value"); } if (x2 < 0) { throw new Exception("Error HeartBeatTimeLimitSec value cannot be negative."); } if (!long.TryParse(textBoxHeartBeatTimeLimitSec.Text, out long x3)) { throw new Exception("Error HeartBeatTimeLimitSec is not numeric value"); } if (x3 < 0) { throw new Exception("Error HeartBeatTimeLimitSec value cannot be negative."); } List <string> TypeConfigReads = new List <string>(); List <Task <string> > Tasks = new List <Task <string> >(); string cmdText = string.Empty; var typeConfigSetting = new TypeConfigSetting { ConfigFile = "LazylogConfig.txt", Category = "Ha", Key = "HeartBeatIntervalSec", Value = textBoxHeartBeatIntervalSec.Text.Trim() }; cmdText = JsonConvert.SerializeObject(typeConfigSetting); Task <string> HeartBeatIntervalSec = dataManager.Execute ("ExecuterRest" , "TypeConfigSetting" , cmdText , CsLib.RequestType.POST , $"https://{ip}:9090" , @"/LazyServer/LazyCommand/PostCmd" , LogClient.Config.Instance.GetValue(LogClient.Category.Api, LogClient.Key.AccessKey) , LogClient.Config.Instance.GetValue(LogClient.Category.Api, LogClient.Key.SecretKey)); Tasks.Add(HeartBeatIntervalSec); typeConfigSetting = new TypeConfigSetting { ConfigFile = "LazylogConfig.txt", Category = "Ha", Key = "HeartBeatTimeLimitSec", Value = textBoxHeartBeatTimeLimitSec.Text.Trim() }; cmdText = JsonConvert.SerializeObject(typeConfigSetting); Task <string> HeartBeatTimeLimitSec = dataManager.Execute ("ExecuterRest" , "TypeConfigSetting" , cmdText , CsLib.RequestType.POST , $"https://{ip}:9090" , @"/LazyServer/LazyCommand/PostCmd" , LogClient.Config.Instance.GetValue(LogClient.Category.Api, LogClient.Key.AccessKey) , LogClient.Config.Instance.GetValue(LogClient.Category.Api, LogClient.Key.SecretKey)); Tasks.Add(HeartBeatTimeLimitSec); await Task.WhenAll(Tasks); WcfResponse wcfResponse; wcfResponse = JsonConvert.DeserializeObject <WcfResponse>(HeartBeatIntervalSec.Result); int responseSuccessCnt = 0; if (wcfResponse.IsSuccess) { responseSuccessCnt++; } wcfResponse = JsonConvert.DeserializeObject <WcfResponse>(HeartBeatTimeLimitSec.Result); if (wcfResponse.IsSuccess) { responseSuccessCnt++; } Task task = ApplyPolicy(ip); await task; if (responseSuccessCnt == 2) { MessageBox.Show("saved"); } else { MessageBox.Show("server response error"); } } catch (Exception ex) { if (ex.Message.Contains("Unexpected character encountered while parsing value")) { MessageBox.Show("server response error"); } else { MessageBox.Show(ex.Message); await ServerListLoad(); } } finally { ControlHelpers.ButtonStatusChange(buttonSavePolicy, "Save Policy"); } }
private async void buttonSavePolicy_Click(object sender, EventArgs e) { try { ControlHelpers.ButtonStatusChange(buttonSavePolicy, "Requested"); if (ControlHelpers.CheckBoxCheckedCnt(dgvServerList) != 1) { throw new Exception("Please select one server"); } string ip = string.Empty; foreach (DataGridViewRow item in dgvServerList.Rows) { if (bool.Parse(item.Cells["CheckBox"].Value.ToString())) { ip = item.Cells["PublicIp"].Value.ToString(); if ( !( item.Cells["Status"].Value.ToString().Equals("RUN", StringComparison.OrdinalIgnoreCase) && item.Cells["Operation"].Value.ToString().Equals("NULL", StringComparison.OrdinalIgnoreCase) ) ) { throw new Exception("The server is not running. Please use after changing the server running state."); } } } if (ip.Length == 0) { throw new Exception("check public ip"); } if (!long.TryParse(textBox_dm_exec_query_stats_IntervalSec.Text, out long x0)) { throw new Exception("Error dm_exec_query_stats interval is not numeric value"); } if (x0 < 0) { throw new Exception("Error dm_exec_query_stats value cannot be negative."); } if (!long.TryParse(textBox_dm_os_workers_IntervalSec.Text, out long x1)) { throw new Exception("Error dm_os_workers interval is not numeric value"); } if (x1 < 0) { throw new Exception("Error dm_os_workers value cannot be negative."); } if (!long.TryParse(textBox_sp_lock2_intervalSec.Text, out long x2)) { throw new Exception("Error sp_lock2 interval is not numeric value"); } if (x2 < 0) { throw new Exception("Error sp_lock2 value cannot be negative."); } if (!long.TryParse(textBoxRetentionPeriodMinutes.Text, out long x3)) { throw new Exception("Error retention period is not numeric value"); } if (x3 < 0) { throw new Exception("Error retention period value cannot be negative."); } List <string> TypeConfigReads = new List <string>(); List <Task <string> > Tasks = new List <Task <string> >(); WcfResponse wcfResponse; string cmdText = string.Empty; var typeConfigSetting = new TypeConfigSetting { ConfigFile = "LazylogConfig.txt", Category = "Sqlmon", Key = "dm_exec_query_stats_ProbeIntervalSec", Value = textBox_dm_exec_query_stats_IntervalSec.Text }; cmdText = JsonConvert.SerializeObject(typeConfigSetting); Task <string> dm_exec_query_stats_IntervalSec = dataManager.Execute ("ExecuterRest" , "TypeConfigSetting" , cmdText , CsLib.RequestType.POST , $"https://{ip}:9090" , @"/LazyServer/LazyCommand/PostCmd" , LogClient.Config.Instance.GetValue(LogClient.Category.Api, LogClient.Key.AccessKey) , LogClient.Config.Instance.GetValue(LogClient.Category.Api, LogClient.Key.SecretKey)); Tasks.Add(dm_exec_query_stats_IntervalSec); typeConfigSetting = new TypeConfigSetting { ConfigFile = "LazylogConfig.txt", Category = "Sqlmon", Key = "dm_os_workers_ProbeIntervalSec", Value = textBox_dm_os_workers_IntervalSec.Text }; cmdText = JsonConvert.SerializeObject(typeConfigSetting); Task <string> dm_os_workers_IntervalSec = dataManager.Execute ("ExecuterRest" , "TypeConfigSetting" , cmdText , CsLib.RequestType.POST , $"https://{ip}:9090" , @"/LazyServer/LazyCommand/PostCmd" , LogClient.Config.Instance.GetValue(LogClient.Category.Api, LogClient.Key.AccessKey) , LogClient.Config.Instance.GetValue(LogClient.Category.Api, LogClient.Key.SecretKey)); Tasks.Add(dm_os_workers_IntervalSec); typeConfigSetting = new TypeConfigSetting { ConfigFile = "LazylogConfig.txt", Category = "Sqlmon", Key = "sp_lock2_ProbeIntervalSec", Value = textBox_sp_lock2_intervalSec.Text }; cmdText = JsonConvert.SerializeObject(typeConfigSetting); Task <string> sp_lock2_ProbeIntervalSec = dataManager.Execute ("ExecuterRest" , "TypeConfigSetting" , cmdText , CsLib.RequestType.POST , $"https://{ip}:9090" , @"/LazyServer/LazyCommand/PostCmd" , LogClient.Config.Instance.GetValue(LogClient.Category.Api, LogClient.Key.AccessKey) , LogClient.Config.Instance.GetValue(LogClient.Category.Api, LogClient.Key.SecretKey)); Tasks.Add(sp_lock2_ProbeIntervalSec); int.TryParse(textBoxRetentionPeriodMinutes.Text.Trim(), out int retentionMinutes); int remainTableCnt = 3; int slideMin = retentionMinutes / remainTableCnt; if (slideMin < 1) { slideMin = 1; } if (remainTableCnt < 2) { remainTableCnt = 2; } typeConfigSetting = new TypeConfigSetting { ConfigFile = "LazylogConfig.txt", Category = "Sqlmon", Key = "dm_exec_query_stats_TableSlideMin", Value = slideMin.ToString() }; cmdText = JsonConvert.SerializeObject(typeConfigSetting); Task <string> dm_exec_query_stats_TableSlideMin = dataManager.Execute ("ExecuterRest" , "TypeConfigSetting" , cmdText , CsLib.RequestType.POST , $"https://{ip}:9090" , @"/LazyServer/LazyCommand/PostCmd" , LogClient.Config.Instance.GetValue(LogClient.Category.Api, LogClient.Key.AccessKey) , LogClient.Config.Instance.GetValue(LogClient.Category.Api, LogClient.Key.SecretKey)); Tasks.Add(dm_exec_query_stats_TableSlideMin); typeConfigSetting = new TypeConfigSetting { ConfigFile = "LazylogConfig.txt", Category = "Sqlmon", Key = "dm_exec_query_stats_RemainTableCnt", Value = remainTableCnt.ToString() }; cmdText = JsonConvert.SerializeObject(typeConfigSetting); Task <string> dm_exec_query_stats_RemainTableCnt = dataManager.Execute ("ExecuterRest" , "TypeConfigSetting" , cmdText , CsLib.RequestType.POST , $"https://{ip}:9090" , @"/LazyServer/LazyCommand/PostCmd" , LogClient.Config.Instance.GetValue(LogClient.Category.Api, LogClient.Key.AccessKey) , LogClient.Config.Instance.GetValue(LogClient.Category.Api, LogClient.Key.SecretKey)); Tasks.Add(dm_exec_query_stats_RemainTableCnt); typeConfigSetting = new TypeConfigSetting { ConfigFile = "LazylogConfig.txt", Category = "Sqlmon", Key = "dm_os_workers_TableSlideMin", Value = slideMin.ToString() }; cmdText = JsonConvert.SerializeObject(typeConfigSetting); Task <string> dm_os_workers_TableSlideMin = dataManager.Execute ("ExecuterRest" , "TypeConfigSetting" , cmdText , CsLib.RequestType.POST , $"https://{ip}:9090" , @"/LazyServer/LazyCommand/PostCmd" , LogClient.Config.Instance.GetValue(LogClient.Category.Api, LogClient.Key.AccessKey) , LogClient.Config.Instance.GetValue(LogClient.Category.Api, LogClient.Key.SecretKey)); Tasks.Add(dm_os_workers_TableSlideMin); typeConfigSetting = new TypeConfigSetting { ConfigFile = "LazylogConfig.txt", Category = "Sqlmon", Key = "dm_os_workers_RemainTableCnt", Value = remainTableCnt.ToString() }; cmdText = JsonConvert.SerializeObject(typeConfigSetting); Task <string> dm_os_workers_RemainTableCnt = dataManager.Execute ("ExecuterRest" , "TypeConfigSetting" , cmdText , CsLib.RequestType.POST , $"https://{ip}:9090" , @"/LazyServer/LazyCommand/PostCmd" , LogClient.Config.Instance.GetValue(LogClient.Category.Api, LogClient.Key.AccessKey) , LogClient.Config.Instance.GetValue(LogClient.Category.Api, LogClient.Key.SecretKey)); Tasks.Add(dm_os_workers_RemainTableCnt); typeConfigSetting = new TypeConfigSetting { ConfigFile = "LazylogConfig.txt", Category = "Sqlmon", Key = "sp_lock2_TableSlideMin", Value = slideMin.ToString() }; cmdText = JsonConvert.SerializeObject(typeConfigSetting); Task <string> sp_lock2_TableSlideMin = dataManager.Execute ("ExecuterRest" , "TypeConfigSetting" , cmdText , CsLib.RequestType.POST , $"https://{ip}:9090" , @"/LazyServer/LazyCommand/PostCmd" , LogClient.Config.Instance.GetValue(LogClient.Category.Api, LogClient.Key.AccessKey) , LogClient.Config.Instance.GetValue(LogClient.Category.Api, LogClient.Key.SecretKey)); Tasks.Add(sp_lock2_TableSlideMin); typeConfigSetting = new TypeConfigSetting { ConfigFile = "LazylogConfig.txt", Category = "Sqlmon", Key = "sp_lock2_RemainTableCnt", Value = remainTableCnt.ToString() }; cmdText = JsonConvert.SerializeObject(typeConfigSetting); Task <string> sp_lock2_RemainTableCnt = dataManager.Execute ("ExecuterRest" , "TypeConfigSetting" , cmdText , CsLib.RequestType.POST , $"https://{ip}:9090" , @"/LazyServer/LazyCommand/PostCmd" , LogClient.Config.Instance.GetValue(LogClient.Category.Api, LogClient.Key.AccessKey) , LogClient.Config.Instance.GetValue(LogClient.Category.Api, LogClient.Key.SecretKey)); Tasks.Add(sp_lock2_RemainTableCnt); await Task.WhenAll(Tasks); wcfResponse = JsonConvert.DeserializeObject <WcfResponse>(dm_exec_query_stats_IntervalSec.Result); if (!wcfResponse.IsSuccess) { throw new Exception(wcfResponse.ErrorMessage); } wcfResponse = JsonConvert.DeserializeObject <WcfResponse>(dm_os_workers_IntervalSec.Result); if (!wcfResponse.IsSuccess) { throw new Exception(wcfResponse.ErrorMessage); } wcfResponse = JsonConvert.DeserializeObject <WcfResponse>(sp_lock2_ProbeIntervalSec.Result); if (!wcfResponse.IsSuccess) { throw new Exception(wcfResponse.ErrorMessage); } wcfResponse = JsonConvert.DeserializeObject <WcfResponse>(dm_exec_query_stats_TableSlideMin.Result); if (!wcfResponse.IsSuccess) { throw new Exception(wcfResponse.ErrorMessage); } wcfResponse = JsonConvert.DeserializeObject <WcfResponse>(dm_exec_query_stats_RemainTableCnt.Result); if (!wcfResponse.IsSuccess) { throw new Exception(wcfResponse.ErrorMessage); } wcfResponse = JsonConvert.DeserializeObject <WcfResponse>(dm_os_workers_TableSlideMin.Result); if (!wcfResponse.IsSuccess) { throw new Exception(wcfResponse.ErrorMessage); } wcfResponse = JsonConvert.DeserializeObject <WcfResponse>(dm_os_workers_RemainTableCnt.Result); if (!wcfResponse.IsSuccess) { throw new Exception(wcfResponse.ErrorMessage); } wcfResponse = JsonConvert.DeserializeObject <WcfResponse>(sp_lock2_TableSlideMin.Result); if (!wcfResponse.IsSuccess) { throw new Exception(wcfResponse.ErrorMessage); } wcfResponse = JsonConvert.DeserializeObject <WcfResponse>(sp_lock2_RemainTableCnt.Result); if (!wcfResponse.IsSuccess) { throw new Exception(wcfResponse.ErrorMessage); } Task task = ApplyPolicy(ip); await task; MessageBox.Show("saved"); } catch (Exception ex) { if (ex.Message.Contains("Unexpected character encountered while parsing value")) { MessageBox.Show("server response error"); } else { MessageBox.Show(ex.Message); await ServerListLoad(); } } finally { ControlHelpers.ButtonStatusChange(buttonSavePolicy, "Save Policy"); } }