コード例 #1
0
ファイル: SearchCommand.cs プロジェクト: rkapl123/logjoint
        async Task IAsyncLogProviderCommandHandler.ContinueAsynchronously(CommandContext ctx)
        {
            using (var innerCancellation = CancellationTokenSource.CreateLinkedTokenSource(ctx.Cancellation, ctx.Preemption))
            {
                var searchRange = new FileRange.Range(
                    searchParams.FromPosition.GetValueOrDefault(ctx.Reader.BeginPosition), ctx.Reader.EndPosition);

                var parserParams = new CreateSearchingParserParams()
                {
                    Range             = searchRange,
                    SearchParams      = searchParams,
                    Cancellation      = innerCancellation.Token,
                    ContinuationToken = continuationToken,
                    ProgressHandler   = pos => UpdateSearchCompletionPercentage(progress, pos, searchRange, false)
                };

                try
                {
                    var parser = ctx.Reader.CreateSearchingParser(parserParams);
                    try
                    {
                        for (; ;)
                        {
                            var msg = await parser.GetNext();

                            if (msg.Message == null || !callback(msg))
                            {
                                break;
                            }
                        }
                    }
                    finally
                    {
                        await parser.Dispose();
                    }
                }
                catch (SearchCancelledException e)                 // todo: impl it for xml reader
                {
                    if (ctx.Preemption.IsCancellationRequested)
                    {
                        continuationToken = e.ContinuationToken;
                    }
                    throw;
                }
            }
        }
コード例 #2
0
        public SearchingParser(
            IPositionedMessagesReader owner,
            CreateSearchingParserParams p,
            TextStreamPositioningParams textStreamPositioningParams,
            DejitteringParams?dejitteringParams,
            Stream rawStream,
            Encoding streamEncoding,
            bool allowPlainTextSearchOptimization,
            LoadedRegex headerRe,
            ILogSourceThreads threads,
            ITraceSourceFactory traceSourceFactory,
            RegularExpressions.IRegexFactory regexFactory
            )
        {
            this.owner        = owner;
            this.parserParams = p;
            this.plainTextSearchOptimizationAllowed = allowPlainTextSearchOptimization && ((p.Flags & MessagesParserFlag.DisablePlainTextSearchOptimization) == 0);
            this.threads        = threads;
            this.requestedRange = p.Range;
            this.textStreamPositioningParams = textStreamPositioningParams;
            this.dejitteringParams           = dejitteringParams;
            this.rawStream      = rawStream;
            this.streamEncoding = streamEncoding;
            this.regexFactory   = regexFactory;
            this.trace          = traceSourceFactory.CreateTraceSource("LogSource", "srchp." + GetHashCode().ToString("x"));
            this.dummyFilter    = new Filter(FilterAction.Include, "", true, new Search.Options(), null, regexFactory);
            var continuationToken = p.ContinuationToken as ContinuationToken;

            if (continuationToken != null)
            {
                this.requestedRange = new FileRange.Range(continuationToken.NextPosition, requestedRange.End);
            }
            this.aligmentTextAccess      = new StreamTextAccess(rawStream, streamEncoding, textStreamPositioningParams);
            this.aligmentSplitter        = new MessagesSplitter(aligmentTextAccess, headerRe.Clone().Regex, headerRe.GetHeaderReSplitterFlags());
            this.aligmentCapture         = new TextMessageCapture();
            this.progressAndCancellation = new ProgressAndCancellation()
            {
                progressHandler   = p.ProgressHandler,
                cancellationToken = p.Cancellation,
                continuationToken = new ContinuationToken()
                {
                    NextPosition = requestedRange.Begin
                }
            };
            this.impl = Enum();
        }
コード例 #3
0
            public PlainTextMatcher(
                CreateSearchingParserParams p,
                TextStreamPositioningParams textStreamPositioningParams,
                bool plainTextSearchOptimizationAllowed,
                RegularExpressions.IRegexFactory regexFactory)
            {
                var fixedOptions = new List <Search.Options>();

                plainTextSearchOptimizationPossible = true;

                if (!plainTextSearchOptimizationAllowed)
                {
                    plainTextSearchOptimizationPossible = false;
                }
                else if (p.SearchParams.Filters.GetDefaultAction() == FilterAction.Exclude)
                {
                    // todo: handle case of multiple positive filters
                    foreach (var filter in p.SearchParams.Filters.Items)
                    {
                        if (filter.Options.Template.Length == 0)
                        {
                            plainTextSearchOptimizationPossible = false;
                        }
                        else
                        {
                            var filterMaxMatchLength = filter.Options.Regexp
                                                                ? textStreamPositioningParams.AlignmentBlockSize
                                                                : filter.Options.Template.Length;
                            maxMatchLength = Math.Max(maxMatchLength, filterMaxMatchLength);
                            var tmp = filter.Options;
                            tmp.ReverseSearch = false;
                            fixedOptions.Add(tmp);
                        };
                    }
                    ;
                }
                else
                {
                    plainTextSearchOptimizationPossible = false;
                }
                if (plainTextSearchOptimizationPossible)
                {
                    opts = fixedOptions.Select(i => i.BeginSearch(regexFactory)).ToArray();
                }
            }
コード例 #4
0
 public ISearchingParser CreateSearchingParser(CreateSearchingParserParams p)
 {
     return(underliyingReader.CreateSearchingParser(p));
 }
コード例 #5
0
 public virtual ISearchingParser CreateSearchingParser(CreateSearchingParserParams p)
 {
     return(null);
 }