Exemplo n.º 1
0
 public ScriptError(Script script, ScriptProcedure procedure, string message) {
     _script = script;
     _proc_item = procedure;
     _message.Append(message.CleanEnd());
     if(script != null)
         _script.Succeed = false;
 }
Exemplo n.º 2
0
        /// <summary>Recursive methode to read and format a script and the refered scripts defined in the #Include statement.</summary>
        /// <param name="par_script">Parent script used in recurtion call</param>
        /// <param name="par_line_number">Parent line number used in recurtion call</param>
        /// <param name="par_lien_of_code">Parent line of code used in recurtion call</param>
        /// <returns>A list of scripts</returns>
        private void FormatScript(Script par_script, int par_line_number) {

            this.TextFormated = this.TextOriginal;
            this.ParentScript = par_script;
            this.ParentLineNumber = par_line_number;

            //Handle includes
            Match match_inc = Regex.Match(this.TextFormated, @"^#Include ""([^""]+)""", RegexOptions.Multiline);
            while (match_inc.Success) {
                this.ChildenScripts = new List<Script>();
                var inc_path = match_inc.Groups[1].Value;
                var inc_line_number = this.TextFormated.GetLineNumber(match_inc);
                foreach (var child_script_path in Utils.ExpandFilePaths(new string[] { inc_path }, ".vbs", this.Directory)) {
                    this.ChildenScripts.Add(new Script(child_script_path, this, inc_line_number));
                }
                match_inc = match_inc.NextMatch();
            }
            this.TextFormated = this.TextFormated.RemoveAll(@"^#Include[^\r\n]*");

            //Handle Console prints
            this.TextFormated = Regex.Replace(this.TextFormated, @"Debug\.Print", @"Wscript.Echo", RegexOptions.Multiline | RegexOptions.IgnoreCase);
            if (par_script == null) {
                //Format CreateObject
                this.TextFormated = Regex.Replace(this.TextFormated, @"Wscript.CreateObject", @"CreateObject", RegexOptions.IgnoreCase);

                //Format Arguments
                this.TextFormated = Regex.Replace(this.TextFormated, @"Wscript\.Arguments\(", @"Wscript.Arguments.Item(", RegexOptions.IgnoreCase);
                //Replace param
                if (this.Param != null)
                    this.TextFormated = Regex.Replace(this.TextFormated, @"\@\bparam\b", this.Param, RegexOptions.IgnoreCase);
                    //this.TextFormated = Regex.Replace(this.TextFormated, @"(\.Start.)""\w+""", "$1\"" + this.Param + "\"", RegexOptions.IgnoreCase);
                //Replace the wrapper instantiation if it's called using "New"
                this.TextFormated = Regex.Replace(this.TextFormated, @"Set ([\w_-]+) = New (SeleniumWrapper\.\w+)", @"Set $1 = CreateObject(""$2"")", RegexOptions.Multiline | RegexOptions.IgnoreCase);
                this.TextFormated = Regex.Replace(this.TextFormated, @"Dim ([\w_-]+) As New (SeleniumWrapper\.\w+)", @"Set $1 = CreateObject(""$2"")", RegexOptions.Multiline | RegexOptions.IgnoreCase);
                
                //Handles With
                var matches_with = Regex.Matches(this.TextFormated, (@"^\[With\((.*)\)\]\s+(Private |Public )?Sub ([\w_]+)"), RegexOptions.IgnoreCase | RegexOptions.Multiline);
                this.ProceduresParams = new Dictionary<string, ProcedureStringParams>(matches_with.Count);
                foreach (Match match in matches_with) {
                    ProceduresParams.Add( match.Groups[3].Value, new ProcedureStringParams{ 
                        Params = match.Groups[1].Value.Trim('\r', '\n', ' '),
                        Line = this.TextFormated.CountLines(0, match.Index)
                    });
                }
                this.TextFormated = this.TextFormated.ReplaceAll(@"^\[With\((.*)\)\]", "");
            }
        }
Exemplo n.º 3
0
 internal void AddTraceLine(Script script, int line_number) {
     StackTrace.Add(new TraceLine(script, line_number));
 }
Exemplo n.º 4
0
 public ScriptError(Script script, ProcedureItem procedure, string err_message)
     : base(script, procedure) {
     StackTrace = new List<TraceLine>();
     Message = err_message.CleanEnd();
     Information = string.Empty;
 }
Exemplo n.º 5
0
 public ScriptSuccess(Script script, ScriptProcedure procedure = null) {
     _script = script;
     _procedure = procedure;
 }
Exemplo n.º 6
0
 internal void AddTrace(Script script, int line_number) {
     var traceline = new TraceLine(script, line_number);
     _stack_trace.Add(traceline);
 }
Exemplo n.º 7
0
 private Script(string script_path, Script parent_script, int parent_line_number)
     : this(script_path) {
     FormatScript(parent_script, parent_line_number);
 }
Exemplo n.º 8
0
 private TraceLine GetTraceLineAt_recursive(int line_number, Script script, Integer line) {
     if (script.ChildenScripts != null) {
         foreach (var child_script in script.ChildenScripts) {
             var trace_line = GetTraceLineAt_recursive(line_number, child_script, line);
             if (trace_line != null)
                 return trace_line;
         }
     }
     if (line.Value - script.LineCount <= 0)
         return new TraceLine(script, line.Value);
     line.Value -= script.LineCount + 1;
     return null;
 }
Exemplo n.º 9
0
 private string GetTextCode_recursive(Script script) {
     var content = new StringBuilder();
     if (script == null) script = this;
     if (script.ChildenScripts != null) {
         foreach(var child_script in script.ChildenScripts)
             content.AppendLine(GetTextCode_recursive(child_script));
     }
     content.AppendLine(script.TextFormated);
     return content.ToString();
 }
Exemplo n.º 10
0
 public ScriptSuccees(Script script, ProcedureItem procedure = null)
     : base(script, procedure) {
 }