Пример #1
0
        private int DoFilter(FilterParams filterParams, int startLine, int maxCount, List <int> filterResultLines,
                             List <int> lastFilterLinesList, List <int> filterHitList, ProgressCallback progressCallback)
        {
            int lineNum         = startLine;
            int count           = 0;
            int callbackCounter = 0;

            try
            {
                filterParams.Reset();
                while ((count++ < maxCount || filterParams.isInRange) && !ShouldCancel)
                {
                    if (lineNum >= _callback.GetLineCount())
                    {
                        return(count);
                    }
                    ILogLine line = _callback.GetLogLine(lineNum);
                    if (line == null)
                    {
                        return(count);
                    }
                    _callback.LineNum = lineNum;
                    if (Util.TestFilterCondition(filterParams, line, _callback))
                    {
                        AddFilterLine(lineNum, false, filterParams, filterResultLines, lastFilterLinesList,
                                      filterHitList);
                    }
                    lineNum++;
                    callbackCounter++;
                    if (lineNum % PROGRESS_BAR_MODULO == 0)
                    {
                        progressCallback(callbackCounter);
                        callbackCounter = 0;
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "Exception while filtering. Please report to developer");
                MessageBox.Show(null,
                                "Exception while filtering. Please report to developer: \n\n" + ex + "\n\n" + ex.StackTrace,
                                "LogExpert");
            }
            return(count);
        }
Пример #2
0
        public Range FindRange(int startLine)
        {
            _logger.Info($"Starting range search for {_filterParams.searchText} ... {_filterParams.rangeSearchText}");
            if (_filterParams.rangeSearchText == null || _filterParams.rangeSearchText.Trim().Length == 0)
            {
                _logger.Info("Range search text not set. Cancelling range search.");
                return(null);
            }
            if (_filterParams.searchText == null || _filterParams.searchText.Trim().Length == 0)
            {
                _logger.Info("Search text not set. Cancelling range search.");
                return(null);
            }

            _filterParams.isRangeSearch = false;
            _filterParams.isInRange     = false;
            int          lineCount      = _callback.GetLineCount();
            int          lineNum        = startLine;
            bool         foundStartLine = false;
            Range        range          = new Range();
            FilterParams tmpParam       = _filterParams.CreateCopy2();

            tmpParam.searchText = _filterParams.rangeSearchText;

            // search backward for starting keyword
            var line = _callback.GetLogLine(lineNum);

            while (lineNum >= 0)
            {
                _callback.LineNum = lineNum;
                if (Util.TestFilterCondition(_filterParams, line, _callback))
                {
                    foundStartLine = true;
                    break;
                }
                lineNum--;
                line = _callback.GetLogLine(lineNum);
                if (lineNum < 0 || Util.TestFilterCondition(tmpParam, line, _callback)
                    ) // do not crash on Ctrl+R when there is not start line found
                {
                    // lower range bound found --> we are not in between a valid range
                    break;
                }
            }
            if (!foundStartLine)
            {
                _logger.Info("Range start not found");
                return(null);
            }
            range.StartLine             = lineNum;
            _filterParams.isRangeSearch = true;
            _filterParams.isInRange     = true;
            lineNum++;
            while (lineNum < lineCount)
            {
                line = _callback.GetLogLine(lineNum);
                _callback.LineNum = lineNum;
                if (!Util.TestFilterCondition(_filterParams, line, _callback))
                {
                    break;
                }
                lineNum++;
            }
            lineNum--;
            range.EndLine = lineNum;

            _logger.Info($"Range search finished. Found {range.EndLine - range.StartLine} lines");

            return(range);
        }