public override async Task <IChasmBlob> ReadObjectAsync(Sha1 objectId, ChasmRequestContext requestContext = default, CancellationToken cancellationToken = default) { (string filePath, string metaPath) = DeriveFileNames(_objectsContainer, objectId); using (IMemoryOwner <byte> owned = await ReadFileAsync(filePath, cancellationToken) .ConfigureAwait(false)) { if (owned == null || owned.Memory.IsEmpty) { return(default);
private async Task <bool> ExistsOnCloudAsync(Sha1 objectId, ChasmRequestContext requestContext = default, CancellationToken cancellationToken = default) { requestContext = ChasmRequestContext.Ensure(requestContext); var opContext = new OperationContext { ClientRequestID = requestContext.CorrelationId, CustomUserAgent = requestContext.CustomUserAgent }; string blobName = DeriveBlobName(objectId); CloudBlobContainer objectsContainer = _objectsContainer.Value; CloudAppendBlob blobRef = objectsContainer.GetAppendBlobReference(blobName); bool exists = await blobRef.ExistsAsync(default, opContext, cancellationToken)
private async Task <bool> ExistsOnCloudAsync(Sha1 objectId, ChasmRequestContext requestContext = default, CancellationToken cancellationToken = default) { requestContext = ChasmRequestContext.Ensure(requestContext); var opContext = new OperationContext { ClientRequestID = requestContext.CorrelationId, CustomUserAgent = requestContext.CustomUserAgent }; CloudTable objectsTable = _objectsTable.Value; TableOperation op = DataEntity.BuildExistsOperation(objectId); try { TableResult result = await objectsTable.ExecuteAsync(op, default, opContext, cancellationToken)
public override Task <bool> ExistsAsync(Sha1 objectId, ChasmRequestContext requestContext = default, CancellationToken cancellationToken = default) { (string filePath, _) = DeriveFileNames(_objectsContainer, objectId); string dir = Path.GetDirectoryName(filePath); if (!Directory.Exists(dir)) { return(Task.FromResult(false)); } bool exists = File.Exists(filePath); return(Task.FromResult(exists)); }
public override async Task <bool> ExistsAsync(Sha1 objectId, ChasmRequestContext requestContext = default, CancellationToken cancellationToken = default) { requestContext = ChasmRequestContext.Ensure(requestContext); // Try disk repo first bool exists = await _diskRepo.ExistsAsync(objectId, requestContext, cancellationToken) .ConfigureAwait(false); // Else go to cloud if (!exists) { exists = await ExistsOnCloudAsync(objectId, requestContext, cancellationToken) .ConfigureAwait(false); } return(exists); }
public override Task <IReadOnlyList <WriteResult <Sha1> > > WriteObjectsAsync(IEnumerable <IChasmBlob> blobs, bool forceOverwrite, ChasmRequestContext requestContext = default, CancellationToken cancellationToken = default) { throw new NotImplementedException(); }
public override Task <WriteResult <Sha1> > WriteObjectAsync(Func <Stream, ValueTask> writeAction, ChasmMetadata metadata, bool forceOverwrite, ChasmRequestContext requestContext = default, CancellationToken cancellationToken = default) { throw new NotImplementedException(); }
public override Task <WriteResult <Sha1> > WriteObjectAsync(ReadOnlyMemory <byte> item, ChasmMetadata metadata, bool forceOverwrite, ChasmRequestContext requestContext = default, CancellationToken cancellationToken = default) { throw new NotImplementedException(); }
public override Task <IReadOnlyDictionary <Sha1, IChasmBlob> > ReadObjectBatchAsync(IEnumerable <Sha1> objectIds, ChasmRequestContext requestContext = default, CancellationToken cancellationToken = default) { throw new NotImplementedException(); }
public override Task <IChasmStream> ReadStreamAsync(Sha1 objectId, ChasmRequestContext requestContext = default, CancellationToken cancellationToken = default) { throw new NotImplementedException(); }
internal static ChasmConcurrencyException MockBuildConcurrencyException(string name, string branch, Exception innerException, ChasmRequestContext requestContext) { return(BuildConcurrencyException(branch, name, innerException, requestContext)); }
private static async Task TestRepository(IChasmRepository repository) { var g = Guid.NewGuid(); var cx = new ChasmRequestContext { CorrelationId = Guid.NewGuid().ToString("D") }; byte[] buffer = g.ToByteArray(); Sha1 sha = s_hasher.HashData(buffer); // Unknown SHA Sha1 usha1 = s_hasher.HashData(Guid.NewGuid().ToByteArray()); Sha1 usha2 = s_hasher.HashData(Guid.NewGuid().ToByteArray()); // Blob var metadata = new ChasmMetadata("application/json", "file123.txt"); Sha1 sha2 = await repository.WriteObjectAsync(new ReadOnlyMemory <byte>(buffer), metadata, false, cx, default); Assert.Equal(sha, sha2); IChasmBlob rdata = await repository.ReadObjectAsync(sha, default); Assert.True(rdata != null); Assert.Equal(16, rdata.Content.Length); Assert.Equal(g, new Guid(rdata.Content.ToArray())); Assert.Equal("application/json", rdata.Metadata.ContentType); Assert.Equal("file123.txt", rdata.Metadata.Filename); IChasmBlob urdata = await repository.ReadObjectAsync(usha1, default); Assert.False(urdata != null); // metadata = new ChasmMetadata("application/text", null); sha2 = await repository.WriteObjectAsync(buffer, metadata, true, cx, default); Assert.Equal(sha, sha2); IChasmBlob cnt2 = await repository.ReadObjectAsync(sha2, default); Assert.Equal(buffer, cnt2.Content.ToArray()); Assert.Equal("application/text", cnt2.Metadata.ContentType); Assert.Null(cnt2.Metadata.Filename); using (IChasmStream stream2 = await repository.ReadStreamAsync(sha2, cx, default)) using (var ms = new MemoryStream()) { stream2.Content.CopyTo(ms); Assert.Equal(buffer, ms.ToArray()); } using (Stream stream2 = new MemoryStream(buffer)) { sha2 = await repository.WriteObjectAsync(stream2, null, true, cx, default); } Assert.Equal(sha, sha2); using (IChasmStream stream2 = await repository.ReadStreamAsync(sha2, cx, default)) using (var ms = new MemoryStream()) { stream2.Content.CopyTo(ms); Assert.Equal(buffer, ms.ToArray()); } // Tree var tree = new TreeNodeMap( new TreeNode("firstItem", NodeKind.Blob, sha), new TreeNode("secondItem", NodeKind.Blob, sha) ); TreeId treeId = await repository.WriteTreeAsync(tree, cx, default); TreeNodeMap?rtree = await repository.ReadTreeAsync(treeId, cx, default); Assert.True(rtree.HasValue); Assert.Equal(tree, rtree.Value); TreeNodeMap?urtree = await repository.ReadTreeAsync(new TreeId(usha1), cx, default); Assert.False(urtree.HasValue); }