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;
|
2019-07-29 09:15:48 +00:00
|
|
|
|
using ASC.Common.DependencyInjection;
|
2019-11-05 10:20:00 +00:00
|
|
|
|
using ASC.Common.Logging;
|
2019-11-01 08:49:08 +00:00
|
|
|
|
using ASC.Core.Common;
|
2019-11-05 10:20:00 +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
|
|
|
|
|
2019-07-29 09:15:48 +00:00
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
2019-11-01 08:49:08 +00:00
|
|
|
|
using Microsoft.Extensions.Options;
|
2019-07-29 09:15:48 +00:00
|
|
|
|
|
|
|
|
|
namespace ASC.Notify
|
|
|
|
|
{
|
|
|
|
|
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);
|
2019-09-25 12:55:35 +00:00
|
|
|
|
var env = hostContext.Configuration.GetValue("ENVIRONMENT", "Production");
|
2019-07-29 09:15:48 +00:00
|
|
|
|
config
|
2019-11-15 08:47:56 +00:00
|
|
|
|
.AddInMemoryCollection(new Dictionary<string, string>
|
|
|
|
|
{
|
|
|
|
|
{"pathToConf", path }
|
|
|
|
|
}
|
|
|
|
|
)
|
2019-07-29 09:15:48 +00:00
|
|
|
|
.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()
|
|
|
|
|
.AddCommandLine(args);
|
2019-07-29 09:15:48 +00:00
|
|
|
|
})
|
|
|
|
|
.ConfigureServices((hostContext, services) =>
|
|
|
|
|
{
|
2020-02-17 08:58:14 +00:00
|
|
|
|
var diHelper = new DIHelper(services);
|
|
|
|
|
|
|
|
|
|
diHelper.AddNLogManager("ASC.Notify", "ASC.Notify.Messages");
|
2019-11-05 10:20:00 +00:00
|
|
|
|
|
2019-11-01 08:49:08 +00:00
|
|
|
|
services.Configure<NotifyServiceCfg>(hostContext.Configuration.GetSection("notify"));
|
2020-02-17 08:58:14 +00:00
|
|
|
|
diHelper.AddSingleton<IConfigureOptions<NotifyServiceCfg>, ConfigureNotifyServiceCfg>();
|
2019-11-01 08:49:08 +00:00
|
|
|
|
|
2020-02-17 08:58:14 +00:00
|
|
|
|
diHelper.TryAddSingleton<CommonLinkUtilitySettings>();
|
|
|
|
|
diHelper.AddSingleton<IConfigureOptions<CommonLinkUtilitySettings>, ConfigureCommonLinkUtilitySettings>();
|
2019-11-01 08:49:08 +00:00
|
|
|
|
|
2020-02-17 08:58:14 +00:00
|
|
|
|
diHelper.AddNotifyServiceLauncher();
|
2019-07-29 09:15:48 +00:00
|
|
|
|
services.AddHostedService<NotifyServiceLauncher>();
|
2019-11-05 10:20:00 +00:00
|
|
|
|
|
2020-02-17 08:58:14 +00:00
|
|
|
|
diHelper
|
2019-11-05 10:20:00 +00:00
|
|
|
|
.AddJabberSenderService()
|
|
|
|
|
.AddSmtpSenderService()
|
|
|
|
|
.AddAWSSenderService();
|
2019-12-20 11:17:01 +00:00
|
|
|
|
|
2020-06-04 13:46:58 +00:00
|
|
|
|
services.AddAutofac(hostContext.Configuration, hostContext.HostingEnvironment.ContentRootPath);
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|