FilesService: used WebApplicationBuilder
This commit is contained in:
parent
89f72e80ad
commit
b3317f35fc
@ -4,7 +4,6 @@ global using System.Collections.Generic;
|
||||
global using System.IO;
|
||||
global using System.Linq;
|
||||
global using System.Linq.Expressions;
|
||||
global using System.Net;
|
||||
global using System.Net.Http;
|
||||
global using System.Threading;
|
||||
global using System.Threading.Tasks;
|
||||
@ -21,12 +20,12 @@ global using ASC.Core.Common.EF;
|
||||
global using ASC.Core.Tenants;
|
||||
global using ASC.ElasticSearch;
|
||||
global using ASC.Feed;
|
||||
global using ASC.Feed.Aggregator;
|
||||
global using ASC.Feed.Data;
|
||||
global using ASC.Files.Core;
|
||||
global using ASC.Files.Core.EF;
|
||||
global using ASC.Files.Core.Security;
|
||||
global using ASC.Files.ThumbnailBuilder;
|
||||
global using ASC.ElasticSearch.Service;
|
||||
global using ASC.Web.Core;
|
||||
global using ASC.Web.Core.Files;
|
||||
global using ASC.Web.Core.Users;
|
||||
@ -45,6 +44,8 @@ global using Microsoft.Extensions.Configuration;
|
||||
global using Microsoft.Extensions.DependencyInjection;
|
||||
global using Microsoft.Extensions.Hosting;
|
||||
global using Microsoft.Extensions.Options;
|
||||
global using Microsoft.AspNetCore.Builder;
|
||||
global using Microsoft.Extensions.Hosting.WindowsServices;
|
||||
|
||||
global using SixLabors.ImageSharp;
|
||||
global using SixLabors.ImageSharp.Formats.Png;
|
||||
|
@ -1,116 +1,118 @@
|
||||
using ASC.ElasticSearch.Service;
|
||||
|
||||
namespace ASC.Files.Service
|
||||
var options = new WebApplicationOptions
|
||||
{
|
||||
public static class Program
|
||||
Args = args,
|
||||
ContentRootPath = WindowsServiceHelpers.IsWindowsService() ? AppContext.BaseDirectory : default
|
||||
};
|
||||
|
||||
var builder = WebApplication.CreateBuilder(options);
|
||||
|
||||
builder.Host.UseSystemd();
|
||||
builder.Host.UseWindowsService();
|
||||
builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory());
|
||||
|
||||
builder.Host.ConfigureAppConfiguration((hostContext, config) =>
|
||||
{
|
||||
var buildedConfig = config.Build();
|
||||
|
||||
var path = buildedConfig["pathToConf"];
|
||||
if (!Path.IsPathRooted(path))
|
||||
{
|
||||
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
|
||||
.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)
|
||||
.AddJsonFile("elastic.json", true)
|
||||
.AddEnvironmentVariables()
|
||||
.AddCommandLine(args)
|
||||
.AddInMemoryCollection(new Dictionary<string, string>
|
||||
{
|
||||
{"pathToConf", path }
|
||||
}
|
||||
);
|
||||
})
|
||||
.ConfigureServices((hostContext, services) =>
|
||||
{
|
||||
services.AddMemoryCache();
|
||||
services.AddHttpClient();
|
||||
|
||||
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(ICacheNotify<>), typeof(KafkaCacheNotify<>));
|
||||
}
|
||||
else if (redisConfiguration != null)
|
||||
{
|
||||
diHelper.TryAdd(typeof(ICacheNotify<>), typeof(RedisCacheNotify<>));
|
||||
|
||||
services.AddStackExchangeRedisExtensions<NewtonsoftSerializer>(redisConfiguration);
|
||||
}
|
||||
else
|
||||
{
|
||||
diHelper.TryAdd(typeof(ICacheNotify<>), typeof(MemoryCacheNotify<>));
|
||||
}
|
||||
|
||||
|
||||
diHelper.RegisterProducts(hostContext.Configuration, hostContext.HostingEnvironment.ContentRootPath);
|
||||
|
||||
if (!bool.TryParse(hostContext.Configuration["disable_elastic"], out var disableElastic))
|
||||
{
|
||||
disableElastic = false;
|
||||
}
|
||||
|
||||
if (!disableElastic)
|
||||
{
|
||||
services.AddHostedService<ElasticSearchIndexService>();
|
||||
diHelper.TryAdd<FactoryIndexer>();
|
||||
diHelper.TryAdd<ElasticSearchService>();
|
||||
//diHelper.TryAdd<FileConverter>();
|
||||
diHelper.TryAdd<FactoryIndexerFile>();
|
||||
diHelper.TryAdd<FactoryIndexerFolder>();
|
||||
}
|
||||
|
||||
services.AddHostedService<FeedAggregatorService>();
|
||||
diHelper.TryAdd<FeedAggregatorService>();
|
||||
|
||||
services.AddHostedService<FeedCleanerService>();
|
||||
diHelper.TryAdd<FeedCleanerService>();
|
||||
|
||||
services.AddHostedService<Launcher>();
|
||||
diHelper.TryAdd<Launcher>();
|
||||
|
||||
diHelper.TryAdd<AuthManager>();
|
||||
diHelper.TryAdd<BaseCommonLinkUtility>();
|
||||
diHelper.TryAdd<FeedAggregateDataProvider>();
|
||||
diHelper.TryAdd<SecurityContext>();
|
||||
diHelper.TryAdd<TenantManager>();
|
||||
diHelper.TryAdd<UserManager>();
|
||||
|
||||
})
|
||||
.ConfigureContainer<ContainerBuilder>((context, builder) =>
|
||||
{
|
||||
builder.Register(context.Configuration, true, false, "search.json", "feed.json");
|
||||
})
|
||||
.ConfigureNLogLogging();
|
||||
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)
|
||||
.AddJsonFile("elastic.json", true)
|
||||
.AddEnvironmentVariables()
|
||||
.AddCommandLine(args)
|
||||
.AddInMemoryCollection(new Dictionary<string, string>
|
||||
{
|
||||
{"pathToConf", path }
|
||||
});
|
||||
});
|
||||
|
||||
builder.Host.ConfigureServices((hostContext, services) =>
|
||||
{
|
||||
services.AddMemoryCache();
|
||||
services.AddHttpClient();
|
||||
|
||||
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(ICacheNotify<>), typeof(KafkaCacheNotify<>));
|
||||
}
|
||||
else if (redisConfiguration != null)
|
||||
{
|
||||
diHelper.TryAdd(typeof(ICacheNotify<>), typeof(RedisCacheNotify<>));
|
||||
|
||||
services.AddStackExchangeRedisExtensions<NewtonsoftSerializer>(redisConfiguration);
|
||||
}
|
||||
else
|
||||
{
|
||||
diHelper.TryAdd(typeof(ICacheNotify<>), typeof(MemoryCacheNotify<>));
|
||||
}
|
||||
|
||||
diHelper.RegisterProducts(hostContext.Configuration, hostContext.HostingEnvironment.ContentRootPath);
|
||||
|
||||
if (!bool.TryParse(hostContext.Configuration["disable_elastic"], out var disableElastic))
|
||||
{
|
||||
disableElastic = false;
|
||||
}
|
||||
|
||||
if (!disableElastic)
|
||||
{
|
||||
services.AddHostedService<ElasticSearchIndexService>();
|
||||
diHelper.TryAdd<FactoryIndexer>();
|
||||
diHelper.TryAdd<ElasticSearchService>();
|
||||
//diHelper.TryAdd<FileConverter>();
|
||||
diHelper.TryAdd<FactoryIndexerFile>();
|
||||
diHelper.TryAdd<FactoryIndexerFolder>();
|
||||
}
|
||||
|
||||
services.AddHostedService<FeedAggregatorService>();
|
||||
diHelper.TryAdd<FeedAggregatorService>();
|
||||
|
||||
services.AddHostedService<FeedCleanerService>();
|
||||
diHelper.TryAdd<FeedCleanerService>();
|
||||
|
||||
services.AddHostedService<Launcher>();
|
||||
diHelper.TryAdd<Launcher>();
|
||||
|
||||
diHelper.TryAdd<AuthManager>();
|
||||
diHelper.TryAdd<BaseCommonLinkUtility>();
|
||||
diHelper.TryAdd<FeedAggregateDataProvider>();
|
||||
diHelper.TryAdd<SecurityContext>();
|
||||
diHelper.TryAdd<TenantManager>();
|
||||
diHelper.TryAdd<UserManager>();
|
||||
});
|
||||
|
||||
builder.Host.ConfigureContainer<ContainerBuilder>((context, builder) =>
|
||||
{
|
||||
builder.Register(context.Configuration, true, false, "search.json", "feed.json");
|
||||
});
|
||||
|
||||
var startup = new BaseWorkerStartup(builder.Configuration);
|
||||
|
||||
startup.ConfigureServices(builder.Services);
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
startup.Configure(app);
|
||||
|
||||
await app.RunAsync();
|
Loading…
Reference in New Issue
Block a user