コード例 #1
0
        private IndexingPolicy CovertToCosmosIndexingPolicy(CustomIndexingPolicy indexingPolicy)
        {
            var cosmosIndexingPolicy = new IndexingPolicy
            {
                IndexingMode = indexingPolicy.Mode,
                Automatic    = indexingPolicy.Mode == IndexingMode.Consistent ? indexingPolicy.Autmatic : false
            };

            if (indexingPolicy.Mode == IndexingMode.None)
            {
                return(cosmosIndexingPolicy);
            }

            foreach (var includedPath in indexingPolicy.IncludedPaths)
            {
                cosmosIndexingPolicy.IncludedPaths.Add(new IncludedPath {
                    Path = includedPath
                });
            }

            foreach (var excludedPath in indexingPolicy.ExcludedPaths)
            {
                cosmosIndexingPolicy.ExcludedPaths.Add(new ExcludedPath {
                    Path = excludedPath
                });
            }


            return(cosmosIndexingPolicy);
        }
コード例 #2
0
 protected CosmosDbBaseRepository(CosmosDbContainerResolver containerResolver, string containerId, string partitionKeyPath,
                                  Func <T, string> idSelector, CustomIndexingPolicy indexingPolicy)
 {
     _containerResolver = containerResolver ?? throw new ArgumentNullException(nameof(containerResolver));
     _containerId       = containerId ?? throw new ArgumentNullException(nameof(containerId));
     _partitionKeyPath  = partitionKeyPath ?? throw new ArgumentNullException(nameof(partitionKeyPath));
     _idSelector        = idSelector ?? throw new ArgumentNullException(nameof(idSelector));
     _indexingPolicy    = indexingPolicy ?? throw new ArgumentNullException(nameof(indexingPolicy));
 }
コード例 #3
0
        public async Task <Container> Resolve(string containerId, string paritionKEyPath, CustomIndexingPolicy indexingPolicy, CancellationToken cancellationToken)
        {
            if (_containers.TryGetValue(containerId, out var container))
            {
                return(container);
            }

            var semaphore = _semaphores.GetOrAdd(containerId, x => new SemaphoreSlim(1, 1));
            await semaphore.WaitAsync(cancellationToken);

            try
            {
                if (_containers.TryGetValue(containerId, out container))
                {
                    return(container);
                }

                var containerProperties = new ContainerProperties
                {
                    Id = containerId,
                    PartitionKeyPath = paritionKEyPath,
                    IndexingPolicy   = CovertToCosmosIndexingPolicy(indexingPolicy)
                };

                _containers[containerId] = await _database.CreateContainerAsync(containerProperties, cancellationToken : cancellationToken);

                return(_containers[containerId]);
            }
            finally
            {
                semaphore.Release();
            }
        }