public async Task CanLoadExactMessageInMiddleOfLog1() { Assert.IsTrue(await screenBuffer.MoveToBookmark(bmks.CreateBookmark(src1.messages.Items[2], 2), BookmarkLookupMode.ExactMatch, cancel)); VerifyMessages(screenBuffer, @"a2-ln_2 b2-ln_0 b2-ln_1 a3-ln_0 a3-ln_1", 0); }
public async Task CanLoadAtMiddle() { await screenBuffer.MoveToBookmark(bmks.CreateBookmark(src.messages.Items[0], 2), BookmarkLookupMode.ExactMatch, cancel); VerifyMessages(screenBuffer, @"0-ln_2 0-ln_3 0-ln_4 0-ln_5 1-ln_0 1-ln_1 1-ln_2", 0); }
public async Task CanLoadBookmark() { await screenBuffer.MoveToBookmark(bmks.CreateBookmark(src.messages.Items[9], 0), BookmarkLookupMode.ExactMatch, cancel); VerifyMessages(screenBuffer, @"9-ln_0 10-ln_0 11-ln_0 12-ln_0 13-ln_0 14-ln_0", 0); }
public async Task CanLoadBookmarkWhenManyMessagesShareTheTimestamp() { src1 = CreateTestSource(messagesCount: 20, linesPerMessage: 1, messagesPrefix: "a", messagesPerTimestamp: 10); src2 = CreateTestSource(messagesCount: 20, linesPerMessage: 1, messagesPrefix: "b", messagesPerTimestamp: 10); screenBuffer = new ScreenBuffer(changeNotification, 3); await screenBuffer.SetSources(new[] { src1, src2 }, cancel); await screenBuffer.MoveToBookmark( bmks.CreateBookmark(src1.messages.Items[5], 0), BookmarkLookupMode.ExactMatch, cancel); VerifyMessages(screenBuffer, @"a5-ln_0 a6-ln_0 a7-ln_0", 0); await screenBuffer.MoveToBookmark( bmks.CreateBookmark(src2.messages.Items[0], 0), BookmarkLookupMode.ExactMatch | BookmarkLookupMode.MoveBookmarkToMiddleOfScreen, cancel); VerifyMessages(screenBuffer, @"a9-ln_0 b0-ln_0 b1-ln_0", 0); }
public async Task ShouldLoadNothingIsViewSizeIsZero() { src = CreateTestSource(messagesCount: 20); screenBuffer = new ScreenBuffer(changeNotification, 0); await screenBuffer.SetSources(new[] { src }, cancel); await screenBuffer.MoveToBookmark( bmks.CreateBookmark(src.messages.Items[5], 0), BookmarkLookupMode.ExactMatch, cancel); Assert.AreEqual(0, screenBuffer.Messages.Count); await screenBuffer.MoveToStreamsEnd(cancel); Assert.AreEqual(0, screenBuffer.Messages.Count); }
public async Task CanLoadExactMessageWhenViewIsLargerThanLogg_WithScrollingToTopMiddleOfScreen() { src = CreateTestSource(messagesCount: 2, linesPerMessage: 3); screenBuffer = new ScreenBuffer(changeNotification, 8.2); await screenBuffer.SetSources(new[] { src }, cancel); Assert.IsTrue(await screenBuffer.MoveToBookmark(bmks.CreateBookmark(src.messages.Items[1], 2), BookmarkLookupMode.ExactMatch | BookmarkLookupMode.MoveBookmarkToMiddleOfScreen, cancel)); VerifyMessages(screenBuffer, @"0-ln_0 0-ln_1 0-ln_2 1-ln_0 1-ln_1 1-ln_2", 0); }
async Task <List <ScreenBufferEntry> > GetSelectedDisplayMessagesEntries() { var viewLines = screenBuffer.Messages; Func <CursorPosition, bool> isGoodDisplayPosition = p => { if (p.Message == null) { return(true); } return(p.DisplayIndex >= 0 && p.DisplayIndex < viewLines.Count); }; var normSelection = selection.Normalize(); if (normSelection.IsEmpty) { return(new List <ScreenBufferEntry>()); } Func <List <ScreenBufferEntry> > defaultGet = () => { int selectedLinesCount = normSelection.Last.DisplayIndex - normSelection.First.DisplayIndex + 1; return(viewLines.Skip(normSelection.First.DisplayIndex).Take(selectedLinesCount).ToList()); }; if (isGoodDisplayPosition(normSelection.First) && isGoodDisplayPosition(normSelection.Last)) { // most common case: both positions are in the screen buffer at the moment return(defaultGet()); } CancellationToken cancellation = CancellationToken.None; IScreenBuffer tmpBuf = screenBufferFactory.CreateScreenBuffer(initialBufferPosition: InitialBufferPosition.Nowhere); await tmpBuf.SetSources(screenBuffer.Sources.Select(s => s.Source), cancellation); if (!await tmpBuf.MoveToBookmark(bookmarksFactory.CreateBookmark(normSelection.First.Message, 0), BookmarkLookupMode.ExactMatch, cancellation)) { // Impossible to load selected message into screen buffer. Rather impossible. return(defaultGet()); } var tasks = screenBuffer.Sources.Select(async sourceBuf => { var sourceMessages = new List <IMessage>(); await sourceBuf.Source.EnumMessages( tmpBuf.Sources.First(sb => sb.Source == sourceBuf.Source).Begin, m => { if (MessagesComparer.Compare(m, normSelection.Last.Message) > 0) { return(false); } sourceMessages.Add(m); return(true); }, EnumMessagesFlag.Forward, LogProviderCommandPriority.AsyncUserAction, cancellation ); return(new { Source = sourceBuf.Source, Messages = sourceMessages }); }).ToList(); await Task.WhenAll(tasks); cancellation.ThrowIfCancellationRequested(); var messagesToSource = tasks.ToDictionary( t => (IMessagesCollection) new MessagesContainers.SimpleCollection(t.Result.Messages), t => t.Result.Source); return (new MessagesContainers.SimpleMergingCollection(messagesToSource.Keys) .Forward(0, int.MaxValue) .SelectMany(m => Enumerable.Range(0, GetTextToDisplay(m.Message.Message).GetLinesCount()).Select( lineIdx => new ScreenBufferEntry() { TextLineIndex = lineIdx, Message = m.Message.Message, Source = messagesToSource[m.SourceCollection], } ) ) .TakeWhile(m => CursorPosition.Compare(CursorPosition.FromViewLine(m.ToViewLine(), 0), normSelection.Last) <= 0) .ToList()); }