public void OpContextTestClientRequestIDOnTable() { CloudTableClient tClient = GenerateCloudTableClient(); CloudTable table = tClient.GetTableReference("test"); string uniqueID = Guid.NewGuid().ToString(); Action act = () => table.Exists(null, new OperationContext() { ClientRequestID = uniqueID }); TestHelper.VerifyHeaderWasSent("x-ms-client-request-id", uniqueID, AzureStorageSelectors.TableTraffic().IfHostNameContains(tClient.Credentials.AccountName), act); act = () => table.EndExists(table.BeginExists(null, new OperationContext() { ClientRequestID = uniqueID }, null, null)); TestHelper.VerifyHeaderWasSent("x-ms-client-request-id", uniqueID, AzureStorageSelectors.TableTraffic().IfHostNameContains(tClient.Credentials.AccountName), act); #if TASK act = () => table.ExistsAsync(null, new OperationContext() { ClientRequestID = uniqueID }).Wait(); TestHelper.VerifyHeaderWasSent("x-ms-client-request-id", uniqueID, AzureStorageSelectors.TableTraffic().IfHostNameContains(tClient.Credentials.AccountName), act); #endif }
public void OpContextTestUserHeadersOnTable() { CloudTableClient tClient = GenerateCloudTableClient(); CloudTable table = tClient.GetTableReference("test"); string uniqueID = Guid.NewGuid().ToString(); OperationContext ctx = new OperationContext(); ctx.UserHeaders = new Dictionary <string, string>(); ctx.UserHeaders.Add("foo", "bar"); Action act = () => table.Exists(null, ctx); TestHelper.VerifyHeaderWasSent(ctx.UserHeaders.Keys.First(), ctx.UserHeaders[ctx.UserHeaders.Keys.First()], AzureStorageSelectors.TableTraffic().IfHostNameContains(tClient.Credentials.AccountName), act); act = () => table.EndExists(table.BeginExists(null, ctx, null, null)); TestHelper.VerifyHeaderWasSent(ctx.UserHeaders.Keys.First(), ctx.UserHeaders[ctx.UserHeaders.Keys.First()], AzureStorageSelectors.TableTraffic().IfHostNameContains(tClient.Credentials.AccountName), act); #if TASK act = () => table.ExistsAsync(null, ctx).Wait(); TestHelper.VerifyHeaderWasSent(ctx.UserHeaders.Keys.First(), ctx.UserHeaders[ctx.UserHeaders.Keys.First()], AzureStorageSelectors.TableTraffic().IfHostNameContains(tClient.Credentials.AccountName), act); #endif }
/// <summary> /// Checks whether the table exists asynchronously. /// </summary> /// <param name="cloudTable">Cloud table.</param> /// <param name="cancellationToken">Cancellation token.</param> /// <returns> /// <c>true</c> if table exists; otherwise, <c>false</c>. /// </returns> public static Task <bool> ExistsAsync( this CloudTable cloudTable, CancellationToken cancellationToken = default(CancellationToken)) { ICancellableAsyncResult asyncResult = cloudTable.BeginExists(null, null); CancellationTokenRegistration registration = cancellationToken.Register(p => asyncResult.Cancel(), null); return(Task <bool> .Factory.FromAsync( asyncResult, result => { registration.Dispose(); return cloudTable.EndExists(result); })); }
public static Task <bool> ExistsAsync(this CloudTable tbl, TableRequestOptions opt, OperationContext ctx, CancellationToken token) { ICancellableAsyncResult result = null; if (opt == null && ctx == null) { result = tbl.BeginExists(null, null); } else { result = tbl.BeginExists(opt, ctx, null, null); } var cancellationRegistration = token.Register(result.Cancel); return(Task.Factory.FromAsync(result, ar => { cancellationRegistration.Dispose(); return tbl.EndExists(ar); })); }
public bool EndExists(IAsyncResult asyncResult) { return(_cloudTable.EndExists(asyncResult)); }