示例#1
0
        public static Task CreateAsync(this CloudTable tbl, TableRequestOptions opt, OperationContext ctx, CancellationToken token)
        {
            ICancellableAsyncResult result = null;

            if (opt == null && ctx == null)
            {
                result = tbl.BeginCreate(null, null);
            }
            else
            {
                result = tbl.BeginCreate(opt, ctx, null, null);
            }

            var cancellationRegistration = token.Register(result.Cancel);

            return(Task.Factory.FromAsync(result, ar =>
            {
                cancellationRegistration.Dispose();
                try
                {
                    tbl.EndCreate(ar);
                }
                catch (StorageException se)
                {
                    // Todo: Use the PnP azure retry block here for transient exceptions
                    throw;
                }
            }));
        }
示例#2
0
        /// <summary>
        ///     Creates a table asynchronously.
        /// </summary>
        /// <param name="cloudTable">Cloud table.</param>
        /// <param name="cancellationToken">Cancellation token.</param>
        /// <returns>Task.</returns>
        public static Task CreateAsync(
            this CloudTable cloudTable,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            ICancellableAsyncResult       asyncResult  = cloudTable.BeginCreate(null, null);
            CancellationTokenRegistration registration = cancellationToken.Register(p => asyncResult.Cancel(), null);

            return(Task.Factory.FromAsync(
                       asyncResult,
                       result =>
            {
                registration.Dispose();
                cloudTable.EndCreate(result);
            }));
        }
示例#3
0
 public ICancellableAsyncResult BeginCreate(AsyncCallback callback, object state)
 {
     return(_cloudTable.BeginCreate(callback, state));
 }