private void RunCommandsFromParser(CommandStringParser parser) { CommandExecutionContext context = new CommandExecutionContext(); foreach (string cmdString in parser.Parse()) { Command parsedCmd = null; string errorDescr; bool valid = parser.ParseCommand(cmdString, false, out parsedCmd, out errorDescr); if (valid) { context.Parsed(cmdString, parsedCmd); } else { // forward parse error to hooks foreach (CommandHook hook in m_hooks) { hook.ParseError(cmdString, errorDescr); } // we can not execute this command continue; } } context.SetLabels(); context.ExecuteAll(); }
// Wrapper=false to keek CommandTrace updates protected override void DoCommandAction() { // internal bool exists = Objects.VariableManager.Instance.IsSet(Variable); // environement string value = Environment.GetEnvironmentVariable(Variable); if (value != null) { exists = true; } CommandStringParser parser = new CommandStringParser(exists ? Then : Else); foreach (string cmdString in parser.Parse()) { Command cmd = null; string errorDescr = ""; parser.ParseCommand(cmdString, true, out cmd, out errorDescr); // only the alias it self shall appear in the command trace cmd.UpdateCommandTrace = false; CommandExecuter.Instance.Execute(cmd); } }
protected override void DoCommandAction() { try { Regex.IsMatch(Filter, ""); } catch (Exception error) { throw new ArgumentException("No valid regular expression given: " + Filter + " " + error.Message); } foreach (Type type in CommandStringParser.GetAllCommandTypes().Where(t => string.IsNullOrEmpty(Filter) ? true : Regex.IsMatch(t.Name, Filter)).OrderBy(t => t.Name)) { OutputManager.WriteOutput(type.Name); } }
protected override void DoCommandAction() { CommandStringParser parser = new CommandStringParser(Commands); foreach (string cmdString in parser.Parse()) { Command cmd = null; string errorDescr = ""; parser.ParseCommand(cmdString, true, out cmd, out errorDescr); // only the alias it self shall appear in the command trace cmd.UpdateCommandTrace = false; string errorDescription = ""; parser.SetParamters(cmd, true, m_overriddenDefaults, ref errorDescription); CommandExecuter.Instance.Execute(cmd); } }
/// <summary> /// No labels here!! /// </summary> public void ExecuteWithOutContext(string commandString) { CommandStringParser parser = new CommandStringParser(commandString); foreach (string cmdString in parser.Parse()) { Command parsedCmd = null; string errorDescr; bool valid = parser.ParseCommand(cmdString, true, out parsedCmd, out errorDescr); if (valid) { Execute(parsedCmd); } else { throw new ArgumentException(errorDescr); } } }
public List <string> ReadCommandFile(string commandFile) { List <string> commandString = new List <string>(); FileStream fs = File.OpenRead(commandFile); byte[] byteBuffer = new byte[fs.Length]; int length = Convert.ToInt32(fs.Length); fs.Read(byteBuffer, 0, length); fs.Close(); CommandStringParser parser = new CommandStringParser(byteBuffer, length); foreach (string cmd in parser.Parse()) { commandString.Add(cmd); } return(commandString); }
protected override void DoCommandAction() { Dictionary <string, int> cmds = new Dictionary <string, int>(); TextReader tr = new StreamReader(CommandCoverageFile); string line = ""; while ((line = tr.ReadLine()) != null) { string[] atoms = Regex.Split(line, ";"); string cmdName = atoms[0]; int cmdCount = int.Parse(atoms[1]); cmds[cmdName] = cmdCount; } tr.Close(); foreach (Type type in CommandStringParser.GetAllCommandTypes().Where(t => !cmds.ContainsKey(t.Name)).OrderBy(t => t.Name)) { OutputManager.WriteOutput("Command " + type.Name + " is uncovered"); } }
protected override void DoCommandAction() { foreach (Type type in CommandStringParser.GetAllCommandTypes().OrderBy(t => t.Name)) { Command command = (Command)Activator.CreateInstance(type); if (!command.PublishCommand) { continue; } string helpFile = command.GetHelpFilePath(); if (!File.Exists(helpFile)) { OutputManager.WriteOutput("Creating " + helpFile); File.Create(helpFile); } else { OutputManager.WriteOutput("File " + helpFile + " already exists"); } } }
protected override void DoCommandAction() { ExpressionParser ep = new ExpressionParser(); int evaluationResult = 0; bool valid = ep.Evaluate(Condition, out evaluationResult); if (!valid) { throw new ArgumentException("Condition" + Condition + " is not a valid arithmetic expression"); } CommandStringParser parser = new CommandStringParser(evaluationResult != 0 ? Then : Else); foreach (string cmdString in parser.Parse()) { Command cmd = null; string errorDescr = ""; parser.ParseCommand(cmdString, true, out cmd, out errorDescr); // only the alias it self shall appear in the command trace cmd.UpdateCommandTrace = false; CommandExecuter.Instance.Execute(cmd); } }
protected override void DoCommandAction() { SortedDictionary <string, string> parameters = new SortedDictionary <string, string>(); foreach (Type type in CommandStringParser.GetAllCommandTypes()) { foreach (FieldInfo fi in type.GetFields()) { // find ParamterField attr foreach (object obj in fi.GetCustomAttributes(true)) { if (obj is Parameter && !parameters.ContainsKey(fi.Name)) { parameters.Add(fi.Name, fi.Name); } } } } foreach (string s in parameters.Keys) { OutputManager.WriteOutput(s); } }
protected override void DoCommandAction() { foreach (Type type in CommandStringParser.GetAllCommandTypes().OrderBy(t => t.Name)) { // create instance to get default value Command cmd = (Command)Activator.CreateInstance(type); bool commandDescriptionFound = false; foreach (Attribute attr in Attribute.GetCustomAttributes(type).Where(a => a is CommandDescription)) { CommandDescription descr = (CommandDescription)attr; if (!string.IsNullOrEmpty(descr.Description)) { commandDescriptionFound = true; break; } } if (!commandDescriptionFound) { OutputManager.WriteOutput(type.Name + " has no Command Description"); } } }
public void Execute(string commandString) { CommandStringParser parser = new CommandStringParser(commandString); RunCommandsFromParser(parser); }
public void Execute(FileInfo fi) { CommandStringParser parser = new CommandStringParser(fi); RunCommandsFromParser(parser); }