示例#1
0
        public static void Test()
        {
            Settings_t env = new Settings_t();

            Microsoft.Extensions.Configuration.IConfigurationBuilder builder =
                new Microsoft.Extensions.Configuration.ConfigurationBuilder()
                .SetBasePath(env.ProjectRootPath)
                // .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) // Microsoft.Extensions.Configuration.Json.dll
                // .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
                // .AddJsonFile("settings.json")
                // .AddYamlFile("settings.yml", optional: false) // Microsoft.Extensions.Configuration.Yaml.dll
                .AddRegistryKey(@"HKEY_CURRENT_USER\Software\COR\All", "/etc/COR/All")
                .AddRegistryKey(@"HKEY_CURRENT_USER\Software\COR\SchemaPorter", "/etc/COR/SchemaPorter")
                // .AddEnvironmentVariables() // Microsoft.Extensions.Configuration.EnvironmentVariables.dll
            ;

            Microsoft.Extensions.Configuration.IConfigurationRoot Configuration = builder.Build();

            // IConfigurationSection thisSection = Configuration.GetSection("AppSettings:token");
            // thisSection.Key
            // thisSection.Value;
            // services.Configure<StorageOptions>(Configuration.GetSection("AzureStorageConfig"));

            // Just the value of the token
            // string configValue = Configuration["AppSettings:token"];


            // https://stackoverflow.com/questions/31453495/how-to-read-appsettings-values-from-config-json-in-asp-net-core
            Newtonsoft.Json.Linq.JObject conf = GetConfigAsJObject(Configuration);
            string configValues = Newtonsoft.Json.JsonConvert.SerializeObject(conf, Newtonsoft.Json.Formatting.Indented);

            System.Console.WriteLine(configValues);
        } // End Sub Test
示例#2
0
        public static void Start(Microsoft.Extensions.Configuration.IConfigurationRoot configuration)
        {
            var serviceProvider = ConfigureServiceProvider(configuration);


            Console.WriteLine(serviceProvider.GetService <GoogleService>().Get());
            Console.WriteLine(serviceProvider.GetService <BingService>().Get());
        }
示例#3
0
        public Startup(IHostingEnvironment env)
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(env.ContentRootPath)
                          .AddJsonFile("appsettings.json");

            Configuration = builder.Build();
        }
示例#4
0
        public static string GetConnectionString(string str)
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile("appsettings.json");

            Configuration = builder.Build();

            return(Configuration.GetConnectionString(str));
        }
示例#5
0
        public static void Main(string[] args)
        {
            Microsoft.Extensions.Configuration.ConfigurationBuilder bconfig = (Microsoft.Extensions.Configuration.ConfigurationBuilder)(new Microsoft.Extensions.Configuration.ConfigurationBuilder());
            //if (args != null)bconfig.AddCommandLine(args).Build();
            bconfig.SetBasePath(BasePath);
            bconfig.AddJsonFile(AppName + ".json", optional: true, reloadOnChange: true);
            _Config = bconfig.Build();

            Start(args);
            Config_OnChanged = Config.GetReloadToken().RegisterChangeCallback(Call_Config_OnChanged, new object[] { Config });
        }
        /// <summary>
        /// Public CTOR, DI does not work correctly, so we pull what we need from Program's statics
        /// </summary>
        public JobEngine()
        {
            _loggerFactory = Program.Services.GetService <ILoggerFactory>();
            _config        = Program.Services.GetService <IConfigurationRoot>();

            // TODO: Set-up persistant storage like SQL or REDIS
            NameValueCollection props = new NameValueCollection
            {
                { "quartz.serializer.type", "binary" }
            };

            factory   = new StdSchedulerFactory(props);
            scheduler = factory.GetScheduler().GetAwaiter().GetResult();
        }
示例#7
0
        public Startup(IHostingEnvironment env)
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(env.ContentRootPath)
                          .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
                          .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: false, reloadOnChange: true)
                          .AddEnvironmentVariables();

            Configuration = builder.Build();

            _launchSettings = new ConfigurationBuilder()
                              .SetBasePath(env.ContentRootPath)
                              .AddJsonFile("Properties\\launchSettings.json")
                              .Build();
        }
