private static Worker CreateDefaultWorker(IRootCommand root, // Func<LoggerConfiguration, Logger>? createLoggerFunc = null, params Action <Worker>[] opts) { var worker = new Worker(root); // if (createLoggerFunc != null) // worker.UseSerilog(createLoggerFunc); // else // worker.UseSerilog(configuration => configuration // .MinimumLevel.Debug() // // .MinimumLevel.Information() // .MinimumLevel.Override("Microsoft", LogEventLevel.Information) // .Enrich.FromLogContext() // .Enrich.WithCaller() // .WriteTo.Console( // outputTemplate: // "[{Timestamp:HH:mm:ss} {Level:u3}] {Message} (at {Caller} in {SourceFileName}:line {SourceFileLineNumber}){NewLine}{Exception}") // // .WriteTo.Console() // .WriteTo.File(Path.Combine("logs", @"access.log"), rollingInterval: RollingInterval.Day) // .CreateLogger()); // Serilog.Debugging.SelfLog.Enable(msg => Debug.WriteLine(msg)); // Serilog.Debugging.SelfLog.Enable(Console.Error); worker.runOnce(); foreach (var opt in opts) { opt(worker); } try { Instance.Worker = worker; // Instance.Logger = worker; // worker.logDebug("EnableDuplicatedCharThrows: {EnableDuplicatedCharThrows}", // worker.EnableDuplicatedCharThrows); if (root != null) { worker.With(root); } } // catch (DuplicationCommandCharException) // { // } // catch (DuplicationFlagCharException) // { // } catch (CmdrException ex) { worker.log?.logError(ex, "Cmdr Error occurs"); throw; // don't ignore it } return(worker); }
internal CommandEngine(IRootCommand rootCommand, IInputManager inputManager) { if (rootCommand == null) { throw new ArgumentNullException(nameof(rootCommand), "No root command provided."); } if (rootCommand.Console == null) { throw new ArgumentNullException(nameof(rootCommand.Console), "No console for root command provided."); } RootCommand = rootCommand; InputManager = inputManager; _cancellationTokenSource = new CancellationTokenSource(); RootCommand.RequestCloseEvent += (sender, e) => { Stop(); }; //TODO: Try reversing the dependency, so that the root command has an engine instead of the engine having a root command. var rc = RootCommand as RootCommandBase; rc?.Initiate(this); }
private static void ExternalConfigLoader(IBaseWorker w, IRootCommand root) { // throw new NotImplementedException(); }
public override void Attach(IRootCommand command) { base.Attach(command); }
public virtual void Attach(IRootCommand command) { }
public static Worker NewWorker(IRootCommand root, params Action <Worker>[] opts) { var worker = CreateDefaultWorker(root, opts); return(worker); }
public CommandEngine(IRootCommand rootCommand) : this(rootCommand, new InputManager(rootCommand.Console)) { }
/// <summary> /// /// </summary> /// <param name="logger"></param> /// <param name="hostApplicationLifetime"></param> /// <param name="rootCommand"></param> /// <param name="serviceScopeFactory"></param> public RootCommandService(ILogger <RootCommandService> logger, IHostApplicationLifetime hostApplicationLifetime, IRootCommand rootCommand, IServiceScopeFactory serviceScopeFactory) { this.Logger = logger; this.HostApplicationLifetime = hostApplicationLifetime; this.RootCommand = rootCommand; this.ServiceScopeFactory = serviceScopeFactory; }
public CommandEngine(IRootCommand rootCommand, CancellationTokenSource cancellationTokenSource = null) : this(rootCommand, new InputManager(rootCommand.Console), cancellationTokenSource) { }