public void TableIfExistsShouldNotHitSecondary() { AssertSecondaryEndpoint(); TableRequestOptions options = new TableRequestOptions(); CloudTableClient client = GenerateCloudTableClient(); CloudTable table = client.GetTableReference(TableTestBase.GenerateRandomTableName()); TestPrimaryOnlyCommand((opt, ctx) => table.CreateIfNotExists(opt, ctx), options); TestPrimaryOnlyCommand((opt, ctx) => table.EndCreateIfNotExists(table.BeginCreateIfNotExists(opt, ctx, null, null)), options); TestPrimaryOnlyCommand((opt, ctx) => table.DeleteIfExists(opt, ctx), options); TestPrimaryOnlyCommand((opt, ctx) => table.EndDeleteIfExists(table.BeginDeleteIfExists(opt, ctx, null, null)), options); }
/// <summary> /// Deletes the table if it exists asynchronously. /// </summary> /// <param name="cloudTable">Cloud table.</param> /// <param name="cancellationToken">Cancellation token.</param> /// <returns> /// <c>true</c> if the table was deleted; otherwise, <c>false</c>. /// </returns> public static Task <bool> DeleteIfExistsAsync( this CloudTable cloudTable, CancellationToken cancellationToken = default(CancellationToken)) { ICancellableAsyncResult asyncResult = cloudTable.BeginDeleteIfExists(null, null); CancellationTokenRegistration registration = cancellationToken.Register(p => asyncResult.Cancel(), null); return(Task <bool> .Factory.FromAsync( asyncResult, result => { registration.Dispose(); return cloudTable.EndDeleteIfExists(result); })); }
public static Task <bool> DeleteIfNotExistsAsync(this CloudTable tbl, TableRequestOptions opt, OperationContext ctx, CancellationToken token) { ICancellableAsyncResult result = null; if (opt == null && ctx == null) { result = tbl.BeginDeleteIfExists(null, null); } else { result = tbl.BeginDeleteIfExists(opt, ctx, null, null); } var cancellationRegistration = token.Register(result.Cancel); return(Task.Factory.FromAsync(result, ar => { cancellationRegistration.Dispose(); return tbl.EndDeleteIfExists(ar); })); }
public bool EndDeleteIfExists(IAsyncResult asyncResult) { return(_cloudTable.EndDeleteIfExists(asyncResult)); }