/// <summary>
        /// Locates and fills RawError.Path property with the first
        /// Windows path values found from RawError.Input property.
        /// </summary>
        /// <param name="parser">The stack trace parser. This parameter
        /// must not be null.</param>
        /// <param name="args">The RawError from which retrieving and
        /// filling Input and Path properties. This parameter cannot not
        /// be null.</param>
        /// <returns>True if a match occured, false otherwise.</returns>
        public bool TryParse(StackTraceParser parser, RawError args)
        {
            int posDriveLetter;
            int posTrailingColon;
            string path;

            UiExceptionHelper.CheckNotNull(parser, "parser");
            UiExceptionHelper.CheckNotNull(args, "args");

            posDriveLetter = lookForDriveLetter(args.Input, 0);
            if (posDriveLetter == -1)
                return (false);

            posTrailingColon = PathCompositeParser.IndexOfTrailingColon(args.Input, posDriveLetter + 3);
            if (posTrailingColon == -1)
                return (false);

            path = args.Input.Substring(posDriveLetter, posTrailingColon - posDriveLetter);
            path = path.Trim();

            if (path.Length <= 3)
                return (false);

            args.Path = path;

            return (true);
        }
        /// <summary>
        /// Locates and fills RawError.Path property with the first
        /// Unix path values found from RawError.Input property.
        /// </summary>
        /// <param name="parser">The stack trace parser. This parameter
        /// must not be null.</param>
        /// <param name="args">The RawError from which retrieving and
        /// filling Input and Path properties. This parameter cannot not
        /// be null.</param>
        /// <returns>True if a match occured, false otherwise.</returns>
        public bool TryParse(StackTraceParser parser, RawError args)
        {
            int posSlash;
            int posColon;
            string path;

            UiExceptionHelper.CheckNotNull(parser, "parser");
            UiExceptionHelper.CheckNotNull(args, "args");

            if ((posSlash = indexOfFirstSlash(args.Input, 0)) == -1)
                return (false);

            if ((posColon = PathCompositeParser.IndexOfTrailingColon(args.Input, posSlash + 1)) == -1)
                return (false);

            path = args.Input.Substring(posSlash, posColon - posSlash);
            path = path.Trim();

            if (path.Length <= 1)
                return (false);

            args.Path = path;

            return (true);
        }
        /// <summary>
        /// Try to match a function name by reading RawError.Input.
        /// If a match is found, the method outputs the result into
        /// RawError.Function and returns true.
        /// </summary>
        /// <param name="parser">An instance of parser, this parameter
        /// cannot be null.</param>
        /// <param name="args">An instance of RawError. This parameter
        /// cannot be null.</param>
        /// <returns>True if a match occurs, false otherwise.</returns>
        public bool TryParse(StackTraceParser parser, RawError args)
        {
            int posEndingParenthesis;
            int posOpeningParenthesis;
            int posName;
            string res;
            int i;

            UiExceptionHelper.CheckNotNull(parser, "parser");
            UiExceptionHelper.CheckNotNull(args, "args");

            posEndingParenthesis = args.Input.LastIndexOf(")");
            posOpeningParenthesis = args.Input.LastIndexOf("(");

            if (posEndingParenthesis == -1 || posOpeningParenthesis == -1 ||
                posOpeningParenthesis > posEndingParenthesis)
                return (false);

            posName = -1;
            for (i = posOpeningParenthesis - 1; i >= 0; i--)
            {
                if (args.Input[i] == ' ')
                    break;

                posName = i;
            }

            if (posName == -1)
                return (false);

            res = args.Input.Substring(posName, posEndingParenthesis - posName + 1);
            args.Function = res;
            
            return (true);
        }       
        /// <summary>
        /// Try to read from a stack trace line a path value given either
        /// under the form of a Windows path or a UNIX path. If a match occurs
        /// the method fills args.Function with the identified data.
        /// </summary>
        /// <param name="parser">The instance of StackTraceParser, this parameter
        /// cannot be null.</param>
        /// <param name="args">The instance of RawError from where read and write
        /// RawError.Input and RawError.Function properties. This parameter
        /// cannot be null.</param>
        /// <returns>True if a match occurs, false otherwise.</returns>
        public bool TryParse(StackTraceParser parser, RawError args)
        {
            foreach (IErrorParser item in _array)
                if (item.TryParse(parser, args))
                    return (true);

            return (false);
        }
