//在当前文件中查找 private void SearchInFile(string filename) { string[] lines = GetLines(filename); var needles = _needles; var comparison = _comparison; for (int i = 0; i < needles.Length; i++) { var needle = needles[i]; for (int lineNumber = 0; lineNumber < lines.Length; lineNumber++) { var line = lines[lineNumber]; if (line.IndexOf(needle, comparison) >= 0) { // found OnFound?.Invoke(needle, filename, line, lineNumber); } } } //Report progress int searched = Interlocked.Increment(ref _searched); if (searched < _files.Count) { ReportProgress((double)searched / _files.Count); } //All files are searched, complete else { OnComplete?.Invoke(); } }
public override void Run() { var sd = _status.GetCurrent(this); if (sd != null) { OnFound?.Invoke(sd); } }
public void ScanSearch(string rawTextString) { foreach (var e in Events.Where(n => (n.EventType == EventType.Search))) { e.iLineSearchMatches = RegularExpression.GetLines((e as EventPattern).RegularExpression, rawTextString); if (e.iLineSearchMatches.Count > 0) { e.Found = true; } } // It the Pattern only contains Search Events and at least one EventPattern was found, then the Pattern Found is True. -Sara if (OnlySearch && (Events.Where(n => n.Found).Count() > 0)) { Found = true; OnFound?.Invoke(this); } }
/// <summary> /// Calls the appropriate StatusUpdate events for this target. /// </summary> public void HandleStatusUpdates(MLImageTracker.Target target, MLImageTracker.Target.Result result) { if (result.Status != Status) { Status = result.Status; if (Status == MLImageTracker.Target.TrackingStatus.Tracked || Status == MLImageTracker.Target.TrackingStatus.Unreliable) { OnFound?.Invoke(target, result); } else { OnLost?.Invoke(target, result); } } else { OnUpdated?.Invoke(target, result); } }
//Public Methods: public void FireFoundEvent() { _visibleStableFoundTime = Time.realtimeSinceStartup; Visible = true; OnFound?.Invoke(); }
/// <summary> /// Returns true when the Pattern found a match /// </summary> public bool Scan(ScanLineArgs args) { if (!Active) { return(false); } // The Pattern was found, thus we no longer need to search for it if (Found) { return(false); } #region Start // To start a EventPattern, search for any START line // There can be one or more start lines, any of them will start the EventPattern if (!_hasStarted) { foreach (var step in Events.Where(n => (n.EventType == EventType.Start || n.EventType == EventType.Search) && n.Found == false)) { if (!StepScan(step as EventPattern, args)) { continue; } if (step.EventType == EventType.Search) { OnFound?.Invoke(this); Log.WriteError($"{Name}: Pattern Search was found.", typeof(PatternComplex).FullName, MethodBase.GetCurrentMethod().Name); if (ScanType == ScanType.Repeating) { Reset(); } return(true); } _hasStarted = true; return(false); // Full patter is not found yet } return(false); // Full EventPattern is not found yet } #endregion Start #region Body // Within the body of the EventPattern you will find 3 types of lines: Optional, Required, RequiredInOrder // Once a line is found, then don't search for it again // Optional and Required lines can occur in any order up to a RequiredInOrder line // Start from the top of the list of body messages until you run into a RequiredInOrder // Attempt to find the first RequiredInOrder line you run into, but not the second // Once a RequiredinOrder is found, then any lines prior to the RequriedInOrder that is not found should be flagged OutOfOrder foreach (var step in Events.Where(n => n.EventType == EventType.Body && n.Found == false)) { if (step.Options.RequiredInOrder) { if (StepScan(step as EventPattern, args)) { // Set all non-found lines prior to the RequiredInOrder as Out of Order foreach (var step2 in Events.Where(n => n.EventType == EventType.Body && n.Found == false)) { if (step2 == step) { break; } step2.OutOfOrder = true; } } return(false); // Full EventPattern is not found yet } if (StepScan(step as EventPattern, args)) { return(false); // Full EventPattern is not found yet } // If we found the start of a 'stop & stop' pair, then move onto the next line. - Sara if (step.BodyStartFound) { break; } } #endregion #region Stop // To Stop a EventPattern, all required lines must be found and then a stop line // If you run into a Stop line before all required lines are found then the EventPattern is reset and not found foreach (var step in Events.Where(n => n.EventType == EventType.Stop || n.EventType == EventType.Reset || n.EventType == EventType.Restart).Where(n => n.Found == false)) { if (!StepScan(step as EventPattern, args)) { continue; } if (step.EventType == EventType.Reset) { Log.WriteError($"{Name}: Pattern was Reset!", typeof(PatternComplex).FullName, MethodBase.GetCurrentMethod().Name); OnReset?.Invoke(this, args.iLine); Reset(); return(false); // Full EventPattern is not found, but reset found - Failure! } if (step.EventType == EventType.Restart) { var newEvents = new List <IEventPattern>(); // Remove all steps above the Restart var index = Events.IndexOf(step) + (step.Options.OneOrMore ? 1 : 0); for (int i = index; i < Events.Count; i++) { newEvents.Add(Events[i]); } Events = newEvents; return(false); } var success = true; // Check if all Required and RequiredInOrder were found foreach (var step3 in Events.Where(n => n.Found == false)) { if (!step3.Options.Required && !step3.Options.RequiredInOrder) { continue; } success = false; break; } if (!success) { Log.WriteError($"{Name}: Pattern started but was not complete!", typeof(PatternComplex).FullName, MethodBase.GetCurrentMethod().Name); Reset(); return(false); // Full EventPattern is not found, but stop found - Failure! } Log.Write($" {Name}: Pattern FOUND!!!", typeof(PatternComplex).FullName, MethodBase.GetCurrentMethod().Name, LogEntryType.Debug); OnFound?.Invoke(this); if (ScanType == ScanType.Repeating) { Reset(); } return(true); // Full eventPattern found! } #endregion Stop if (args.LastLine && _hasStarted) { var success = true; foreach (var step3 in Events.Where(n => n.Found == false)) { if (!step3.Options.Required && !step3.Options.RequiredInOrder) { continue; } success = false; break; } if (!success) { return(false); } OnFound?.Invoke(this); return(true); // Full EventPattern found! } // To Reset a EventPattern, a reset line must be found // If this occurs the EventPattern is reset return(false); }
public void doFound() { OnFound?.Invoke(); }