当前位置: 首页>>代码示例>>C#>>正文


C# ConfigurationBuilder.Add方法代码示例

本文整理汇总了C#中Microsoft.Framework.Configuration.ConfigurationBuilder.Add方法的典型用法代码示例。如果您正苦于以下问题:C# ConfigurationBuilder.Add方法的具体用法?C# ConfigurationBuilder.Add怎么用?C# ConfigurationBuilder.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Framework.Configuration.ConfigurationBuilder的用法示例。


在下文中一共展示了ConfigurationBuilder.Add方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        public int Main(string[] args)
        {
            var builder = new ConfigurationBuilder();
            builder.Add(new JsonConfigurationSource("config.json"));
            var config = builder.Build();
            var webjobsConnectionString = config["Data:AzureWebJobsStorage:ConnectionString"];
            var dbConnectionString = config["Data:DefaultConnection:ConnectionString"];

            if (string.IsNullOrWhiteSpace(webjobsConnectionString))
            {
                Console.WriteLine("The configuration value for Azure Web Jobs Connection String is missing.");
                return 10;
            }

            if (string.IsNullOrWhiteSpace(dbConnectionString))
            {
                Console.WriteLine("The configuration value for Database Connection String is missing.");
                return 10;
            }

            var jobHostConfig = new JobHostConfiguration(webjobsConnectionString);
            var host = new JobHost(jobHostConfig);

            host.RunAndBlock();
            return 0;
        }
开发者ID:Ranireddy,项目名称:PartsUnlimited,代码行数:26,代码来源:Program.cs

示例2: Main

        public int Main(string[] args)
        {
            var builder = new ConfigurationBuilder();
            builder.Add(new JsonConfigurationProvider("config.json"));
            var config = builder.Build();
            var webjobsConnectionString = config["Data:AzureWebJobsStorage:ConnectionString"];
            var dbConnectionString = config["Data:DefaultConnection:ConnectionString"];
            if (string.IsNullOrWhiteSpace(webjobsConnectionString))
            {
                Console.WriteLine("The configuration value for Azure Web Jobs Connection String is missing.");
                return 10;
            }

            if (string.IsNullOrWhiteSpace(dbConnectionString))
            {
                Console.WriteLine("The configuration value for Database Connection String is missing.");
                return 10;
            }

            var jobHostConfig = new JobHostConfiguration(config["Data:AzureWebJobsStorage:ConnectionString"]);
            var host = new JobHost(jobHostConfig);
            var methodInfo = typeof(Functions).GetMethods().First();

            host.Call(methodInfo);
            return 0;
        }
开发者ID:dpiessens,项目名称:PartsUnlimited,代码行数:26,代码来源:Program.cs