Exemple #5
0
        public RawError AcceptValue(IErrorParser parser, string error)
        {
            RawError res;

            res = new RawError(error);
            Assert.That(parser.TryParse(_stack, res), Is.True, "Failed to parse \"{0}\"", error);

            return (res);
        }
        /// <summary>
        /// Try to match a function name by reading RawError.Input.
        /// If a match is found, the method outputs the result into
        /// RawError.Function and returns true.
        /// </summary>
        /// <param name="parser">An instance of parser, this parameter
        /// cannot be null.</param>
        /// <param name="args">An instance of RawError. This parameter
        /// cannot be null.</param>
        /// <returns>True if a match occurs, false otherwise.</returns>
        public bool TryParse(StackTraceParser parser, RawError args)
        {
            int posEndingParenthesis;
            int posOpeningParenthesis;
            int posName;
            int endName;
            string res;
            int i;

            UiExceptionHelper.CheckNotNull(parser, "parser");
            UiExceptionHelper.CheckNotNull(args, "args");

            posEndingParenthesis = args.Input.LastIndexOf(")");
            posOpeningParenthesis = args.Input.LastIndexOf("(");

            if (posEndingParenthesis == -1 || posOpeningParenthesis == -1 ||
                posOpeningParenthesis > posEndingParenthesis)
                return (false);

            endName = posOpeningParenthesis;
            for (i = posOpeningParenthesis - 1; i >= 0; i--)
            {
                if (args.Input[i] != ' ')
                    break;

                endName = i;
            }

            posName = -1;
            for (i = endName - 1; i >= 0; i--)
            {
                if (args.Input[i] == ' ')
                    break;

                posName = i;
            }

            // Added this test to allow for odd case where we would
            // otherwise include the leading "at" or "à" in name.
            if (posName == 0)
                return false;

            if (posName == -1)
                return (false);

            res = args.Input.Substring(posName, posEndingParenthesis - posName + 1);
            args.Function = res;
            
            return (true);
        }       
        /// <summary>
        /// Reads args.Input and try to locate a line number information.
        /// If a match occurs the method fills args.Line with the identified
        /// integer.
        /// </summary>
        /// <param name="parser">The StackTraceParser instance. The
        /// parameter cannot be null.</param>
        /// <param name="args">The RawError instance from where read and
        /// write Input and Line properties. The parameter cannot be null.</param>
        /// <returns>True if a match occurs, false otherwise.</returns>
        public bool TryParse(StackTraceParser parser, RawError args)
        {
            int posTrailingColon;
            int line;

            UiExceptionHelper.CheckNotNull(parser, "parser");
            UiExceptionHelper.CheckNotNull(args, "args");

            if ((posTrailingColon = args.Input.LastIndexOf(":")) == -1)
                return (false);

            if ((line = lookForLastInteger(args.Input, posTrailingColon)) <= 0)                
                return (false);

            args.Line = line;

            return (true);
        }
        /// <summary>
        /// Reads and transforms the given stack trace into a manageable and ordered
        /// set of ErrorItem instances. The resulting set is stored into Items property.
        /// </summary>
        /// <param name="stackTrace">A string value that should contain a .Net stack trace.</param>
        public void Parse(string stackTrace)
        {
            DefaultTextManager lines;
            RawError rawError;

            _items.Clear();

            lines = new DefaultTextManager();
            lines.Text = stackTrace;

            foreach (string line in lines)
            {
                rawError = new RawError(line);

                if (!_functionParsers.TryParse(this, rawError))
                    continue;

                _pathParsers.TryParse(this, rawError);
                _lineNumberParsers.TryParse(this, rawError);

                _items.Add(rawError.ToErrorItem());
            }

            return;
        }