示例#1
0
        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());
        }
示例#2
0
        /// <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
                );
        }