public override async Task RunAsync(CommandLineProcessor processor, IConsoleHost host) { var schema = JsonSchema4.FromJson(InputJson); var generator = new TypeScriptGenerator(schema); var code = generator.GenerateFile(); WriteOutput(host, code); }
/// <summary>Gets the argument value.</summary> /// <param name="consoleHost">The command line host.</param> /// <param name="args">The arguments.</param> /// <param name="property">The property.</param> /// <returns>The value.</returns> /// <exception cref="System.InvalidOperationException">Either the argument Name or Position can be set, but not both.</exception> /// <exception cref="InvalidOperationException">Either the argument Name or Position can be set, but not both.</exception> /// <exception cref="InvalidOperationException">The parameter has no default value.</exception> public override object GetValue(IConsoleHost consoleHost, string[] args, PropertyInfo property) { if (!string.IsNullOrEmpty(Name) && Position > 0) throw new InvalidOperationException("Either the argument Name or Position can be set, but not both."); var value = GetPositionalArgumentValue(args); if (value == null) value = GetNamedArgumentValue(args, Name); if (value != null) return ConvertToType(value.ToString(), property.PropertyType); if (!IsInteractiveMode(args) && DefaultValue != null) return ConvertToType(DefaultValue.ToString(), property.PropertyType); var stringVal = consoleHost.ReadValue(GetFullParameterDescription(property)); if (stringVal == "[default]") { if (DefaultValue != null) return ConvertToType(DefaultValue.ToString(), property.PropertyType); throw new InvalidOperationException("The parameter has no default value."); } return ConvertToType(stringVal, property.PropertyType); }
private void PrintCommand(IConsoleHost host, KeyValuePair<string, Type> pair) { var commandType = pair.Value; host.WriteMessage("---------------------\n"); host.WriteMessage("Command: "); host.WriteMessage(pair.Key + "\n"); var descriptionAttribute = commandType.GetCustomAttribute<DescriptionAttribute>(); if (descriptionAttribute != null) host.WriteMessage(" " + descriptionAttribute.Description + "\n"); host.WriteMessage("\nArguments: \n"); foreach (var property in commandType.GetRuntimeProperties()) { var argumentAttribute = property.GetCustomAttribute<ArgumentAttribute>(); if (argumentAttribute != null) { if (argumentAttribute.Position > 0) host.WriteMessage(" Argument Position " + argumentAttribute.Position + "\n"); else host.WriteMessage(" " + argumentAttribute.Name.ToLowerInvariant() + "\n"); var parameterDescriptionAttribute = property.GetCustomAttribute<DescriptionAttribute>(); if (parameterDescriptionAttribute != null) host.WriteMessage(" " + parameterDescriptionAttribute.Description + "\n"); } } }
public override async Task<object> RunAsync(CommandLineProcessor processor, IConsoleHost host) { var document = await RunAsync(); if (TryWriteFileOutput(host, () => document.ToJson()) == false) return document; return null; }
public virtual Task Detach(IConsoleHost host) { if (ReferenceEquals(Host, host)) { Host = null; } return Task.FromResult<object>(null); }
public override async Task <object> RunAsync(CommandLineProcessor processor, IConsoleHost host) { var code = await RunAsync(); await TryWriteFileOutputAsync(host, () => code).ConfigureAwait(false); return(code); }
private async Task InstallTemplatesAsync(IConsoleHost host) { ConsoleUtilities.Write("Install templates? [yes|no]"); if (Console.ReadLine() == "yes") { await ExecuteCommandAsync("dotnet new --install Microsoft.AspNetCore.SpaTemplates::*", host); } }
public override async Task RunAsync(CommandLineProcessor processor, IConsoleHost host) { var clientGenerator = new SwaggerToTypeScriptGenerator(InputSwaggerService); clientGenerator.Class = Class; var output = clientGenerator.GenerateFile(); WriteOutput(host, output); }
/// <summary>Runs the asynchronous.</summary> /// <param name="processor">The processor.</param> /// <param name="host">The host.</param> /// <returns></returns> public override async Task <object> RunAsync(CommandLineProcessor processor, IConsoleHost host) { var document = await RunAsync(); await TryWriteFileOutputAsync(host, () => document.ToJson()).ConfigureAwait(false); return(document); }
public override Task <object> RunAsync(CommandLineProcessor processor, IConsoleHost host) { var projects = GetProjectPaths().Select(p => ProjectExtensions.LoadProject(p)).ToList(); var projectNames = projects.Select(p => System.IO.Path.GetFileNameWithoutExtension(p.Project.FullPath)); foreach (var project in projects.Select(p => p.Project)) { try { using (var projectInformation = ProjectExtensions.LoadProject(project.FullPath)) { var newProjectsToReference = new List <Project>(); var assemblyReferencesToRemove = new List <ProjectItem>(); foreach (var reference in projectInformation.Project.Items .Where(r => r.ItemType == "Reference" && projectNames.Contains(r.UnevaluatedInclude.Split(',').First()))) { assemblyReferencesToRemove.Add(reference); var projectToReference = projects.First(p => System.IO.Path.GetFileNameWithoutExtension(p.Project.FullPath) == reference.EvaluatedInclude.Split(',').First()); newProjectsToReference.Add(projectToReference.Project); } foreach (var item in assemblyReferencesToRemove) { projectInformation.Project.RemoveItem(item); } foreach (var projectToReference in newProjectsToReference) { var refProjectDirectory = System.IO.Path.GetFullPath(System.IO.Path.GetDirectoryName(projectToReference.FullPath)); var relativePath = PathUtilities.ToRelativePath(refProjectDirectory, System.IO.Path.GetFullPath(System.IO.Path.GetDirectoryName(project.FullPath))); var path = System.IO.Path.Combine(relativePath, System.IO.Path.GetFileName(projectToReference.FullPath)); var metaData = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("Name", System.IO.Path.GetFileNameWithoutExtension(projectToReference.FullPath)) }; projectInformation.Project.AddItem("ProjectReference", path, metaData); } projectInformation.Project.Save(); } } catch (Exception e) { host.WriteError("The project '" + project.FullPath + "' could not be loaded: " + e.Message + "\n"); } } foreach (var project in projects) { project.Dispose(); } return(Task.FromResult <object>(null)); }
/// <summary> /// ShowInfo about record inserted /// </summary> /// <param name="host"></param> /// <param name="hashsedPassword"></param> private void ShowInfo(IConsoleHost host, string hashsedPassword) { host.WriteMessage("AvatarName: " + FirstValue); host.WriteMessage("\n"); host.WriteMessage("AvatarPassword: "******"\n"); host.WriteMessage("INFO: Record inserted."); host.WriteMessage("\n"); }
protected void Render(IConsoleHost consoleHost, string text) { var lines = FiggleFonts.Slant.Render(text).Split('\n').Select(s => s.TrimEnd('\r')).ToArray(); for (int i = 0; i < lines.Length; i++) { consoleHost.WriteLine(_Colors[i].Invoke(lines[i])); } }
private async Task ExecuteDocumentAsync(IConsoleHost host, string filePath) { host.WriteMessage("\nExecuting file '" + filePath + "'...\n"); var document = await LoadDocumentAsync(filePath); await document.ExecuteAsync(); host.WriteMessage("Done.\n"); }
private void Usage(IConsoleHost consoleHost, string commandName) { consoleHost.WriteLine($"Usage: {commandName} [-f <font name>] [-h] <message>"); consoleHost.WriteLine(" Available font names:"); foreach (var fontName in _Fonts.Value.Keys.OrderBy(name => name)) { consoleHost.WriteLine($" - {fontName}"); } }
public override Task <object> RunAsync(CommandLineProcessor processor, IConsoleHost host) { using (var projects = LoadProjects()) { ReplaceAssemblyReferencesWithProjects(projects, host); } return(Task.FromResult <object>(null)); }
public static async Task <int> RunAsync( string executable, IReadOnlyList <string> args, IConsoleHost console = null, TimeSpan?timeout = null) { var arguments = ToArguments(args); var startInfo = new ProcessStartInfo { FileName = executable, Arguments = arguments, UseShellExecute = false, RedirectStandardOutput = console != null, RedirectStandardError = console != null, }; console?.WriteMessage($"Executing {executable} {arguments}{Environment.NewLine}"); using (var process = Process.Start(startInfo)) { var tcs = new TaskCompletionSource <bool>(); process.EnableRaisingEvents = true; process.Exited += (_, eventArgs) => { if (process.ExitCode == 0) { tcs.TrySetResult(true); } else { tcs.TrySetException(new Exception($"Process failed with non-zero exit code '{process.ExitCode}'.")); } }; if (console != null) { process.OutputDataReceived += (_, eventArgs) => console.WriteMessage(eventArgs.Data + Environment.NewLine); process.ErrorDataReceived += (_, eventArgs) => console.WriteError(eventArgs.Data + Environment.NewLine); process.BeginErrorReadLine(); process.BeginOutputReadLine(); } var result = await Task.WhenAny(tcs.Task, Task.Delay(timeout ?? TimeSpan.FromSeconds(60 * 5))).ConfigureAwait(false); if (result != tcs.Task) { throw new InvalidOperationException($"Process {startInfo.FileName} timed out."); } else { console?.WriteMessage($"Done executing command. Exit Code: {process.ExitCode}.{Environment.NewLine}"); return(process.ExitCode); } } }
/// <summary> /// Creates an instance of the SynchronizingConsoleHostWrapper /// class that wraps the given IConsoleHost implementation and /// invokes its calls through the given SynchronizationContext. /// </summary> /// <param name="wrappedConsoleHost"> /// The IConsoleHost implementation that will be wrapped. /// </param> /// <param name="syncContext"> /// The SynchronizationContext which will be used for invoking /// host operations calls on the proper thread. /// </param> public SynchronizingConsoleHostWrapper( IConsoleHost wrappedConsoleHost, SynchronizationContext syncContext) { Validate.IsNotNull("wrappedConsoleHost", wrappedConsoleHost); Validate.IsNotNull("syncContext", syncContext); this.wrappedConsoleHost = wrappedConsoleHost; this.syncContext = syncContext; }
/// <summary> /// Writes normal output to the user interface. /// </summary> /// <param name="consoleHost"> /// The IConsoleHost implementation to use for WriteOutput calls. /// </param> /// <param name="outputString"> /// The output string to be written. /// </param> /// <param name="includeNewLine"> /// If true, a newline should be appended to the output's contents. /// </param> public static void WriteOutput( this IConsoleHost consoleHost, string outputString, bool includeNewLine) { consoleHost.WriteOutput( outputString, includeNewLine, OutputType.Normal); }
/// <summary> /// Writes output of a particular type to the user interface /// with a newline ending. /// </summary> /// <param name="consoleHost"> /// The IConsoleHost implementation to use for WriteOutput calls. /// </param> /// <param name="outputString"> /// The output string to be written. /// </param> /// <param name="outputType"> /// Specifies the type of output to be written. /// </param> public static void WriteOutput( this IConsoleHost consoleHost, string outputString, OutputType outputType) { consoleHost.WriteOutput( outputString, true, OutputType.Normal); }
protected void WriteOutput(IConsoleHost host, string output) { if (string.IsNullOrEmpty(Output)) host.WriteMessage(output); else { File.WriteAllText(Output, output, Encoding.UTF8); host.WriteMessage("Client code successfully written to file."); } }
public override Task <object> RunAsync(CommandLineProcessor processor, IConsoleHost host) { foreach (var projectPath in GetProjectPaths()) { ConsoleUtilities.WriteColor(System.IO.Path.GetFileName(projectPath) + ":\n", ConsoleColor.Green); host.WriteMessage(projectPath.Replace(Directory.GetCurrentDirectory(), "") + "\n"); } return(Task.FromResult <object>(null)); }
public override async Task RunAsync(CommandLineProcessor processor, IConsoleHost host) { var schema = JsonSchema4.FromJson(InputJson); var generator = new CSharpGenerator(schema); generator.Namespace = Namespace; var code = generator.GenerateFile(); WriteOutput(host, code); }
/// <summary>Initializes a new instance of the <see cref="CommandLineProcessor" /> class.</summary> /// <param name="consoleHost">The command line host.</param> /// <param name="dependencyResolver">The dependency resolver.</param> public CommandLineProcessor(IConsoleHost consoleHost, IDependencyResolver dependencyResolver = null, bool registerDefaultHelpCommand = true) { _consoleHost = consoleHost; _dependencyResolver = dependencyResolver; if (registerDefaultHelpCommand) { RegisterCommand <HelpCommand>("help"); } }
public void Invoke(IConsoleHost consoleHost, string[] args) { consoleHost.WriteLine($"{Cyan("Framework Description")} - {RuntimeInformation.FrameworkDescription}"); consoleHost.WriteLine($"{Cyan("Process Architecture")} - {RuntimeInformation.ProcessArchitecture}"); consoleHost.WriteLine($"{Cyan("OS Architecture")} - {RuntimeInformation.OSArchitecture}"); consoleHost.WriteLine($"{Cyan("OS Description")} - {RuntimeInformation.OSDescription}"); consoleHost.WriteLine($"{Cyan("OS Platform")} - {Environment.OSVersion.Platform}"); consoleHost.WriteLine($"{Cyan("OS Version")} - {Environment.OSVersion.Version}"); consoleHost.WriteLine($"{Cyan("OS Version ServicePack")} - {Environment.OSVersion.ServicePack}"); }
public override async Task <object> RunAsync(CommandLineProcessor processor, IConsoleHost host) { var service = await RunAsync(); if (TryWriteFileOutput(host, () => service.ToJson()) == false) { return(service); } return(null); }
public override async Task <object> RunAsync(CommandLineProcessor processor, IConsoleHost host) { var documentJson = await RunIsolatedAsync((string)null); var document = await SwaggerDocument.FromJsonAsync(documentJson, expectedSchemaType : OutputType).ConfigureAwait(false); await this.TryWriteDocumentOutputAsync(host, () => document).ConfigureAwait(false); return(document); }
public override async Task <object> RunAsync(CommandLineProcessor processor, IConsoleHost host) { var result = await RunAsync(); foreach (var pair in result) { await TryWriteFileOutputAsync(pair.Key, host, () => pair.Value).ConfigureAwait(false); } return(result); }
public override async Task RunAsync(CommandLineProcessor processor, IConsoleHost host) { var clientGenerator = new SwaggerToCSharpGenerator(InputSwaggerService); clientGenerator.Class = Class; clientGenerator.Namespace = Namespace; clientGenerator.OperationGenerationMode = OperationGenerationMode; var output = clientGenerator.GenerateFile(); WriteOutput(host, output); }
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously public async Task <object> RunAsync(CommandLineProcessor processor, IConsoleHost host) #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously { //Connect and create users collection for LiteDB.org //LiteDB connection LiteDatabase db = new LiteDatabase(@"UsersObjects.db"); //Get users collection var col = db.GetCollection <Users>("users"); //Create Scrypt Password ScryptEncoder encoder = new ScryptEncoder(); string hashsedPassword = encoder.Encode(SecondValue); if (col.Count() == 0) { // Create your new customer instance var user = new Users { UserName = FirstValue, UserPassword = hashsedPassword, IsActive = true }; // Create unique index in Name field col.EnsureIndex(x => x.UserName, true); // Insert new customer document (Id will be auto-incremented) col.Insert(user); ShowInfo(host, hashsedPassword); } else { // Create your new customer instance var user = new Users { UserName = FirstValue, UserPassword = hashsedPassword, IsActive = true }; // Insert new customer document (Id will be auto-incremented) try { col.Insert(user); ShowInfo(host, hashsedPassword); } catch (LiteDB.LiteException e) { host.WriteMessage("ERROR: " + e.Message); host.WriteMessage("\n"); } } return(null); }
public override Task <object> RunAsync(CommandLineProcessor processor, IConsoleHost host) { if (Version.IndexOf(".") < 0) { host.WriteError("Version number must include at least two parts \n"); return(Task.FromResult <object>(null)); } bool isReplaceOnly = !ACTION_FORCE.Equals(Action, StringComparison.InvariantCultureIgnoreCase); var globalProperties = TryGetGlobalProperties(); foreach (var projectPath in GetProjectPaths()) { try { using (var projectInformation = ProjectExtensions.LoadProject(projectPath, globalProperties)) { bool projectHasVersion = projectInformation.Project.HasVersion(); bool projectGeneratesPackage = projectInformation.Project.GeneratesPackage(); if (projectGeneratesPackage && (projectHasVersion || !isReplaceOnly)) { var versions = ChangeVersion(projectInformation.Project, "Version"); if (!versions.Item1.Equals(versions.Item2)) { host.WriteMessage($"[x] {(projectHasVersion ? "Replaced" : "Set")} version of {System.IO.Path.GetFileName(projectPath)}" + " from " + versions.Item2 + " to " + versions.Item1 + "\n"); if (!Simulate) { projectInformation.Project.Save(); } } else { host.WriteMessage($"[ ] Skipping {System.IO.Path.GetFileName(projectPath)} is already set to {versions.Item1}\n"); } } else { host.WriteMessage($"[ ] Ignoring {System.IO.Path.GetFileName(projectPath)}: {( !projectGeneratesPackage ? "Not GeneratePackageOnBuild" : "No version in Project")}\n"); } } } catch (Exception e) { host.WriteError(e + "\n"); } } return(Task.FromResult <object>(null)); }
/// <summary> /// Starts the session using the provided IConsoleHost implementation /// for the ConsoleService. /// </summary> /// <param name="consoleHost"> /// An IConsoleHost implementation which is used to interact with the /// host's user interface. /// </param> public void StartSession(IConsoleHost consoleHost) { // Create a workspace to contain open files this.Workspace = new Workspace(); // Initialize all services this.PowerShellContext = new PowerShellContext(); this.LanguageService = new LanguageService(this.PowerShellContext); this.AnalysisService = new AnalysisService(); this.DebugService = new DebugService(this.PowerShellContext); }
public override async Task <object> RunAsync(CommandLineProcessor processor, IConsoleHost host) { var configuration = ReferenceSwitcherConfiguration.Load(Configuration); SwitchToPackages(host, configuration); await RemoveProjectsFromSolutionAsync(configuration, host); configuration.Save(); return(null); }
public void Invoke(IConsoleHost consoleHost, string[] args) { if (args.Skip(1).Any()) { consoleHost.WriteLine($"Usage: {args[0]}"); } else { consoleHost.Clear(); } }
protected async Task ExecuteCommandAsync(string command, string arguments, IConsoleHost host) { if (Simulate) { host.WriteMessage("SIMULATE " + command); } else { await ProcessUtilities.ExecuteAsync(command, arguments, Verbose); } }
public override async Task Attach(IConsoleHost host) { var context = SynchronizationContext.Current; await Task.WhenAll(base.Attach(host), _runspace.OpenTaskAsync()); _hostDispatcher = new HostDispatcher(Host, context); // Display Prompt await WritePrompt(); }
public async Task<object> RunAsync(CommandLineProcessor processor, IConsoleHost host) { if (!DynamicApis.FileExists("nswag.json")) { await CreateDocumentAsync("nswag.json"); host.WriteMessage("nswag.json file created."); } else host.WriteMessage("nswag.json already exists."); return null; }
public static void RunExecCommands(IConsoleHost consoleHost, IReadOnlyList <string>?commands) { if (commands == null) { return; } foreach (var cmd in commands) { consoleHost.ExecuteCommand(cmd); } }
private async Task CreateApplicationProjectAsync(string appDirectory, IConsoleHost host) { Directory.SetCurrentDirectory(appDirectory); await ExecuteCommandAsync("dotnet", "new " + Type, host); await ExecuteCommandAsync("dotnet", "restore", host); if (File.Exists("package.json")) { await ExecuteCommandAsync("npm", "i", host); } }
public override async Task <object> RunAsync(CommandLineProcessor processor, IConsoleHost host) { var schema = await GetJsonSchemaAsync().ConfigureAwait(false); var generator = new CSharpGenerator(schema, Settings); var code = generator.GenerateFile(Name); await TryWriteFileOutputAsync(host, () => code).ConfigureAwait(false); return(code); }
/// <summary>Runs the command.</summary> /// <param name="processor">The processor.</param> /// <param name="host">The host.</param> /// <returns>The input object for the next command.</returns> public Task<object> RunAsync(CommandLineProcessor processor, IConsoleHost host) { foreach (var pair in processor.Commands) { if (pair.Key != "help") { PrintCommand(host, pair); host.ReadValue("Press <enter> key for next command..."); } } return Task.FromResult<object>(null); }
/// <summary>Gets the argument value.</summary> /// <param name="consoleHost">The command line host.</param> /// <param name="args">The arguments.</param> /// <param name="property">The property.</param> /// <returns>The value.</returns> public override object GetValue(IConsoleHost consoleHost, string[] args, PropertyInfo property) { foreach (var argument in args) { if (argument == "-" + ShortName) return true; if (argument == "--" + LongName) return true; } return false; }
protected bool TryWriteFileOutput(string path, IConsoleHost host, Func<string> generator) { if (!string.IsNullOrEmpty(path)) { var directory = DynamicApis.PathGetDirectoryName(path); if (!string.IsNullOrEmpty(directory) && !DynamicApis.DirectoryExists(directory)) DynamicApis.DirectoryCreateDirectory(directory); DynamicApis.FileWriteAllText(path, generator()); host?.WriteMessage("Code has been successfully written to file.\n"); return true; } return false; }
private void PrintCommand(IConsoleHost host, KeyValuePair<string, Type> pair) { var commandType = pair.Value; host.WriteMessage("\n"); host.WriteMessage("USAGE\n"); host.WriteMessage("=====\n"); host.WriteMessage("myapp.exe myCommand /myParameter:myValue /mySecondParameter:myValue\n\n\n"); host.WriteMessage("AVAILABLE COMMANDS\n"); host.WriteMessage("==================\n\n"); host.WriteMessage("Command: "); host.WriteMessage(pair.Key + "\n"); var commandAttribute = commandType.GetTypeInfo().GetCustomAttribute<CommandAttribute>(); if (commandAttribute != null && !string.IsNullOrEmpty(commandAttribute.Description)) host.WriteMessage(" " + commandAttribute.Description + "\n"); else { dynamic descriptionAttribute = commandType.GetTypeInfo().GetCustomAttributes().SingleOrDefault(a => a.GetType().Name == "DescriptionAttribute"); if (descriptionAttribute != null) host.WriteMessage(" " + descriptionAttribute.Description + "\n"); } host.WriteMessage("\nArguments: \n"); foreach (var property in commandType.GetRuntimeProperties()) { var argumentAttribute = property.GetCustomAttribute<ArgumentAttribute>(); if (argumentAttribute != null && !string.IsNullOrEmpty(argumentAttribute.Name)) { if (argumentAttribute.Position > 0) host.WriteMessage(" Argument Position " + argumentAttribute.Position + "\n"); else host.WriteMessage(" " + argumentAttribute.Name + "\n"); if (!string.IsNullOrEmpty(argumentAttribute.Description)) host.WriteMessage(" " + argumentAttribute.Description + "\n"); dynamic parameterDescriptionAttribute = property.GetCustomAttributes().SingleOrDefault(a => a.GetType().Name == "DescriptionAttribute"); if (parameterDescriptionAttribute != null) host.WriteMessage(" " + parameterDescriptionAttribute.Description + "\n"); } } }
public async Task<object> RunAsync(CommandLineProcessor processor, IConsoleHost host) { if (!string.IsNullOrEmpty(Input)) await ExecuteDocumentAsync(host, Input); else { if (DynamicApis.FileExists("nswag.json")) await ExecuteDocumentAsync(host, "nswag.json"); var files = DynamicApis.DirectoryGetFiles(DynamicApis.DirectoryGetCurrentDirectory(), "*.nswag"); if (files.Any()) { foreach (var file in files) await ExecuteDocumentAsync(host, file); } else host.WriteMessage("Current directory does not contain any .nswag files."); } return null; }
public IronPythonHost(IConsoleHost host) { Console = host; output = new MemoryStream(); output.SetLength(0); pyRuntime = Python.CreateRuntime(); pyRuntime.IO.SetOutput(output, Encoding.ASCII); pyEngine = Python.GetEngine(pyRuntime); pyScope = pyEngine.CreateScope(); ExecutePythonCode("import clr"); ExecutePythonCode("import Microsoft"); ExecutePythonCode("clr.AddReference(\"Microsoft.Xna.Framework\")"); ExecutePythonCode("import Microsoft.Xna.Framework"); ExecutePythonCode("import Microsoft.Xna.Framework.Graphics"); ExecutePythonCode("from Microsoft.Xna.Framework import *"); ExecutePythonCode("from Microsoft.Xna.Framework.Graphics import *"); SetVariable("_runtime", this); Console.Echo("[HOST] Using IRONPYTHON v2.7.1"); }
/// <summary>Gets the argument value.</summary> /// <param name="consoleHost">The command line host.</param> /// <param name="args">The arguments.</param> /// <param name="property">The property.</param> /// <returns>The value.</returns> public abstract object GetValue(IConsoleHost consoleHost, string[] args, PropertyInfo property);
public async Task<object> RunAsync(CommandLineProcessor processor, IConsoleHost host) { host.WriteMessage(string.Format("Clone {{ Repository={0}, Quiet={1} }}", Repository, Quiet)); return null; }
public TestConsoleChoicePromptHandler( IConsoleHost consoleHost, TaskCompletionSource<bool> promptShownTask) : base(consoleHost) { this.promptShownTask = promptShownTask; }
/// <summary> /// Creates a new instance of the ConsoleServicePSHost class /// with the given IConsoleHost implementation. /// </summary> /// <param name="consoleHost"> /// The IConsoleHost that will be used to perform host actions for this class. /// </param> public ConsoleServicePSHost(IConsoleHost consoleHost) { this.consoleHost = consoleHost; this.hostUserInterface = new ConsoleServicePSHostUserInterface(consoleHost); }
public virtual Task Attach(IConsoleHost host) { Host = host; return TaskEx.FromCompleted(); }
public HostDispatcher(IConsoleHost host, SynchronizationContext ownerContext) { _host = host; _ownerContext = ownerContext; }
/// <summary> /// Creates an instance of the ConsoleInputPromptHandler class. /// </summary> /// <param name="consoleHost"> /// The IConsoleHost implementation to use for writing to the /// console. /// </param> public ConsoleInputPromptHandler(IConsoleHost consoleHost) { this.consoleHost = consoleHost; }
async Task ListenForMessages() { this.messageLoopSyncContext = SynchronizationContext.Current; // Ensure that the console is using UTF-8 encoding System.Console.InputEncoding = Encoding.UTF8; System.Console.OutputEncoding = Encoding.UTF8; // Open the standard input/output streams this.inputStream = System.Console.OpenStandardInput(); this.outputStream = System.Console.OpenStandardOutput(); IMessageSerializer messageSerializer = null; IMessageProcessor messageProcessor = null; // Use a different serializer and message processor based // on whether this instance should host a language server // debug adapter. if (this.runDebugAdapter) { DebugAdapter debugAdapter = new DebugAdapter(); debugAdapter.Initialize(); messageProcessor = debugAdapter; messageSerializer = new V8MessageSerializer(); } else { // Set up the LanguageServer LanguageServer languageServer = new LanguageServer(); languageServer.Initialize(); messageProcessor = languageServer; messageSerializer = new JsonRpcMessageSerializer(); } // Set up the reader and writer this.messageReader = new MessageReader( this.inputStream, messageSerializer); this.messageWriter = new MessageWriter( this.outputStream, messageSerializer); // Set up the console host which will send events // through the MessageWriter this.consoleHost = new StdioConsoleHost(messageWriter); // Set up the PowerShell session this.editorSession = new EditorSession(); this.editorSession.StartSession(this.consoleHost); this.editorSession.PowerShellContext.OutputWritten += powerShellContext_OutputWritten; if (this.runDebugAdapter) { // Attach to debugger events from the PowerShell session this.editorSession.DebugService.DebuggerStopped += DebugService_DebuggerStopped; } // Run the message loop bool isRunning = true; while (isRunning) { Message newMessage = null; try { // Read a message from stdin newMessage = await this.messageReader.ReadMessage(); } catch (MessageParseException e) { // TODO: Write an error response Logger.Write( LogLevel.Error, "Could not parse a message that was received:\r\n\r\n" + e.ToString()); // Continue the loop continue; } // Process the message await messageProcessor.ProcessMessage( newMessage, this.editorSession, this.messageWriter); } }
public override async Task RunAsync(CommandLineProcessor processor, IConsoleHost host) { var output = await RunAsync(); WriteOutput(host, output); }
/// <summary>Runs the command.</summary> /// <param name="processor">The processor.</param> /// <param name="host">The host.</param> /// <returns>The output.</returns> public Task<object> RunAsync(CommandLineProcessor processor, IConsoleHost host) { host.WriteMessage("\nNSwag version: " + SwaggerDocument.ToolchainVersion + "\n"); host.WriteMessage("NJsonSchema version: " + JsonSchema4.ToolchainVersion + "\n"); return Task.FromResult<object>(null); }
public override Task<object> RunAsync(CommandLineProcessor processor, IConsoleHost host) { var schema = JsonSchema4.FromJson(InputJson); var generator = new CSharpGenerator(schema, Settings); var code = generator.GenerateFile(Name); if (TryWriteFileOutput(host, () => code) == false) return Task.FromResult<object>(code); return Task.FromResult<object>(null); }
public override async Task RunAsync(CommandLineProcessor processor, IConsoleHost host) { var settings = new CSharpGeneratorSettings { Namespace = Namespace, RequiredPropertiesMustBeDefined = RequiredPropertiesMustBeDefined, DateTimeType = DateTimeType }; var schema = JsonSchema4.FromJson(InputJson); var generator = new CSharpGenerator(schema, settings); var code = generator.GenerateFile(); WriteOutput(host, code); }