示例3: CreateOrderProcessTask

        public static void CreateOrderProcessTask([Queue("orders")] CloudQueue orderQueue)
        {
            Console.WriteLine("Starting Create Order Process Task");
            try
            {
                var builder = new ConfigurationBuilder();
                builder.Add(new JsonConfigurationSource("config.json"));
                var config = builder.Build();
                var connectionString = config["Data:DefaultConnection:ConnectionString"];

                using (var context = new PartsUnlimitedContext(connectionString))
                {
                    var orders = context.Orders.Where(x => !x.Processed).ToList();
                    Console.WriteLine("Found {0} orders to process", orders.Count);

                    foreach (var order in orders)
                    {
                        var productIds = context.OrderDetails.Where(x => x.OrderId == order.OrderId).Select(x => x.ProductId).ToList();
                        var items = context.Products
                            .Where(x => productIds.Contains(x.ProductId))
                            .ToList();

                        var orderItems = items.Select(
                                x => new LegacyOrderItem
                                {
                                    SkuNumber = x.SkuNumber,
                                    Price = x.Price
                                }).ToList();

                        var queueOrder = new LegacyOrder
                        {
                            Address = order.Address,
                            Country = order.Country,
                            City = order.City,
                            Phone = order.Phone,
                            CustomerName = order.Name,
                            OrderDate = order.OrderDate,
                            PostalCode = order.PostalCode,
                            State = order.State,
                            TotalCost = order.Total,
                            Discount = order.Total,
                            Items = orderItems
                        };
                        var settings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() };
                        var message = JsonConvert.SerializeObject(queueOrder, settings);
                        orderQueue.AddMessage(new CloudQueueMessage(message));
                        order.Processed = true;
                    }
                    context.SaveChanges();
                    Console.WriteLine("Orders successfully processed.");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
开发者ID:GersonDias,项目名称:PartsUnlimited,代码行数:57,代码来源:Functions.cs

示例4: ConfigurationServiceBase

 protected ConfigurationServiceBase(string basePath, params string[] paths)
 {
     var cb = new ConfigurationBuilder();
     foreach (var provider in paths.Select(p => new JsonConfigurationProvider(basePath + @"\"+ p)))
     {
         cb.Add(provider);
     }
     Config = cb.Build();
 }
开发者ID:domenkogler,项目名称:Framework-old,代码行数:9,代码来源:ConfigurationService.cs

示例5: LoadJson

 public static IConfiguration LoadJson(string configFile)
 {
     var config = new ConfigurationBuilder();
     var source = new JsonConfigurationSource("path", true);
     using (var stream = typeof(EmbeddedConfiguration).GetTypeInfo().Assembly.GetManifestResourceStream("Autofac.Configuration.Test.Files." + configFile))
     {
         typeof(JsonConfigurationSource).GetMethod("Load", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(source, new object[] { stream });
     }
     config.Add(source, false);
     return config.Build();
 }
开发者ID:juntor,项目名称:Autofac.Configuration,代码行数:11,代码来源:EmbeddedConfiguration.cs

示例6: Main

        public void Main(string[] args)
        {
            var builder = new ConfigurationBuilder();
            Console.WriteLine("Initial Config Sources: " + builder.Sources.Count());

            var defaultSettings = new MemoryConfigurationSource();
            defaultSettings.Set("username", "Guest");
            builder.Add(defaultSettings);
            Console.WriteLine("Added Memory Source. Sources: " + builder.Sources.Count());

            builder.AddCommandLine(args);
            Console.WriteLine("Added Command Line Source. Sources: " + builder.Sources.Count());

            var config = builder.Build();
            string username = config.Get("username");

            Console.WriteLine($"Hello, {username}!");
        }
开发者ID:alibaba0012013,项目名称:aspnet-docs,代码行数:18,代码来源:Program.cs

示例7: Startup

        public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv, ILoggerFactory loggerFactory)
        {
            loggerFactory.MinimumLevel = LogLevel.Information;
            loggerFactory.AddConsole();

            var apiConfig = ConfigReader.Get(appEnv.ApplicationBasePath + @"\serviceConfigSource.json");

            var builder = new ConfigurationBuilder(appEnv.ApplicationBasePath)
                            .AddJsonFile("config.json")
                            .AddEnvironmentVariables();

            builder.Add(new ServiceConfigurationSource(
                apiConfig.ApiKey,
                apiConfig.UriFormat,
                "test",
                "hello"));

            Configuration = builder.Build();
        }
开发者ID:antonyfrancis,项目名称:simple-config-service,代码行数:19,代码来源:Startup.cs

示例8: CreateServer

        public static IDisposable CreateServer(Func<HttpContext, Task> app)
        {
            Action<IApplicationBuilder> startup = builder =>
            {
                builder.Use(async (ct, next) =>
                {
                    try
                    {
                        // Kestrel does not return proper error responses:
                        // https://github.com/aspnet/KestrelHttpServer/issues/43
                        await next();
                    }
                    catch (Exception ex)
                    {
                        if (ct.Response.HasStarted)
                        {
                            throw;
                        }

                        ct.Response.StatusCode = 500;
                        ct.Response.Headers.Clear();
                        await ct.Response.WriteAsync(ex.ToString());
                    }
                });
                builder.UseWebSockets();
                builder.Run(c => app(c));
            };

            var configBuilder = new ConfigurationBuilder();
            configBuilder.Add(new MemoryConfigurationSource());
            var config = configBuilder.Build();
            config["server.urls"] = "http://localhost:54321";

            var host = new WebHostBuilder(CallContextServiceLocator.Locator.ServiceProvider, config)
                .UseServer("Microsoft.AspNet.Server.Kestrel")
                .UseStartup(startup)
                .Build();

            return host.Start();
        }
开发者ID:591studybar,项目名称:WebSockets,代码行数:40,代码来源:KestrelWebSocketHelpers.cs

示例9: UpdateProductProcessTaskAsync

        public async static Task UpdateProductProcessTaskAsync([QueueTrigger("product")] ProductMessage message)
        {
            var builder = new ConfigurationBuilder();
            builder.Add(new JsonConfigurationProvider("config.json"));
            var config = builder.Build();
            var connectionString = config["Data:DefaultConnection:ConnectionString"];

            using (var context = new PartsUnlimitedContext(connectionString))
            {
                var dbProductList = await context.Products.ToListAsync();
                foreach (var queueProduct in message.ProductList)
                {
                    var dbProduct = dbProductList.SingleOrDefault(x => x.SkuNumber == queueProduct.SkuNumber);

                    if (dbProduct != null)
                    {
                        dbProduct.Inventory = queueProduct.Inventory;
                        dbProduct.LeadTime = queueProduct.LeadTime;
                    }
                }
                await context.SaveChangesAsync(CancellationToken.None);
            }
        }
开发者ID:dpiessens,项目名称:PartsUnlimited,代码行数:23,代码来源:Functions.cs

示例10: Startup

        public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
        {
            // Setup configuration sources.

            var builder = new ConfigurationBuilder(appEnv.ApplicationBasePath)
                .AddIniFile("data.ini")
                .AddJsonFile("config.json")
                .AddJsonFile($"config.{env.EnvironmentName}.json", optional: true);

            //Command line: Data:Value=1
            var defaultSettings = new MemoryConfigurationSource();
            defaultSettings.Set("username", "Guest");
            builder.Add(defaultSettings);

            if (env.IsDevelopment())
            {
                // This reads the configuration keys from the secret store.
                // For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
                builder.AddUserSecrets();
            }
            builder.AddEnvironmentVariables();
            Configuration = builder.Build();
        }
开发者ID:tkopacz,项目名称:aspnet5-tkdemo-beta7,代码行数:23,代码来源:Startup.cs

示例11: Start

        private BackTelemetryChannel Start(string assemblyName)
        {
            var customConfig = new MemoryConfigurationSource();
            customConfig.Set("server.urls", this.BaseHost);
            var configBuilder = new ConfigurationBuilder();
            configBuilder.Add(customConfig);
            var config = configBuilder.Build();

            var services = new ServiceCollection();
            services.AddTransient<IApplicationEnvironment, ApplicationEnvironment>();
            var serviceProvider = services.BuildServiceProvider();

            var engine = CreateBuilder(config)
                .UseServer("Microsoft.AspNet.Server.WebListener")
                .UseStartup(assemblyName)
                .UseEnvironment("Production")
                .Build();
            this.hostingEngine = engine.Start();

            return (BackTelemetryChannel)engine.ApplicationServices.GetService<ITelemetryChannel>();
        }
开发者ID:hackathonvixion,项目名称:ApplicationInsights-aspnet5,代码行数:21,代码来源:InProcessServer.cs

示例12: SetUpDefaultAssembly

 private static IConfiguration SetUpDefaultAssembly(string assemblyName)
 {
     var source = new MemoryConfigurationSource();
     source.Add("defaultAssembly", assemblyName);
     var config = new ConfigurationBuilder();
     config.Add(source);
     return config.Build();
 }
开发者ID:jango2015,项目名称:Autofac.Configuration,代码行数:8,代码来源:ConfigurationExtensionsFixture.cs


注:本文中的Microsoft.Framework.Configuration.ConfigurationBuilder.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。