Ejemplo n.º 1
0
        static bool RunScripts(Options options)
        {
            StdInOut.HideInfo = (bool)options["noinfo"];
            var starttime = DateTime.Now;

            StdInOut.LogStart(starttime);

            //Check log path
            var logpath = (string)options["out"];

            if (logpath != null)
            {
                logpath = logpath.Replace("{DATETIME}", DateTime.Now.ToString("yyyyMMdd-HHmmss"));
                if (logpath.IndexOf("{ID}") != -1)
                {
                    var id          = 0;
                    var new_logpath = string.Empty;
                    while (true)
                    {
                        new_logpath = logpath.Replace("{ID}", (++id).ToString());
                        if (!File.Exists(new_logpath))
                        {
                            break;
                        }
                    }
                    logpath = new_logpath;
                }
                if (logpath.IndexOfAny(Path.GetInvalidPathChars()) != -1)
                {
                    StdInOut.LogError("Invalide log file path.", "Argument: " + (string)options["out"]);
                    return(false);
                }
            }

            string[] list_scripts_path;
            try {
                list_scripts_path = Utils.ExpandFilePaths(options.Files, "vbs");
            } catch (FileNotFoundException ex) {
                StdInOut.LogError(ex.Message, "Argument: " + ex.FileName);
                return(false);
            }

            var runner  = new MultiScriptRunner((int)options["threads"]);
            var results = runner.Run(list_scripts_path, (string[])options["args"], (string[])options["params"], (string)options["filter"], (bool)options["debug"]);

            //Print final result
            StdInOut.LogResults(results, starttime, DateTime.Now);

            //Save log file
            if (!string.IsNullOrEmpty(logpath))
            {
                StdInOut.SaveTo(logpath);
            }
            return(results.Exists((r) => !r.Succeed) == false);
        }
Ejemplo n.º 2
0
        static bool RunScripts(ConsoleArguments options) {

            var starttime = DateTime.Now;
            Logger.LogStart(starttime);
            Logger.HideInfo = (bool)options["noinfo"];

            //Check log path
            var logpath = (string)options["out"];
            if (logpath != null) {
                if (logpath.IndexOf("{t}") != -1) {
                    logpath = logpath.Replace("{t}", DateTime.Now.ToString("yyyyMMdd-HHmmss"));
                }
                if (logpath.IndexOf("{n}") != -1) {
                    var id = 0;
                    string new_logpath;
                    do {
                        new_logpath = logpath.Replace("{n}", (++id).ToString());
                    } while (File.Exists(new_logpath));
                    logpath = new_logpath;
                }
                if (logpath.IndexOfAny(Path.GetInvalidPathChars()) != -1) {
                    Logger.LogError("Invalide log file path.", string.Concat("Argument: ", options["out"]));
                    return false;
                }
            }

            string[] list_scripts_path;
            try {
                list_scripts_path = Utils.ExpandFilePaths(options.Files, @"\.vbs$|\.js$");
            } catch (FileNotFoundException ex) {
                Logger.LogError(ex.Message, "Argument: " + ex.FileName);
                return false;
            }

            var runner = new MultiScriptRunner((int)options["threads"]);
            var results = runner.Run(list_scripts_path, (string[])options["args"], (string[])options["params"], (string)options["filter"], (bool)options["debug"]);

            //Print final result
            Logger.LogResults(results, starttime, DateTime.Now);

            //Save log file                
            if (!string.IsNullOrEmpty(logpath)) {
                Logger.SaveTo(logpath);
            }
            return results.Exists((r) => !r.Succeed) == false;
        }