/// <summary> /// Initializes a new instance of the <see cref="WebProcessMonitor"/> class. /// </summary> /// <param name="process">The process.</param> public WebProcessMonitor(ConsoleHost.IProcessHost process) : base(process) { process.RegisterOutputConsumer(this.outputStream); this.hostWrapper = new WebProcessMonitor.ProcessHostWrapper(process); this.host = WebProcessMonitor.ProcessMonitorHost.Create(); this.hostSponser.Register(this.host); }
private void Select_Mintty_clicked(object sender, RoutedEventArgs e) { var dialog = new OpenFileDialog(); dialog.FileName = "mintty.exe"; if (dialog.ShowDialog() == true) { if (dialog.SafeFileName == "mintty.exe") { Config.Instance.MinttyPath = dialog.FileName; ConsoleHost.LoadMinttyHost(); } } }
static void Main(string[] args) { try { ConsoleHost host = new ConsoleHost(new ServiceHost()); host.Run(); Environment.Exit(0); } catch (Exception ex) { Console.WriteLine("Hosted service exception: {0}", ex.Message); Environment.Exit(1); } }
async Task PreviewAndExecuteUpdateActionsforAllPackages(NuGetProject project) { var packageManager = ConsoleHost.CreatePackageManager(); var context = CreateResolutionContext(); var actions = await packageManager.PreviewUpdatePackagesAsync( project, context, this, PrimarySourceRepositories, PrimarySourceRepositories, ConsoleHost.Token); await ExecuteActions(project, actions, packageManager, context.SourceCacheContext); }
public static NAutowired.Core.IConsoleHost BuildConsoleHost(string[] args) { var config = LoadConfig(); return(ConsoleHost.CreateDefaultBuilder(services => { services.AddTransient(typeof(ICommandLineArguments), serviceProvider => new CommandLineArguments(args)); services.AddTransient(typeof(INumeralSystem), serviceProvider => new NumeralSystem(config.NumeralSystemBase)); }, new List <string> { "LcdNumbers" }, new string[0]) .Build()); }
static void Main(string[] args) { var host = ConsoleHost.Create(); host.ParseArguments <ApplicationArguments>(args) .SetVersion("1.0", "1.0.0"); host.UseStartup <Startup>() .Build(); if (host.HostingEnvironment.IsDevelopment()) { Console.ReadKey(); } }
private static void Main(string[] args) { ConsoleHost.WithOptions( new Dictionary <string, Func <CancellationToken, Task> > { { "Provision Resources", ProvisionResourcesAsync }, { "Run Dispatching Processor", RunAsync } }); }
public static int Start(InitialSessionState initialSessionState, string?bannerText, string?helpText, string[] args) { if (initialSessionState == null) { throw PSTraceSource.NewArgumentNullException(nameof(initialSessionState)); } if (args == null) { throw PSTraceSource.NewArgumentNullException(nameof(args)); } ConsoleHost.ParseCommandLine(args); ConsoleHost.DefaultInitialSessionState = initialSessionState; return(ConsoleHost.Start(bannerText, helpText)); }
protected async Task InstallPackageByIdentityAsync( NuGetProject project, PackageIdentity identity, ResolutionContext resolutionContext, INuGetProjectContext projectContext, bool isPreview) { try { var packageManager = ConsoleHost.CreatePackageManager(); var actions = await packageManager.PreviewInstallPackageAsync( project, identity, resolutionContext, projectContext, PrimarySourceRepositories, null, ConsoleHost.Token); if (isPreview) { PreviewNuGetPackageActions(actions); } else { NuGetPackageManager.SetDirectInstall(identity, projectContext); await packageManager.ExecuteNuGetProjectActionsAsync( project, actions, this, resolutionContext.SourceCacheContext, ConsoleHost.Token); NuGetPackageManager.ClearDirectInstall(projectContext); } } catch (InvalidOperationException ex) { if (ex.InnerException is PackageAlreadyInstalledException) { Log(ProjectManagement.MessageLevel.Info, ex.Message); } else { throw ex; } } }
static void Main(string[] args) { Console.OutputEncoding = Encoding.UTF8; _consoleApplication = ConsoleHost .CreateDefaultBuilder(args, new ConsoleHostConfigurationOptions { ConsulConfigurationOptions = new ConsulConfigurationOptions { AppsettingsFileName = "appsettings-async.json" } }) .Build() as IConsoleApplication; Console.WriteLine(JsonConvert.SerializeObject(_consoleApplication.Configuration)); Console.ReadKey(); }
protected void Preprocess() { ThrowErrorIfProjectNotOpen(); UpdateActiveSourceRepository(Source); project = ConsoleHost.GetNuGetProject(ProjectName); DetermineFileConflictAction(); ParseUserInputForId(); ParseUserInputForVersion(); // The following update to ActiveSourceRepository may get overwritten if the 'Id' was just a path to a nupkg if (readFromDirectPackagePath) { UpdateActiveSourceRepository(Source); } ActionType = NuGetActionType.Install; }
async Task PreviewAndExecuteUpdateActionsforSinglePackage(NuGetProject project) { ConsoleHostNuGetPackageManager packageManager = null; var installedPackage = (await project.GetInstalledPackagesAsync(ConsoleHost.Token)) .FirstOrDefault(p => string.Equals(p.PackageIdentity.Id, Id, StringComparison.OrdinalIgnoreCase)); if (installedPackage != null) { // set _installed to true, if package to update is installed. isPackageInstalled = true; packageManager = ConsoleHost.CreatePackageManager(); var actions = Enumerable.Empty <NuGetProjectAction> (); var resolutionContext = CreateResolutionContext(); // If -Version switch is specified if (!string.IsNullOrEmpty(Version)) { actions = await packageManager.PreviewUpdatePackagesAsync( new PackageIdentity (installedPackage.PackageIdentity.Id, PowerShellCmdletsUtility.GetNuGetVersionFromString(Version)), project, resolutionContext, this, PrimarySourceRepositories, EnabledSourceRepositories, ConsoleHost.Token); } else { actions = await packageManager.PreviewUpdatePackagesAsync( installedPackage.PackageIdentity.Id, project, resolutionContext, this, PrimarySourceRepositories, EnabledSourceRepositories, ConsoleHost.Token); } await ExecuteActions(project, actions, packageManager, resolutionContext.SourceCacheContext); } }
protected async Task UninstallPackageByIdAsync( NuGetProject project, string packageId, UninstallationContext uninstallContext, INuGetProjectContext projectContext, bool isPreview) { ConsoleHostNuGetPackageManager packageManager = ConsoleHost.CreatePackageManager(); IEnumerable <NuGetProjectAction> actions = await packageManager.PreviewUninstallPackageAsync(project, packageId, uninstallContext, projectContext, ConsoleHost.Token); if (isPreview) { PreviewNuGetPackageActions(actions); } else { await packageManager.ExecuteNuGetProjectActionsAsync(project, actions, projectContext, ConsoleHost.Token); } }
public static async Task <int> Run <T>(string[] args, T commandLineBinding) where T : ICommandLineBinding { var initialisationInformation = new InitialisationInformation(); initialisationInformation.AddMessage(MessageType.Information, $"Received command line {string.Join(" ", args.Select(x => $"[{x}]"))}"); var consoleHost = new ConsoleHost(); var parserType = typeof(CommandLineParser <>).MakeGenericType(commandLineBinding.CommandLineType); var commandLineParser = (ICommandLineParser)Activator.CreateInstance(parserType); var parseResult = commandLineParser.Parse(args, initialisationInformation); switch (parseResult.ParseResult) { case ParseResult.Failed: consoleHost.ReportInitialisation(initialisationInformation); return(ReturnCodes.CommandLineParsingFailed); case ParseResult.SuccessfulAndExit: consoleHost.ReportInitialisation(initialisationInformation); return(ReturnCodes.Success); default: var applicationBootstrapper = commandLineBinding.CreateBootstrapper(parseResult.CommandLine); IApplication application = null; try { application = applicationBootstrapper.Bootstrap(); } catch (Exception ex) { initialisationInformation.AddMessage(MessageType.Error, $"Failed to bootstrap{Environment.NewLine}{ex}"); consoleHost.ReportInitialisation(initialisationInformation); return(ReturnCodes.BoostrapFailed); } var returnCode = await consoleHost.Run(application, initialisationInformation); return((int)returnCode); } }
BeginProcessing() { try { string outFilename = Host.UI.StopTranscribing(); if (outFilename != null) { PSObject outputObject = new PSObject( StringUtil.Format(TranscriptStrings.TranscriptionStopped, outFilename)); outputObject.Properties.Add(new PSNoteProperty("Path", outFilename)); WriteObject(outputObject); } } catch (Exception e) { ConsoleHost.CheckForSevereException(e); throw PSTraceSource.NewInvalidOperationException( e, TranscriptStrings.ErrorStoppingTranscript, e.Message); } }
/// <summary> /// Create a package repository from the source by trying to resolve relative paths. /// </summary> protected SourceRepository CreateRepositoryFromSource(string source) { if (source == null) { throw new ArgumentNullException(nameof(source)); } var packageSource = new NuGet.Configuration.PackageSource(source); var repository = ConsoleHost.CreateRepository(packageSource); var resource = repository.GetResource <PackageSearchResource> (); // resource can be null here for relative path package source. if (resource == null) { Uri uri; // if it's not an absolute path, treat it as relative path if (Uri.TryCreate(source, UriKind.Relative, out uri)) { throw new NotImplementedException(); //string outputPath; //bool? exists; //string errorMessage; //// translate relative path to absolute path //if (TryTranslatePSPath (source, out outputPath, out exists, out errorMessage) && exists == true) { // source = outputPath; // packageSource = new Configuration.PackageSource (outputPath); //} } } var sourceRepo = ConsoleHost.CreateRepository(packageSource); // Right now if packageSource is invalid, CreateRepository will not throw. Instead, resource returned is null. var newResource = repository.GetResource <PackageSearchResource> (); if (newResource == null) { // Try to create Uri again to throw UriFormat exception for invalid source input. new Uri(source); } return(sourceRepo); }
private static void RunAsDaemon(string[] args) { logger.Info("Running as daemon"); try { Start(null, new StringsEventArgs(args)); if (CheckConsole()) { logger.Info("Application running. Press Ctrl+C to shut down."); } ConsoleHost.WaitForShutdownAsync().GetAwaiter().GetResult(); } catch (Exception ex) { ShowUnhandledException(ex); } finally { Stop(null, EventArgs.Empty); } }
List <NuGetProject> GetNuGetProjects() { if (HasSelectedProjectName()) { return new List <NuGetProject> { ConsoleHost.GetNuGetProject(ProjectName) } } ; return(ConsoleHost.GetNuGetProjects().ToList()); } bool HasSelectedProjectName() { return(ProjectName != null); } void WriteInstalledPackages() { CheckSolutionIsOpen(); var packagesToDisplay = GetInstalledPackagesAsync(projects, Filter, Skip, First, ConsoleHost.Token); WriteInstalledPackages(packagesToDisplay.Result); } void WriteInstalledPackages(Dictionary <NuGetProject, IEnumerable <NuGet.Packaging.PackageReference> > packages) { List <PowerShellInstalledPackage> view = PowerShellInstalledPackage.GetPowerShellPackageView(packages, ConsoleHost.SolutionManager, ConsoleHost.Settings); if (view.Any()) { WritePackagesToOutputPipeline(view); } else { Log(MessageLevel.Info, GettextCatalog.GetString("No packages installed.")); } }
protected override void BeginProcessing() { InternalHost host = base.Host as InternalHost; if (host != null) { ConsoleHost externalHost = host.ExternalHost as ConsoleHost; if (externalHost != null) { if (!externalHost.IsTranscribing) { base.WriteObject(TranscriptStrings.TranscriptionNotInProgress); } try { string str = externalHost.StopTranscribing(); base.WriteObject(StringUtil.Format(TranscriptStrings.TranscriptionStopped, str)); } catch (Exception exception1) { Exception exception = exception1; ConsoleHost.CheckForSevereException(exception); object[] message = new object[1]; message[0] = exception.Message; throw PSTraceSource.NewInvalidOperationException(exception, "TranscriptStrings", "ErrorStoppingTranscript", message); } return; } else { throw PSTraceSource.NewNotSupportedException("TranscriptStrings", "HostDoesNotSupportTranscript", new object[0]); } } else { throw PSTraceSource.NewNotSupportedException("TranscriptStrings", "HostDoesNotSupportTranscript", new object[0]); } }
private static async Task Main(string[] args) { // キャッシュ WeatherModel.CacheWeatherIcons(General.WeatherIconsPath); // 設定読み込み Settings = SettingLoader.Load <SettingModel>(); if (string.IsNullOrWhiteSpace(Settings?.OpenWeatherMap.ApiKey)) { Log.WriteLogLine("OpenWeatherMap へ接続するための API Key が見つかりません", Log.LogType.Error); await ConsoleHost.WaitAsync(); return; } SetTimer(); Connect(); await ConsoleHost.WaitAsync(); Disconnect(); }
static void Main(string[] args) { var options = new Dictionary <string, Func <CancellationToken, Task> >() { { "Add a movie", AddMovieAsync }, { "Update a movie", UpdateMovieAsync }, { "Delete a movie", DeleteMovieAsync }, { "Add a person", AddPersonAsync }, { "Update a person", UpdatePersonAsync }, { "Delete a person", DeletePersonAsync }, { "List movies", ListMoviesAsync }, { "List persons", ListPersonsAsync } }; ConsoleHost.RunWithOptionsAsync(options).Wait(); }
static void Main(string[] args) { var host = new ConsoleHost(); host.WriteMessage("NSwag command line: v" + typeof(SwaggerInfo).Assembly.GetName().Version + "\n"); host.WriteMessage("Visit http://NSwag.org for more information.\n"); host.WriteMessage("Execute the 'help' command to show a list of all the available commands.\n"); try { var processor = new CommandLineProcessor(host); processor.RegisterCommand <WebApiToSwaggerCommand>("webapi2swagger"); processor.RegisterCommand <JsonSchemaToCSharpCommand>("jsonschema2csclient"); processor.RegisterCommand <JsonSchemaToTypeScriptCommand>("jsonschema2tsclient"); processor.RegisterCommand <SwaggerToCSharpClientCommand>("swagger2csclient"); processor.RegisterCommand <SwaggerToCSharpWebApiControllerCommand>("swagger2cscontroller"); processor.RegisterCommand <SwaggerToTypeScriptCommand>("swagger2tsclient"); processor.Process(args); } catch (Exception exception) { var savedForegroundColor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Red; host.WriteMessage(exception.ToString()); Console.ForegroundColor = savedForegroundColor; } if (Debugger.IsAttached) { Console.WriteLine("Press <any> key to exit..."); Console.ReadKey(); } }
IPackageRepository CreatePackageRepositoryForActivePackageSource() { PackageSource packageSource = ConsoleHost.GetActivePackageSource(Source); return(registeredPackageRepositories.CreateRepository(packageSource)); }
IPackageManagementProject GetProject() { return(ConsoleHost.GetProject(Source, ProjectName)); }
IPackageManagementProject GetSelectedProject(IPackageRepository repository) { string projectName = GetSelectedProjectName(); return(ConsoleHost.GetProject(repository, projectName)); }
IConsoleHostFileConflictResolver CreateFileConflictResolver() { return(ConsoleHost.CreateFileConflictResolver(FileConflictAction)); }
IPackageManagementProject GetProject() { string source = null; return(ConsoleHost.GetProject(source, ProjectName)); }
/// <summary> /// Starts the specified output stream. /// </summary> /// <param name="outputStream">The output stream.</param> /// <param name="processHost">The process host.</param> public void Start(MemoryMessageStream outputStream, ConsoleHost.IProcessHost processHost) { this.outputStream = outputStream; this.processHost = processHost; AppDomain.CurrentDomain.SetData(".output", this.outputStream); AppDomain.CurrentDomain.SetData(".processHost", this.processHost); this.sponsor.Register((MarshalByRefObject)this.processHost); this.sponsor.Register(this.outputStream); this.webServer.Start(); }
void UninstallPackage() { NuGetProject project = ConsoleHost.GetNuGetProject(ProjectName); UninstallPackageByIdAsync(project, Id, CreateUninstallContext(), this, WhatIf.IsPresent).Wait(); }
IPackageRepository GetActivePackageRepository() { PackageSource packageSource = ConsoleHost.GetActivePackageSource(Source); return(ConsoleHost.GetPackageRepository(packageSource)); }
protected IDisposable CreateEventsMonitor() { return(ConsoleHost.CreateEventsMonitor(this)); }
IPackageManagementProject GetSelectedProject() { string projectName = GetSelectedProjectName(); return(ConsoleHost.GetProject(Source, projectName)); }
/// <summary> /// Initializes a new instance of the <see cref="ProcessHostWrapper"/> class. /// </summary> /// <param name="inner">The inner interface.</param> public ProcessHostWrapper(ConsoleHost.IProcessHost inner) { this.inner = inner; }