DocSpace-client/common/services/ASC.Data.Storage.Migration/Program.cs

81 lines
3.2 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using System.IO;
2021-06-16 13:54:36 +00:00
using System.Threading.Tasks;
using ASC.Api.Core;
using ASC.Common;
using ASC.Common.Caching;
using ASC.Common.DependencyInjection;
using ASC.Common.Utils;
2020-11-02 16:27:08 +00:00
using Autofac;
using Autofac.Extensions.DependencyInjection;
2021-06-16 13:54:36 +00:00
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace ASC.Data.Storage.Migration
{
public class Program
{
public async static Task Main(string[] args)
{
var host = CreateHostBuilder(args).Build();
await host.RunAsync();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.UseSystemd()
.UseWindowsService()
2021-06-16 13:54:36 +00:00
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
.ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup<BaseWorkerStartup>())
.ConfigureAppConfiguration((hostContext, config) =>
2021-06-16 13:54:36 +00:00
{
var buided = config.Build();
var path = buided["pathToConf"];
if (!Path.IsPathRooted(path))
{
path = Path.GetFullPath(CrossPlatform.PathCombine(hostContext.HostingEnvironment.ContentRootPath, path));
}
config.SetBasePath(path);
var env = hostContext.Configuration.GetValue("ENVIRONMENT", "Production");
config
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{env}.json", true)
.AddJsonFile($"appsettings.services.json", true)
.AddJsonFile("storage.json")
.AddJsonFile("notify.json")
2021-09-03 15:04:06 +00:00
.AddJsonFile($"notify.{env}.json", true)
2021-06-16 13:54:36 +00:00
.AddJsonFile("kafka.json")
.AddJsonFile($"kafka.{env}.json", true)
.AddEnvironmentVariables()
2020-11-26 17:30:57 +00:00
.AddCommandLine(args)
2021-06-16 13:54:36 +00:00
.AddInMemoryCollection(new Dictionary<string, string>
2020-11-26 17:30:57 +00:00
{
2021-06-16 13:54:36 +00:00
{"pathToConf", path }
}
);
})
.ConfigureServices((hostContext, services) =>
2021-01-13 09:41:29 +00:00
{
2021-06-16 13:54:36 +00:00
services.AddMemoryCache();
2020-10-18 16:34:30 +00:00
var diHelper = new DIHelper(services);
diHelper.TryAdd(typeof(ICacheNotify<>), typeof(KafkaCache<>));
diHelper.RegisterProducts(hostContext.Configuration, hostContext.HostingEnvironment.ContentRootPath);
2021-06-16 13:54:36 +00:00
diHelper.TryAdd<MigrationServiceLauncher>();
services.AddHostedService<MigrationServiceLauncher>();
})
2020-11-02 16:27:08 +00:00
.ConfigureContainer<ContainerBuilder>((context, builder) =>
{
builder.Register(context.Configuration);
2021-08-08 13:19:54 +00:00
})
.ConfigureNLogLogging();
}
}