Esempio n. 1
0
        /// <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);
        }
        public void GetArgumentListShouldReturnCorrectArgumentList(string argument)
        {
            var argumentList = ArgumentProcessorUtilities.GetArgumentList(argument, ArgumentProcessorUtilities.SemiColonArgumentSeparator, "test exception.");

            argumentList.SequenceEqual(new string[] { "abc.txt", "tracelevel=info", "newkey=newvalue" });
        }