Esempio n. 1
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);
        }
Esempio n. 2
0
        static async Task <ScreenBufferLinesRange> GetScreenBufferLines(
            IMessagesSource src,
            DateTime dt,
            int maxCount,
            MessageTextGetter displayTextGetter,
            Diagnostics diag,
            CancellationToken cancellation)
        {
            var startFrom = await src.GetDateBoundPosition(dt, ValueBound.Lower,
                                                           LogProviderCommandPriority.RealtimeUserAction, cancellation);

            cancellation.ThrowIfCancellationRequested();
            var lines = new List <DisplayLine>();
            var additionalMessagesCount = 0;
            await src.EnumMessages(
                startFrom.Position,
                msg =>
            {
                var messagesLinesCount = displayTextGetter(msg).GetLinesCount();
                for (int i = 0; i < messagesLinesCount; ++i)
                {
                    lines.Add(new DisplayLine(msg, i, messagesLinesCount, displayTextGetter, src));
                }
                var pastRequestedTime = msg.Time.ToLocalDateTime() > dt;
                if (!pastRequestedTime)
                {
                    return(true);
                }
                ++additionalMessagesCount;
                return(additionalMessagesCount < maxCount);
            },
                EnumMessagesFlag.Forward | EnumMessagesFlag.IsActiveLogPositionHint,
                LogProviderCommandPriority.RealtimeUserAction,
                cancellation
                );

            cancellation.ThrowIfCancellationRequested();
            var srcPositionsRange = src.PositionsRange;
            ScreenBufferLinesRange ret;

            ret.Lines         = lines;
            ret.BeginPosition = lines.Count > 0 ? lines[0].Message.Position : srcPositionsRange.End;
            if (lines.Count > 0)
            {
                ret.EndPosition = lines[lines.Count - 1].Message.EndPosition;
            }
            else
            {
                ret.EndPosition = srcPositionsRange.End;
            }
            diag.VerifyLines(ret.Lines, src.HasConsecutiveMessages);
            return(ret);
        }
Esempio n. 3
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);
        }