DocSpace-buildtools/common/services/ASC.Notify/Program.cs

107 lines
4.2 KiB
C#
Raw Normal View History

2019-11-15 08:47:56 +00:00
using System.Collections.Generic;
using System.IO;
2019-07-29 09:15:48 +00:00
using System.Threading.Tasks;
2019-10-22 16:08:37 +00:00
2021-06-16 13:54:36 +00:00
using ASC.Api.Core;
2020-02-17 08:58:14 +00:00
using ASC.Common;
2020-10-27 15:34:22 +00:00
using ASC.Common.Caching;
2019-07-29 09:15:48 +00:00
using ASC.Common.DependencyInjection;
using ASC.Common.Utils;
2020-10-27 15:34:22 +00:00
using ASC.Core.Notify.Senders;
2019-07-29 09:15:48 +00:00
using ASC.Notify.Config;
2019-10-22 16:08:37 +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;
2019-07-29 09:15:48 +00:00
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using StackExchange.Redis.Extensions.Core.Configuration;
using StackExchange.Redis.Extensions.Newtonsoft;
2019-07-29 09:15:48 +00:00
namespace ASC.Notify
{
public class Program
{
public async static Task Main(string[] args)
2019-07-29 09:15:48 +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>())
2019-07-29 09:15:48 +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));
2019-07-29 09:15:48 +00:00
}
config.SetBasePath(path);
2019-09-25 12:55:35 +00:00
var env = hostContext.Configuration.GetValue("ENVIRONMENT", "Production");
2019-07-29 09:15:48 +00:00
config
.AddJsonFile("appsettings.json")
2019-09-25 12:49:21 +00:00
.AddJsonFile($"appsettings.{env}.json", true)
2019-12-20 11:17:01 +00:00
.AddJsonFile($"appsettings.services.json", true)
2019-07-29 09:15:48 +00:00
.AddJsonFile("storage.json")
.AddJsonFile("notify.json")
2021-09-03 15:04:06 +00:00
.AddJsonFile($"notify.{env}.json", true)
2019-08-23 12:49:23 +00:00
.AddJsonFile("kafka.json")
2019-11-14 09:21:15 +00:00
.AddJsonFile($"kafka.{env}.json", true)
.AddJsonFile("redis.json")
.AddJsonFile($"redis.{env}.json", true)
2020-06-04 13:26:31 +00:00
.AddEnvironmentVariables()
2020-11-26 17:30:57 +00:00
.AddCommandLine(args)
.AddInMemoryCollection(new Dictionary<string, string>
{
{"pathToConf", path }
}
);
2019-07-29 09:15:48 +00:00
})
.ConfigureServices((hostContext, services) =>
{
2021-01-13 09:41:29 +00:00
services.AddMemoryCache();
2020-02-17 08:58:14 +00:00
var diHelper = new DIHelper(services);
var redisConfiguration = hostContext.Configuration.GetSection("Redis").Get<RedisConfiguration>();
if (redisConfiguration != null)
{
diHelper.TryAdd(typeof(ICacheNotify<>), typeof(RedisCache<>));
2022-01-14 07:42:43 +00:00
services.AddStackExchangeRedisExtensions<NewtonsoftSerializer>(redisConfiguration);
}
else
{
diHelper.TryAdd(typeof(ICacheNotify<>), typeof(MemoryCacheNotify<>));
}
diHelper.RegisterProducts(hostContext.Configuration, hostContext.HostingEnvironment.ContentRootPath);
2019-11-05 10:20:00 +00:00
2019-11-01 08:49:08 +00:00
services.Configure<NotifyServiceCfg>(hostContext.Configuration.GetSection("notify"));
2020-10-19 15:53:15 +00:00
diHelper.TryAdd<NotifyServiceLauncher>();
2020-10-20 13:24:46 +00:00
2020-10-27 15:34:22 +00:00
diHelper.TryAdd<JabberSender>();
diHelper.TryAdd<SmtpSender>();
diHelper.TryAdd<AWSSender>(); // fix private
2019-07-29 09:15:48 +00:00
services.AddHostedService<NotifyServiceLauncher>();
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();
2019-07-29 09:15:48 +00:00
}
}