DocSpace-buildtools/products/ASC.Files/Service/Program.cs

96 lines
3.8 KiB
C#
Raw Normal View History

2020-04-23 09:38:50 +00:00
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
2021-06-16 13:54:36 +00:00
using ASC.Api.Core;
2020-04-23 09:38:50 +00:00
using ASC.Common;
using ASC.Common.Caching;
2020-04-23 09:38:50 +00:00
using ASC.Common.DependencyInjection;
using ASC.Common.Utils;
2020-04-29 14:11:31 +00:00
using ASC.ElasticSearch;
2020-06-03 14:53:58 +00:00
using ASC.Feed.Aggregator;
2021-05-30 18:52:32 +00:00
using ASC.Files.ThumbnailBuilder;
using ASC.Web.Files.Core.Search;
2020-04-23 09:38:50 +00:00
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;
2020-04-23 09:38:50 +00:00
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace ASC.Files.Service
{
public class Program
{
public async static Task Main(string[] args)
2020-04-23 09:38:50 +00:00
{
var host = CreateHostBuilder(args).Build();
await host.RunAsync();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.UseSystemd()
.UseWindowsService()
2020-11-02 16:27:08 +00:00
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
2021-06-16 13:54:36 +00:00
.ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup<BaseWorkerStartup>())
2020-04-23 09:38:50 +00:00
.ConfigureAppConfiguration((hostContext, config) =>
{
var buided = config.Build();
var path = buided["pathToConf"];
if (!Path.IsPathRooted(path))
{
path = Path.GetFullPath(CrossPlatform.PathCombine(hostContext.HostingEnvironment.ContentRootPath, path));
2020-04-23 09:38:50 +00:00
}
config.SetBasePath(path);
var env = hostContext.Configuration.GetValue("ENVIRONMENT", "Production");
config
.AddInMemoryCollection(new Dictionary<string, string>
{
{"pathToConf", path }
}
)
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{env}.json", true)
2020-06-04 10:54:13 +00:00
.AddJsonFile($"appsettings.services.json", true)
2020-04-23 09:38:50 +00:00
.AddJsonFile("storage.json")
.AddJsonFile("notify.json")
.AddJsonFile("kafka.json")
.AddJsonFile($"kafka.{env}.json", true)
2021-06-15 12:57:16 +00:00
.AddJsonFile("elastic.json", true)
2020-06-04 13:26:31 +00:00
.AddEnvironmentVariables()
.AddCommandLine(args);
2020-04-23 09:38:50 +00:00
})
.ConfigureServices((hostContext, services) =>
{
2021-01-13 09:41:29 +00:00
services.AddMemoryCache();
2020-04-23 09:38:50 +00:00
var diHelper = new DIHelper(services);
2020-10-18 16:34:30 +00:00
diHelper.TryAdd(typeof(ICacheNotify<>), typeof(KafkaCache<>));
diHelper.RegisterProducts(hostContext.Configuration, hostContext.HostingEnvironment.ContentRootPath);
2020-04-23 09:38:50 +00:00
services.AddHostedService<ServiceLauncher>();
diHelper.TryAdd<ServiceLauncher>();
2020-06-03 14:53:58 +00:00
services.AddHostedService<FeedAggregatorService>();
diHelper.TryAdd<FeedAggregatorService>();
2021-05-30 18:52:32 +00:00
services.AddHostedService<Launcher>();
diHelper.TryAdd<Launcher>();
//diHelper.TryAdd<FileConverter>();
diHelper.TryAdd<FactoryIndexerFile>();
diHelper.TryAdd<FactoryIndexerFolder>();
2020-11-02 16:27:08 +00:00
})
.ConfigureContainer<ContainerBuilder>((context, builder) =>
{
builder.Register(context.Configuration, true, false, "search.json", "feed.json");
2021-08-08 13:19:54 +00:00
})
.ConfigureNLogLogging();
2020-04-23 09:38:50 +00:00
}
}