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

88 lines
3.7 KiB
C#
Raw Normal View History

2022-02-16 13:14:31 +00:00
namespace ASC.Notify;
public static class Program
2019-07-29 09:15:48 +00:00
{
2022-02-16 13:14:31 +00:00
public async static Task Main(string[] args)
2019-07-29 09:15:48 +00:00
{
2022-02-16 13:14:31 +00:00
var host = CreateHostBuilder(args).Build();
2022-02-16 13:14:31 +00:00
await host.RunAsync();
}
2022-02-16 13:14:31 +00:00
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.UseSystemd()
.UseWindowsService()
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
.ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup<BaseWorkerStartup>())
.ConfigureAppConfiguration((hostContext, config) =>
{
var buided = config.Build();
var path = buided["pathToConf"];
if (!Path.IsPathRooted(path))
2019-07-29 09:15:48 +00:00
{
2022-02-16 13:14:31 +00:00
path = Path.GetFullPath(CrossPlatform.PathCombine(hostContext.HostingEnvironment.ContentRootPath, path));
}
config.SetBasePath(path);
var env = hostContext.Configuration.GetValue("ENVIRONMENT", "Production");
config
.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)
.AddJsonFile("redis.json")
.AddJsonFile($"redis.{env}.json", true)
.AddEnvironmentVariables()
.AddCommandLine(args)
.AddInMemoryCollection(new Dictionary<string, string>
{
2020-11-26 17:30:57 +00:00
{"pathToConf", path }
2022-02-16 13:14:31 +00:00
}
);
})
.ConfigureServices((hostContext, services) =>
{
services.AddMemoryCache();
var diHelper = new DIHelper(services);
2020-02-17 08:58:14 +00:00
2022-02-16 13:14:31 +00:00
var redisConfiguration = hostContext.Configuration.GetSection("Redis").Get<RedisConfiguration>();
var kafkaConfiguration = hostContext.Configuration.GetSection("kafka").Get<KafkaSettings>();
2022-02-16 13:14:31 +00:00
if (kafkaConfiguration != null)
{
diHelper.TryAdd(typeof(ICacheNotify<>), typeof(KafkaCacheNotify<>));
}
else if (redisConfiguration != null)
{
diHelper.TryAdd(typeof(ICacheNotify<>), typeof(RedisCacheNotify<>));
2022-01-14 07:42:43 +00:00
2022-02-16 13:14:31 +00:00
services.AddStackExchangeRedisExtensions<NewtonsoftSerializer>(redisConfiguration);
}
else
{
diHelper.TryAdd(typeof(ICacheNotify<>), typeof(MemoryCacheNotify<>));
}
2022-02-16 13:14:31 +00:00
diHelper.RegisterProducts(hostContext.Configuration, hostContext.HostingEnvironment.ContentRootPath);
2019-11-05 10:20:00 +00:00
2022-02-16 13:14:31 +00:00
services.Configure<NotifyServiceCfg>(hostContext.Configuration.GetSection("notify"));
2019-11-01 08:49:08 +00:00
2022-02-16 13:14:31 +00:00
diHelper.TryAdd<NotifyServiceLauncher>();
2020-10-20 13:24:46 +00:00
2022-02-16 13:14:31 +00:00
diHelper.TryAdd<JabberSender>();
diHelper.TryAdd<SmtpSender>();
diHelper.TryAdd<AWSSender>(); // fix private
2020-10-27 15:34:22 +00:00
2019-07-29 09:15:48 +00:00
services.AddHostedService<NotifyServiceLauncher>();
2022-02-16 13:14:31 +00:00
})
.ConfigureContainer<ContainerBuilder>((context, builder) =>
{
builder.Register(context.Configuration);
})
.ConfigureNLogLogging();
2019-07-29 09:15:48 +00:00
}