private static IConfiguration GetConfiguration() { var configurationBuilder = new ConfigurationBuilder() .AddJsonFile("appsettings.json", false) .AddJsonFile(SubtitleDownloaderSettingsLocator.GetUserSettingsFileName(), true); var environment = Environment.GetEnvironmentVariable("Environment"); if (environment != null) { configurationBuilder.AddJsonFile($"appsettings.{environment}.json", true); } return(configurationBuilder.Build()); }
/// <summary> /// Save user settings. /// </summary> /// <param name="settings"></param> /// <returns>Task which saves the user settings.</returns> private async Task SaveUserSettingsAsync(SubtitleDownloaderSettings settings) { var settingsJson = JsonConvert.SerializeObject(settings, Formatting.Indented); var settingsDirectory = SubtitleDownloaderSettingsLocator.GetUserSettingsDirectory(); var settingsFileName = SubtitleDownloaderSettingsLocator.GetUserSettingsFileName(); if (!Directory.Exists(settingsDirectory)) { Directory.CreateDirectory(settingsDirectory); } await File.WriteAllTextAsync( settingsFileName, settingsJson ); }