using FluentFTP.Helpers; using NLog.Web; using RealTimeCalcPositionService; using YieldChain.Commons; using YLErp; using YLErp.Abstract; using YLErp.Helpers; using YLErp.Model; internal class Program { private static async Task Main(string[] args) { var host = Host.CreateDefaultBuilder(args) .ConfigureAppConfiguration((ctx, cfgBuilder) => { var config = cfgBuilder.Build(); var vpath = config.GetSection("AppSettings").GetValue("VirtualPathRoot"); OtcAppContext.Initialize(new InnerServer(vpath).MapPath); }) .ConfigureServices((hostContext, services) => { YLServiceLocator.SetServiceCollection(services); var appConfig = hostContext.Configuration; services.Configure(appConfig.GetSection("KafkaConfig")); AppManager.Initialize(YLErp.Enums.SubSystemName.RealTimeCalcPosition, appConfig); services.AddSingleton(); services.AddHostedService(); services.AddHostedService(); services.AddHostedService(); }).ConfigureLogging(logging => { logging.ClearProviders(); logging.SetMinimumLevel(LogLevel.Trace); }) .UseNLog() .Build(); //YLServiceLocator.SetServiceProvider(host.Services); await host.RunAsync(); } class InnerServer { public string VirtualRootPath { get; private set; } public InnerServer(string virtualRootPath) { VirtualRootPath = virtualRootPath.TrimToNull() ?? AppContext.BaseDirectory; } public string MapPath(string path) { if (string.IsNullOrEmpty(path)) { return VirtualRootPath; } if (OperatingSystem.IsWindows()) { path = path.TrimStart(MapPathTrim).Replace('/', '\\'); } else { path = path.TrimStart(MapPathTrim).Replace('\\', '/'); } if (path.StartsWith("App_", StringComparison.OrdinalIgnoreCase) || path.Equals("Scripts") || path.Equals("Style")) { return Path.Combine(VirtualRootPath, path); } return Path.Combine(VirtualRootPath, path); } static readonly char[] MapPathTrim = new[] { '~', '/', '\\' }; } }