コード例 #1
0
 private static async Task CreateBlobIfNoneExists(ICloudBlob updateBlob)
 {
     if (!await updateBlob.ExistsAsync())
     {
         await BlobUtils.CreateEmptyBlob(updateBlob);
     }
 }
コード例 #2
0
ファイル: UpdateBlobWrapper.cs プロジェクト: sergeybykov/Yams
 private async Task FetchOrCreate()
 {
     if (!await _blob.ExistsAsync())
     {
         await BlobUtils.CreateEmptyBlob(_blob);
     }
 }
コード例 #3
0
ファイル: BlobUtilsTest.cs プロジェクト: youscan/Yams
        private async Task <CloudBlobDirectory> CreateBlobsTree()
        {
            // root
            // |__b1
            // |__b2
            // |__d1
            // |  |__b1
            // |  |__b2
            // |__d2
            // |  |__b3
            // |  |__b4
            // |  |__d3
            // |  |  |__b5
            // |  |  |__b6
            // |__d4
            // |  |__d5
            // |  |  |__b7

            var container = _blobClient.GetContainerReference("container");

            container.CreateIfNotExists();

            var root = container.GetDirectoryReference("root");

            ICloudBlob b1 = root.GetBlockBlobReference("b1");
            await BlobUtils.CreateEmptyBlob(b1);

            ICloudBlob b2 = root.GetBlockBlobReference("b2");
            await BlobUtils.CreateEmptyBlob(b2);

            var        d1   = root.GetDirectoryReference("d1");
            ICloudBlob d1b1 = d1.GetBlockBlobReference("b1");
            ICloudBlob d1b2 = d1.GetBlockBlobReference("b2");
            await BlobUtils.CreateEmptyBlob(d1b1);

            await BlobUtils.CreateEmptyBlob(d1b2);

            var        d2   = root.GetDirectoryReference("d2");
            ICloudBlob d2b3 = d2.GetBlockBlobReference("b3");
            ICloudBlob d2b4 = d2.GetBlockBlobReference("b4");
            await BlobUtils.CreateEmptyBlob(d2b3);

            await BlobUtils.CreateEmptyBlob(d2b4);

            var        d2d3   = d2.GetDirectoryReference("d3");
            ICloudBlob d2d3b5 = d2d3.GetBlockBlobReference("b5");
            ICloudBlob d2d3b6 = d2d3.GetBlockBlobReference("b6");
            await BlobUtils.CreateEmptyBlob(d2d3b5);

            await BlobUtils.CreateEmptyBlob(d2d3b6);

            await BlobUtils.CreateEmptyBlob(
                root.GetDirectoryReference("d4").GetDirectoryReference("d5").GetBlockBlobReference("b7"));

            return(root);
        }
コード例 #4
0
        private async Task <CloudBlockBlob> CreateEmptyBlob(string blobName)
        {
            const string       containerName = "container";
            CloudBlobContainer container     = _blobClient.GetContainerReference(containerName);

            container.CreateIfNotExists();
            CloudBlockBlob blob = container.GetBlockBlobReference(blobName);
            await BlobUtils.CreateEmptyBlob(blob);

            return(blob);
        }
コード例 #5
0
ファイル: UpdateBlobTest.cs プロジェクト: ksunair/Yams
        private async Task TestThatLockFailsIfBlobLeaseCantBeAcquired(IBlobLease blobLeaseStub)
        {

            var leaseFactoryMock = new StubIBlobLeaseFactory
            {
                CreateLease_ICloudBlob = blob => blobLeaseStub
            };
            var testBlob = _container.GetBlockBlobReference("testBlob");
            await BlobUtils.CreateEmptyBlob(testBlob);
            UpdateBlob updateBlob = new UpdateBlob(testBlob, leaseFactoryMock);
            Assert.False(await updateBlob.TryLock());
        }
コード例 #6
0
        public async Task TestNameOfBlobInDirectory()
        {
            string blobName = "blob";

            CloudBlobContainer container = _blobClient.GetContainerReference("container");

            container.CreateIfNotExists();
            CloudBlobDirectory directory = container.GetDirectoryReference("directory");
            CloudBlockBlob     blob      = directory.GetBlockBlobReference(blobName);
            await BlobUtils.CreateEmptyBlob(blob);

            AzureBlob azureBlob = new AzureBlob(blob);

            Assert.AreEqual(blobName, azureBlob.Name);
        }
