public DFrameWorkerApp(DFrameWorkerOptions options) : this(options, new IServiceProviderIsService(), null !) { this.cancellationTokenSource = new CancellationTokenSource(); this.Context = new ConsoleAppContext() { CancellationToken = cancellationTokenSource.Token }; }
static async Task RunDFrameWorkerAsyncCore(IHostBuilder hostBuilder, DFrameWorkerOptions options, Action <HostBuilderContext, DFrameWorkerOptions> configureOptions) { hostBuilder = hostBuilder .ConfigureServices((hostContext, services) => { configureOptions(hostContext, options); services.AddSingleton(options); }); var app = ConsoleApp.CreateFromHostBuilder(hostBuilder, new string[0], x => { // this affects indesirable result so disable auto replace. x.ReplaceToUseSimpleConsoleLogger = false; }); app.AddCommands <DFrameWorkerApp>(); await app.RunAsync(); }
DFrameWorkerApp(DFrameWorkerOptions options, IServiceProviderIsService isService, IServiceProvider serviceProvider) { var workloadCollection = DFrameWorkloadCollection.FromAssemblies(options.WorkloadAssemblies, options.IncludesDefaultHttpWorkload, isService); #if UNITY_2020_1_OR_NEWER var logger = new ILogger <DFrameWorkerEngine>(); #else var logger = serviceProvider.GetRequiredService <ILogger <DFrameWorkerEngine> >(); #endif foreach (var item in workloadCollection.All) { logger.LogInformation($"Loaded {item.Name} workload."); } this.engines = new DFrameWorkerEngine[Math.Max(1, options.VirtualProcess)]; for (int i = 0; i < engines.Length; i++) { engines[i] = new DFrameWorkerEngine(logger, workloadCollection, options, isService, serviceProvider); } }
public static Task RunDFrameWorkerAsync(this IHostBuilder hostBuilder, DFrameWorkerOptions options) { return(RunDFrameWorkerAsyncCore(hostBuilder, options, (_, __) => { })); }