/// <summary> /// Returns true when the Step found a match /// </summary> public bool StepScan(EventPattern step, ScanLineArgs args) { var s = string.Empty; var expression = step.RegularExpression; if (step.Options.BodyStop && step.BodyStartFound) { expression = step.RegularExpressionBodyStop; } step.Found = step.IsRegularExpression ? RegularExpression.HasMatch(args.Line, expression) : Common.GetStringFromLog(args.Line, step.RegularExpression, ref s); if (step.Found) { Log.Write($" {step.Parent.Name}: Step {step.EventType}, \"{step.RegularExpression.Insert(1, "__")}\"", typeof(EventPattern).FullName, MethodBase.GetCurrentMethod().Name, LogEntryType.Debug); // 'Prior' option requires that a exact EventPattern is found prior to this EventPattern if (step.Options.Prior && LastFound != null) { var _priorStep = step.Parent.Events[step.Parent.Events.IndexOf(step) - step.Options.PriorIndex]; if ((!_priorStep.Found && _priorStep.EventTag == step.Options.PriorPattern) || _priorStep.EventTag != step.Options.PriorPattern) { Log.Write($"EventPattern found, however the expected Prior EventPattern should be '{step.Options.PriorPattern}' at Index {step.Options.PriorIndex}", typeof(EventPattern).FullName, MethodBase.GetCurrentMethod().Name, LogEntryType.Debug); step.Found = false; return(false); } } // 'FirstRepeat' will only allow the first match to stay a match, any events that are found after are skipped if (step.Options.FirstRepeat && LastFound != null && LastFound.Options.FirstRepeat && LastFound.EventTag == step.EventTag) { step.Found = false; return(false); } if (step.Options.BodyStop) { if (step.BodyStartFound) { step.DateTimeBodyStop = RegularExpression.GetDateTime(EventService.GetDateTimeRegularExpression(args.SourceType), args.Line); step.iLineBodyStop = args.iLine; step.LineBodyStop = args.Line; } else { step.DateTime = RegularExpression.GetDateTime(EventService.GetDateTimeRegularExpression(args.SourceType), args.Line); step.iLine = args.iLine; step.Line = args.Line; } } else { step.DateTime = RegularExpression.GetDateTime(EventService.GetDateTimeRegularExpression(args.SourceType), args.Line); step.iLine = args.iLine; step.Line = args.Line; } step.Found = true; step.Match(step.Parent); // Last Repeat if (step.Options.LastRepeat && LastFound != null && LastFound.Options.LastRepeat && step.EventTag == LastFound.EventTag) { step.Parent.Events.Remove(LastFound); LastFound = null; } // 'BodyStop' option represents a start and stop eventPattern. if (step.Options.BodyStop) { if (!step.BodyStartFound) { step.BodyStartFound = true; step.Found = false; return(false); } step.BodyStopFound = true; } // When an EventPattern is found that can occur OneOrMore times // Clone the EventPattern // If Required or RequiredInOrder, remove these flags and make the next EventPattern Optional if (step.Options.OneOrMore) { var index = step.Parent.Events.FindIndex(p => p.Identifier == step.Identifier); var e = step.Clone(step.Parent); e.NewIdentifier(); if (step.Options.Required || step.Options.RequiredInOrder) { e.Options.Required = false; e.Options.RequiredInOrder = false; e.Options.Optional = true; } step.Parent.Events.Insert(index + 1, e); } LastFound = step; } return(step.Found); }