private async Task WriteAsync(NetCore.Blobs.Blob blob, Stream sourceStream, CancellationToken cancellationToken) { string fullPath = ToFullPath(blob); byte[] value = sourceStream.ToByteArray(); using (ServiceFabricTransaction tx = GetTransaction()) { IReliableDictionary <string, byte[]> coll = await OpenCollectionAsync().ConfigureAwait(false); IReliableDictionary <string, BlobMetaTag> metaColl = await OpenMetaCollectionAsync().ConfigureAwait(false); var meta = new BlobMetaTag { LastModificationTime = DateTimeOffset.UtcNow, Length = value.LongLength, Md = value.GetHash(HashType.Md5).ToHexString() }; await metaColl.AddOrUpdateAsync(tx.Tx, fullPath, meta, (k, v) => meta).ConfigureAwait(false); await coll.AddOrUpdateAsync(tx.Tx, fullPath, value, (k, v) => value).ConfigureAwait(false); await tx.CommitAsync().ConfigureAwait(false); } }
public async Task <IReadOnlyCollection <NetCore.Blobs.Blob> > GetBlobsAsync(IEnumerable <string> fullPaths, CancellationToken cancellationToken) { GenericValidation.CheckBlobFullPaths(fullPaths); var result = new List <NetCore.Blobs.Blob>(); using (ServiceFabricTransaction tx = GetTransaction()) { IReliableDictionary <string, byte[]> coll = await OpenCollectionAsync().ConfigureAwait(false); foreach (string fullPath in fullPaths) { ConditionalValue <byte[]> value = await coll.TryGetValueAsync(tx.Tx, ToFullPath(fullPath)).ConfigureAwait(false); if (!value.HasValue) { result.Add(null); } else { var meta = new NetCore.Blobs.Blob(fullPath) { Size = value.Value.Length }; result.Add(meta); } } } return(result); }