Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
0
 public void Update(LogMatch result)
 {
     if (result.Start < Start)
     {
         Start = result.Start;
     }
     if (End < result.Start)
     {
         End = result.Start;                     //the duration of the result is not taken into account for simplicity
     }
     if (result.Duration.HasValue)
     {
         Durations.Add(result.Duration.Value);
     }
     else
     {
         Failures++;
     }
 }