Exemple #1
0
        private async Task UpdateCatalogAsync(CosmosBundleDocument bundle, CosmosCabinetDrawerChanges changes)
        {
            var updatedCatalogEntry = changes.UpdatedCatalogEntry;

            if (updatedCatalogEntry != null)
            {
                await _repositoryContainer
                .Catalog
                .UpsertItemAsync(updatedCatalogEntry)
                .ConfigureAwait(false);

                return;
            }

            if (changes.UpdatedDrawer.Position == MaximumCabinetDrawerItemCount)
            {
                return;
            }

            var asLinq = _repositoryContainer
                         .Cabinet
                         .GetItemLinqQueryable <CosmosDataAvailable>();

            var query =
                from dataAvailable in asLinq
                where dataAvailable.PartitionKey == changes.UpdatedDrawer.Id
                orderby dataAvailable.SequenceNumber
                select(long?) dataAvailable.SequenceNumber;

            var nextSequenceNumber = await query
                                     .Skip(changes.UpdatedDrawer.Position)
                                     .Take(1)
                                     .AsCosmosIteratorAsync()
                                     .FirstOrDefaultAsync()
                                     .ConfigureAwait(false);

            if (!nextSequenceNumber.HasValue)
            {
                return;
            }

            var partitionKey = string.Join('_', bundle.Recipient, bundle.Origin);
            var contentType  = bundle.ContentType;

            var nextCatalogEntry = new CosmosCatalogEntry
            {
                Id                 = Guid.NewGuid().ToString(),
                PartitionKey       = partitionKey,
                ContentType        = contentType,
                NextSequenceNumber = nextSequenceNumber.Value,
            };

            await _repositoryContainer
            .Catalog
            .UpsertItemAsync(nextCatalogEntry)
            .ConfigureAwait(false);
        }
Exemple #2
0
 private async Task DeleteOldCatalogEntryAsync(CosmosCatalogEntry entry)
 {
     try
     {
         await _repositoryContainer
         .Catalog
         .DeleteItemAsync <CosmosCatalogEntry>(entry.Id, new PartitionKey(entry.PartitionKey))
         .ConfigureAwait(false);
     }
     catch (CosmosException ex) when(ex.StatusCode == HttpStatusCode.NotFound)
     {
         // Concurrent calls may have removed the file.
     }
 }