private void PopulateBasicCommandInfo(StringBuilder sb) { var help = new CommentStore(); help.ReadComments(Environment.CurrentDirectory); // Basic info about command sb.AppendLine("Name: " + _commandType.Name); var helpText = help.GetTypeDocumentationIfExists(_commandType); if (helpText != null) { sb.AppendLine(); sb.AppendLine("Description: " + helpText); } sb.AppendLine(); sb.AppendLine("USAGE: "); sb.Append(EnvironmentInfo.IsLinux ? "./rdmp" : "./rdmp.exe"); sb.Append(" cmd "); sb.Append(BasicCommandExecution.GetCommandName(_commandType.Name)); sb.Append(" "); }
public int Run(IRDMPPlatformRepositoryServiceLocator repositoryLocator, IDataLoadEventListener listener, ICheckNotifier checkNotifier, GracefulCancellationToken token) { _input = new ConsoleInputManager(repositoryLocator, checkNotifier); _listener = listener; _invoker = new CommandInvoker(_input); _invoker.CommandImpossible += (s, c) => Console.WriteLine($"Command Impossible:{c.Command.ReasonCommandImpossible}"); _invoker.CommandCompleted += (s, c) => Console.WriteLine("Command Completed"); _commands = _invoker.GetSupportedCommands().ToDictionary( k => BasicCommandExecution.GetCommandName(k.Name), v => v, StringComparer.CurrentCultureIgnoreCase); _picker = _options.CommandArgs != null && _options.CommandArgs.Any() ? new CommandLineObjectPicker(_options.CommandArgs, repositoryLocator) : null; if (string.IsNullOrWhiteSpace(_options.CommandName)) { RunCommandExecutionLoop(repositoryLocator); } else { RunCommand(_options.CommandName); } return(0); }
public RunUI(IActivateItems activator) : base(activator) { InitializeComponent(); _commandsDictionary = new Dictionary <string, Type>(StringComparer.CurrentCultureIgnoreCase); _argsDictionary.Add(typeof(IActivateItems), () => activator); _commandCaller = new CommandInvoker(activator); _commandCaller.CommandImpossible += (s, e) => MessageBox.Show(e.Command.ReasonCommandImpossible); _commandCaller.CommandCompleted += (s, e) => this.Close(); var commands = _commandCaller.GetSupportedCommands(); foreach (var c in commands) { var name = BasicCommandExecution.GetCommandName(c.Name); if (!_commandsDictionary.ContainsKey(name)) { _commandsDictionary.Add(name, c); } } comboBox1.Items.AddRange(_commandsDictionary.Keys.ToArray()); }
private void DataGridView1OnCellMouseClick(object sender, DataGridViewCellMouseEventArgs e) { if (e.RowIndex == -1) { return; } if (e.Button == MouseButtons.Right) { var menu = new ContextMenuStrip(); foreach (BasicCommandExecution cmd in GetCommands(e.RowIndex)) { BasicCommandExecution cmd1 = cmd; var mi = new ToolStripMenuItem(cmd.GetCommandName(), null, (s, x) => cmd1.Execute()); menu.Items.Add(mi); } if (menu.Items.Count != 0) { menu.Items.Add(new ToolStripSeparator()); } menu.Items.Add("View as text", null, (s, ex) => WideMessageBox.Show("Full Text", dataGridView1.Rows[e.RowIndex])); menu.Show(Cursor.Position.X, Cursor.Position.Y); } }
public override void Execute() { var commandCaller = new CommandInvoker(BasicActivator); string commands = string.Join(Environment.NewLine, commandCaller.GetSupportedCommands() .Select(t => BasicCommandExecution.GetCommandName(t.Name)) .OrderBy(s => s)); BasicActivator.Show(commands); base.Execute(); }
public int Run(IRDMPPlatformRepositoryServiceLocator repositoryLocator, IDataLoadEventListener listener, ICheckNotifier checkNotifier, GracefulCancellationToken token) { _input = new ConsoleInputManager(repositoryLocator, checkNotifier); // if there is a single command we are running then disable user input // but allow it if the input is ./rdmp cmd (i.e. run in a loop prompting for commands) _input.DisallowInput = !string.IsNullOrWhiteSpace(_options.CommandName); _listener = listener; _invoker = new CommandInvoker(_input); _invoker.CommandImpossible += (s, c) => Console.WriteLine($"Command Impossible:{c.Command.ReasonCommandImpossible}"); _invoker.CommandCompleted += (s, c) => Console.WriteLine("Command Completed"); _commands = _invoker.GetSupportedCommands().ToDictionary( k => BasicCommandExecution.GetCommandName(k.Name), v => v, StringComparer.CurrentCultureIgnoreCase); _picker = _options.CommandArgs != null && _options.CommandArgs.Any() ? new CommandLineObjectPicker(_options.CommandArgs, _input) : null; if (!string.IsNullOrWhiteSpace(_options.File) && _options.Script == null) { throw new Exception("Command line option File was provided but Script property was null. The host API failed to deserialize the file or correctly use the ExecuteCommandOptions class"); } if (_options.Script != null) { RunScript(_options.Script, repositoryLocator); } else if (string.IsNullOrWhiteSpace(_options.CommandName)) { RunCommandExecutionLoop(repositoryLocator); } else { RunCommand(_options.CommandName); } return(0); }
private void Run() { var commandInvoker = new CommandInvoker(_activator); commandInvoker.CommandImpossible += (o, e) => { _activator.Show("Command Impossible because:" + e.Command.ReasonCommandImpossible); }; var commands = commandInvoker.GetSupportedCommands(); var dlg = new ConsoleGuiBigListBox <Type>("Choose Command", "Run", true, commands.ToList(), (t) => BasicCommandExecution.GetCommandName(t.Name), false); if (dlg.ShowDialog()) { try { commandInvoker.ExecuteCommand(dlg.Selected, null); } catch (Exception exception) { _activator.ShowException("Run Failed", exception); } } }
private void RunCommand(string command) { if (_commands.ContainsKey(command)) { _invoker.ExecuteCommand(_commands[command], _picker); } else { _listener.OnNotify(this, new NotifyEventArgs(ProgressEventType.Error, $"Unknown or Unsupported Command '{command}', use {BasicCommandExecution.GetCommandName<ExecuteCommandListSupportedCommands>()} to see available commands")); } }
private void RunCommand(string command) { if (_commands.ContainsKey(command)) { _invoker.ExecuteCommand(_commands[command], _picker); } else { var suggestions = _commands.Keys.Where(c => CultureInfo.CurrentCulture.CompareInfo.IndexOf(c, command, CompareOptions.IgnoreCase) >= 0).ToArray(); StringBuilder msg = new StringBuilder($"Unknown or Unsupported Command '{command}', use {BasicCommandExecution.GetCommandName<ExecuteCommandListSupportedCommands>()} to see available commands"); if (suggestions.Any()) { msg.AppendLine("Similar commands include:" + Environment.NewLine + string.Join(Environment.NewLine, suggestions)); } _listener.OnNotify(this, new NotifyEventArgs(ProgressEventType.Error, msg.ToString())); } }
public override void Execute() { base.Execute(); var invoker = new CommandInvoker(BasicActivator); var commandCtor = invoker.GetConstructor(_commandType); var help = new CommentStore(); help.ReadComments(Environment.CurrentDirectory); var sb = new StringBuilder(); if (commandCtor == null || !invoker.IsSupported(commandCtor)) { sb.AppendLine($"Command '{_commandType.Name}' is not supported by the current input type ({BasicActivator.GetType().Name})"); } else { sb.AppendLine("COMMAND:" + _commandType.FullName); var helpText = help.GetTypeDocumentationIfExists(_commandType); if (helpText != null) { sb.AppendLine(helpText); } sb.AppendLine("USAGE:"); sb.Append(EnvironmentInfo.IsLinux ? "./rdmp" : "./rdmp.exe"); sb.Append(" cmd "); sb.Append(BasicCommandExecution.GetCommandName(_commandType.Name)); sb.Append(" "); var sbParameters = new StringBuilder(); sbParameters.AppendLine("PARAMETERS:"); foreach (ParameterInfo p in commandCtor.GetParameters()) { var req = new RequiredArgument(p); //automatic delegates require no user input or CLI entry (e.g. IActivateItems) if (invoker.GetDelegate(req).IsAuto) { continue; } sb.Append($"<{req.Name}> "); sbParameters.AppendLine($"{req.Name}\t{req.Type.Name}\t{req.DemandIfAny?.Description}"); } sb.AppendLine(); sb.AppendLine(sbParameters.ToString()); } BasicActivator.Show(sb.ToString()); }