Esempio n. 1
0
        public async Task<bool> ApplyFilter(LogLine logLine)
        {
            if (string.IsNullOrEmpty(logLine.Content) || string.IsNullOrEmpty(_source.SearchPhrase))
                return false;

            var sw = new Stopwatch();
            sw.Start();

            bool wasApplied;
            switch (_source.PhraseType)
            {
                case PhraseType.Literal:
                    wasApplied = ApplyLiteral(logLine);
                    break;
                case PhraseType.Regex:
                    wasApplied = ApplyRegex(logLine);
                    break;
                default:
                    wasApplied = false;
                    break;
            }

            sw.Stop();
            Debug.WriteLineIf(
                wasApplied && sw.ElapsedMilliseconds > 0, 
                $"HideLine filter applied in {sw.ElapsedMilliseconds}ms.");

            return wasApplied;
        }
        private bool ApplyLiteral(LogLine logLine)
        {
            if (logLine.Content.IndexOf(_source.SearchPhrase, _comparisonRule) == -1) // not droids you're looking for
                return false;

            logLine.Highlight = LogHighlight.Find;
            return true;
        }
        private bool ApplyRegex(LogLine logLine)
        {
            var regex = new Regex(_source.SearchPhrase);
            if (!regex.IsMatch(logLine.Content))
                return false;

            logLine.Highlight = LogHighlight.Find;
            return true;
        }
Esempio n. 4
0
        public async Task<bool> ApplyFilter(LogLine logLine)
        {
            if (string.IsNullOrEmpty(logLine.Content) || !_source.ErrorPhraseCollection.Any())
                return false;

            if (_source.ErrorPhraseCollection.All(word => logLine.Content.IndexOf(word, StringComparison.OrdinalIgnoreCase) == -1))
                return false;

            logLine.Highlight = LogHighlight.Error;
            return true;
        }
Esempio n. 5
0
        private bool ApplyLiteral(LogLine logLine)
        {
            if (logLine.Content.IndexOf(_source.SearchPhrase, _source.ComparisonRule) != -1)
            {
                ExtractContext(logLine);
                return false;
            }
            
            logLine.Highlight = LogHighlight.Hide;

            return true;
        }
Esempio n. 6
0
        private bool ApplyRegex(LogLine logLine)
        {
            var regex = new Regex(_source.SearchPhrase);
            if (regex.IsMatch(logLine.Content))
            {
                ExtractContext(logLine);
                return false;
            }
            
            logLine.Highlight = LogHighlight.Hide;

            return true;
        }
        /// <summary>
        /// Applies the filter.
        /// </summary>
        /// <param name="logLine">The log line.</param>
        /// <returns></returns>
        public async Task<bool> ApplyFilter(LogLine logLine)
        {
            if (string.IsNullOrEmpty(logLine.Content) || string.IsNullOrEmpty(_source.SearchPhrase))
                return false;

            bool wasApplied;
            switch (_phraseType)
            {
                case PhraseType.Literal:
                    wasApplied = ApplyLiteral(logLine);
                    break;
                case PhraseType.Regex:
                    wasApplied = ApplyRegex(logLine);
                    break;
                default:
                    wasApplied = false;
                    break;
            }

            return wasApplied;
        }
Esempio n. 8
0
 public async Task<bool> ApplyFilter(LogLine logLine)
 {
     logLine.DeFilter();
     return true;
 }
Esempio n. 9
0
        private void ExtractContext(LogLine logLine)
        {
            if (_source.SearchMode != SearchMode.Filter)
                return;

            var lineIndex = _source.LogLines.IndexOf(logLine);
            var lineContext = ExtractContext(lineIndex, _source.LogLines.ToArray());
            _source.LogLines[lineIndex].LineContext = string.IsNullOrEmpty(lineContext)
                ? logLine.Content
                : lineContext;
        }
Esempio n. 10
0
        private string ExtractContext(int currentIndex, LogLine[] logarray)
        {
            var startIndex = currentIndex - _headCount;
            var sliceSize = Range;

            // make sure we don't go out of bounds
            if (startIndex < 0)
            {
                sliceSize += startIndex;
                startIndex = 0;
            }

            if (startIndex + sliceSize > logarray.Length)
                sliceSize = logarray.Length - startIndex;

            // get the slice
            var slice = new LogLine[sliceSize];
            Array.Copy(logarray, startIndex, slice, 0, sliceSize);

            return GetContextContent(slice);
        }