Example #1
0
        //TODO merge similarities with batch execution
        private async Task <int> ExecuteChangesAsync(IReadOnlyList <StateEntry> stateEntries,
                                                     CancellationToken cancellationToken = default(CancellationToken))
        {
            var tableGroups = stateEntries.GroupBy(s => s.EntityType);
            var allTasks    = new List <Task <TableResult> >();

            foreach (var tableGroup in tableGroups)
            {
                var table = new AtsTable(tableGroup.Key.TableName());
                var tasks = tableGroup.Select(entry => CreateRequest(table, entry))
                            .TakeWhile(operation => !cancellationToken.IsCancellationRequested)
                            .Select(request => Connection.ExecuteRequestAsync(request, Logger, cancellationToken));
                allTasks.AddRange(tasks);

                if (cancellationToken.IsCancellationRequested)
                {
                    break;
                }
            }
            try
            {
                await Task.WhenAll(allTasks);
            }
            catch (StorageException exception)
            {
                var handled = HandleStorageException(exception, stateEntries);
                if (handled != null)
                {
                    throw handled;
                }
                throw;
            }
            return(allTasks.Count(t => t.Result.HttpStatusCode < (int)HttpStatusCode.BadRequest));
        }
        public override async Task <bool> EnsureDeletedAsync([NotNull] IModel model, CancellationToken cancellationToken = default(CancellationToken))
        {
            Check.NotNull(model, "model");

            var tasks = model.EntityTypes
                        .Select(type => new DeleteTableRequest(new AtsTable(type.TableName())))
                        .Select(request => _connection.ExecuteRequestAsync(request, cancellationToken: cancellationToken))
                        .ToList();

            await Task.WhenAll(tasks).ConfigureAwait(continueOnCapturedContext: false);

            return(tasks.Any(t => t.Result));
        }
Example #3
0
        public override async Task <bool> EnsureDeletedAsync(IModel model, CancellationToken cancellationToken = default(CancellationToken))
        {
            Check.NotNull(model, "model");

            var tasks = model.EntityTypes
                        .Select(type => new DeleteTableRequest(new AtsTable(type.AzureTableStorage().Table)))
                        .Select(request => _connection.ExecuteRequestAsync(request, cancellationToken: cancellationToken))
                        .ToList();

            var deleted = await Task.WhenAll(tasks).WithCurrentCulture();

            return(deleted.Any());
        }