Exemplo n.º 1
0
        /// <inheritdoc />
        public async ValueTask UpdateAsBatchAsync(
            IEnumerable <TItem> items,
            CancellationToken cancellationToken = default)
        {
            List <TItem> list = items.ToList();

            string partitionKey = GetPartitionKeyValue(list);

            Container container = await _containerProvider.GetContainerAsync();

            TransactionalBatch batch = container.CreateTransactionalBatch(new PartitionKey(partitionKey));

            foreach (TItem item in list)
            {
                TransactionalBatchItemRequestOptions options = new();

                if (item is IItemWithEtag itemWithEtag)
                {
                    options.IfMatchEtag = itemWithEtag.Etag;
                }

                batch.UpsertItem(item, options);
            }

            using TransactionalBatchResponse response = await batch.ExecuteAsync(cancellationToken);

            if (!response.IsSuccessStatusCode)
            {
                throw new BatchOperationException <TItem>(response);
            }
        }
Exemplo n.º 2
0
        public async Task UpsertStatuses(IReadOnlyCollection <ResourceSearchParameterStatus> statuses)
        {
            EnsureArg.IsNotNull(statuses, nameof(statuses));

            if (statuses.Count == 0)
            {
                return;
            }

            foreach (IEnumerable <ResourceSearchParameterStatus> statusBatch in statuses.TakeBatch(100))
            {
                using IScoped <Container> clientScope = _containerScopeFactory.Invoke();
                TransactionalBatch batch = clientScope.Value.CreateTransactionalBatch(new PartitionKey(SearchParameterStatusWrapper.SearchParameterStatusPartitionKey));

                foreach (SearchParameterStatusWrapper status in statusBatch.Select(x => x.ToSearchParameterStatusWrapper()))
                {
                    status.LastUpdated = Clock.UtcNow;
                    batch.UpsertItem(status);
                }

                await batch.ExecuteAsync();
            }
        }
Exemplo n.º 3
0
 public override void Apply(TransactionalBatch transactionalBatch, PartitionKeyPath partitionKeyPath)
 {
     transactionalBatch.UpsertItem(item, options);
 }
 public void UpsertItem <T>(T item, TransactionalBatchItemRequestOptions options = null)
 {
     Batch.UpsertItem(item, options);
 }