public void Construct() { var path = (GetPlatformOs.Current == PlatformOs.Windows) ? $@"c:/motNext/Tests/Sqlite/Test.sqlite" : $@"~/Projects/Tests/Sqlite/Test.sqlite"; try { var sqlite = new MotDatabaseServer <MotSqliteServer>(path); // Only do the MOT8 test if its a 32 bit platform. In unit tests it fails otherwise. // ODBC Connection Failed: ERROR [IM014] [Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and Application if (GetPlatformOs.Current == PlatformOs.Windows && IntPtr.Size == 4) { // This fails because MOT only has 32 bit drivers and the unit test doesn't seem to want to enable "prefer 32 bit" var odbc = new MotDatabaseServer <MotOdbcServer>($"dsn=MOT8;UID={MotAccessSecurity.DecodeString(_dbaUserName)};PWD={MotAccessSecurity.DecodeString(_dbaPassword)}"); } // CleanUp File.Delete(path); } catch (Exception ex) { Console.WriteLine(ex); Assert.Fail(ex.Message); } }
protected void SaveConfiguration() { try { var configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); var settings = configFile.AppSettings.Settings; if (IsNewUserName) { settings["UserName"].Value = MotAccessSecurity.EncodeString(UserName); } if (IsNewPassword) { settings["Password"].Value = MotAccessSecurity.EncodeString(Password); } configFile.Save(ConfigurationSaveMode.Modified); ConfigurationManager.RefreshSection(configFile.AppSettings.SectionInformation.Name); } catch (Exception ex) { EventLogger.Error($"Failed to save configuration: {ex.Message}"); throw; } }
public void TestDecoder() { var original = "The quick brown fox jumped over the lazy dog"; var encrypted = MotAccessSecurity.EncodeString(original); var decrypted = MotAccessSecurity.DecodeString(encrypted); if (decrypted != original) { Assert.Fail($"Decryption failure. Expected {original} and got {decrypted}"); } }
protected void LoadConfiguration() { try { var appSettings = ConfigurationManager.AppSettings; DbUser = appSettings["DbUser"]; DbPassword = appSettings["DbPassword"]; DbServer = appSettings["DbServer"]; DbServerType = appSettings["DbServerType"]; DbName = appSettings["DbName"]; DbServerIp = appSettings["DbServerIp"]; DbServerPort = appSettings["DbServerPort"]; RefreshRate = Convert.ToInt32(appSettings["RefreshRate"] ?? "60"); PreferAscii = (appSettings["PreferASCII"] ?? "false") == "true"; GatewayIp = appSettings["GatewayIp"]; GatewayPort = Convert.ToInt32(appSettings["GatewayPort"] ?? "24042"); UserName = appSettings["Username"] ?? "None"; Password = appSettings["Password"] ?? "None;"; // // If there is a username & password and its the first use, encode them and put // them back into the config file. // if (UserName != "None" && Password != "None") { if (!MotAccessSecurity.IsEncoded(UserName)) { IsNewUserName = true; } else { UserName = MotAccessSecurity.DecodeString(appSettings["UserName"]); } if (!MotAccessSecurity.IsEncoded(Password)) { IsNewPassword = true; } else { Password = MotAccessSecurity.DecodeString(appSettings["Password"]); } } } catch (Exception ex) { EventLogger.Error($"Error saving configuration file: {ex.Message}"); } }
protected void LoadConfiguration() { try { var appSettings = ConfigurationManager.AppSettings; ListenerPort = Convert.ToInt32(appSettings["ListenerPort"] ?? "24025"); GatewayPort = Convert.ToInt32(appSettings["GatewayPort"] ?? "24042"); GatewayAddress = appSettings["GatewayAddress"] ?? "127.0.0.1"; WinMonitorDirectory = appSettings["WinMonitorDirectory"] ?? @"c:\motnext\io"; NixMonitorDirectory = appSettings["NixMonitorDirectory"] ?? @"~/motnext/io"; WatchFileSystem = (appSettings["WatchFileSystem"] ?? "false") == "true"; WatchSocket = (appSettings["WatchSocket"] ?? "false") == "true"; DebugMode = (appSettings["Debug"] ?? "false") == "true"; AllowZeroTQ = (appSettings["AllowZeroTQ"] ?? "false") == "true"; DefaultStoreLoc = appSettings["DefaultStoreLoc"] ?? "000000"; UseAscii = (appSettings["PreferASCII"] ?? "false") == "true"; UserName = appSettings["UserName"] ?? "None"; Password = appSettings["Password"] ?? "None"; // // If there is a username & password and its the first use, encode them and put // them back into the config file. // if (UserName != "None" && Password != "None") { if (!MotAccessSecurity.IsEncoded(UserName)) { IsNewUserName = true; } else { UserName = MotAccessSecurity.DecodeString(appSettings["UserName"]); } if (!MotAccessSecurity.IsEncoded(Password)) { IsNewPassword = true; } else { Password = MotAccessSecurity.DecodeString(appSettings["Password"]); } } } catch (Exception ex) { EventLogger.Error($"Failed to load configuration: {ex.Message}"); throw; } }
protected void SaveConfiguration() { try { var configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); var settings = configFile.AppSettings.Settings; settings["DbUser"].Value = DbUser; settings["DbPassword"].Value = DbPassword; settings["DbServer"].Value = DbServer; settings["DbServerType"].Value = DbServerType; settings["DbName"].Value = DbName; settings["DbServerIp"].Value = DbServerIp; settings["DbServerPort"].Value = DbServerPort; settings["GatewayIp"].Value = GatewayIp; settings["GatewayPort"].Value = GatewayPort.ToString(); if (IsNewUserName) { settings["UserName"].Value = MotAccessSecurity.EncodeString(UserName); } if (IsNewPassword) { settings["Password"].Value = MotAccessSecurity.EncodeString(Password); } configFile.Save(ConfigurationSaveMode.Modified); ConfigurationManager.RefreshSection(configFile.AppSettings.SectionInformation.Name); } catch (Exception ex) { EventLogger.Error($"Error saving configuration file: {ex.Message}"); } }