コード例 #7
0
        public async Task TestDownloadBlobsFromBlobDirectory()
        {
            CloudBlobContainer container = _blobClient.GetContainerReference("container");

            container.CreateIfNotExists();

            CloudBlobDirectory root = container.GetDirectoryReference("root");

            ICloudBlob b1 = root.GetBlockBlobReference("b1");
            await BlobUtils.CreateEmptyBlob(b1);

            ICloudBlob b2 = root.GetBlockBlobReference("b2");
            await BlobUtils.CreateEmptyBlob(b2);

            CloudBlobDirectory d1   = root.GetDirectoryReference("d1");
            ICloudBlob         d1b1 = d1.GetBlockBlobReference("b1");
            ICloudBlob         d1b2 = d1.GetBlockBlobReference("b2");
            await BlobUtils.CreateEmptyBlob(d1b1);

            await BlobUtils.CreateEmptyBlob(d1b2);

            CloudBlobDirectory d2   = root.GetDirectoryReference("d2");
            ICloudBlob         d2b3 = d2.GetBlockBlobReference("b3");
            ICloudBlob         d2b4 = d2.GetBlockBlobReference("b4");
            await BlobUtils.CreateEmptyBlob(d2b3);

            await BlobUtils.CreateEmptyBlob(d2b4);

            CloudBlobDirectory d2d3   = d2.GetDirectoryReference("d3");
            ICloudBlob         d2d3b5 = d2d3.GetBlockBlobReference("b5");
            ICloudBlob         d2d3b6 = d2d3.GetBlockBlobReference("b6");
            await BlobUtils.CreateEmptyBlob(d2d3b5);

            await BlobUtils.CreateEmptyBlob(d2d3b6);

            await BlobUtils.CreateEmptyBlob(
                root.GetDirectoryReference("d4").GetDirectoryReference("d5").GetBlockBlobReference("b7"));

            // The hierarchy in the blob storage is as follows:
            //
            // root
            // |__b1
            // |__b2
            // |__d1
            // |  |__b1
            // |  |__b2
            // |__d2
            // |  |__b3
            // |  |__b4
            // |  |__d3
            // |  |  |__b5
            // |  |  |__b6
            // |__d4
            // |  |__d5
            // |  |  |__b7

            string tempPath = Path.Combine(Path.GetTempPath(), "TestDownloadBlobsFromBlobDirectory");
            await BlobUtils.DownloadBlobDirectory(root, tempPath);

            ISet <string> relativePathSet = new HashSet <string>();

            foreach (string path in Directory.GetFiles(tempPath, "*.*", SearchOption.AllDirectories))
            {
                string hash = path.Remove(0, tempPath.Length);
                relativePathSet.Add(hash);
            }

            Assert.AreEqual(9, relativePathSet.Count);
            Assert.IsTrue(relativePathSet.Contains("\\b1"));
            Assert.IsTrue(relativePathSet.Contains("\\b2"));
            Assert.IsTrue(relativePathSet.Contains("\\d1\\b1"));
            Assert.IsTrue(relativePathSet.Contains("\\d1\\b2"));
            Assert.IsTrue(relativePathSet.Contains("\\d2\\b3"));
            Assert.IsTrue(relativePathSet.Contains("\\d2\\b4"));
            Assert.IsTrue(relativePathSet.Contains("\\d2\\d3\\b5"));
            Assert.IsTrue(relativePathSet.Contains("\\d2\\d3\\b6"));
            Assert.IsTrue(relativePathSet.Contains("\\d4\\d5\\b7"));
        }
コード例 #8
0
 private Task CreateEmptyBlob(ICloudBlob blob)
 {
     return(BlobUtils.CreateEmptyBlob(blob));
 }
コード例 #9
0
 private async Task CreateEmptyBlob(ICloudBlob blob)
 {
     await BlobUtils.CreateEmptyBlob(blob);
 }