/// <summary> /// Initializes with the argument that was provided with the command. /// </summary> /// <param name="argument">Argument that was provided with the command.</param> public void Initialize(string argument) { var enableDump = false; var exceptionMessage = string.Format(CultureInfo.CurrentUICulture, CommandLineResources.InvalidBlameArgument, argument); Dictionary <string, string> collectDumpParameters = null; if (!string.IsNullOrWhiteSpace(argument)) { // Get blame argument list. var blameArgumentList = ArgumentProcessorUtilities.GetArgumentList(argument, ArgumentProcessorUtilities.SemiColonArgumentSeparator, exceptionMessage); // Get collect dump key. var collectDumpKey = blameArgumentList[0]; bool isCollectDumpKeyValid = ValidateCollectDumpKey(collectDumpKey); // Check if dump should be enabled or not. enableDump = isCollectDumpKeyValid && IsDumpCollectionSupported(); // Get collect dump parameters. var collectDumpParameterArgs = blameArgumentList.Skip(1); collectDumpParameters = ArgumentProcessorUtilities.GetArgumentParameters(collectDumpParameterArgs, ArgumentProcessorUtilities.EqualNameValueSeparator, exceptionMessage); } // Initialize blame. InitializeBlame(enableDump, collectDumpParameters); }
/// <summary> /// Initializes with the argument that was provided with the command. /// </summary> /// <param name="argument">Argument that was provided with the command.</param> public void Initialize(string argument) { string exceptionMessage = string.Format(CultureInfo.CurrentUICulture, CommandLineResources.LoggerUriInvalid, argument); // Throw error in case logger argument null or empty. if (string.IsNullOrWhiteSpace(argument)) { throw new CommandLineException(exceptionMessage); } // Get logger argument list. var loggerArgumentList = ArgumentProcessorUtilities.GetArgumentList(argument, ArgumentProcessorUtilities.SemiColonArgumentSeparator, exceptionMessage); // Get logger identifier. var loggerIdentifier = loggerArgumentList[0]; if (loggerIdentifier.Contains("=")) { throw new CommandLineException(exceptionMessage); } // Get logger parameters var loggerParameterArgs = loggerArgumentList.Skip(1); var loggerParameters = ArgumentProcessorUtilities.GetArgumentParameters(loggerParameterArgs, ArgumentProcessorUtilities.EqualNameValueSeparator, exceptionMessage); // Add logger to run settings. LoggerUtilities.AddLoggerToRunSettings(loggerIdentifier, loggerParameters, runSettingsManager); }
/// <summary> /// Initializes with the argument that was provided with the command. /// </summary> /// <param name="argument">Argument that was provided with the command.</param> public void Initialize(string argument) { string exceptionMessage = string.Format(CultureInfo.CurrentUICulture, CommandLineResources.InvalidDiagArgument, argument); // Throw error if argument is null or empty. if (string.IsNullOrWhiteSpace(argument)) { throw new CommandLineException(exceptionMessage); } // Get diag argument list. var diagArgumentList = ArgumentProcessorUtilities.GetArgumentList(argument, ArgumentProcessorUtilities.SemiColonArgumentSeparator, exceptionMessage); // Get diag file path. // Note: Even though semi colon is valid file path, we are not respecting the file name having semi-colon [As we are separating arguments based on semi colon]. var diagFilePathArg = diagArgumentList[0]; var diagFilePath = GetDiagFilePath(diagFilePathArg); // Get diag parameters. var diagParameterArgs = diagArgumentList.Skip(1); var diagParameters = ArgumentProcessorUtilities.GetArgumentParameters(diagParameterArgs, ArgumentProcessorUtilities.EqualNameValueSeparator, exceptionMessage); // Initialize diag logging. InitializeDiagLogging(diagFilePath, diagParameters); // Write version to the log here, because that is the // first place where we know if we log or not. EqtTrace.Verbose($"Version: {Product.Version}"); }
public void GetArgumentParametersShouldReturnCorrectParameterDictionary() { var parameterDict = ArgumentProcessorUtilities.GetArgumentParameters(new string[] { "key1=value1", "key2=value2", "key3=value3" }, ArgumentProcessorUtilities.EqualNameValueSeparator, "test exception."); var expectedDict = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" }, { "key3", "value3" } }; CollectionAssert.AreEqual(parameterDict.OrderBy(kv => kv.Key).ToList(), expectedDict.OrderBy(kv => kv.Key).ToList()); }
public void GetArgumentParametersShouldThrowErrorOnInvalidParameters(string[] parameterArgs) { try { ArgumentProcessorUtilities.GetArgumentParameters(parameterArgs, ArgumentProcessorUtilities.EqualNameValueSeparator, "test exception."); } catch (Exception e) { Assert.IsTrue(e.GetType().Equals(typeof(CommandLineException))); Assert.IsTrue(e.Message.Contains("test exception.")); } }
/// <summary> /// Initializes with the argument that was provided with the command. /// </summary> /// <param name="argument">Argument that was provided with the command.</param> public void Initialize(string argument) { var enableDump = false; var enableHangDump = false; var exceptionMessage = string.Format(CultureInfo.CurrentUICulture, CommandLineResources.InvalidBlameArgument, argument); Dictionary <string, string> collectDumpParameters = null; if (!string.IsNullOrWhiteSpace(argument)) { // Get blame argument list. var blameArgumentList = ArgumentProcessorUtilities.GetArgumentList(argument, ArgumentProcessorUtilities.SemiColonArgumentSeparator, exceptionMessage); Func <string, bool> isDumpCollect = a => Constants.BlameCollectDumpKey.Equals(a, StringComparison.OrdinalIgnoreCase); Func <string, bool> isHangDumpCollect = a => Constants.BlameCollectHangDumpKey.Equals(a, StringComparison.OrdinalIgnoreCase); // Get collect dump key. var hasCollectDumpKey = blameArgumentList.Any(isDumpCollect); var hasCollectHangDumpKey = blameArgumentList.Any(isHangDumpCollect); // Check if dump should be enabled or not. enableDump = hasCollectDumpKey && IsDumpCollectionSupported(); // Check if dump should be enabled or not. enableHangDump = hasCollectHangDumpKey && IsHangDumpCollectionSupported(); if (!enableDump && !enableHangDump) { Output.Warning(false, string.Format(CultureInfo.CurrentUICulture, CommandLineResources.BlameIncorrectOption, argument)); } else { // Get collect dump parameters. var collectDumpParameterArgs = blameArgumentList.Where(a => !isDumpCollect(a) && !isHangDumpCollect(a)); collectDumpParameters = ArgumentProcessorUtilities.GetArgumentParameters(collectDumpParameterArgs, ArgumentProcessorUtilities.EqualNameValueSeparator, exceptionMessage); } } // Initialize blame. InitializeBlame(enableDump, enableHangDump, collectDumpParameters); }