コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CosmosDBService"/> class.
        /// </summary>
        /// <param name="configuration">Configuration.</param>
        /// <param name="azure">Azure management connection.</param>
        /// <param name="logger">Logger.</param>
        public CosmosDBService(IConfiguration configuration, AzureService azure, ILogger <CosmosDBService> logger)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            if (azure == null)
            {
                throw new ArgumentNullException(nameof(azure));
            }

            this.logger = logger;

            var cosmosDBContainerResourceId = configuration["cosmosDBContainer"];

            logger.LogInformation(
                "Initializing connection to Cosmos DB container {cosmosDBContainerResourceId}",
                cosmosDBContainerResourceId);

            ParseCosmosDBContainerResourceId(
                cosmosDBContainerResourceId,
                out string cosmosDBResourceId,
                out string cosmosDBDatabase,
                out string cosmosDBContainer);

            var cosmosDB = this.ConnectToCosmosDBAccount(azure, cosmosDBResourceId);

            this.container = this.ConnectToCosmosDBContainer(cosmosDB, cosmosDBDatabase, cosmosDBContainer);
        }
コード例 #2
0
 private ICosmosDBAccount ConnectToCosmosDBAccount(AzureService azure, string cosmosDBResourceId)
 {
     try
     {
         return(azure
                .Azure
                .CosmosDBAccounts
                .GetById(cosmosDBResourceId));
     }
     catch (Exception e)
     {
         this.logger.LogCritical(
             e,
             "Couldn't retrieve Cosmos DB account keys for rule {cosmosDBResourceId}",
             cosmosDBResourceId);
         throw;
     }
 }