2021-10-21 13:23:26 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Threading.Tasks;
|
2021-07-13 18:17:18 +00:00
|
|
|
|
|
2021-08-08 13:19:54 +00:00
|
|
|
|
using ASC.Api.Core;
|
2021-10-21 13:23:26 +00:00
|
|
|
|
using ASC.Common;
|
|
|
|
|
using ASC.Common.Caching;
|
|
|
|
|
using ASC.Common.DependencyInjection;
|
|
|
|
|
using ASC.Common.Utils;
|
|
|
|
|
using ASC.ElasticSearch;
|
|
|
|
|
using ASC.Web.CRM.Core.Search;
|
2021-07-13 18:17:18 +00:00
|
|
|
|
|
2021-10-21 13:23:26 +00:00
|
|
|
|
using Autofac;
|
|
|
|
|
using Autofac.Extensions.DependencyInjection;
|
2021-07-13 18:17:18 +00:00
|
|
|
|
|
2021-10-21 13:23:26 +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;
|
2021-10-21 13:23:26 +00:00
|
|
|
|
|
|
|
|
|
namespace ASC.CRM.BackgroundTasks
|
|
|
|
|
{
|
|
|
|
|
class Program
|
|
|
|
|
{
|
|
|
|
|
public async static Task Main(string[] args)
|
|
|
|
|
{
|
|
|
|
|
var host = CreateHostBuilder(args).Build();
|
|
|
|
|
|
|
|
|
|
await host.RunAsync();
|
2021-10-13 08:07:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-21 13:23:26 +00:00
|
|
|
|
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
|
|
|
|
Host.CreateDefaultBuilder(args)
|
|
|
|
|
.UseSystemd()
|
2021-11-25 13:48:08 +00:00
|
|
|
|
.UseWindowsService()
|
2021-10-21 13:23:26 +00:00
|
|
|
|
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
|
|
|
|
|
.ConfigureAppConfiguration((hostContext, config) =>
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
.AddInMemoryCollection(new Dictionary<string, string>
|
|
|
|
|
{
|
|
|
|
|
{"pathToConf", path }
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
.AddJsonFile("appsettings.json")
|
|
|
|
|
.AddJsonFile($"appsettings.{env}.json", true)
|
|
|
|
|
.AddJsonFile($"appsettings.services.json", true)
|
|
|
|
|
.AddJsonFile("storage.json")
|
|
|
|
|
.AddJsonFile("notify.json")
|
|
|
|
|
.AddJsonFile($"notify.{env}.json", true)
|
|
|
|
|
.AddJsonFile("kafka.json")
|
|
|
|
|
.AddJsonFile($"kafka.{env}.json", true)
|
2022-02-04 17:44:03 +00:00
|
|
|
|
.AddJsonFile("rabbitmq.json")
|
|
|
|
|
.AddJsonFile($"rabbitmq.{env}.json", true)
|
2021-12-21 16:16:34 +00:00
|
|
|
|
.AddJsonFile("redis.json")
|
|
|
|
|
.AddJsonFile($"redis.{env}.json", true)
|
2021-10-21 13:23:26 +00:00
|
|
|
|
.AddEnvironmentVariables()
|
|
|
|
|
.AddCommandLine(args);
|
|
|
|
|
})
|
|
|
|
|
.ConfigureServices((hostContext, services) =>
|
|
|
|
|
{
|
|
|
|
|
services.AddMemoryCache();
|
|
|
|
|
|
|
|
|
|
var diHelper = new DIHelper(services);
|
|
|
|
|
|
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-02-04 17:44:03 +00:00
|
|
|
|
var rabbitMQConfiguration = hostContext.Configuration.GetSection("RabbitMQ").Get<RabbitMQSettings>();
|
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<>));
|
|
|
|
|
}
|
2022-02-04 17:44:03 +00:00
|
|
|
|
else if (rabbitMQConfiguration != null)
|
|
|
|
|
{
|
|
|
|
|
diHelper.TryAdd(typeof(ICacheNotify<>), typeof(RabbitMQCache<>));
|
|
|
|
|
}
|
2022-01-27 12:20:51 +00:00
|
|
|
|
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-10-21 13:23:26 +00:00
|
|
|
|
|
|
|
|
|
diHelper.RegisterProducts(hostContext.Configuration, hostContext.HostingEnvironment.ContentRootPath);
|
2021-10-13 08:07:03 +00:00
|
|
|
|
|
2021-10-21 13:23:26 +00:00
|
|
|
|
services.AddHostedService<ServiceLauncher>();
|
|
|
|
|
diHelper.TryAdd<ServiceLauncher>();
|
|
|
|
|
diHelper.TryAdd<FactoryIndexerCase>();
|
|
|
|
|
diHelper.TryAdd<FactoryIndexerContact>();
|
|
|
|
|
diHelper.TryAdd<FactoryIndexerContactInfo>();
|
|
|
|
|
diHelper.TryAdd<FactoryIndexerDeal>();
|
|
|
|
|
diHelper.TryAdd<FactoryIndexerEvents>();
|
|
|
|
|
diHelper.TryAdd<FactoryIndexerFieldValue>();
|
|
|
|
|
diHelper.TryAdd<FactoryIndexerInvoice>();
|
|
|
|
|
diHelper.TryAdd<FactoryIndexerTask>();
|
2021-12-21 16:16:34 +00:00
|
|
|
|
|
2021-10-21 13:23:26 +00:00
|
|
|
|
})
|
|
|
|
|
.ConfigureContainer<ContainerBuilder>((context, builder) =>
|
|
|
|
|
{
|
|
|
|
|
builder.Register(context.Configuration, true, false, "search.json");
|
|
|
|
|
})
|
|
|
|
|
.ConfigureNLogLogging();
|
|
|
|
|
}
|
|
|
|
|
}
|