Beispiel #1
0
        public void EnumMessages(long fromPosition, Func <IMessage, bool> callback, EnumMessagesFlag flags)
        {
            var forward = (flags & EnumMessagesFlag.Forward) != 0;
            var idx     = ListUtils.GetBound(messages, null,
                                             forward ? ValueBound.Lower : ValueBound.UpperReversed,
                                             new PositionsComparer(fromPosition));

            if (forward)
            {
                for (; idx < messages.Count; ++idx)
                {
                    if (!callback(messages[idx]))
                    {
                        return;
                    }
                }
            }
            else
            {
                for (; idx >= 0; --idx)
                {
                    if (messages[idx].EndPosition <= fromPosition && !callback(messages[idx]))
                    {
                        return;
                    }
                }
            }
        }
Beispiel #2
0
        static async Task <ScreenBufferLinesRange> GetScreenBufferLines(
            IMessagesSource src,
            long startFrom,
            int maxCount,
            EnumMessagesFlag flags,
            MessageTextGetter displayTextGetter,
            Diagnostics diag,
            CancellationToken cancellation,
            bool doNotCountFirstMessage = false             // todo: needed?
            )
        {
            var backward       = (flags & EnumMessagesFlag.Backward) != 0;
            var lines          = new List <DisplayLine>();
            var loadedMessages = 0;
            var linesToIgnore  = 0;
            await src.EnumMessages(startFrom, msg =>
            {
                var messagesLinesCount = displayTextGetter(msg).GetLinesCount();
                if (backward)
                {
                    for (int i = messagesLinesCount - 1; i >= 0; --i)
                    {
                        lines.Add(new DisplayLine(msg, i, messagesLinesCount, displayTextGetter, src));
                    }
                }
                else
                {
                    for (int i = 0; i < messagesLinesCount; ++i)
                    {
                        lines.Add(new DisplayLine(msg, i, messagesLinesCount, displayTextGetter, src));
                    }
                }
                if (diag.IsEnabled)
                {
                    diag.VerifyLines(backward ? Enumerable.Reverse(lines) : lines, src.HasConsecutiveMessages);
                }
                ++loadedMessages;
                if (doNotCountFirstMessage && loadedMessages == 1)
                {
                    linesToIgnore = lines.Count;
                }
                return((lines.Count - linesToIgnore) < maxCount);
            }, flags | EnumMessagesFlag.IsActiveLogPositionHint, LogProviderCommandPriority.RealtimeUserAction, cancellation);

            cancellation.ThrowIfCancellationRequested();
            var firstRead = lines.FirstOrDefault();

            if (backward)
            {
                lines.Reverse();
            }
            var badPosition = backward ? src.PositionsRange.Begin : src.PositionsRange.End;
            ScreenBufferLinesRange ret;

            ret.Lines         = lines;
            ret.BeginPosition = lines.Count > 0 ? lines[0].Message.Position : badPosition;
            ret.EndPosition   = lines.Count > 0 ? lines[lines.Count - 1].Message.EndPosition : badPosition;
            diag.VerifyLines(ret.Lines, src.HasConsecutiveMessages);
            return(ret);
        }
Beispiel #3
0
 Task LogViewer.IMessagesSource.EnumMessages(
     long fromPosition, Func <IMessage, bool> callback, EnumMessagesFlag flags,
     LogProviderCommandPriority priority, CancellationToken cancellation)
 {
     ssr.EnumMessages(fromPosition, callback, flags);
     return(Task.FromResult(1));
 }
Beispiel #4
0
 public EnumMessagesCommand(long startFrom, EnumMessagesFlag flags, Func <IMessage, bool> callback)
 {
     this.flags     = flags;
     this.startFrom = startFrom;
     this.positionToContinueAsync = startFrom;
     this.callback  = callback;
     this.direction = (flags & EnumMessagesFlag.Backward) != 0 ?
                      MessagesParserDirection.Backward : MessagesParserDirection.Forward;
 }
 Task IMessagesSource.EnumMessages(long fromPosition, Func <IMessage, bool> callback,
                                   EnumMessagesFlag flags, LogProviderCommandPriority priority, CancellationToken cancellation)
 {
     if (ls.IsDisposed)
     {
         throw new OperationCanceledException();
     }
     return(ls.Provider.EnumMessages(fromPosition, callback, flags, priority, cancellation));
 }
