Beispiel #1
0
        public static async Task <bool> DeleteIfExistsAsync(this CloudBlockBlob blob)
        {
            var tcs = new TaskCompletionSource <bool>();

            blob.BeginDeleteIfExists(iar =>
            {
                try { tcs.TrySetResult(blob.EndDeleteIfExists(iar)); }
                catch (OperationCanceledException) { tcs.TrySetCanceled(); }
                catch (Exception ex) { tcs.TrySetException(ex); }
            }, null);
            return(await tcs.Task);
        }
        public static async Task DeleteIfExists(this CloudBlockBlob blob)
        {
            var tcs = new TaskCompletionSource <object>();

            blob.BeginDeleteIfExists(iar =>
            {
                try { blob.EndDownloadToStream(iar); tcs.TrySetResult(null); }
                catch (OperationCanceledException) { tcs.TrySetCanceled(); }
                catch (Exception ex) { tcs.TrySetException(ex); }
            }, null);
            await tcs.Task;
        }
Beispiel #3
0
        public void BlobIfExistsShouldNotHitSecondary()
        {
            AssertSecondaryEndpoint();

            BlobRequestOptions options = new BlobRequestOptions();

            CloudBlobContainer container = BlobTestBase.GetRandomContainerReference();

            TestPrimaryOnlyCommand((opt, ctx) => container.CreateIfNotExists(opt, ctx), options);
            TestPrimaryOnlyCommand((opt, ctx) => container.EndCreateIfNotExists(container.BeginCreateIfNotExists(opt, ctx, null, null)), options);
            TestPrimaryOnlyCommand((opt, ctx) => container.DeleteIfExists(null, opt, ctx), options);
            TestPrimaryOnlyCommand((opt, ctx) => container.EndDeleteIfExists(container.BeginDeleteIfExists(null, opt, ctx, null, null)), options);

            CloudBlockBlob blockBlob = container.GetBlockBlobReference("blob1");

            TestPrimaryOnlyCommand((opt, ctx) => blockBlob.DeleteIfExists(DeleteSnapshotsOption.None, null, opt, ctx), options);
            TestPrimaryOnlyCommand((opt, ctx) => blockBlob.EndDeleteIfExists(blockBlob.BeginDeleteIfExists(DeleteSnapshotsOption.None, null, opt, ctx, null, null)), options);

            CloudPageBlob pageBlob = container.GetPageBlobReference("blob2");

            TestPrimaryOnlyCommand((opt, ctx) => pageBlob.DeleteIfExists(DeleteSnapshotsOption.None, null, opt, ctx), options);
            TestPrimaryOnlyCommand((opt, ctx) => pageBlob.EndDeleteIfExists(pageBlob.BeginDeleteIfExists(DeleteSnapshotsOption.None, null, opt, ctx, null, null)), options);
        }