public async Task EnsureDbSetupAsync()
        {
            Microsoft.Azure.Cosmos.DatabaseResponse database = await _cosmosClient.CreateDatabaseIfNotExistsAsync(_databaseName);

            foreach (var container in _containers)
            {
                await database.Database.CreateContainerIfNotExistsAsync(container.Name, $"{container.PartitionKey}");
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a Cosmos DB database and a container with the specified partition key.
        /// This will be used to pull the FlowCal repo information
        /// </summary>
        /// <returns></returns>
        private static async Task <ICosmosService> InitializeCosmosClientInstanceAsync(IConfigurationSection configurationSection)
        {
            string         databaseName  = configurationSection.GetSection("DatabaseName").Value;
            string         containerName = configurationSection.GetSection("ContainerName").Value;
            string         account       = configurationSection.GetSection("Account").Value;
            string         key           = configurationSection.GetSection("Key").Value;
            CosmosClient   client        = new Microsoft.Azure.Cosmos.CosmosClient(account, key);
            ICosmosService cosmosService = new CosmosService(client, databaseName, containerName);

            Microsoft.Azure.Cosmos.DatabaseResponse database = await client.CreateDatabaseIfNotExistsAsync(databaseName);

            await database.Database.CreateContainerIfNotExistsAsync(containerName, "/appName");

            return(cosmosService);
        }
Esempio n. 3
0
        internal override async Task <string> GetRIDAsync(CancellationToken cancellationToken = default(CancellationToken))
        {
            DatabaseResponse databaseResponse = await this.ReadAsync(cancellationToken : cancellationToken);

            return(databaseResponse?.Resource?.ResourceId);
        }