private List <LogEntry> FindItemsMatchingToSearchCriteria()
        {
            Cursor origOwnerCursor = Owner.Cursor;

            Owner.Cursor = Cursors.WaitCursor;
            this.Cursor  = Cursors.WaitCursor;

            try
            {
                compiledSearchInput = new CompiledSearchInput(this);

                //Save to recent searches
                if (!this.prevFindWhat.Equals(compiledSearchInput.FindWhat, StringComparison.OrdinalIgnoreCase))
                {
                    this.settings.SearchHistory.AddText(compiledSearchInput.FindWhat);
                    this.LoadRecentTexts();
                }


                List <LogEntry> logEntries = this.context.GetLogEntries();

                List <LogEntry> foundEntriesList = new List <LogEntry>();
                for (int i = 0; i < logEntries.Count; i++)
                {
                    LogEntry logEntry = logEntries[i];
                    bool     found    =
                        (compiledSearchInput.MatchPatternType(PatternItemType.Date) && SearchText(compiledSearchInput, logEntry.DateText))
                        ||
                        (compiledSearchInput.MatchPatternType(PatternItemType.Thread) && SearchText(compiledSearchInput, logEntry.Thread))
                        ||
                        (compiledSearchInput.MatchPatternType(PatternItemType.Type) && SearchText(compiledSearchInput, logEntry.Type))
                        ||
                        (compiledSearchInput.MatchPatternType(PatternItemType.Class) && SearchText(compiledSearchInput, logEntry.Class))
                        ||
                        (compiledSearchInput.MatchPatternType(PatternItemType.Message) && SearchText(compiledSearchInput, logEntry.Message));

                    if (found)
                    {
                        logEntry.FoundOnLine = i;
                        foundEntriesList.Add(logEntry);
                    }
                }

                return(foundEntriesList);
            }
            catch (Exception ex)
            {
                log.Error("Error during search: " + ex.ToString());
                MessageBox.Show(ex.Message, "Error during search", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                Owner.Cursor = origOwnerCursor;
                this.Cursor  = Cursors.Default;
            }
            return(new List <LogEntry>());
        }
        private bool SearchText(CompiledSearchInput input, string findWhere)
        {
            if (findWhere == null)
            {
                return(false);
            }

            int length;

            return(SearchText(input, findWhere, 0, out length) > -1);
        }
 public void ResetSearchResults()
 {
     if (foundEntries != null)
     {
         foundEntries.ForEach(e => e.FoundOnLine = -1);
         foundEntries        = null;
         compiledSearchInput = null;
         ReflectChangesInFoundList();
     }
     SetStatusText("Nothing has been searched.", Color.FromKnownColor(KnownColor.ControlText));
 }
 private int SearchText(CompiledSearchInput input, string findWhere, int startIndex, out int length)
 {
     if (input.RegEx != null)
     {
         Match match = input.RegEx.Match(findWhere, startIndex);
         if (match.Success)
         {
             length = match.Length;
             return(match.Index);
         }
         else
         {
             length = -1;
             return(-1);
         }
     }
     else
     {
         length = input.FindWhat.Length;
         return(findWhere.IndexOf(input.FindWhat, startIndex, input.StringComparison));
     }
 }