private static IDictionary ParseCliVars(string[] args) { Hashtable result = new Hashtable(); foreach (string s in args) { if (s.StartsWith("-D:") || s.StartsWith("-d:")) { Variable var = new Variable(); string[] v = s.Substring(3).Split('='); if (v.Length >= 1) { var.name = v[0]; if (v.Length == 2) var.value = v[1]; result[var.name] = var; } } } return (result.Count > 0) ? result: null; }
// Variable replacement private static void ReplaceVariables(ParallelTest[] target, Variable[] variables) { if (variables == null || target == null) return; foreach (Variable var in variables) foreach (ParallelTest test in target) ReplaceVariableOnTest(test, var); }
// Command line variable handling private static Variable[] ParseVariablesFromCommandLine( string[] args, Variable[] variables) { // variables from the command line, if defined, are prefixed with "-D:" if (args == null) return variables; IDictionary varsFromCli = ParseCliVars(args); if (varsFromCli == null) return variables; return MergeVars(varsFromCli, variables); }
private static string ReplaceVar(string source, Variable var) { if (source == null) return null; return source.Replace(var.name, var.value); }
private static string[] ReplaceVarArray(string[] source, Variable var) { if (source == null) return null; for (int i = 0; i < source.Length; ++i) { source[i] = ReplaceVar(source[i], var); } return source; }
private static void ReplaceVariableOnTest(ParallelTest t, Variable var) { t.Agents = ReplaceVarArray(t.Agents, var); t.Name = ReplaceVar (t.Name, var); foreach (TestConf tc in t.Tests) { tc.Name = ReplaceVar(tc.Name, var); tc.Assembly = ReplaceVar(tc.Assembly, var); tc.TestToRun = ReplaceVar(tc.TestToRun, var); tc.Machine = ReplaceVar(tc.Machine, var); tc.TestParams = ReplaceVarArray(tc.TestParams, var); tc.StartBarrier = ReplaceVar(tc.StartBarrier, var); tc.EndBarrier = ReplaceVar(tc.EndBarrier, var); tc.WaitBarriers = ReplaceVarArray(tc.WaitBarriers, var); } }
private static string ReplaceVar(string source, Variable var) { if (source == null) return null; if (var == null) return source; if (string.IsNullOrEmpty(var.name)) return source; return source.Replace(var.name, var.value); }