Example #1
0
        public IEnumerable <LogMatch> Apply(ParsedLine line)
        {
            if (parameters == null)
            {
                throw new InvalidOperationException("Parameters must be initialised");
            }

            if ((parameters.Url == null || line.Uri.OriginalString.ToLowerInvariant().Contains(parameters.Url.ToLowerInvariant())) &&
                (perIdRegex == null || perIdRegex.IsMatch(line.Uri.Query)))
            {
                yield return(new LogMatch(line.Start, line.Uri.OriginalString, TimeSpan.FromMilliseconds(line.Duration)));
            }
        }
Example #2
0
        public IEnumerable <LogMatch> Apply(ParsedLine line)
        {
            if (parameters == null)
            {
                throw new InvalidOperationException("Parameters must be initialised");
            }

            var path = line.Uri.OriginalString.ToLowerInvariant();

            if (path.Contains(parameters.Url.ToLowerInvariant())) //i think the warning is a compiler idiosyncracy, to report
            {
                var perIdSearch = perIdRegex.Match(path);
                if (perIdSearch.Success)
                {
                    var user = perIdSearch.Groups["perId"].Value;
                    if (!attemptsByUser.ContainsKey(user))
                    {
                        attemptsByUser[user] = line.Start;
                    }
                }
            }
            else if (path.Contains(parameters.SuccessPattern.ToLowerInvariant()))
            {
                var perIdSearch = perIdRegex.Match(path);
                if (perIdSearch.Success)
                {
                    var user = perIdSearch.Groups["perId"].Value; //avoiding this duplication is not elegant in a code using yield return
                    if (attemptsByUser.ContainsKey(user))
                    {
                        var taskDuration = line.Start - attemptsByUser[user] + TimeSpan.FromMilliseconds(line.Duration);
                        var match        = new LogMatch(line.Start, $"Successful completion of the task in {taskDuration.TotalSeconds}s", taskDuration);
                        attemptsByUser.Remove(user);
                        yield return(match);
                    }
                }
            }

            var tooOld       = line.Start - parameters.SuccessTimeOut;
            var keysToRemove = from k in attemptsByUser.Keys
                               where attemptsByUser[k] < tooOld
                               select k;

            foreach (var k in keysToRemove)
            {
                yield return(new LogMatch(attemptsByUser[k], "Failed attempt of the task"));

                attemptsByUser.Remove(k);
            }
        }