public static IConfiguration CreateSettings(string filename)
        {
            if (System.String.IsNullOrEmpty(filename))
            {
                filename = "appSettings.json";
            }

            if (!File.Exists(Directory.GetCurrentDirectory() + "/" + filename))
            {
                SettingsWriter writer = new SettingsWriter();
            }

            try
            {
                IConfiguration configuration = new ConfigurationBuilder()
                                               .SetBasePath(Directory.GetCurrentDirectory())
                                               .AddJsonFile(filename, optional: false, reloadOnChange: true)
                                               .Build();
                return(configuration);
            }
            catch (FormatException)
            {
                throw new Exceptions.InvalidSettingsConfigurationException(
                          $"The selected settings file {filename} is not formatted correctly. You can either re-create it or default to appSettings.json by calling CreateSettings() without any overflows."
                          );
            }
            catch (FileNotFoundException)
            {
                throw new Exceptions.InvalidSettingsFileException(
                          $"The settings file {filename} does not exist. You can either create it or default to appSettings.json by calling CreateSettings() without any overflows."
                          );
            }
        }
        public static IConfiguration CreateSettings()
        {
            if (!File.Exists(Directory.GetCurrentDirectory() + "/appSettings.json"))
            {
                SettingsWriter writer = new SettingsWriter();
            }
            IConfiguration configuration = new ConfigurationBuilder()
                                           .SetBasePath(Directory.GetCurrentDirectory())
                                           .AddJsonFile("appSettings.json", optional: false, reloadOnChange: true)
                                           .Build();

            return(configuration);
        }
Exemplo n.º 3
0
        public static IConfiguration CreateSettings(string filename)
        {
            
            if (String.IsNullOrEmpty(filename)) { filename = "appSettings.json"; }
            if (!File.Exists(Directory.GetCurrentDirectory() + "/"+filename))
            {
                SettingsWriter writer = new SettingsWriter();
            }


            IConfiguration configuration = new ConfigurationBuilder()
                .SetBasePath(Directory.GetCurrentDirectory())
                .AddJsonFile(filename, optional: false, reloadOnChange: true)
                .Build();
            return configuration;
        }