public async Task <bool> DeleteContainer(ContainerDefinition containerDefinition)
        {
            Container sdkContainer = await Internal_GetContainer(containerDefinition.ContainerId);

            var sdkResponse = await sdkContainer.DeleteContainerAsync();

            var deleteResponse = sdkResponse.ToCosmosDbResponse();

            if (!deleteResponse.IsSuccessful)
            {
                // TODO: need logging
                // TODO: throw exception?
                return(false);
            }

            if (_containerCache.TryRemove(containerDefinition.ContainerId, out ICosmosDbContainer removedContainer))
            {
                // container was removed from cache successfully
                return(true);
            }

            // container was not removed from cache...but do we really care?
            // TODO: do we care if cache entry is not removed properly?
            return(true);
        }
        public async Task <ICosmosDbContainer> GetContainer(string containerId)
        {
            // TODO: Avoid searching for container via ID, prefer type instead
            ContainerDefinition definition = GetContainerDefinition(containerId);

            return(await this.CreateContainer(definition));
        }
Esempio n. 3
0
        public async Task <ICosmosDbContainer> GetContainer(string containerId)
        {
            Container container = await Internal_GetContainer(containerId);

            ContainerDefinition definition = GetContainerDefinition(containerId);

            return(new CosmosDbContainer(definition, this, container));
        }
Esempio n. 4
0
 public async Task <ICosmosDbContainer> GetContainer(string containerId)
 {
     return(await _containerCache.GetOrAddAsync <string, ICosmosDbContainer>(containerId, async id =>
     {
         Container container = await Internal_GetContainer(containerId);
         ContainerDefinition definition = GetContainerDefinition(containerId);
         return new CosmosDbContainer(definition, this, container);
     }));
 }
        public void AddContainerDefinition(ContainerDefinition containerDefinition)
        {
            ContainerDefinition existing = GetContainerDefinition(containerDefinition.ContainerId);

            //ContainerDefinition existing = GetContainerDefinitionForType(containerDefinition.EntityType);
            if (existing is null)
            {
                _containerDefinitions.Add(containerDefinition);
                return;
            }

            throw new NotImplementedException();
        }
        public async Task <ICosmosDbContainer> CreateContainer(ContainerDefinition containerDefinition)
        {
            return(await _containerCache.GetOrAddAsync(containerDefinition.ContainerId, async id =>
            {
                //ContainerDefinition definition = GetContainerDefinitionForType(containerDefinition.EntityType);
                ContainerDefinition definition = GetContainerDefinition(containerDefinition.ContainerId);

                // Container cosmosSdkContainer = await Internal_GetContainer(containerDefinition.ContainerId);
                Container cosmosSdkContainer = await Internal_EnsureContainerExists(await this.GetDatabase(), containerDefinition);

                var container = new CosmosDbContainer(definition, this, cosmosSdkContainer);

                return _containerFactory == null ? container : _containerFactory.Create(container);
            }));
        }
Esempio n. 7
0
        public async Task <ICosmosDbContainer> CreateContainer(ContainerDefinition containerDefinition)
        {
            return(await _containerCache.GetOrAddAsync(containerDefinition.ContainerId, async id =>
            {
                Container cosmosSdkContainer = await Internal_GetContainer(containerDefinition.ContainerId);
                ContainerDefinition definition = GetContainerDefinition(containerDefinition.ContainerId);
                var container = new CosmosDbContainer(definition, this, cosmosSdkContainer);

                if (_containerFactory != null)
                {
                    return _containerFactory.Create(container);
                }
                else
                {
                    return container;
                }
            }));
        }
Esempio n. 8
0
 private static async Task <Container> Internal_EnsureContainerExists(Database db, ContainerDefinition containerDefinition)
 {
     return(await Internal_EnsureContainerExists(db, containerDefinition.ContainerId, containerDefinition.PartitionKeyPath, containerDefinition.Throughput));
 }
Esempio n. 9
0
        public ContainerDefinition GetContainerDefinitionForType(Type t)
        {
            ContainerDefinition containerDefForT = _containerDefinitions.FirstOrDefault(def => def.EntityType == t);

            return(containerDefForT);
        }
Esempio n. 10
0
        public ContainerDefinition GetContainerDefinition(string containerId)
        {
            ContainerDefinition containerDef = _containerDefinitions.FirstOrDefault(def => def.ContainerId == containerId);

            return(containerDef);
        }
Esempio n. 11
0
        public async Task <ICosmosDbContainer> GetContainer <TEntity>()
        {
            ContainerDefinition definition = GetContainerDefinitionForType <TEntity>();

            return(await GetContainer(definition.ContainerId));
        }
Esempio n. 13
0
        public async Task <ICosmosDbContainer> GetContainer(string containerId)
        {
            ContainerDefinition definition = GetContainerDefinition(containerId);

            return(await this.CreateContainer(definition));
        }