public override async Task <int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { int result = 0; await _session.Run(() => { cancellationToken.ThrowIfCancellationRequested(); result = _inlinedStream.Read(buffer, offset, count); }); return(result); }
private async ValueTask <PostStoreEntityId[]> DoQueryByFlags(IEsentSession session, PostStoreEntityType type, PostStoreEntityId?parentId, IList <Guid> havingFlags) { return(await session.Run(() => { var found = new List <HashSet <int> >(); if (havingFlags != null && havingFlags.Count > 0) { using (var table = OpenPostsTable(session, OpenTableGrbit.ReadOnly)) { foreach (var flag in havingFlags) { if (parentId != null) { var index = table.Indexes.DirectParentFlagsIndex; index.SetAsCurrentIndex(); found.Add(index.EnumerateAsRetrieveIdFromIndexView(index.CreateKey(parentId.Value.Id, flag)).Select(id => id.Id).ToHashSet()); } else { var index = table.Indexes.TypeFlagsIndex; index.SetAsCurrentIndex(); found.Add(index.EnumerateAsRetrieveIdFromIndexView(index.CreateKey((byte)type, flag)).Select(id => id.Id).ToHashSet()); } } } } if (found.Count == 0) { goto CancelLabel; } var r = found[0]; foreach (var f in found.Skip(1)) { r.IntersectWith(f); } return r.Select(id => new PostStoreEntityId() { Id = id }).ToArray(); CancelLabel: return new PostStoreEntityId[0]; })); }
private async ValueTask <List <PostStoreEntityId> > FilterByFlags(PostStoreEntityType type, PostStoreEntityId?parentId, IList <Guid> havingFlags, IList <Guid> notHavingFlags, IEsentSession session) { var bookmarks = await DoQueryByFlags(session, type, parentId, havingFlags); if (bookmarks == null || bookmarks.Length == 0) { return(new List <PostStoreEntityId>()); } return(await session.Run(() => { var result = new List <PostStoreEntityId>(); var nhs = notHavingFlags != null ? new HashSet <Guid>(notHavingFlags) : new HashSet <Guid>(); using (var table = OpenPostsTable(session, OpenTableGrbit.ReadOnly)) { foreach (var bm in bookmarks) { if (table.Indexes.PrimaryIndex.Find(table.Indexes.PrimaryIndex.CreateKey(bm.Id))) { if (nhs.Count > 0) { if (table.Columns.Flags.Values.All(v => v?.Value == null || !nhs.Contains(v?.Value ?? Guid.Empty))) { result.Add(new PostStoreEntityId() { Id = table.Columns.Id }); } } else { result.Add(new PostStoreEntityId() { Id = table.Columns.Id }); } } } } return result; })); }