/// <summary> /// Extract the arguments and validate them; also validate the supplied options when simple /// </summary> public void ExtractAndValidateArguments() { ParseArguments(); foreach (var key in ParsedArguments.Keys) { var lower = key.ToLowerInvariant(); switch (lower) { case "register": Register = true; Registration registration; Enum.TryParse(GetArgumentValue("register"), true, out registration); Registration = registration; break; case "target": Target = GetArgumentValue("target"); break; case "targetdir": TargetDir = GetArgumentValue("targetdir"); break; case "targetargs": TargetArgs = GetArgumentValue("targetargs"); break; case "output": OutputFile = GetArgumentValue("output"); break; case "mergeoutput": MergeExistingOutputFile = true; break; case "nodefaultfilters": NoDefaultFilters = true; break; case "mergebyhash": MergeByHash = true; break; case "regex": RegExFilters = true; break; case "showunvisited": ShowUnvisited = true; break; case "returntargetcode": ReturnTargetCode = true; ReturnCodeOffset = ExtractValue <int>("returntargetcode", () => { throw new InvalidOperationException("The return target code offset must be an integer"); }); break; case "filter": Filters = ExtractFilters(GetArgumentValue("filter")); break; case "filterfile": FilterFile = GetArgumentValue("filterfile"); break; case "excludebyattribute": AttributeExclusionFilters = GetArgumentValue("excludebyattribute") .Split(';').ToList(); break; case "excludebyfile": FileExclusionFilters = GetArgumentValue("excludebyfile") .Split(';').ToList(); break; case "hideskipped": HideSkipped = ExtractSkipped(GetArgumentValue("hideskipped")); break; case "coverbytest": TestFilters = GetArgumentValue("coverbytest") .Split(';').ToList(); TraceByTest = TestFilters.Any(); break; case "log": var value = GetArgumentValue("log"); LogLevel = (Level)typeof(Level).GetFields(BindingFlags.Static | BindingFlags.Public) .First(x => string.Compare(x.Name, value, true, CultureInfo.InvariantCulture) == 0).GetValue(typeof(Level)); break; case "service": Service = true; ServiceEnvironment val; if (Enum.TryParse(GetArgumentValue("service"), true, out val)) { ServiceEnvironment = val; } break; case "servicestarttimeout": var timeoutValue = GetArgumentValue("servicestarttimeout"); ServiceStartTimeout = ParseTimeoutValue(timeoutValue); break; case "oldstyle": OldStyleInstrumentation = true; break; case "enableperformancecounters": EnablePerformanceCounters = true; break; case "threshold": Threshold = ExtractValue <ulong>("threshold", () => { throw new InvalidOperationException("The threshold must be an integer"); }); break; case "skipautoprops": SkipAutoImplementedProperties = true; break; case "?": PrintUsage = true; break; case "version": PrintVersion = true; break; default: throw new InvalidOperationException(string.Format("The argument '-{0}' is not recognised", key)); } } ValidateArguments(); }
/// <summary> /// Extract the arguments and validate them; also validate the supplied options when simple /// </summary> public void ExtractAndValidateArguments() { ParseArguments(); foreach (var key in ParsedArguments.Keys) { var lower = key.ToLowerInvariant(); switch (lower) { case "register": Register = true; Registration registration; Enum.TryParse(GetArgumentValue("register"), true, out registration); Registration = registration; break; case "target": Target = GetArgumentValue("target"); break; case "targetdir": TargetDir = GetArgumentValue("targetdir"); break; case "searchdirs": SearchDirs = GetArgumentValue("searchdirs").Split(';'); break; case "excludedirs": ExcludeDirs = GetArgumentValue("excludedirs") .Split(';') .Where(_ => _ != null) .Select(_ => Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), _))) .Where(Directory.Exists) .Distinct() .ToArray(); break; case "targetargs": TargetArgs = GetArgumentValue("targetargs"); break; case "output": OutputFile = GetArgumentValue("output"); break; case "mergeoutput": MergeExistingOutputFile = true; break; case "nodefaultfilters": NoDefaultFilters = true; break; case "mergebyhash": MergeByHash = true; break; case "regex": RegExFilters = true; break; case "showunvisited": ShowUnvisited = true; break; case "returntargetcode": ReturnTargetCode = true; ReturnCodeOffset = ExtractValue <int>("returntargetcode", () => { throw new InvalidOperationException("The return target code offset must be an integer"); }); break; case "communicationtimeout": CommunicationTimeout = ExtractValue <int>("communicationtimeout", () => { throw new InvalidOperationException(string.Format("The communication timeout must be an integer: {0}", GetArgumentValue("communicationtimeout"))); }); CommunicationTimeout = Math.Max(Math.Min(CommunicationTimeout, 600000), 10000); break; case "filter": Filters = ExtractFilters(GetArgumentValue("filter")); break; case "filterfile": FilterFile = GetArgumentValue("filterfile"); break; case "excludebyattribute": AttributeExclusionFilters = GetArgumentValue("excludebyattribute") .Split(';').ToList(); break; case "excludebyfile": FileExclusionFilters = GetArgumentValue("excludebyfile") .Split(';').ToList(); break; case "hideskipped": HideSkipped = ExtractSkipped(GetArgumentValue("hideskipped")); break; case "coverbytest": TestFilters = GetArgumentValue("coverbytest") .Split(';').ToList(); TraceByTest = TestFilters.Any(); break; case "log": var value = GetArgumentValue("log"); LogLevel = (Level)typeof(Level).GetFields(BindingFlags.Static | BindingFlags.Public) .First(x => string.Compare(x.Name, value, true, CultureInfo.InvariantCulture) == 0).GetValue(typeof(Level)); break; case "service": Service = true; ServiceEnvironment val; if (Enum.TryParse(GetArgumentValue("service"), true, out val)) { ServiceEnvironment = val; } break; case "servicestarttimeout": var timeoutValue = GetArgumentValue("servicestarttimeout"); ServiceStartTimeout = ParseTimeoutValue(timeoutValue); break; case "oldstyle": OldStyleInstrumentation = true; break; case "enableperformancecounters": EnablePerformanceCounters = true; break; case "threshold": Threshold = ExtractValue <ulong>("threshold", () => { throw new InvalidOperationException("The threshold must be an integer"); }); break; case "skipautoprops": SkipAutoImplementedProperties = true; break; case "safemode": SafeMode = ExtractSafeMode(GetArgumentValue("safemode")) == Framework.SafeMode.On; break; case "?": PrintUsage = true; break; case "version": PrintVersion = true; break; case "diagmode": DiagMode = true; break; case "ignorectrlc": IgnoreCtrlC = true; break; case "sendvisitpointstimerinterval": SendVisitPointsTimerInterval = ExtractValue <uint>("sendvisitpointstimerinterval", () => { throw new InvalidOperationException("The send visit points timer interval must be a non-negative integer"); }); break; default: throw new InvalidOperationException(string.Format("The argument '-{0}' is not recognised", key)); } } ValidateArguments(); }
/// <summary> /// Extract the arguments and validate them; also validate the supplied options when simple /// </summary> public void ExtractAndValidateArguments() { foreach (var key in ParsedArguments.Keys) { var lower = key.ToLowerInvariant(); switch (lower) { case "register": Register = true; UserRegistration = (GetArgumentValue("register").ToLowerInvariant() == "user"); break; case "target": Target = GetArgumentValue("target"); break; case "targetdir": TargetDir = GetArgumentValue("targetdir"); break; case "targetargs": TargetArgs = GetArgumentValue("targetargs"); break; case "output": OutputFile = GetArgumentValue("output"); break; case "nodefaultfilters": NoDefaultFilters = true; break; case "mergebyhash": MergeByHash = true; break; case "showunvisited": ShowUnvisited = true; break; case "returntargetcode": ReturnTargetCode = true; ReturnCodeOffset = ExtractValue <int>("returntargetcode", () => { throw new InvalidOperationException("The return target code offset must be an integer"); }); break; case "filter": Filters = ExtractFilters(GetArgumentValue("filter")); break; case "filterfile": FilterFile = GetArgumentValue("filterfile"); break; case "excludebyattribute": AttributeExclusionFilters = GetArgumentValue("excludebyattribute") .Split(';').ToList(); break; case "excludebyfile": FileExclusionFilters = GetArgumentValue("excludebyfile") .Split(';').ToList(); break; case "hideskipped": HideSkipped = ExtractSkipped(GetArgumentValue("hideskipped")); break; case "coverbytest": TestFilters = GetArgumentValue("coverbytest") .Split(';').ToList(); TraceByTest = TestFilters.Any(); break; case "log": var value = GetArgumentValue("log"); LogLevel = (Level)typeof(Level).GetFields(BindingFlags.Static | BindingFlags.Public) .First(x => string.Compare(x.Name, value, true, CultureInfo.InvariantCulture) == 0).GetValue(typeof(Level)); break; case "service": Service = true; break; case "oldstyle": OldStyleInstrumentation = true; break; case "enableperformancecounters": EnablePerformanceCounters = true; break; case "threshold": Threshold = ExtractValue <ulong>("threshold", () => { throw new InvalidOperationException("The threshold must be an integer"); }); break; case "?": PrintUsage = true; break; default: throw new InvalidOperationException(string.Format("The argument {0} is not recognised", key)); } } if (PrintUsage) { return; } if (string.IsNullOrWhiteSpace(Target)) { throw new InvalidOperationException("The target argument is required"); } }
/// <summary> /// Extract the arguments and validate them; also validate the supplied options when simple /// </summary> public void ExtractAndValidateArguments() { ParseArguments(); foreach (var key in ParsedArguments.Keys) { var lower = key.ToLowerInvariant(); switch (lower) { case "register": Register = true; Enum.TryParse(GetArgumentValue("register"), true, out Registration registration); Registration = registration; break; case "codepulseport": CodePulsePort = ExtractValue("codepulseport", 0, ushort.MaxValue, error => throw new InvalidOperationException($"The Code Pulse port must be a valid port number. {error}.")); break; case "codepulsehost": CodePulseHost = GetArgumentValue("codepulsehost"); break; case "codepulseconnecttimeout": CodePulseConnectTimeout = ExtractValue("codepulseconnecttimeout", 0, int.MaxValue, error => throw new InvalidOperationException($"The Code Pulse connection timeout must be a non-negative number. {error}.")); break; case "target": Target = GetArgumentValue("target"); break; case "targetdir": TargetDir = GetArgumentValue("targetdir"); break; case "searchdirs": SearchDirs = GetArgumentValue("searchdirs").Split(';'); break; case "excludedirs": ExcludeDirs = GetArgumentValue("excludedirs") .Split(';') .Where(_ => _ != null) .Select(_ => Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), _))) .Where(Directory.Exists) .Distinct() .ToArray(); break; case "targetargs": TargetArgs = GetArgumentValue("targetargs"); break; case "nodefaultfilters": NoDefaultFilters = true; break; case "mergebyhash": MergeByHash = true; break; case "regex": RegExFilters = true; break; case "showunvisited": ShowUnvisited = true; break; case "returntargetcode": ReturnTargetCode = true; ReturnCodeOffset = ExtractValue("returntargetcode", 0, int.MaxValue, error => throw new InvalidOperationException($"The return target code offset must be an integer. {error}.")); break; case "communicationtimeout": CommunicationTimeout = ExtractValue("communicationtimeout", 10000, 60000, error => throw new InvalidOperationException($"The communication timeout ({GetArgumentValue("communicationtimeout")}) must be an integer. {error}.")); break; case "filter": Filters = ExtractFilters(GetArgumentValue("filter")); break; case "filterfile": FilterFile = GetArgumentValue("filterfile"); break; case "excludebyattribute": AttributeExclusionFilters = GetArgumentValue("excludebyattribute") .Split(';').ToList(); break; case "excludebyfile": FileExclusionFilters = GetArgumentValue("excludebyfile") .Split(';').ToList(); break; case "hideskipped": HideSkipped = ExtractSkipped(GetArgumentValue("hideskipped")); break; case "coverbytest": TestFilters = GetArgumentValue("coverbytest") .Split(';').ToList(); TraceByTest = TestFilters.Any(); break; case "log": var value = GetArgumentValue("log"); var fieldValue = typeof(Level).GetFields(BindingFlags.Static | BindingFlags.Public).FirstOrDefault(x => string.Compare(x.Name, value, true, CultureInfo.InvariantCulture) == 0); if (fieldValue == null) { throw new InvalidOperationException($"'{value}' is an invalid value for log parameter."); } LogLevel = (Level)fieldValue.GetValue(typeof(Level)); break; case "iis": Iis = true; break; case "iisapppoolidentity": IisAppPoolIdentity = GetArgumentValue("iisapppoolidentity"); break; case "servicecontroltimeout": var timeoutValue = ExtractValue("servicecontroltimeout", 5, 60, error => throw new InvalidOperationException($"The service control timeout must be a non-negative integer. {error}.")); ServiceControlTimeout = TimeSpan.FromSeconds(timeoutValue); break; case "enableperformancecounters": EnablePerformanceCounters = true; break; case "threshold": Threshold = ExtractValue <ulong>("threshold", 0, int.MaxValue, error => throw new InvalidOperationException($"The threshold must be an integer. {error}.")); break; case "skipautoprops": SkipAutoImplementedProperties = true; break; case "?": PrintUsage = true; break; case "version": PrintVersion = true; break; case "diagmode": DiagMode = true; break; case "sendvisitpointstimerinterval": SendVisitPointsTimerInterval = ExtractValue("sendvisitpointstimerinterval", 0u, 60u * 60u * 1000u, error => throw new InvalidOperationException($"The send visit points timer interval must be a non-negative integer. {error}")); break; default: throw new InvalidOperationException($"The argument '-{key}' is not recognised"); } } ValidateArguments(); }