BotSharp/BotSharp.WebHost/Program.cs

52 lines
1.7 KiB
C#
Raw Normal View History

2018-08-28 21:45:56 +00:00
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using System;
using System.IO;
using System.Linq;
namespace BotSharp.WebHost
{
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
Microsoft.AspNetCore.WebHost.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((hostingContext, config) =>
{
var env = hostingContext.HostingEnvironment;
2018-09-13 21:52:19 +00:00
string dir = Path.GetFullPath(env.ContentRootPath);
string settingsFolder = Path.Combine(dir, "Settings");
2018-10-02 16:46:24 +00:00
// locate setting folder
2018-09-13 21:52:19 +00:00
if (!Directory.Exists(settingsFolder))
{
dir = Path.GetFullPath(env.ContentRootPath + "/..");
}
settingsFolder = Path.Combine(dir, "Settings");
2018-10-02 16:46:24 +00:00
if (!Directory.Exists(settingsFolder))
{
dir = Path.GetFullPath(env.ContentRootPath + "/bin");
}
settingsFolder = Path.Combine(dir, "Settings");
Console.WriteLine($"Read settings from {settingsFolder}");
2018-10-02 16:46:24 +00:00
2018-09-13 21:52:19 +00:00
var settings = Directory.GetFiles(settingsFolder, "*.json");
2018-08-28 21:45:56 +00:00
settings.ToList().ForEach(setting =>
{
config.AddJsonFile(setting, optional: false, reloadOnChange: true);
});
})
2018-10-04 02:40:00 +00:00
.UseUrls("http://0.0.0.0:7500")
2018-08-28 21:45:56 +00:00
.UseStartup<Startup>()
.Build();
}
}