本文整理汇总了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;
}
示例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;
}
示例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);
}
}
示例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();
}
示例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();
}
示例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}!");
}
示例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();
}
示例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();
}
示例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);
}
}
示例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();
}
示例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>();
}
示例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();
}