示例#8
0
    } // End Function EscapeString

    static void Main(string[] args)
    {
        string ms = GetMsCon();
        string pg = GetPgCon();

        ms = EscapeString(ms);
        pg = EscapeString(pg);

        // DESKTOP-4P9UFE8
        System.Console.WriteLine($"MS: {ms}\r\nPG: {pg}");

        ConsoleEnvironment env = new ConsoleEnvironment();

        // https://stackoverflow.com/questions/40169673/read-appsettings-in-asp-net-core-console-application


        // Microsoft.Extensions.Configuration
        // Microsoft.Extensions.Configuration.Json
        // Set to copy to output
        Microsoft.Extensions.Configuration.IConfigurationBuilder builder =
            new Microsoft.Extensions.Configuration.ConfigurationBuilder()
            .SetBasePath(env.ContentRootPath)
            .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
            .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
            .AddJsonFile($"appsettings.{env.MachineName}.json", optional: true)
            .AddEnvironmentVariables()
            .AddUserSecrets()
        ;



        // myc - connection
        // time added - dbtype
        // System.Collections.Generic.Dictionary<System.Guid, System.Data.Common.DbConnection> didi;
        // System.Collections.Generic.Dictionary<System.Guid, CoreDb.ReadDAL> didi;
        // new { DAL = CoreDb.ReadDAL, Con=null, dateTimeAdded}



        // '...Visual Studio 2017\Projects\Loggy\CoreDbTest\bin\Debug\netcoreapp1.0\appsettings.json'.'

        Config = builder.Build();

        Console.WriteLine($"option1 = {Config.GetSection("ConnectionStrings")[env.MachineName]}");

        System.Collections.Generic.List <string> list = new System.Collections.Generic.List <string>();


        foreach (IConfigurationSection kvp in Config.GetSection("ConnectionStrings").GetChildren())
        {
            System.Console.WriteLine($"{kvp.Key}:\t{kvp.Value}");

            if (System.StringComparer.OrdinalIgnoreCase.Equals(kvp.Key, env.MachineName))
            {
                System.Console.WriteLine(kvp.Value);
            }
        } // Next kvp



        foreach (IConfigurationSection kvp in Config.GetSection("ConnectionStrings").GetChildren())
        {
            System.Console.WriteLine($"{kvp.Key}:\t{kvp.Value}");


            if (System.StringComparer.OrdinalIgnoreCase.Equals(kvp.Key, env.MachineName))
            {
                System.Console.WriteLine(kvp.Value);
            }
        } // Next kvp



        // CoreDb.DalConfig conme = new CoreDb.DalConfig("constring");

        CoreDb.DalConfig con = new CoreDb.DalConfig(
            delegate(CoreDb.DalConfig config)
        {
            string sectionName = Config.GetSection("DbProviderName").Value;
            if (sectionName == null)
            {
                sectionName = "ConnectionStrings";
            }

            string cs = Config.GetSection(sectionName).GetSection(env.MachineName).Value;

            if (cs == null)
            {
                cs = Config.GetSection(sectionName).GetSection("DefaultConnection").Value;
            }

            if (cs == null)
            {
                throw new System.IO.InvalidDataException("No connection string found");
            }

            return(cs);
        }
            );


        System.Console.WriteLine(con.ConnectionString);



        string strJSO = Newtonsoft.Json.JsonConvert.SerializeObject(Config, Newtonsoft.Json.Formatting.Indented);

        System.Console.WriteLine(strJSO);

        // Overwrites configuration, but one value at a time,
        // does not replace entire section.
        string foo = Config.GetConnectionString("PG3");

        System.Console.WriteLine(foo);
        foo = Config.GetConnectionString("DefaultConnection");
        System.Console.WriteLine(foo);
        foo = Config.GetConnectionString("DefaultConnection2");
        System.Console.WriteLine(foo);


        Console.WriteLine("Hello World!");
    }
示例#9
0
 public Startup(IWebHostEnvironment HostEnv)
 {
     ConfString = new ConfigurationBuilder().SetBasePath(HostEnv.ContentRootPath).AddJsonFile("DBSettings.json").Build(); // Построение настроек базы данных
 }
 /// <summary>
 /// CTOR
 /// </summary>
 /// <param name="loggerFactory">ILoggerFactory</param>
 /// <param name="config">IConfigurationRoot</param>
 public ConfigurationDumper(Microsoft.Extensions.Logging.ILoggerFactory loggerFactory, IConfigurationRoot config)
 {
     _logger = loggerFactory.CreateLogger <ConfigurationDumper>();
     _config = config;
 }