private void ReadStarConfigs() { var serverConfig = new JsonFileConfiguration <ServerConfiguration>(ServerConfigFile, _jsonSettings); serverConfig.Load(); ServerConfig = serverConfig.Config; Configurations.Add(serverConfig); }
protected string GetConnectionString(string connectionName) { if (!string.IsNullOrEmpty(_connectionString)) { return(_connectionString); } var config = JsonFileConfiguration.Get(false); return(_connectionString = config.GetConnectionString(connectionName)); }
public void JsonFileConfiguration_ToggleFileFromConstructor_Success() { //Arrange string filePath = @"C:/DammyFile.json"; //Act var result = new JsonFileConfiguration(filePath); //Assert Assert.IsNotNull(result, "JsonFileConfiguration can't be null"); Assert.AreEqual(filePath, result.FilePath); }
public void JsonFileConfiguration_ConstructorFull_Success(ConfigurationTestCaseData testCase) { //Arrange string filePath = @"C:/DammyFile.json"; //Act var result = new JsonFileConfiguration(filePath, testCase.IsActiveReload.Value, testCase.DefaultToggleFlag.Value, testCase.UseDefault.Value); //Assert Assert.IsNotNull(result, "JsonFileConfiguration can't be null"); Assert.AreEqual(testCase.ExpectedIsActiveReload, result.IsAcvtiveReload); Assert.AreEqual(testCase.ExpectedDefaultToggleFlag, result.DefaultToggleFlag); Assert.AreEqual(testCase.ExpectedUseDefault, result.UseDefaultToggleFlag); }
public void JsonFileConfiguration_ToggleSectionHasBeenChanged_Success() { //Arrange string filePath = @"C:/DammyFile.json"; string expectedSectionPath = @"features.toggles"; var configuration = new JsonFileConfiguration(filePath); //Act var result = configuration.AddToggleSectionPath(expectedSectionPath); //Assert Assert.IsNotNull(result, "JsonFileConfiguration can't be null"); Assert.AreEqual(expectedSectionPath, result.SectionPath); }
public void JsonFileConfiguration_ToggleFileHasBeenChanged_Success() { //Arrange string filePath = @"C:/DammyFile.json"; string filePath2 = @"C:/DammyFile.json"; var configuration = new JsonFileConfiguration(filePath); //Act var result = configuration.AddToggleFilePath(filePath2); //Assert Assert.IsNotNull(result, "JsonFileConfiguration can't be null"); Assert.AreEqual(filePath2, result.FilePath); }
public void JsonFileConfiguration_ConstructorNoConfiguratioOptions_Success() { //Arrange string filePath = @"C:/DammyFile.json"; bool expectedIsActiveReload = false; bool expectedDefaultToggleFlag = false; bool expectedUseDefault = true; //Act var result = new JsonFileConfiguration(filePath); //Assert Assert.IsNotNull(result, "JsonFileConfiguration can't be null"); Assert.AreEqual(expectedIsActiveReload, result.IsAcvtiveReload); Assert.AreEqual(expectedDefaultToggleFlag, result.DefaultToggleFlag); Assert.AreEqual(expectedUseDefault, result.UseDefaultToggleFlag); }
static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException; XmlConfigurator.Configure(); _configFile = new JsonFileConfiguration <SharpConfig>("sharpconfig.json", new JsonSerializerSettings()); _configFile.Load(); try { Run(); } catch (Exception ex) { ex.LogError(); return; } if (StarMain.Instance.ServerConfig.RunAsService) { if (MonoHelper.IsRunningOnMono) { StarLog.DefaultLogger.Info("You are currently running Mono version {0}", MonoHelper.GetMonoVersion()); WaitForUnixExit(); } ServiceBase.Run(new StarService()); return; } Console.CancelKeyPress += Console_CancelKeyPress; Console.SetError(TextWriter.Null); if (MonoHelper.IsRunningOnMono) { StarLog.DefaultLogger.Info("You are currently running Mono version {0}", MonoHelper.GetMonoVersion()); WaitForUnixExit(); } else { NativeMethods.SetConsoleCtrlHandler(ConsoleCtrlCheck, true); } while (!_shutdown) { try { string input = Console.ReadLine(); if (input != null) { string[] ex = input.Split(' '); if (ex[0].Equals("exit", StringComparison.OrdinalIgnoreCase)) { TimeSpan?ts = null; if (ex.Length == 2) { double time; if (double.TryParse(ex[1], out time)) { ts = TimeSpan.FromMinutes(time); } } Shutdown(false, ts); if (!ts.HasValue) { break; } } StarMain.Instance.ConsoleCommandManager.TryPassConsoleCommand(input); } } catch { } } }
/// <summary> /// Method to create a new dummy Json file in the designated working directory. /// </summary> /// <param name="fileType"></param> internal static void CreateDummyJsonFile(string fileType) { JArray outputFileArray = new JArray(); JObject dummyJsonFile = new JObject(); string outputFileName = ""; if (fileType == FormBase.GlobalParameters.JsonTableMappingFileName) // Table Mapping { dummyJsonFile = new JObject( new JProperty("enabledIndicator", true), new JProperty("tableMappingHash", "NewHash"), new JProperty("versionId", 0), new JProperty("sourceTable", "STG_EXAMPLESYSTEM_EXAMPLETABLE"), new JProperty("sourceConnection", null), new JProperty("targetTable", "HUB_EXAMPLE"), new JProperty("targetConnectionKey", null), new JProperty("businessKeyDefinition", "EXAMPLE"), new JProperty("drivingKeyDefinition", ""), new JProperty("filterCriteria", "") ); outputFileName = JsonFileConfiguration.TableMappingJsonFileName(); } else if (fileType == FormBase.GlobalParameters.JsonModelMetadataFileName) // Physical Model { dummyJsonFile = new JObject( new JProperty("versionAttributeHash", "NewHash"), new JProperty("versionId", 0), new JProperty("databaseName", "Sample database"), new JProperty("schemaName", "[dbo]"), new JProperty("tableName", "Sample Table"), new JProperty("columnName", "Sample Column"), new JProperty("dataType", "nvarchar"), new JProperty("characterLength", "100"), new JProperty("numericPrecision", "0"), new JProperty("numericScale", "0"), new JProperty("ordinalPosition", "1"), new JProperty("primaryKeyIndicator", "N"), new JProperty("multiActiveIndicator", "N") ); outputFileName = JsonFileConfiguration.PhysicalModelJsonFileName(); } else if (fileType == FormBase.GlobalParameters.JsonAttributeMappingFileName) // Attribute Mapping { dummyJsonFile = new JObject( new JProperty("attributeMappingHash", "NewHash"), new JProperty("versionId", 0), new JProperty("sourceTable", "SOURCE_TABLE"), new JProperty("sourceAttribute", "EXAMPLE_FROM_ATTRIBUTE"), new JProperty("targetTable", "TARGET_TABLE"), new JProperty("targetAttribute", "EXAMPLE_TO_ATTRIBUTE"), new JProperty("notes", "") ); outputFileName = JsonFileConfiguration.AttributeMappingJsonFileName(); } else { // No action - issue in code } // Spool to disk outputFileArray.Add(dummyJsonFile); string json = JsonConvert.SerializeObject(outputFileArray, Formatting.Indented); File.WriteAllText(outputFileName, json); }