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
|
|
|
|
|
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;
|
2019-11-05 10:20:00 +00:00
|
|
|
|
using ASC.Common.Logging;
|
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;
|
|
|
|
|
|
2019-07-29 09:15:48 +00:00
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
|
|
|
|
|
namespace ASC.Notify
|
|
|
|
|
{
|
|
|
|
|
public class Program
|
|
|
|
|
{
|
|
|
|
|
public static async Task Main(string[] args)
|
|
|
|
|
{
|
|
|
|
|
var host = Host.CreateDefaultBuilder(args)
|
2020-11-02 16:27:08 +00:00
|
|
|
|
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
|
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(Path.Combine(hostContext.HostingEnvironment.ContentRootPath, path));
|
|
|
|
|
}
|
|
|
|
|
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")
|
2019-08-23 12:49:23 +00:00
|
|
|
|
.AddJsonFile("kafka.json")
|
2019-11-14 09:21:15 +00:00
|
|
|
|
.AddJsonFile($"kafka.{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);
|
|
|
|
|
|
2020-10-29 08:13:51 +00:00
|
|
|
|
LogNLogExtension.ConfigureLog(diHelper, "ASC.Notify", "ASC.Notify.Messages");
|
2020-10-27 15:34:22 +00:00
|
|
|
|
diHelper.TryAdd(typeof(ICacheNotify<>), typeof(KafkaCache<>));
|
2021-01-26 09:29:50 +00:00
|
|
|
|
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) =>
|
|
|
|
|
{
|
2021-01-26 09:29:50 +00:00
|
|
|
|
builder.Register(context.Configuration);
|
2019-07-29 09:15:48 +00:00
|
|
|
|
})
|
|
|
|
|
.UseConsoleLifetime()
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
using (host)
|
|
|
|
|
{
|
|
|
|
|
// Start the host
|
|
|
|
|
await host.StartAsync();
|
|
|
|
|
|
|
|
|
|
// Wait for the host to shutdown
|
|
|
|
|
await host.WaitForShutdownAsync();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|