pavelbannov
dba3efb235
# Conflicts: # common/ASC.Api.Core/GlobalUsings.cs # common/ASC.Common/Caching/AscCache.cs # common/ASC.Common/Collections/CachedDictionaryBase.cs # common/ASC.Common/Collections/HttpRequestDictionary.cs # common/ASC.Common/DIHelper.cs # common/ASC.Common/Data/StreamExtension.cs # common/ASC.Common/Data/TempStream.cs # common/ASC.Common/DependencyInjection/AutofacExtension.cs # common/ASC.Common/Logging/Log.cs # common/ASC.Common/Logging/SelfCleaningTarget.cs # common/ASC.Common/Logging/SpecialFolderPathConverter.cs # common/ASC.Common/Mapping/MappingProfile.cs # common/ASC.Common/Security/AscRandom.cs # common/ASC.Common/Security/Authorizing/AuthorizingException.cs # common/ASC.Common/Security/Authorizing/Constants.cs # common/ASC.Common/Security/Authorizing/Domain/Role.cs # common/ASC.Common/Security/Cryptography/Hasher.cs # common/ASC.Common/Threading/DistributedTask.cs # common/ASC.Common/Threading/DistributedTaskQueue.cs # common/ASC.Common/Utils/DnsLookup.cs # common/ASC.Common/Utils/HtmlUtil.cs # common/ASC.Common/Utils/HttpRequestExtensions.cs # common/ASC.Common/Utils/JsonWebToken.cs # common/ASC.Common/Utils/MailAddressUtils.cs # common/ASC.Common/Utils/RandomString.cs # common/ASC.Common/Utils/TimeZoneConverter/TimeZoneConverter.cs # common/ASC.Common/Utils/VelocityFormatter.cs # common/ASC.Common/Utils/Wildcard.cs # common/ASC.Common/Web/MimeMapping.cs # common/ASC.Common/Web/VirtualPathUtility.cs # common/services/ASC.ClearEvents/Program.cs # products/ASC.Files/Core/ThirdPartyApp/BoxApp.cs # products/ASC.Files/Core/ThirdPartyApp/GoogleDriveApp.cs
82 lines
3.4 KiB
C#
82 lines
3.4 KiB
C#
namespace ASC.Webhooks.Service
|
|
{
|
|
public static class Program
|
|
{
|
|
public async static Task Main(string[] args)
|
|
{
|
|
var host = CreateHostBuilder(args).Build();
|
|
|
|
await host.RunAsync();
|
|
}
|
|
|
|
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))
|
|
{
|
|
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("kafka.json")
|
|
.AddJsonFile($"kafka.{env}.json", true)
|
|
.AddJsonFile("redis.json")
|
|
.AddJsonFile($"redis.{env}.json", true)
|
|
.AddEnvironmentVariables()
|
|
.AddCommandLine(args);
|
|
})
|
|
.ConfigureServices((hostContext, services) =>
|
|
{
|
|
services.AddMemoryCache();
|
|
|
|
var diHelper = new DIHelper(services);
|
|
|
|
var redisConfiguration = hostContext.Configuration.GetSection("Redis").Get<RedisConfiguration>();
|
|
var kafkaConfiguration = hostContext.Configuration.GetSection("kafka").Get<KafkaSettings>();
|
|
|
|
if (kafkaConfiguration != null)
|
|
{
|
|
diHelper.TryAdd(typeof(IEventBus<>), typeof(EventBusKafka<>));
|
|
}
|
|
else if (redisConfiguration != null)
|
|
{
|
|
diHelper.TryAdd(typeof(IEventBus<>), typeof(EventBusRedis<>));
|
|
|
|
services.AddStackExchangeRedisExtensions<NewtonsoftSerializer>(redisConfiguration);
|
|
}
|
|
else
|
|
{
|
|
diHelper.TryAdd(typeof(IEventBus<>), typeof(EventBusMemoryCache<>));
|
|
}
|
|
|
|
diHelper.TryAdd<DbWorker>();
|
|
|
|
services.AddHostedService<WebhookHostedService>();
|
|
diHelper.TryAdd<WebhookHostedService>();
|
|
|
|
})
|
|
.ConfigureContainer<ContainerBuilder>((context, builder) =>
|
|
{
|
|
builder.Register(context.Configuration, false, false);
|
|
})
|
|
.ConfigureNLogLogging();
|
|
}
|
|
}
|