public
Created

Find load syntax ( // load "module1", "module2"

  • Download Gist
findLoadSyntax.cs
C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
// find load syntax
var scriptLines = Regex.Split(script, "\r\n|\r|\n");
var isComment = new Func<string, bool>((s) => s.TrimStart().StartsWith("//"));
var trimCommentSlashes = new Func<string, string>((s) => { return s.TrimStart().TrimStart('/').TrimStart(); });
var commandKeyWord = "load";
 
var loadLines = scriptLines.Where(t => isComment(t) && trimCommentSlashes(t).StartsWith(commandKeyWord + " "));
 
foreach (var line in loadLines)
{
 
var parameters = trimCommentSlashes(line).Substring(commandKeyWord.Length).TrimStart();
 
var modules = parameters.Split(',');
 
foreach (var module in modules)
{
var moduleName = module.Replace("\"", "");
ExecuteScript(moduleName);
}
}
 
var result = session.Execute(script) ?? "No result";

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.