/// <summary> /// process script data from parser /// </summary> protected override void ProcessData() { base.ProcessData(); foreach (SourceLine line in Parser.Lines) { if (line.ColumnCount > 0) { ActionLine actLine = new ActionLine(); actLine.ActionName = line.Columns[0].ToLower(); for (int i = 1; i < line.ColumnCount; i++) { string[] pairs = line.Columns[i].Split(Constants.PropertyDelimeter.ToCharArray(), 2); if (pairs.Length != 2) throw new FormatException(Constants.Messages.Error_Parsing_Script); if (Constants.KeywordWindow.Equals(pairs[0], StringComparison.CurrentCultureIgnoreCase)) actLine.WindowName = pairs[1].ToLower(); else if (Constants.KeywordControl.Equals(pairs[0], StringComparison.CurrentCultureIgnoreCase)) actLine.ControlName = pairs[1].ToLower(); else actLine.Arguments[pairs[0].ToLower()] = pairs[1]; } ActionLines.Add(actLine); } } }
/// <summary> /// process script data from parser /// </summary> protected override void ProcessData() { base.ProcessData(); foreach (SourceLine line in Parser.Lines) { if (line.ColumnCount > 0) { ActionLine actLine = new ActionLine(); actLine.ActionName = line.Columns[0].ToLower(); for (int i = 1; i < line.ColumnCount; i++) { string[] pairs = line.Columns[i].Split(Constants.PropertyDelimeter.ToCharArray(), 2); if (pairs.Length != 2) { throw new FormatException(Constants.Messages.Error_Parsing_Script); } if (Constants.KeywordWindow.Equals(pairs[0], StringComparison.CurrentCultureIgnoreCase)) { actLine.WindowName = pairs[1].ToLower(); } else if (Constants.KeywordControl.Equals(pairs[0], StringComparison.CurrentCultureIgnoreCase)) { actLine.ControlName = pairs[1].ToLower(); } else { actLine.Arguments[pairs[0].ToLower()] = pairs[1]; } } ActionLines.Add(actLine); } } }
/// <summary> /// get corresponding Action object from all Action Managers /// </summary> /// <param name="actLine">the action line</param> /// <returns>the found action</returns> private Action getAction(ActionLine actLine) { int i = 0; Action action = null; while (action == null && i < ActionManagers.Count) { action = ActionManagers[i++].getAction(actLine); } return(action); }
/// <summary> /// create an action for the line /// </summary> /// <param name="actLine">the action line</param> /// <returns>the action</returns> public abstract Action getAction(ActionLine actLine);
/// <summary> /// get corresponding Action object from all Action Managers /// </summary> /// <param name="actLine">the action line</param> /// <returns>the found action</returns> private Action getAction(ActionLine actLine) { int i = 0; Action action = null; while (action == null && i < ActionManagers.Count) action = ActionManagers[i++].getAction(actLine); return action; }
/// <summary> /// execute the script /// </summary> private void Run() { IReporter reporter = Reporter.NewInstance; reporter.BeginReport("path"); while (Scripts.Count > 0) { CurrentScript = Scripts.Pop(); // begin new section in report if (CurrentScript.CurrentLineNumber == 0) { reporter.BeginScript(CurrentScript.Name); } // loop for each line of current script while (CurrentScript.HasNextLine) { ActionLine actLine = CurrentScript.Next(); if (actLine.ActionName == Constants.ActionUseInterface) { Interface newInterface = new Interface(Parser.NewInstance); newInterface.FileName = actLine.Arguments[Constants.KeywordInterface] + Parser.FileExtension; Interfaces.Add(newInterface.Name, newInterface); } else if (actLine.ActionName == Constants.ActionStartScript) { Script newScript = new Script(Parser.NewInstance); newScript.FileName = actLine.Arguments[Constants.KeywordScript] + Parser.FileExtension; Scripts.Push(CurrentScript); CurrentScript = newScript; // begin new section in report reporter.BeginScript(CurrentScript.Name); } else { Action action = getAction(actLine); if (action == null) { throw new InvalidOperationException("No action named '" + actLine.ActionName + "'"); } if (!action.IsValid()) { throw new InvalidOperationException("Invalid arguments for action named '" + actLine.ActionName + "'"); } int ret = action.Execute(); action.Reset(); // write result of executing to report reporter.WriteLine(); } } // end section in report if (CurrentScript.CurrentLineNumber > 0) { reporter.EndScript(); } } }