public static Task <bool> CreateIfNotExistsAsync(this CloudTable table, CancellationToken ct = default(CancellationToken)) { ICancellableAsyncResult ar = table.BeginCreateIfNotExists(null, null); ct.Register(ar.Cancel); return(Task.Factory.FromAsync <bool>(ar, table.EndCreateIfNotExists)); }
public static Task <bool> CreateIfNotExistsAsync(this CloudTable tbl, TableRequestOptions opt, OperationContext ctx, CancellationToken token) { ICancellableAsyncResult result = null; if (opt == null && ctx == null) { result = tbl.BeginCreateIfNotExists(null, null); } else { result = tbl.BeginCreateIfNotExists(opt, ctx, null, null); } var cancellationRegistration = token.Register(result.Cancel); return(Task.Factory.FromAsync(result, ar => { cancellationRegistration.Dispose(); return tbl.EndCreateIfNotExists(ar); })); }
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> /// Creates the table if it does not already exist asynchronously. /// </summary> /// <param name="cloudTable">Cloud table.</param> /// <param name="cancellationToken">Cancellation token.</param> /// <returns> /// <c>true</c> if table was created; otherwise, <c>false</c>. /// </returns> public static Task <bool> CreateIfNotExistsAsync( this CloudTable cloudTable, CancellationToken cancellationToken = default(CancellationToken)) { ICancellableAsyncResult asyncResult = cloudTable.BeginCreateIfNotExists(null, null); CancellationTokenRegistration registration = cancellationToken.Register(p => asyncResult.Cancel(), null); return(Task <bool> .Factory.FromAsync( asyncResult, result => { registration.Dispose(); return cloudTable.EndCreateIfNotExists(result); })); }
public ICancellableAsyncResult BeginCreateIfNotExists(AsyncCallback callback, object state) { return(_cloudTable.BeginCreateIfNotExists(callback, state)); }