public void AppSettingsLoader_Load_CollectionHandlesTypes() { var mockSettingsLoader = new SettingLoaderMock(); mockSettingsLoader.Settings.Add("StringCollection", "string1,string2,string3"); mockSettingsLoader.Settings.Add("IntCollection", "1,2,3"); mockSettingsLoader.Settings.Add("EnumCollection", "Option0,Option1,Option2"); var settings = new SettingsCollections(); Assert.IsTrue(AppSettingsLoader.Load(mockSettingsLoader, ref settings), "Load returned false"); CollectionAssert.AreEqual( mockSettingsLoader.Settings["StringCollection"].Split(','), settings.StringCollection.ToArray(), "String collection not set"); CollectionAssert.AreEqual( mockSettingsLoader.Settings["IntCollection"].Split(',').Select(i => Int32.Parse(i)).ToArray(), settings.IntCollection.ToArray(), "Int collection not set"); CollectionAssert.AreEqual( mockSettingsLoader.Settings["EnumCollection"].Split(',').Select(e => Enum.Parse(typeof(Option), e, false)).ToArray(), settings.EnumCollection.ToArray(), "Enum collection not set"); }
public void AppSettings_Load_DevConnectionStringsOverrides() { string csName = "OptionalSetting"; string expected = "dev"; string csName2 = "cs2"; string expected2 = "value2"; var devLoader = new SettingLoaderMock(); devLoader.ConnectionStrings.Add(csName, expected); var prodLoader = new SettingLoaderMock(); prodLoader.ConnectionStrings.Add(csName, "prod"); prodLoader.ConnectionStrings.Add(csName2, expected2); var settings = new SettingsConnectionStrings(); AppSettingsLoader.DevSettings = devLoader; Assert.IsTrue(AppSettingsLoader.Load(prodLoader, ref settings), "Load returned false"); Assert.AreEqual(2, settings.ConnectionStrings.Count); Assert.AreEqual(settings.ConnectionStrings[csName], expected); Assert.AreEqual(settings.ConnectionStrings[csName2], expected2); }
public async void Run(IBackgroundTaskInstance taskInstance) { // // TODO: Insert code to perform background work // // If you start any asynchronous methods here, prevent the task // from closing prematurely by using BackgroundTaskDeferral as // described in http://aka.ms/backgroundtaskdeferral // _deferral = taskInstance.GetDeferral(); var appSettingsLoader = new AppSettingsLoader(); var appSettings = await appSettingsLoader.GetAppSetings(); ISettings settings; var isProdEnvironment = true; if (isProdEnvironment) { settings = appSettings.ProdEnvironment; } else { settings = appSettings.DevEnvironment; } var lightPointManager = new LightPointsMenager(settings); await lightPointManager.StartMqttServer(); await lightPointManager.ConnectToSignalRServer(); }
public static void InitServices(IServiceCollection services, IConfiguration config = null) { if (config != null) { var loader = new AppSettingsLoader(); loader.LoadFromConfigFile(config); } services.AddTransient <IRssService, RssService>(); services.AddTransient <IBlogStorage, BlogStorage>(); services.AddTransient <ISearchService, SearchService>(); services.AddTransient <ICustomService, CustomService>(); services.AddTransient <IDataService, DataService>(); // add blog route from ApplicationSettings services.Configure <Microsoft.AspNetCore.Mvc.MvcOptions>(opt => opt.UseBlogRoutePrefix(new Microsoft.AspNetCore.Mvc.RouteAttribute(ApplicationSettings.BlogRoute))); // add route constraint services.Configure <RouteOptions>(options => options.ConstraintMap.Add("author", typeof(AuthorRouteConstraint))); AddDatabase(services); AddFileProviders(services); }
public void AppSettingsLoader_Load_NoExceptionIfHasOptionalSettingOnClass() { var mockSettingsLoader = new SettingLoaderMock(); var settings = new SettingsOptionalClass(); AppSettingsLoader.Load(mockSettingsLoader, ref settings); }
public RepositoryTestBase() { AppSettingsLoader.TrySetupSettingsFile(); var settings = new EnvironmentSettings(); DbFactory = new NpgsqlDbFactory(settings); Work = new UnitOfWork(DbFactory); }
public void AppSettingsLoader_Load_ExceptionIfRequiredSettingDoesNotExist() { var mockSettingsLoader = new SettingLoaderMock(); var settings3 = new Settings3(); AppSettingsLoader.Load(mockSettingsLoader, ref settings3); }
public void AppSettingsLoader_Load_NoExceptionWhenClassOptional() { var mockSettingsLoader = new SettingLoaderMock(); var settings = new SettingsOptionalConnectionString(); // Should not throw an exception AppSettingsLoader.Load(mockSettingsLoader, ref settings); Assert.IsNull(settings.ConnectionString); }
static JsonSettingLoaderTests() { string currentDir = Directory.GetCurrentDirectory(); string jsonFile = Path.Combine(currentDir, "SettingsTestData.json"); ISettingLoader jsonSettingLoader = AppSettingsFactory.GetJsonSettingLoader(jsonFile); _settings = new JsonSettings(); AppSettingsLoader.Load(jsonSettingLoader, ref _settings); }
public void AppSettingsLoader_Load_NoExceptionIfOptionalSettingDoesNotExist() { var mockSettingsLoader = new SettingLoaderMock(); // Set the required setting to avoid the exception, but don't set the optional setting mockSettingsLoader.Settings.Add("RequiredSetting", "Exists"); var settings3 = new Settings3(); AppSettingsLoader.Load(mockSettingsLoader, ref settings3); }
public void AppSettingsLoader_Load_LoadsString() { var mockSettingsLoader = new SettingLoaderMock(); mockSettingsLoader.Settings.Add("IsFoobar", "Foobar"); var settings = new Settings(); Assert.IsTrue(AppSettingsLoader.Load(mockSettingsLoader, ref settings), "Load returned false"); Assert.AreEqual("Foobar", settings.IsFoobar, "String setting not set"); }
public void AppSettingsLoader_Load_LoadsUndecoratedPropertyWhenClassIsDecorated() { var mockSettingsLoader = new SettingLoaderMock(); mockSettingsLoader.Settings.Add("Is42", "42"); var settings2 = new Settings2(); Assert.IsTrue(AppSettingsLoader.Load(mockSettingsLoader, ref settings2), "Load returned false"); Assert.AreEqual(42, settings2.Is42, "Int setting not set"); }
public void AppSettingsLoader_Load_UsesKeyOverride() { var mockSettingsLoader = new SettingLoaderMock(); mockSettingsLoader.Settings.Add("IsFooBar", "Foobar"); var settings2 = new Settings2(); Assert.IsTrue(AppSettingsLoader.Load(mockSettingsLoader, ref settings2), "Load returned false"); Assert.AreEqual("Foobar", settings2.IsFoo, "String setting not set"); }
public void AppSettingsLoader_Load_LoadsBool() { var mockSettingsLoader = new SettingLoaderMock(); mockSettingsLoader.Settings.Add("IsTrue", "true"); var settings = new Settings(); Assert.IsTrue(AppSettingsLoader.Load(mockSettingsLoader, ref settings), "Load returned false"); Assert.IsTrue(settings.IsTrue, "Boolean setting not set to true"); }
public void AppSettingsLoader_Load_LoadsInt() { var mockSettingsLoader = new SettingLoaderMock(); mockSettingsLoader.Settings.Add("Is42", "42"); var settings = new Settings(); Assert.IsTrue(AppSettingsLoader.Load(mockSettingsLoader, ref settings), "Load returned false"); Assert.AreEqual(42, settings.Is42, "Int setting not set"); }
public void AppSettingsLoader_Load_LoadsEnumByValue() { var mockSettingsLoader = new SettingLoaderMock(); Option option = Option.Option2; mockSettingsLoader.Settings.Add("IsOption2", ((int)option).ToString()); var settings = new Settings(); Assert.IsTrue(AppSettingsLoader.Load(mockSettingsLoader, ref settings), "Load returned false"); Assert.AreEqual(option, settings.IsOption2, "Enum setting not set"); }
public void AppSettingsLoader_Load_LoadsGuid() { var mockSettingsLoader = new SettingLoaderMock(); Guid guid = Guid.NewGuid(); mockSettingsLoader.Settings.Add("IsGuid", guid.ToString()); var settings = new Settings(); Assert.IsTrue(AppSettingsLoader.Load(mockSettingsLoader, ref settings), "Load returned false"); Assert.AreEqual(guid, settings.IsGuid, "Guid setting not set"); }
public void AppSettingsLoader_Load_LoadsDateTime() { var mockSettingsLoader = new SettingLoaderMock(); DateTime today = DateTime.Today; mockSettingsLoader.Settings.Add("IsToday", today.ToString()); var settings = new Settings(); Assert.IsTrue(AppSettingsLoader.Load(mockSettingsLoader, ref settings), "Load returned false"); Assert.AreEqual(today, settings.IsToday, "DateTime setting not set"); }
public void AppSetingsLoader_Load_LoadsConnectionStringsWhenPropertyIsDecoratedWithConnectionString() { var connectionStringName = "Name"; var connectionStringValue = "Value"; var mockSettingLoader = new SettingLoaderMock(); mockSettingLoader.ConnectionStrings.Add(connectionStringName, connectionStringValue); var settings = new Settings(); Assert.IsTrue(AppSettingsLoader.Load(mockSettingLoader, ref settings), "Load returned flase"); Assert.IsTrue(settings.ConnectionStrings.ContainsKey(connectionStringName)); }
public void AppSettings_Load_CollectionHandlesSpaces() { string[] values = new[] { "one", "two", "three" }; var mockSettingsLoader = new SettingLoaderMock(); mockSettingsLoader.Settings.Add("Values", String.Join(", ", values)); var settings = new ListVarieties(); Assert.IsTrue(AppSettingsLoader.Load(mockSettingsLoader, ref settings), "Load returned false"); CollectionAssert.AreEqual(values, settings.Values); }
public void AppSetingsLoader_Load_LoadsAConnectionString() { var connectionStringName = "SingleConnectionString"; var connectionStringValue = "ConnectionStringValue"; var mockSettingLoader = new SettingLoaderMock(); mockSettingLoader.ConnectionStrings.Add(connectionStringName, connectionStringValue); var settings = new Settings(); Assert.IsTrue(AppSettingsLoader.Load(mockSettingLoader, ref settings), "Load returned flase"); Assert.AreEqual(connectionStringValue, settings.SingleConnectionString); }
public void AppSettings_Load_NoDevSettingPresentLoadsAsNormal() { string settingName = "OptionalSetting"; string prodSetting = "prod"; var devLoader = new SettingLoaderMock(); var prodLoader = new SettingLoaderMock(); prodLoader.Settings.Add(settingName, prodSetting); var settings = new SettingsOptionalClass(); AppSettingsLoader.DevSettings = devLoader; Assert.IsTrue(AppSettingsLoader.Load(prodLoader, ref settings), "Load returned false"); Assert.AreEqual(prodSetting, settings.OptionalSetting); }
public void AppSettings_Load_DevSettingOverrides() { string settingName = "OptionalSetting"; string devSetting = "dev"; var devLoader = new SettingLoaderMock(); devLoader.Settings.Add(settingName, devSetting); var prodLoader = new SettingLoaderMock(); prodLoader.Settings.Add(settingName, "prod"); var settings = new SettingsOptionalClass(); AppSettingsLoader.DevSettings = devLoader; Assert.IsTrue(AppSettingsLoader.Load(prodLoader, ref settings), "Load returned false"); Assert.AreEqual(devSetting, settings.OptionalSetting); }
public static void Main(string[] args) { Console.WriteLine(CurrentDirectory); var configRoot = new ConfigurationBuilder() .SetBasePath(CurrentDirectory) .AddJsonFile("appSettings.json", optional: true, reloadOnChange: true) .Build(); var appSettings = AppSettingsLoader.Load(configRoot); //Host.CreateDefaultBuilder(args) var webHostBuilder = new WebHostBuilder() .SuppressStatusMessages(true) .ConfigureLogging((hostingContext, loggingBuilder) => { loggingBuilder .AddConsoleFormatter <CustomConsoleFormatter, CustomConsoleFormatterOptions>(options => { }) .AddConfiguration(appSettings.LoggingConfig) .AddConsole(options => options.FormatterName = nameof(CustomConsoleFormatter)); }) .ConfigureServices(services => { services .AddSingleton(appSettings) .AddSingleton <IRequestManager, RequestManager>() .AddSingleton <ITinfoilIndexBuilder, TinfoilIndexBuilder>() .AddSingleton <IFileFilter, FileFilter>(); }) .UseConfiguration(configRoot) .UseKestrel((ctx, options) => { options.Configure(appSettings.KestrelConfig); }) .UseContentRoot(appSettings.ServedDirectory) .UseStartup <Startup>(); webHostBuilder.Build().Run(); }
public void AppSettingsLoader_Load_ExceptionOnFailToParse() { var mockSettingsLoader = new SettingLoaderMock(); mockSettingsLoader.Settings.Add("Is42", "fourty-two"); var settings = new Settings(); bool exceptionCaught = false; try { AppSettingsLoader.Load(mockSettingsLoader, ref settings); } catch (AggregateException aggEx) { exceptionCaught = true; Assert.AreEqual(1, aggEx.InnerExceptions.Count); } Assert.IsTrue(exceptionCaught, "An exception was not thrown"); }
/// <summary> /// Creates the connection string from the default connection string, the class name and method name. /// </summary> /// <param name="stackDepth"></param> /// <returns></returns> public static DbConnectionString Create(string className, string methodName = "") { var defConn = AppSettingsLoader.GetConfiguration().GetConnectionString("DefaultConnection"); return(Create(defConn, className, methodName)); }
public static void Main(string[] args) { const string?CONFIG_FILE_NAME = "TinfoilWebServer.config.json"; IConfigurationRoot configRoot; try { configRoot = new ConfigurationBuilder() .SetBasePath(CurrentDirectory) .AddJsonFile(CONFIG_FILE_NAME, optional: true, reloadOnChange: true) .Build(); } catch (Exception ex) { Console.Error.WriteLine($"Failed to build configuration: {ex.Message}{Environment.NewLine}Is «{CONFIG_FILE_NAME}» a valid JSON file?"); Environment.ExitCode = 1; return; } IAppSettings?appSettings; string[]? settingsLoadingErrors; try { appSettings = AppSettingsLoader.Load(configRoot, out settingsLoadingErrors); } catch (Exception ex) { Console.Error.WriteLine($"Failed to load configuration from file «{CONFIG_FILE_NAME}»: {ex.Message}"); Environment.ExitCode = 1; return; } var webHostBuilder = new WebHostBuilder() .SuppressStatusMessages(true) .ConfigureLogging((hostingContext, loggingBuilder) => { loggingBuilder .AddConsoleFormatter <CustomConsoleFormatter, CustomConsoleFormatterOptions>(options => { }) .AddConfiguration(appSettings.LoggingConfig) .AddConsole(options => options.FormatterName = nameof(CustomConsoleFormatter)); }) .ConfigureServices(services => { services .AddSingleton(appSettings) .AddSingleton <IRequestManager, RequestManager>() .AddSingleton <IServedDirAliasMap, ServedDirAliasMap>() .AddSingleton <IPhysicalPathConverter, PhysicalPathConverter>() .AddSingleton <IFileFilter, FileFilter>() .AddSingleton <IUrlCombinerFactory, UrlCombinerFactory>() .AddSingleton <IJsonSerializer, JsonSerializer>() .AddSingleton <ICachedTinfoilIndexBuilder, CachedTinfoilIndexBuilder>() .AddSingleton <ITinfoilIndexBuilder, TinfoilIndexBuilder>(); }) .UseConfiguration(configRoot) .UseKestrel((ctx, options) => { options.Configure(appSettings.KestrelConfig); }) .UseStartup <Startup>(); var webHost = webHostBuilder.Build(); var logger = webHost.Services.GetRequiredService <ILogger <Program> >(); if (settingsLoadingErrors.Length > 0) { logger.LogError($"Settings error:{settingsLoadingErrors.ToMultilineString()}"); } webHost.Run(); }
private void BtnLoadSelectedClick(object sender, EventArgs e) { _logRef.Target.Clear(); _logRef.Target.LogDebug("Loading commenced..."); var nameSpace = cBoxNameSpaces.Text; using (ICoreClient client = _factory.Create()) { if (chkDeleteAllConfig.Checked) { chkDeleteAllConfig.Checked = false; client.DeleteTypedObjects(null, Expr.StartsWith(Expr.SysPropItemName, nameSpace + ".Configuration.")); } if (chkDeleteAllStatus.Checked) { chkDeleteAllStatus.Checked = false; client.DeleteTypedObjects(null, Expr.StartsWith(Expr.SysPropItemName, nameSpace + ".Status.")); } if (chkDeleteAllAppSettings.Checked) { chkDeleteAllAppSettings.Checked = false; client.DeleteObjects <AppCfgRuleV2>(Expr.ALL); } if (chkMDSProviderMaps.Checked) { if (nameSpace == "FpML.V4r7") { //Orion.Configuration.MarketDataConfigHelper.LoadProviderRules(_logRef.Target, client); } else { MarketDataConfigHelper.LoadProviderRules(_logRef.Target, client, nameSpace); } chkMDSProviderMaps.Checked = false; } if (chkPricingStructureDefs.Checked) { if (nameSpace == "FpML.V4r7") { //Orion.Configuration.PricingStructureLoader.LoadPricingStructures(_logRef.Target, client); } else { PricingStructureLoader.LoadPricingStructures(_logRef.Target, client, nameSpace); } chkPricingStructureDefs.Checked = false; } if (chkAlertMonitorRules.Checked) { if (nameSpace == "FpML.V4r7") { //Orion.Configuration.AlertRulesLoader.Load(_logRef.Target, client); } else { AlertRulesLoader.Load(_logRef.Target, client, nameSpace); } chkAlertMonitorRules.Checked = false; } if (chkFileImportRules.Checked) { if (nameSpace == "FpML.V4r7") { //Orion.Configuration.FileImportRuleLoader.Load(_logRef.Target, client); } else { FileImportRuleLoader.Load(_logRef.Target, client, nameSpace); } chkFileImportRules.Checked = false; } if (chkTradeImportRules.Checked) { if (nameSpace == "FpML.V4r7") { //Orion.Configuration.TradeImportRuleLoader.Load(_logRef.Target, client); } else { TradeImportRuleLoader.Load(_logRef.Target, client, nameSpace); } chkTradeImportRules.Checked = false; } if (chkStressRules.Checked) { if (nameSpace == "FpML.V4r7") { //Orion.Configuration.StressDefinitionLoader.LoadStressDefinitions(_logRef.Target, client); //Orion.Configuration.StressDefinitionLoader.LoadScenarioDefinitions(_logRef.Target, client); } else { StressDefinitionLoader.LoadStressDefinitions(_logRef.Target, client, nameSpace); StressDefinitionLoader.LoadScenarioDefinitions(_logRef.Target, client, nameSpace); } chkStressRules.Checked = false; } if (chkAppSettings.Checked) { if (nameSpace == "FpML.V4r7") { //Orion.Configuration.AppSettingsLoader.Load(_logRef.Target, client); } else { AppSettingsLoader.Load(_logRef.Target, client, nameSpace); } chkAppSettings.Checked = false; } if (chkInstrumentsConfig.Checked) { if (nameSpace == "FpML.V4r7") { //Orion.Configuration.ConfigDataLoader.LoadInstrumentsConfig(_logRef.Target, client); } else { ConfigDataLoader.LoadInstrumentsConfig(_logRef.Target, client, nameSpace); } chkInstrumentsConfig.Checked = false; } if (chkAlgorithmConfig.Checked) { if (nameSpace == "FpML.V4r7") { //Orion.Configuration.ConfigDataLoader.LoadPricingStructureAlgorithm(_logRef.Target, client); } else { ConfigDataLoader.LoadPricingStructureAlgorithm(_logRef.Target, client, nameSpace); } chkAlgorithmConfig.Checked = false; } if (chkDateRules.Checked) { if (nameSpace == "FpML.V4r7") { //Orion.Configuration.ConfigDataLoader.LoadDateRules(_logRef.Target, client); } else { ConfigDataLoader.LoadDateRules(_logRef.Target, client, nameSpace); } chkDateRules.Checked = false; } if (bondDataCheckBox.Checked) { if (nameSpace == "FpML.V4r7") { //Orion.Configuration.MarketLoader.LoadFixedIncomeData(_logRef.Target, client); } else { MarketLoader.LoadFixedIncomeData(_logRef.Target, client, nameSpace); } bondDataCheckBox.Checked = false; } if (checkBoxMarkets.Checked) { if (nameSpace == "FpML.V4r7") { //Orion.Configuration.MarketLoader.Load(_logRef.Target, client); } else { MarketLoader.Load(_logRef.Target, client, nameSpace); } checkBoxMarkets.Checked = false; } if (checkBoxFpML.Checked) { if (nameSpace == "FpML.V4r7") { //Orion.Configuration.ConfigDataLoader.LoadFpml(_logRef.Target, client); //Orion.Configuration.ConfigDataLoader.LoadGwml(_logRef.Target, client); } else { ConfigDataLoader.LoadFpMLCodes(_logRef.Target, client, nameSpace); } checkBoxFpML.Checked = false; } if (checkBoxHolidayDates.Checked) { if (nameSpace == "FpML.V4r7") { //Orion.Configuration.ConfigDataLoader.LoadNewHolidayDates(_logRef.Target, client); } else { ConfigDataLoader.LoadNewHolidayDates(_logRef.Target, client, nameSpace); } checkBoxHolidayDates.Checked = false; } } _logRef.Target.LogDebug("Load completed."); }