internal BindingContext(InvocationContext invocationContext) { InvocationContext = invocationContext; ServiceProvider = new ServiceProvider(this); ServiceProvider.AddService(_ => InvocationContext); ServiceProvider.AddService(_ => InvocationContext.GetCancellationToken()); }
protected override async Task <NewCommandStatus> ExecuteAsync( UninstallCommandArgs args, IEngineEnvironmentSettings environmentSettings, ITelemetryLogger telemetryLogger, InvocationContext context) { using TemplatePackageManager templatePackageManager = new TemplatePackageManager(environmentSettings); TemplatePackageCoordinator templatePackageCoordinator = new TemplatePackageCoordinator( telemetryLogger, environmentSettings, templatePackageManager); return(await templatePackageCoordinator.EnterUninstallFlowAsync(args, context.GetCancellationToken()).ConfigureAwait(false)); }
protected override async Task <NewCommandStatus> ExecuteAsync( SearchCommandArgs args, IEngineEnvironmentSettings environmentSettings, ITelemetryLogger telemetryLogger, InvocationContext context) { using TemplatePackageManager templatePackageManager = new TemplatePackageManager(environmentSettings); //we need to await, otherwise templatePackageManager will be disposed. return(await CliTemplateSearchCoordinator.SearchForTemplateMatchesAsync( environmentSettings, templatePackageManager, args, environmentSettings.GetDefaultLanguage(), context.GetCancellationToken()).ConfigureAwait(false)); }
public virtual Task <int> Bind(InvocationContext context) { if (context == null) { return(Task.FromResult(1)); } var cancelToken = context.GetCancellationToken(); if (cancelToken.IsCancellationRequested) { return(Task.FromCanceled <int>(cancelToken)); } ModelBinder.UpdateInstance(Target, context.BindingContext); return(Task.FromResult(0)); }
public async Task <int> InvokeAsync(InvocationContext context) { var parseResult = context.ParseResult; var concurrent = parseResult.ValueForOption(_concurrent); var directory = parseResult.ValueForOption(_directory); var services = parseResult.ValueForArgument(_services) !.ToList(); _logger.BoolOption(nameof(concurrent), concurrent); _logger.Option(nameof(directory), directory !); _logger.Option(nameof(services), services !); var toInstall = _registry .Join( services !, x => x.Key, x => x, (pair, _) => (Name: pair.Key, Service: pair.Value), StringComparer.OrdinalIgnoreCase) .ToList(); var names = toInstall.Select(x => x.Name).ToList(); _logger.ServicesToInstall(names); _logger.UnmatchedServices(services.Except(names, StringComparer.OrdinalIgnoreCase)); try { await _installer.InstallAsync( toInstall.Select(x => x.Service), concurrent, directory, context.GetCancellationToken()); _logger.InstallationSucceeded(); return(context.ResultCode); } catch (Exception e) { _logger.InstallationFailed(e); return(1); } }
public InvocationLifetime( IOptions <InvocationLifetimeOptions> options, IHostingEnvironment environment, IApplicationLifetime applicationLifetime, InvocationContext context = null, ILoggerFactory loggerFactory = null) { Options = options?.Value ?? throw new ArgumentNullException(nameof(options)); Environment = environment ?? throw new ArgumentNullException(nameof(environment)); ApplicationLifetime = applicationLifetime ?? throw new ArgumentNullException(nameof(applicationLifetime)); // if InvocationLifetime is added outside of a System.CommandLine // invocation pipeline context will be null. // Use default cancellation token instead, and become a noop lifetime. invokeCancelToken = context?.GetCancellationToken() ?? default; Logger = (loggerFactory ?? NullLoggerFactory.Instance) .CreateLogger("Microsoft.Hosting.Lifetime"); }