void IObserver <DiagnosticListener> .OnCompleted() { _httpTrace.Info("DiagListeners finished transmitting data."); }
public void Parse(string[] args) { _trace.Info(nameof(Parse)); ArgUtil.NotNull(args, nameof(args)); _trace.Info("Parsing {0} args", args.Length); string argScope = null; foreach (string arg in args) { _trace.Info("parsing argument"); HasArgs = HasArgs || arg.StartsWith("--"); _trace.Info("HasArgs: {0}", HasArgs); if (string.Equals(arg, "/?", StringComparison.Ordinal)) { Flags.Add("help"); } else if (!HasArgs) { _trace.Info("Adding Command: {0}", arg); Commands.Add(arg.Trim()); } else { // it's either an arg, an arg value or a flag if (arg.StartsWith("--") && arg.Length > 2) { string argVal = arg.Substring(2); _trace.Info("arg: {0}", argVal); // this means two --args in a row which means previous was a flag if (argScope != null) { _trace.Info("Adding flag: {0}", argScope); Flags.Add(argScope.Trim()); } argScope = argVal; } else if (!arg.StartsWith("-")) { // we found a value - check if we're in scope of an arg if (argScope != null && !Args.ContainsKey(argScope = argScope.Trim())) { if (SecretArgNames.Contains(argScope)) { _secretMasker.AddValue(arg); } _trace.Info("Adding option '{0}': '{1}'", argScope, arg); // ignore duplicates - first wins - below will be val1 // --arg1 val1 --arg1 val1 Args.Add(argScope, arg); argScope = null; } } else { // // ignoring the second value for an arg (val2 below) // --arg val1 val2 // ignoring invalid things like empty - and -- // --arg val1 -- --flag _trace.Info("Ignoring arg"); } } } _trace.Verbose("done parsing arguments"); // handle last arg being a flag if (argScope != null) { Flags.Add(argScope); } _trace.Verbose("Exiting parse"); }
public string GetDirectory(WellKnownDirectory directory) { string path; switch (directory) { case WellKnownDirectory.Bin: path = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); break; case WellKnownDirectory.Diag: path = Path.Combine( GetDirectory(WellKnownDirectory.Root), Constants.Path.DiagDirectory); break; case WellKnownDirectory.Externals: path = Path.Combine( GetDirectory(WellKnownDirectory.Root), Constants.Path.ExternalsDirectory); break; case WellKnownDirectory.LegacyPSHost: path = Path.Combine( GetDirectory(WellKnownDirectory.Externals), Constants.Path.LegacyPSHostDirectory); break; case WellKnownDirectory.Root: path = new DirectoryInfo(GetDirectory(WellKnownDirectory.Bin)).Parent.FullName; break; case WellKnownDirectory.ServerOM: path = Path.Combine( GetDirectory(WellKnownDirectory.Externals), Constants.Path.ServerOMDirectory); break; case WellKnownDirectory.Tf: path = Path.Combine( GetDirectory(WellKnownDirectory.Externals), Constants.Path.TfDirectory); break; case WellKnownDirectory.Tee: path = Path.Combine( GetDirectory(WellKnownDirectory.Externals), Constants.Path.TeeDirectory); break; case WellKnownDirectory.Temp: path = Path.Combine( GetDirectory(WellKnownDirectory.Work), Constants.Path.TempDirectory); break; case WellKnownDirectory.Tasks: path = Path.Combine( GetDirectory(WellKnownDirectory.Work), Constants.Path.TasksDirectory); break; case WellKnownDirectory.TaskZips: path = Path.Combine( GetDirectory(WellKnownDirectory.Work), Constants.Path.TaskZipsDirectory); break; case WellKnownDirectory.Tools: path = Environment.GetEnvironmentVariable("AGENT_TOOLSDIRECTORY") ?? Environment.GetEnvironmentVariable(Constants.Variables.Agent.ToolsDirectory); if (string.IsNullOrEmpty(path)) { path = Path.Combine( GetDirectory(WellKnownDirectory.Work), Constants.Path.ToolDirectory); } break; case WellKnownDirectory.Update: path = Path.Combine( GetDirectory(WellKnownDirectory.Work), Constants.Path.UpdateDirectory); break; case WellKnownDirectory.Work: var configurationStore = GetService <IConfigurationStore>(); AgentSettings settings = configurationStore.GetSettings(); ArgUtil.NotNull(settings, nameof(settings)); ArgUtil.NotNullOrEmpty(settings.WorkFolder, nameof(settings.WorkFolder)); path = Path.GetFullPath(Path.Combine( GetDirectory(WellKnownDirectory.Root), settings.WorkFolder)); break; default: throw new NotSupportedException($"Unexpected well known directory: '{directory}'"); } _trace.Info($"Well known directory '{directory}': '{path}'"); return(path); }
public void Parse(String[] args) { _trace.Info("Parse()"); if (args == null) { throw new ArgumentNullException(nameof(args)); } _trace.Info("Parse {0} args", args.Length); if (args.Length == 0) { _trace.Info("No args"); return; } string argScope = null; foreach (string arg in args) { _trace.Info("parsing argument"); _trace.Info("arg: {0}", arg); HasArgs = HasArgs || arg.StartsWith("--"); _trace.Info("HasArgs: {0}", HasArgs); if (!HasArgs) { _trace.Info("Adding Command: {0}", arg); Commands.Add(arg.Trim()); } else { // it's either an arg, an arg value or a flag if (arg.StartsWith("--") && arg.Length > 2) { string argVal = arg.Substring(2); _trace.Info("arg: {0}", argVal); // this means two --args in a row which means previous was a flag if (argScope != null) { _trace.Info("Adding flag: {0}", argScope); Flags.Add(argScope.Trim()); } argScope = argVal; } else if (!arg.StartsWith("-")) { // we found a value - check if we're in scope of an arg if (argScope != null && !Args.ContainsKey(argScope)) { _trace.Info("Adding option {0} value: {1}", argScope, arg); // ignore duplicates - first wins - below will be val1 // --arg1 val1 --arg1 val1 Args.Add(argScope.Trim(), arg); argScope = null; } } else { // // ignoring the second value for an arg (val2 below) // --arg val1 val2 // ignoring invalid things like empty - and -- // --arg val1 -- --flag _trace.Info("Ignoring: {0}", arg); } } } _trace.Verbose("done parsing arguments"); // handle last arg being a flag if (argScope != null) { Flags.Add(argScope); } _trace.Verbose("Exiting parse"); }