public Result <object> FirstCommandCallback(ICommandHost host, IList <string> arguments, object executionResult) { host.Message(string.Concat(arguments)); return(Result.Successful(null)); }
public async Task PrintHelp(ICommandHost host) { if (!string.IsNullOrWhiteSpace(host.HelpText)) { var lines = Regex.Split(host.HelpText, "\r\n|\r|\n"); foreach (var line in lines) { await host.WriteLine(line.Trim()); await Task.Delay(100); } } else { var knownCommands = new List <string> { "help", "files.list", "files.open", "mails.list", "mails.open", "connect" }; await host.WriteLine("known commands:".Pastel(Color.Gray)); foreach (var command in knownCommands) { await host.WriteLine(command); } } }
public async Task Execute(ICommandHost host, string?json) { object?parameter; if (string.IsNullOrWhiteSpace(json) || ParameterType == null) { parameter = null; } else { parameter = JsonConvert.DeserializeObject(json, ParameterType); } var parameters = new List <object?> { host }; if (ParameterCount == 2) { parameters.Add(parameter); } if (Method.Invoke(Instance, parameters.ToArray()) is Task task) { await task; } }
private Result <object> Divide(ICommandHost host, IList <string> arguments, object executionResult) { //check if argument==0 return(ParseCommand(arguments, executionResult, (res, arg) => res / arg)); }
/// <summary> /// Setup constructor /// </summary> /// <param name="mainForm">The form to add a menu to</param> /// <param name="commandHost">This command host is used to execute commands for all menu items managed by this service</param> public MenuService( Form mainForm, ICommandHost commandHost ) { Arguments.CheckNotNull( mainForm, "mainForm" ); Arguments.CheckNotNull( commandHost, "commandHost" ); m_Form = mainForm; m_CommandHost = commandHost; }
public async Task CreateUser(ICommandHost host, CreateUserParameters?parameters) { if (parameters?.Name == null) { await host.WriteLine($"Usage: user.create {"{ name: \"userName\"}".Pastel(Color.Aquamarine)}..."); } else { await host.WriteLine($"Creating User {parameters.Name?.Pastel(Color.Aquamarine)}..."); } }
private async Task ParseSequence(ICommandHost host, Data.File file) { var reader = new StreamReader($"./config/{file.Sequence}"); var deserializer = new DeserializerBuilder() .WithNamingConvention(CamelCaseNamingConvention.Instance) .Build(); var parser = new Parser(reader); parser.Consume <StreamStart>(); string?speaker = null; string speakerColor = "68C355"; bool isNewLine = true; while (parser.Accept <DocumentStart>(out _)) { var step = deserializer.Deserialize <SequenceStep>(parser); if (step.Speaker != null) { speaker = step.Speaker; } if (step.SpeakerColor != null) { speakerColor = step.SpeakerColor; } if (!string.IsNullOrWhiteSpace(speaker) && isNewLine) { await host.Write($"{speaker}: ".Pastel(speakerColor)); } foreach (var c in step.Text) { await host.Write(c.ToString().Pastel(step.Color)); await Task.Delay(1000 / step.Speed); } //await host.Write(step.Text.Pastel(step.Color)); if (step.LineBreak) { isNewLine = true; await host.WriteLine(); } else { isNewLine = false; } await Task.Delay(step.Delay); } }
public async Task ListMails(ICommandHost host) { var id = 0; await host.WriteLine($"ID\t\t{"Date".PadRight(15)}\t\t\t{"From".PadRight(50)}\t\tSubject"); foreach (var mail in host.Mails) { await host.WriteLine($"[{id++.ToString().Pastel(Color.Coral)}]\t{mail.Timestamp.ToString("yyyy-MMM-dd ddd").Pastel(Color.Azure)}\t\t\t{mail.From.PadRight(50).Pastel(Color.Aqua)}\t\t{mail.Subject}"); await Task.Delay(200); } }
/// <summary> /// Setup constructor /// </summary> /// <param name="commandHost">Command host. Used to execute commands from items in this group and sub groups</param> /// <param name="item">Tool strip item that this group is bound to</param> /// <param name="groupInfo">Group information</param> public MenuGroup( ICommandHost commandHost, ToolStripMenuItem item, MenuGroupInfo groupInfo ) { Arguments.CheckNotNull( commandHost, "commandHost" ); Arguments.CheckNotNull( item, "item" ); Arguments.CheckNotNull( groupInfo, "groupInfo" ); m_CommandHost = commandHost; m_Ordinal = groupInfo.Ordinal; m_Item = item; item.Tag = this; item.Text = groupInfo.Text; item.Name = groupInfo.Name; }
public async Task OpenMail(ICommandHost host, OpenMailParameters?parameters) { if (parameters?.Id == null) { await host.WriteLine($"Usage: mails.open {"{ id: 0}".Pastel(Color.Aquamarine)}..."); return; } var mails = host.Mails.ToList(); if (mails.Count <= parameters.Id || parameters.Id < 0) { await host.WriteLine($"Invalid ID {parameters.Id}".Pastel(Color.Red)); return; } var mail = mails[parameters.Id.Value]; await host.WriteLine($"Date: {mail.Timestamp}".Pastel(Color.Gray)); await Task.Delay(100); await host.WriteLine($"From: {mail.From}".Pastel(Color.Gray)); await Task.Delay(100); await host.WriteLine($"To: {mail.To}".Pastel(Color.Gray)); await Task.Delay(100); await host.WriteLine($"Subject: {mail.Subject}".Pastel(Color.Coral)); await Task.Delay(100); await host.WriteLine(); await Task.Delay(100); var lines = Regex.Split(mail.Text, "\r\n|\r|\n"); foreach (var line in lines) { await host.WriteLine(line.Trim()); await Task.Delay(100); } await host.WriteLine(); }
public async Task List(ICommandHost host) { foreach (var file in host.Files) { if (file.Passwords == null || !file.Passwords.Any()) { await host.WriteLine($" {file.Name}"); } else { await host.WriteLine($"🔒 {file.Name}"); } await Task.Delay(200); } }
public Result <object> ConsoleWriteCallback(ICommandHost host, IList <string> arguments, object executionResult) { if (arguments.Count == 1) { System.Console.WriteLine(arguments[0]); return(Result.Successful(null)); } else if (executionResult != null) { System.Console.WriteLine(executionResult); } return(Result.Failed("Wrong number of arguments")); }
private Result <object> FirstCommandCallback(ICommandHost host, IList <string> arguments, object executionResult) { if (arguments.Count == 1) { Number = Double.Parse(arguments[0]); return(Result.Successful(Number)); } else if (executionResult != null) { Number += (double)executionResult; return(Result.Successful(Number)); } return(Result.Failed("Wrong number of arguments")); }
private Result <object> Calculate(ICommandHost host, IList <string> arguments, object executionResult) { if (arguments.Count == 1) { return(ParseString(arguments[0])); } else if (executionResult != null) { double result; try { result = Convert.ToDouble(executionResult); return(Result.Successful(result)); } catch (Exception ex) { Result.Failed("Invalid argument " + ex.Message); } } return(Result.Failed("Wrong number of arguments")); }
private Result <object> Rollback(ICommandHost host, IList <string> arguments, object executionResult) { return(Result.Failed("rolling back", 0d)); }
public ShellEvents(IBus bus, ICommandHost commandHost) { _bus = bus; _commandHost = commandHost; }
public async Task Open(ICommandHost host, FilesOpenParameters?parameters) { if (string.IsNullOrWhiteSpace(parameters?.File)) { await host.WriteLine($"Usage: files.open {"{ file: \"fileName\"}".Pastel(Color.Aquamarine)}..."); return; } var file = host.Files.FirstOrDefault(f => f.Name == parameters.File); if (file == null) { await host.WriteLine($"File {parameters.File} not found!".Pastel(Color.Red)); return; } if (file.Passwords != null && file.Passwords.Any()) { if (string.IsNullOrWhiteSpace(parameters.Password)) { await host.WriteLine("Missing parameter \"password\"".Pastel(Color.Red)); await host.WriteLine($"Usage: files.open {"{ file: \"fileName\", password:\"password\"}".Pastel(Color.Aquamarine)}..."); return; } if (!file.Passwords.Contains(parameters.Password)) { await host.WriteLine("Invalid password!".Pastel(Color.Red)); return; } } if (!string.IsNullOrWhiteSpace(file.Text)) { var lines = Regex.Split(file.Text, "\r\n|\r|\n"); foreach (var line in lines) { await host.WriteLine(line.Trim()); await Task.Delay(100); } //await host.WriteLine(file.Text); return; } if (!string.IsNullOrWhiteSpace(file.YouTube)) { await host.OpenYouTube(file.YouTube); return; } if (!string.IsNullOrWhiteSpace(file.Sequence) && File.Exists($"./config/{file.Sequence}")) { await ParseSequence(host, file); return; } await host.WriteLine($"File {parameters.File} is empty.".Pastel(Color.Yellow)); }
private Result <object> Subtract(ICommandHost host, IList <string> arguments, object executionResult) { return(ParseCommand(arguments, executionResult, (res, arg) => res - arg)); }
public async Task Connect(ICommandHost host, ConnectCommandParameters?parameters) { if (parameters?.Host == null) { await host.WriteLine($"Usage: connect {"{ host: \"hostname\"}".Pastel(Color.Aquamarine)}..."); return; } var h = host.GetHost(parameters.Host); if (h == null) { await host.WriteLine($"Unknown host {parameters.Host}".Pastel(Color.Red)); return; } await host.Write($"Establishing connection to {parameters.Host.Pastel(Color.Aquamarine)}..."); await Task.Delay(500); if (h.Users != null && h.Users.Any()) { if (string.IsNullOrWhiteSpace(parameters.User)) { await host.WriteLine(); await host.WriteLine("Missing parameter \"user\"".Pastel(Color.Red)); await host.WriteLine($"Usage: connect {"{ host: \"hostname\", user: \"username\"}".Pastel(Color.Aquamarine)}..."); return; } var user = h.Users.FirstOrDefault(u => u.UserName == parameters.User); if (user == null) { await host.WriteLine(); await host.WriteLine($"Unknown user {parameters.User}".Pastel(Color.Red)); return; } if (user.Passwords != null && user.Passwords.Any()) { if (string.IsNullOrWhiteSpace(parameters.Password)) { await host.WriteLine(); await host.WriteLine("Missing parameter \"password\"".Pastel(Color.Red)); await host.WriteLine($"Usage: connect {"{ host: \"hostname\", user: \"username\", password: \"password\"}".Pastel(Color.Aquamarine)}..."); return; } if (!user.Passwords.Contains(parameters.Password)) { await host.WriteLine(); await host.WriteLine("Invalid password".Pastel(Color.Red)); return; } } host.CurrentUser = user.UserName; } else { host.CurrentUser = null; } host.CurrentHost = parameters.Host; await host.WriteLine(" connected!"); }
public CommandServer(ICommandHost host) { _host = host; }
private Result <object> SubCommandCallback(ICommandHost host, IList <string> arguments, object executionResult) { return(Result.Successful(null)); }