示例#1
0
        Task IScreenBuffer.SetDisplayTextGetter(MessageTextGetter displayTextGetter, CancellationToken cancellation)
        {
            if (this.displayTextGetter == displayTextGetter)
            {
                return(Task.FromResult(0));
            }
            this.displayTextGetter = displayTextGetter;
            changeNotification.Post();
            var currentTop = EnumScreenBufferLines().FirstOrDefault();

            return(PerformBuffersTransaction(
                       string.Format("SetDisplayTextGetter({0})", displayTextGetter),
                       cancellation, 
 modifyBuffers: tmp => Task.WhenAll(tmp.Select(b => b.LoadAround(GetMaxBufferSize(viewSize), cancellation))), 
 getPivotLine: (lines, bufs) => 
                         {
                
 var candidate = new DisplayLine();
                if (!currentTop.IsEmpty)
                {
                    candidate = lines.FirstOrDefault(l => MessagesComparer.Compare(l.Message, currentTop.Message) == 0 && l.LineIndex == currentTop.LineIndex); 
                                            if (candidate.IsEmpty)
                    {
                        candidate = lines.FirstOrDefault(l => MessagesComparer.Compare(l.Message, currentTop.Message) == 0);
                    }
                }
                if (candidate.IsEmpty)
                {
                    candidate = lines.FirstOrDefault();
                }
                if (candidate.IsEmpty)
                {
                    return null;
                }
                
                                   return Tuple.Create(candidate, -scrolledLines); 

            } 
)); 

        }
示例#2
0
        async Task <bool> IScreenBuffer.MoveToBookmark(
            IBookmark bookmark,
            BookmarkLookupMode mode,
            CancellationToken cancellation)
        {
            var matchMode = mode & BookmarkLookupMode.MatchModeMask;
            Func <DisplayLine, int> cmp = (DisplayLine l) =>
            {
                var ret = MessagesComparer.CompareLogSourceConnectionIds(l.Message.GetConnectionId(), bookmark.LogSourceConnectionId);
                if (ret == 0)
                {
                    ret = Math.Sign(l.Message.Position - bookmark.Position);
                }
                if (ret == 0)
                {
                    ret = Math.Sign(l.LineIndex - bookmark.LineIndex);
                }
                return(ret);
            };

            return(await PerformBuffersTransaction(
                       string.Format("MoveToBookmark({0})", mode),
                       cancellation,
                       modifyBuffers : tmp => Task.WhenAll(tmp.Select(buf =>
                                                                      matchMode == BookmarkLookupMode.ExactMatch && buf.Source.LogSourceHint?.ConnectionId == bookmark.LogSourceConnectionId ?
                                                                      buf.LoadAround(bookmark.Position, GetMaxBufferSize(viewSize) + bookmark.LineIndex, cancellation) :
                                                                      buf.LoadAt(bookmark.Time.ToLocalDateTime(), GetMaxBufferSize(viewSize) + bookmark.LineIndex, cancellation)
                                                                      )),
                       getPivotLine : (lines, bufs) =>
            {
                DisplayLine ret = new DisplayLine();
                if (matchMode == BookmarkLookupMode.ExactMatch)
                {
                    ret = lines.FirstOrDefault(l => cmp(l) == 0);
                }
                else if (matchMode == BookmarkLookupMode.FindNearestMessage)
                {
                    ret = lines.FirstOrDefault(l => cmp(l) >= 0);
                    if (ret.IsEmpty)
                    {
                        ret = lines.LastOrDefault(l => cmp(l) < 0);
                    }
                }
                return ret.Message == null ? null : Tuple.Create(ret, ComputeMatchedLinePosition(mode));
            }
                       ) != null);
        }