static ISettingsProvider GetJsonProvider() { var storage = new FileStreamStorageProvider("config.json"); var provider = new JsonSettingsProvider(storage); return(provider); }
public static void AddSettingsProvider(this IMutableDependencyResolver services) { string settingsPath = ""; var platformInfo = AvaloniaLocator.Current.GetService <IRuntimePlatform>().GetRuntimeInfo(); AppSettings defaultAppSettings = null; if (platformInfo.OperatingSystem == OperatingSystemType.WinNT) { settingsPath = Environment.ExpandEnvironmentVariables("%APPDATA%\\SampleAvaloniaApplicationClient\\appsettings.json"); defaultAppSettings = new AppSettings(); } else if (platformInfo.OperatingSystem == OperatingSystemType.Linux) { settingsPath = Environment.ExpandEnvironmentVariables("/%HOME%/SampleAvaloniaApplicationClient/appsettings.json"); defaultAppSettings = new AppSettings() { DbFilename = "/%HOME%/SampleAvaloniaApplicationClient/data.db", LogsFolder = "/%HOME%/SampleAvaloniaApplicationClient/Logs" }; } var settingsProvider = new JsonSettingsProvider <AppSettings>(settingsPath, defaultAppSettings, new JsonSerializerOptions() { WriteIndented = true }); services.RegisterLazySingleton <ISettingsProvider <AppSettings> >(() => new JsonSettingsProvider <AppSettings>(settingsPath, defaultAppSettings, new JsonSerializerOptions() { WriteIndented = true })); }
public void settings_are_loaded_from_json_file() { var provider = new JsonSettingsProvider("settings.json"); var settings = provider.Load(); Assert.AreEqual("1", settings["sample1"]); Assert.AreEqual("2", settings["sample2"]); }
public void an_exception_is_thrown_if_environment_not_found() { Assert.Throws<KeyNotFoundException>(() => { var provider = new JsonSettingsProvider("broken.settings.json"); provider.Load(); }); }
public static ConfigurationServiceBuilder AddJson <TSettings>(this ConfigurationServiceBuilder builder, string path, Action <IServiceProvider, SettingsProviderOptions> configure) where TSettings : class, new() => AddProvider(builder, serviceProvider => { var settingsProviderOptions = new SettingsProviderOptions(); configure?.Invoke(serviceProvider, settingsProviderOptions); var provider = new JsonSettingsProvider <TSettings>(settingsProviderOptions, path); return(provider); });
public void symbols_in_a_config_file_are_replaced_with_values_from_figs_config() { using (var stream = File.OpenRead("sample.config")) { var parser = new DefaultConfigurationParser(Encoding.ASCII); var provider = new JsonSettingsProvider("settings.json"); var settings = provider.Load(); var result = parser.Parse(stream, settings); Assert.AreEqual(File.ReadAllText("expected.config"), result); } }
public void GetSettings_CreateNewAndCheckSettings() { //Arrange string jsonPath = Environment.CurrentDirectory + "\\TestFiles\\AppSettings.json"; //Act var settingsProvider = new JsonSettingsProvider(jsonPath); var settings = settingsProvider.GetSettings(); //Assert Assert.AreEqual("*****@*****.**", settings.To); }
public void an_exception_is_thrown_when_key_missing_from_figs_config() { Assert.Throws<KeyNotFoundException>(() => { using (var stream = File.OpenRead("missing.sample.config")) { var parser = new DefaultConfigurationParser(Encoding.ASCII); var provider = new JsonSettingsProvider("settings.json"); var settings = provider.Load(); parser.Parse(stream, settings); } }); }
/// <summary> /// Constructor /// </summary> private SettingsManager() { if (_localSettingsStore == null) { _localSettingsStore = new LocalSettingsStore(); } if (_settingsProvider == null) { _settingsProvider = new JsonSettingsProvider(_localSettingsStore); } LoadSettings(); }
public void UnknownOverrideTest() { var configJson = @"{ connectionString: ""kama"" }"; var fs = new Mock <IFileSystem>(); fs.Setup(x => x.ReadFile(It.IsAny <string>())).Returns(configJson); var args = new Mock <ICommandLineArgumentsProvider>(); args.Setup(x => x.GetArguments()).Returns(new[] { "--p:ConnectionStringas", "ala ma kota" }); var settings = new JsonSettingsProvider(new NullLog(), fs.Object, args.Object); Assert.Equal("kama", settings.ConnectionString); }
/// <summary> /// Main method /// </summary> internal static void Main() { ISettingsProvider settingsProvider = new JsonSettingsProvider(); IPhraseProvider phraseProvider = new JsonPhraseProvider(settingsProvider); IInputOutputDevice inputOutputDevice = new ConsoleIODevice(); IBoard board = new Board(); IDrawOnBoard drawOnBoard = new DrawOnBoard(); var game = new Game( phraseProvider: phraseProvider, inputOutputDevice: inputOutputDevice, settingsProvider: settingsProvider, board: board, drawOnBoard: drawOnBoard); game.Run(); }
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); //Register dialog service singlton var dialogService = new Dialog(null); dialogService.Register <MainWindowViewModel, MainWindow>(); dialogService.Register <MessageDialogViewModel, MessageDialog>(); dialogService.Register <ConfigureDialogViewModel, ConfigureDialog>(); dialogService.Register <AboutViewModel, AboutDialog>(); DI.AddSinglton <IDialogService>(dialogService); //Register Categories Provider as singlton ICategoriesProvider catsProvider = new CategoriesProvider(); DI.AddSinglton <ICategoriesProvider>(catsProvider); //Register message composer as singlton. DI.AddSinglton <IMessageComposer>(new MessageComposer()); var assetsConfig = new AssetsSourceConfiguration(Environment.CurrentDirectory + "\\Configs\\ExcelConfig.json"); DI.AddSinglton <IAssetSourceConfiguration>(assetsConfig); var appSettingsProvider = new JsonSettingsProvider(Environment.CurrentDirectory + "\\Configs\\AppSettings.json"); DI.AddSinglton <ISettingsProvider>(appSettingsProvider); var assetsSource = new ExcelAssetReader(); assetsSource.Configure(assetsConfig); DI.AddSinglton <IAssetSource>(assetsSource); DI.AddSinglton <IClipBoard>(new ClipboardService()); //Register mail service as scoped DI.AddService <IMailService, OutlookMailService>(); DI.AddTransient(typeof(MainWindowViewModel)); DI.Construct(); IRC.Helpdesk.ViewModels.DI.SetProvider(DI.Provider); DI.GetService <IDialogService>().ShowWindow <MainWindowViewModel>(DI.GetService <MainWindowViewModel>(), true); }
public static SettingsProviderDictionary AddJson <TSettings>(this SettingsProviderDictionary providers, string path, Action <SettingsProviderOptions> configure = null) where TSettings : class, new() { if (providers == null) { throw new ArgumentNullException(nameof(providers)); } var options = new SettingsProviderOptions(); configure?.Invoke(options); var provider = new JsonSettingsProvider <TSettings>(options, path); providers.Add(provider); return(providers); }
public void AllSettingsNoOverridesTest() { var configJson = @"{ connectionString: ""kama"", webClientDelay: ""10"", importerDelta: ""88"", importIntervalMinutes: ""34"" }"; var fs = new Mock <IFileSystem>(); fs.Setup(x => x.ReadFile(It.IsAny <string>())).Returns(configJson); var args = new Mock <ICommandLineArgumentsProvider>(); args.Setup(x => x.GetArguments()).Returns(new string[] { }); var settings = new JsonSettingsProvider(new NullLog(), fs.Object, args.Object); Assert.Equal("kama", settings.ConnectionString); Assert.Equal(TimeSpan.FromMilliseconds(10), settings.WebClientDelay); Assert.Equal(88, settings.ImporterDelta); }
public void MultipleEntriesJsonHasExpectedValue(string key, string value) { var provider = new JsonSettingsProvider("MultipleEntries.json"); Assert.Equal(value, provider[key]); }
public void SingleEntriesJsonHasExpectedKeys(string key) { var provider = new JsonSettingsProvider("MultipleEntries.json"); Assert.Contains(key, provider.AllKeys); }
public void MultipleEntriesJsonHasExpectedNumberOfKeys() { var provider = new JsonSettingsProvider("MultipleEntries.json"); Assert.Equal(3, provider.AllKeys.Count()); }
public void SingleEntryJsonHasExpectedValue() { var provider = new JsonSettingsProvider("SingleEntry.json"); Assert.Equal("5", provider["Test:Value"]); }
public void SingleEntryJsonHasExpectedKey() { var provider = new JsonSettingsProvider("SingleEntry.json"); Assert.Contains("Test:Value", provider.AllKeys); }
public void SingleEntryJsonHasExpectedNumberOfKeys() { var provider = new JsonSettingsProvider("SingleEntry.json"); Assert.Equal(1, provider.AllKeys.Count()); }
/// <summary> /// Applies json options to all requets to the service. /// </summary> private static void ApplyJsonOptions(MvcJsonOptions jsonOptions) { var jsonSettingsProvider = new JsonSettingsProvider(new TypeMapCollection()); jsonSettingsProvider.PopulateSettings(jsonOptions.SerializerSettings); }