Example #1
0
 public void ProcessCommandOn(List<HostAction> actions, Command com)
 {
     var acts = from act in actions
             where act.Name.ToLowerInvariant () == com.Name.ToLowerInvariant ()
         select act;
     foreach (var act in acts)
         act.Run (com.Source, com.Args);
 }
Example #2
0
 /// <summary>
 /// Parses the specified command.
 /// </summary>
 /// <param name="com">The command.</param>
 /// <param name="source">The source.</param> 
 public static Command Parse(string com, IUpstream source = null)
 {
     var command = new Command ();
     command.Source = source;
     com = com.Trim ();
     if (com.Contains (" ")) {
         command.Name = new string (com.TakeWhile (c => c != ' ').ToArray ());
         var argstr = new string (com.Skip (com.IndexOf (' ') + 1).ToArray ());
         var accum = new StringBuilder ();
         var i = 0;
         var awaitquote = false;
         var lst = new List<string> ();
         while (i < argstr.Length) {
             if (argstr [i] == '"' && awaitquote) {
                 i++;
                 awaitquote = false;
             } else if (argstr [i] == '"' && !awaitquote) {
                 i++;
                 awaitquote = true;
             }
             if (i == argstr.Length)
                 break;
             if (argstr [i] == ' ' && !awaitquote) {
                 lst.Add (accum.ToString ());
                 accum.Clear ();
             } else {
                 accum.Append (argstr [i]);
             }
             ++i;
         }
         lst.Add (accum.ToString ());
         command.Args = lst.ToArray ();
     } else {
         command.Name = com;
         command.Args = new string[0];
     }
     return command;
 }
Example #3
0
 public void ProcessCommand(Command com)
 {
     ProcessCommandOn (actions, com);
 }