예제 #1
0
 public Result <object> FirstCommandCallback(ICommandHost host,
                                             IList <string> arguments,
                                             object executionResult)
 {
     host.Message(string.Concat(arguments));
     return(Result.Successful(null));
 }
예제 #2
0
        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);
                }
            }
        }
예제 #3
0
        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;
            }
        }
예제 #4
0
파일: Commands.cs 프로젝트: gmich/Gem
 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;
 }
예제 #6
0
 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)}...");
     }
 }
예제 #7
0
        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);
            }
        }
예제 #8
0
        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);
            }
        }
예제 #9
0
        /// <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;
        }
예제 #10
0
        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();
        }
예제 #11
0
 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);
     }
 }
예제 #12
0
파일: Commands.cs 프로젝트: gmich/Gem
 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"));
 }
예제 #13
0
파일: Commands.cs 프로젝트: gmich/Gem
 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"));
 }
예제 #14
0
파일: Commands.cs 프로젝트: gmich/Gem
 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"));
 }
예제 #15
0
파일: Commands.cs 프로젝트: gmich/Gem
 private Result <object> Rollback(ICommandHost host,
                                  IList <string> arguments,
                                  object executionResult)
 {
     return(Result.Failed("rolling back", 0d));
 }
예제 #16
0
 public ShellEvents(IBus bus, ICommandHost commandHost)
 {
     _bus = bus;
     _commandHost = commandHost;
 }
예제 #17
0
        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));
        }
예제 #18
0
파일: Commands.cs 프로젝트: gmich/Gem
 private Result <object> Subtract(ICommandHost host,
                                  IList <string> arguments,
                                  object executionResult)
 {
     return(ParseCommand(arguments, executionResult, (res, arg) => res - arg));
 }
예제 #19
0
        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!");
        }
예제 #20
0
 public CommandServer(ICommandHost host)
 {
     _host = host;
 }
예제 #21
0
파일: Commands.cs 프로젝트: gmich/Gem
 private Result <object> SubCommandCallback(ICommandHost host,
                                            IList <string> arguments,
                                            object executionResult)
 {
     return(Result.Successful(null));
 }
예제 #22
0
 public ShellEvents(IBus bus, ICommandHost commandHost)
 {
     _bus         = bus;
     _commandHost = commandHost;
 }