Beispiel #6
0
        Task ILogProvider.EnumMessages(
            long startFrom,
            Func <IMessage, bool> callback,
            EnumMessagesFlag flags,
            LogProviderCommandPriority priority,
            CancellationToken cancellation
            )
        {
            CheckDisposed();
            var     ret = new EnumMessagesCommand(startFrom, flags, callback);
            Command cmd = new Command(Command.CommandType.Get, priority, tracer, cancellation, ret);

            PostCommand(cmd);
            if ((flags & EnumMessagesFlag.IsActiveLogPositionHint) != 0)
            {
                Interlocked.Exchange(ref activePositionHint, startFrom);
                PostCommand(new Command(Command.CommandType.UpdateCache, LogProviderCommandPriority.SmoothnessEnsurance, tracer,
                                        cancellation, new UpdateCacheCommandHandler(this, tracer, messagesCacheBackbuffer, host.GlobalSettings)));
            }
            return(ret.Task);
        }
Beispiel #7
0
        static async Task <ScreenBufferMessagesRange> GetScreenBufferLines(
            IMessagesSource src,
            long startFrom,
            int maxCount,
            EnumMessagesFlag flags,
            bool rawLogMode,
            CancellationToken cancellation,
            bool doNotCountFirstMessage = false
            )
        {
            var backward       = (flags & EnumMessagesFlag.Backward) != 0;
            var lines          = new List <DisplayLine>();
            var loadedMessages = 0;
            var linesToIgnore  = 0;
            await src.EnumMessages(startFrom, msg =>
            {
                var messagesLinesCount = msg.GetDisplayText(rawLogMode).GetLinesCount();
                if (backward)
                {
                    for (int i = messagesLinesCount - 1; i >= 0; --i)
                    {
                        lines.Add(new DisplayLine(msg, i, messagesLinesCount));
                    }
                }
                else
                {
                    for (int i = 0; i < messagesLinesCount; ++i)
                    {
                        lines.Add(new DisplayLine(msg, i, messagesLinesCount));
                    }
                }
                ++loadedMessages;
                if (doNotCountFirstMessage && loadedMessages == 1)
                {
                    linesToIgnore = lines.Count;
                }
                return((lines.Count - linesToIgnore) < maxCount);
            }, flags | EnumMessagesFlag.IsActiveLogPositionHint, LogProviderCommandPriority.RealtimeUserAction, cancellation);

            cancellation.ThrowIfCancellationRequested();
            var firstRead = lines.FirstOrDefault();

            if (backward)
            {
                lines.Reverse();
            }
            var badPosition = backward ? src.PositionsRange.Begin : src.PositionsRange.End;
            ScreenBufferMessagesRange ret;

            ret.Lines         = lines;
            ret.BeginPosition = lines.Count > 0 ? lines[0].Message.Position : badPosition;
            if (lines.Count == 0)
            {
                ret.EndPosition = badPosition;
            }
            else
            {
                ret.EndPosition = lines[lines.Count - 1].Message.EndPosition;
            }
            return(ret);
        }
Beispiel #8
0
 void ICombinedSourceSearchResult.EnumMessages(long fromPosition, Func <IMessage, bool> callback, EnumMessagesFlag flags)
 {
     messages.EnumMessages(fromPosition, callback, flags);
 }
Beispiel #9
0
 Task IMessagesSource.EnumMessages(long fromPosition, Func <IMessage, bool> callback,
                                   EnumMessagesFlag flags, LogProviderCommandPriority priority, CancellationToken cancellation)
 {
     return(ls.Provider.EnumMessages(fromPosition, callback, flags, priority, cancellation));
 }