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

84 lines
3.2 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;
using ASC.Common;
2020-04-29 14:11:31 +00:00
using ASC.Common.Caching;
2020-04-23 09:38:50 +00:00
using ASC.Common.DependencyInjection;
using ASC.Common.Logging;
2020-04-29 14:11:31 +00:00
using ASC.ElasticSearch;
2020-06-03 14:53:58 +00:00
using ASC.Feed.Aggregator;
2020-04-29 14:11:31 +00:00
using ASC.Web.Files.Core.Search;
using ASC.Web.Files.Utils;
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 static async Task Main(string[] args)
{
var host = Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((hostContext, config) =>
{
var buided = config.Build();
var path = buided["pathToConf"];
if (!Path.IsPathRooted(path))
{
path = Path.GetFullPath(Path.Combine(hostContext.HostingEnvironment.ContentRootPath, path));
}
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)
2020-06-04 13:26:31 +00:00
.AddEnvironmentVariables()
.AddCommandLine(args);
2020-04-23 09:38:50 +00:00
})
.ConfigureServices((hostContext, services) =>
{
var diHelper = new DIHelper(services);
diHelper.AddNLogManager("ASC.Files");
services.AddHostedService<ServiceLauncher>();
2020-04-29 14:11:31 +00:00
diHelper
.AddServiceLauncher()
.AddFileConverterService()
.AddKafkaService()
.AddFactoryIndexerFileService()
.AddFactoryIndexerFolderService();
2020-04-23 09:38:50 +00:00
2020-06-03 14:53:58 +00:00
diHelper.AddNLogManager("ASC.Feed.Agregator");
services.AddHostedService<FeedAggregatorService>();
diHelper
.AddFeedAggregatorService();
2020-06-04 10:54:13 +00:00
services.AddAutofac(hostContext.Configuration, hostContext.HostingEnvironment.ContentRootPath, true, false, "search.json", "feed.json");
2020-04-23 09:38:50 +00:00
})
.UseConsoleLifetime()
.Build();
using (host)
{
// Start the host
await host.StartAsync();
// Wait for the host to shutdown
await host.WaitForShutdownAsync();
}
}
}
}