Beispiel #1
0
        internal virtual async Task ExecuteBatchAndCreateTableIfNotExistsAsync(
            Dictionary <string, IStorageTableOperation> partition, CancellationToken cancellationToken)
        {
            IStorageTableBatchOperation batch = _table.CreateBatch();

            foreach (var operation in partition.Values)
            {
                batch.Add(operation);
            }

            if (batch.Count > 0)
            {
                StorageException exception = null;

                try
                {
                    // Commit the batch
                    await _table.ExecuteBatchAsync(batch, cancellationToken);
                }
                catch (StorageException e)
                {
                    if (!e.IsNotFoundTableNotFound())
                    {
                        throw new StorageException(e.GetDetailedErrorMessage(), e);
                    }

                    exception = e;
                }

                if (exception != null)
                {
                    // Make sure the table exists
                    await _table.CreateIfNotExistsAsync(cancellationToken);

                    // Commit the batch
                    try
                    {
                        await _table.ExecuteBatchAsync(batch, cancellationToken);
                    }
                    catch (StorageException e)
                    {
                        throw new StorageException(e.GetDetailedErrorMessage(), e);
                    }
                }
            }
        }