private void buttonDecode_Click(object sender, EventArgs e) { try { switch (algorithm) { case Algorithm.Base64Unicode: textBoxDecode.Text = TranString.DecodeBase64Unicode(textBoxEncode.Text); break; case Algorithm.Base64: textBoxDecode.Text = TranString.DecodeBase64(textBoxEncode.Text); break; case Algorithm.UrlEncode: textBoxDecode.Text = TranString.DecodeUrlDecode(textBoxEncode.Text); break; case Algorithm.AES: textBoxDecode.Text = TranString.DecodeAES(textBoxEncode.Text, textBoxKey.Text); break; case Algorithm.Rijndael: textBoxDecode.Text = TranString.DecodeRijndael(textBoxEncode.Text, textBoxRijndaelKey.Text, textBoxRijndaelVector.Text); break; default: throw new ArgumentOutOfRangeException($"algorithm : {algorithm}"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void FillConnectionInfo(string clusterName, string radioConnectionType, bool usePrivateIp) { // master slave domain try { string ip = string.Empty; string port = string.Empty; string userid = string.Empty; string password = string.Empty; string db = "master"; int connectTimeoutSec = 3; int commandTimeoutSec = 30; string masterServerName = string.Empty; string slaveServerName = string.Empty; string serverName = string.Empty; foreach (var a in fileDb.TBL_CLUSTER_SERVER.Data) { if (a.Key.clusterName.Equals(clusterName) && a.Value.serverRole.Equals("MASTER", StringComparison.OrdinalIgnoreCase)) { masterServerName = a.Key.serverName; } else if ((a.Key.clusterName.Equals(clusterName) && a.Value.serverRole.Equals("SLAVE", StringComparison.OrdinalIgnoreCase))) { slaveServerName = a.Key.serverName; } } serverName = radioConnectionType.Equals("SLAVE", StringComparison.OrdinalIgnoreCase) == false ? masterServerName : slaveServerName; if (!serverName.Equals("")) { if (usePrivateIp) { ip = fileDb.TBL_SERVER.Data[new TBL_SERVER_KEY { serverName = serverName }].serverPrivateIp; } else { ip = fileDb.TBL_SERVER.Data[new TBL_SERVER_KEY { serverName = serverName }].serverPublicIp; } if (radioConnectionType.Equals("DOMAIN", StringComparison.OrdinalIgnoreCase)) { ip = fileDb.TBL_CLUSTER.Data[new TBL_CLUSTER_KEY { clusterName = clusterName }].domainName; } port = fileDb.TBL_SERVER.Data[new TBL_SERVER_KEY { serverName = serverName }].serverPort; userid = fileDb.TBL_SERVER.Data[new TBL_SERVER_KEY { serverName = serverName }].serverUserId; password = TranString.DecodeRijndael( fileDb.TBL_SERVER.Data[new TBL_SERVER_KEY { serverName = serverName }].serverPassword, LogClient.Config.Instance.GetCryptionKey()); textBoxServerName.Text = serverName; textBoxIP.Text = ip; textBoxPort.Text = port; textBoxUserId.Text = userid; textBoxPassword.Text = password; textBoxConnectionTimeoutSec.Text = connectTimeoutSec.ToString(); textBoxCommandTimeoutSec.Text = commandTimeoutSec.ToString(); comboBoxDatabase.Text = db; } else { textBoxServerName.Text = ""; textBoxIP.Text = ""; textBoxPort.Text = ""; textBoxUserId.Text = ""; textBoxPassword.Text = ""; textBoxConnectionTimeoutSec.Text = ""; textBoxCommandTimeoutSec.Text = ""; comboBoxDatabase.Text = ""; } } catch (Exception ex) { //MessageBox.Show(ex.Message); throw; } }
public async Task <bool> LastConnectionTest(string serverName) { bool returnValue = false; await 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 = @"select top 1 'normal' as healthStatus"; cmd.CommandTimeout = 5; SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { config.DatabaseValue <string>(reader["healthStatus"]); } reader.Close(); returnValue = true; } conn.Close(); log.Warn("last connection test success!"); } } catch (Exception ex) { log.Error(string.Format("{0}, {1}", ex.Message, ex.StackTrace)); } } return(returnValue); }
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); }
private void UpdateEncryptedSqlPassword(object sender, SqlPasswordArgs e) { DecryptedPassword = TranString.DecodeRijndael(e.SqlEncryptedPassword, LogClient.Config.Instance.GetCryptionKey()); }
public Config() { logClientConfig = LogClient.Config.Instance; logClientConfig.SqlPasswordChangedEvent += UpdateEncryptedSqlPassword; while (!logClientConfig.KeySettingCompleted()) { Thread.Sleep(2000); Console.WriteLine("Wait For AccessKey and SecretKey"); } listData = new List <string>(); dicData = new Dictionary <Tuple <Category, Key>, string>(); dataSettingFullName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, dataSettingFileName); LoadFile2List(dataSettingFullName, listData); LoadDataList2Dictionary(listData, dicData); ConfigLoaded = true; while (true) { if (!logClientConfig.SqlIdPassordSettingCompleted()) { Thread.Sleep(2000); Console.WriteLine("Wait For SqlId SqlPass"); } else { try { if (!LogClient.Config.Instance.GetValue(LogClient.Category.Repository, LogClient.Key.SqlEncryptedPassword).Trim().Equals("")) { DecryptedPassword = TranString.DecodeRijndael( LogClient.Config.Instance.GetValue(LogClient.Category.Repository, LogClient.Key.SqlEncryptedPassword), LogClient.Config.Instance.GetCryptionKey()); } break; } catch (Exception ex) { log.Error(string.Format("Cryption Error : {0}, {1}", ex.Message, ex.StackTrace)); Thread.Sleep(2000); } } } // Sender:::Type:::B ncp if (GetValue(Category.Sender, Key.Type).Equals("b", StringComparison.OrdinalIgnoreCase)) { log.Error("Database Create Skipped Sender:::Type:::B"); DbConfigLoad(); log.Error("database configuration load completed!"); } else { //// schema gen CounterLoaded = false; if (IsExistsRepository(GetValue(Category.Repository, Key.InitialCatalog))) { log.Warn("Database Create Skipped"); } else { try { if (!Directory.Exists(GetValue(Category.Repository, Key.DatabaseFilePath))) { Directory.CreateDirectory(GetValue(Category.Repository, Key.DatabaseFilePath)); } if (!Directory.Exists(GetValue(Category.Repository, Key.LogFilePath))) { Directory.CreateDirectory(GetValue(Category.Repository, Key.LogFilePath)); } if (Common.QueryExecuter(GetConnectionString(InitialCatalog.Master) , string.Format(CreateRepositoryQuery, GetValue(Category.Repository, Key.InitialCatalog), GetValue(Category.Repository, Key.DatabaseFilePath), GetValue(Category.Repository, Key.LogFilePath)))) { log.Warn("Database Create Success"); } } catch (Exception ex) { log.Error(string.Format("{0}, {1}", ex.Message, ex.StackTrace)); } } } try { CounterLoaded = IsExistsCounterDetails(); if (GetValue(Category.Perfmon, Key.SkipLoadCounter).ToUpper() == "Y" && CounterLoaded) { log.Warn("Schema Create Skipped"); } else { if (Common.QueryExecuter(GetConnectionString(InitialCatalog.Repository), CreateSchemaQuery)) { log.Warn("Schema Create Success"); } else { log.Warn("Schema Create Failed"); } } //// schema gen completed LocalIp = Common.GetLocalIpAddress(IpType.LocalFirstIp); LocalPort = GetPort(); SetSqlVersion(); } catch (Exception ex) { log.Error(string.Format("{0}, {1}", ex.Message, ex.StackTrace)); } }