public Page(CompressedPage cPage, int maxForce) { this.Owner = cPage.Owner; this.Book = cPage.Book; this.Section = cPage.Section; this.Number = cPage.Number; this.MarginR = cPage.MarginR; this.MarginL = cPage.MarginL; this.MarginB = cPage.MarginB; this.MarginT = cPage.MarginT; this.X1 = cPage.X1; this.X2 = cPage.X2; this.Y1 = cPage.Y1; this.Y2 = cPage.Y2; Strokes = new List <Stroke>(); if (cPage.Strokes != null) { if (cPage.Strokes.Count > 0) { foreach (CompressedStroke cStroke in cPage.Strokes) { this.Strokes.Add(new Stroke(cStroke, maxForce)); } } } }
private async Task TestPageWriteAndRead(PagesCluster clusterPage, long pageId, Dictionary <long, byte[]> cache) { var messagePageId = new MessagePageId(pageId); var hasPage = await clusterPage.HasPageAsync(messagePageId); Assert.IsFalse(hasPage); var msg = new MessageContentGrpcModel { Created = DateTime.UtcNow, Data = new [] { (byte)pageId, (byte)pageId, (byte)pageId }, MessageId = pageId, }; var content = new CompressedPage(new MessagePageId(pageId), new [] { msg }); cache.Add(pageId, content.ZippedContent.ToArray()); await clusterPage.WriteAsync(messagePageId, content); hasPage = await clusterPage.HasPageAsync(messagePageId); Assert.IsTrue(hasPage); var resultContent = await clusterPage.ReadAsync(messagePageId); resultContent.ZippedContent.AssertAllBytesAreEqualWith(content.ZippedContent); }
public async Task WriteAsync(MessagePageId pageId, CompressedPage pageData) { var tocIndex = GetPageTocIndex(pageId); if (_tocPage == null) { await InitIndexPageAsync(true); } var nextPageNoToWrite = await GetNextPageNoToWriteAsync(tocIndex, pageData.ZippedContent.Length); await AzurePageBlob.WriteBytesAsync(pageData.ZippedContent, nextPageNoToWrite, new WriteBytesOptions { SplitRoundTripsPageSize = 4096 }); await WritePagePositionAllocationToc(tocIndex, nextPageNoToWrite, pageData.ZippedContent.Length); }
public async Task <CompressedPage> ReadAsync(MessagePageId pageId) { try { //If we do not have exceptions - can remove this try/catch GetPageTocIndex(pageId); } catch (Exception e) { Console.WriteLine("Can not get TocIndex for page: " + pageId.Value + "; TopicId:" + TopicId); Console.WriteLine(e); throw; } var tocIndex = GetPageTocIndex(pageId); var(position, length) = await GetPagePositionAllocationToc(tocIndex, false); if (length == 0) { return(CompressedPage.CreateEmpty(pageId)); } try { //If we do not have exceptions - can remove this try/catch var fullPages = MyAzurePageBlobUtils.CalculateRequiredPagesAmount(length); var result = await AzurePageBlob.ReadAsync(position, fullPages); var buffer = result.GetBuffer(); return(new CompressedPage(pageId, new ReadOnlyMemory <byte>(buffer, 0, (int)length))); } catch (Exception) { Console.WriteLine("Problem with reading page: " + pageId + " TocIndex: " + tocIndex + "; position:" + position + " Length:" + length); return(CompressedPage.CreateEmpty(pageId)); } }
public ReadOnlyContentPage(CompressedPage compressedPage) { PageId = compressedPage.PageId; _compressedPage = compressedPage; }