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;
|
2020-10-26 16:38:23 +00:00
|
|
|
|
using ASC.Common.Caching;
|
2020-04-23 09:38:50 +00:00
|
|
|
|
using ASC.Common.DependencyInjection;
|
2021-04-16 13:26:26 +00:00
|
|
|
|
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;
|
2020-10-26 16:38:23 +00:00
|
|
|
|
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;
|
|
|
|
|
|
2021-12-21 16:16:34 +00:00
|
|
|
|
using StackExchange.Redis.Extensions.Core.Configuration;
|
|
|
|
|
using StackExchange.Redis.Extensions.Newtonsoft;
|
|
|
|
|
|
2020-04-23 09:38:50 +00:00
|
|
|
|
namespace ASC.Files.Service
|
|
|
|
|
{
|
2022-01-21 10:47:56 +00:00
|
|
|
|
public static class Program
|
2020-04-23 09:38:50 +00:00
|
|
|
|
{
|
2021-04-23 13:54:12 +00:00
|
|
|
|
public async static Task Main(string[] args)
|
2020-04-23 09:38:50 +00:00
|
|
|
|
{
|
2021-04-23 13:54:12 +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))
|
|
|
|
|
{
|
2021-04-16 13:26:26 +00:00
|
|
|
|
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
|
|
|
|
|
.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")
|
2021-09-03 15:04:06 +00:00
|
|
|
|
.AddJsonFile($"notify.{env}.json", true)
|
2020-04-23 09:38:50 +00:00
|
|
|
|
.AddJsonFile("kafka.json")
|
|
|
|
|
.AddJsonFile($"kafka.{env}.json", true)
|
2021-12-21 16:16:34 +00:00
|
|
|
|
.AddJsonFile("redis.json")
|
|
|
|
|
.AddJsonFile($"redis.{env}.json", true)
|
2021-06-15 12:57:16 +00:00
|
|
|
|
.AddJsonFile("elastic.json", true)
|
2020-06-04 13:26:31 +00:00
|
|
|
|
.AddEnvironmentVariables()
|
2021-09-23 17:58:39 +00:00
|
|
|
|
.AddCommandLine(args)
|
|
|
|
|
.AddInMemoryCollection(new Dictionary<string, string>
|
|
|
|
|
{
|
|
|
|
|
{"pathToConf", path }
|
|
|
|
|
}
|
|
|
|
|
);
|
2020-04-23 09:38:50 +00:00
|
|
|
|
})
|
|
|
|
|
.ConfigureServices((hostContext, services) =>
|
|
|
|
|
{
|
2021-01-13 09:41:29 +00:00
|
|
|
|
services.AddMemoryCache();
|
2022-02-11 16:01:38 +00:00
|
|
|
|
services.AddHttpClient();
|
2021-01-13 09:41:29 +00:00
|
|
|
|
|
2020-04-23 09:38:50 +00:00
|
|
|
|
var diHelper = new DIHelper(services);
|
2020-10-18 16:34:30 +00:00
|
|
|
|
|
2022-01-13 11:24:14 +00:00
|
|
|
|
var redisConfiguration = hostContext.Configuration.GetSection("Redis").Get<RedisConfiguration>();
|
2022-01-27 12:20:51 +00:00
|
|
|
|
var kafkaConfiguration = hostContext.Configuration.GetSection("kafka").Get<KafkaSettings>();
|
2022-01-13 11:24:14 +00:00
|
|
|
|
|
2022-01-27 12:20:51 +00:00
|
|
|
|
if (kafkaConfiguration != null)
|
|
|
|
|
{
|
|
|
|
|
diHelper.TryAdd(typeof(ICacheNotify<>), typeof(KafkaCache<>));
|
|
|
|
|
}
|
|
|
|
|
else if (redisConfiguration != null)
|
2022-01-13 11:24:14 +00:00
|
|
|
|
{
|
|
|
|
|
diHelper.TryAdd(typeof(ICacheNotify<>), typeof(RedisCache<>));
|
2022-01-14 07:42:43 +00:00
|
|
|
|
|
|
|
|
|
services.AddStackExchangeRedisExtensions<NewtonsoftSerializer>(redisConfiguration);
|
2022-01-13 11:24:14 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
diHelper.TryAdd(typeof(ICacheNotify<>), typeof(MemoryCacheNotify<>));
|
|
|
|
|
}
|
2021-01-26 09:29:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
diHelper.RegisterProducts(hostContext.Configuration, hostContext.HostingEnvironment.ContentRootPath);
|
2021-11-01 14:31:22 +00:00
|
|
|
|
|
|
|
|
|
if (!bool.TryParse(hostContext.Configuration["disable_elastic"], out var disableElastic))
|
|
|
|
|
{
|
|
|
|
|
disableElastic = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!disableElastic)
|
|
|
|
|
{
|
|
|
|
|
services.AddHostedService<ServiceLauncher>();
|
|
|
|
|
diHelper.TryAdd<ServiceLauncher>();
|
|
|
|
|
//diHelper.TryAdd<FileConverter>();
|
|
|
|
|
diHelper.TryAdd<FactoryIndexerFile>();
|
|
|
|
|
diHelper.TryAdd<FactoryIndexerFolder>();
|
|
|
|
|
}
|
2020-10-26 16:38:23 +00:00
|
|
|
|
|
2020-06-03 14:53:58 +00:00
|
|
|
|
services.AddHostedService<FeedAggregatorService>();
|
2020-10-26 16:38:23 +00:00
|
|
|
|
diHelper.TryAdd<FeedAggregatorService>();
|
|
|
|
|
|
2021-05-30 18:52:32 +00:00
|
|
|
|
services.AddHostedService<Launcher>();
|
|
|
|
|
diHelper.TryAdd<Launcher>();
|
|
|
|
|
|
2020-11-02 16:27:08 +00:00
|
|
|
|
})
|
|
|
|
|
.ConfigureContainer<ContainerBuilder>((context, builder) =>
|
|
|
|
|
{
|
2021-04-23 13:54:12 +00:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|