Exemplo n.º 1
0
        /// <summary>
        /// Recreate the Cosmos Client / Container (after a key rotation)
        /// </summary>
        /// <param name="cosmosUrl">Cosmos URL</param>
        /// <param name="cosmosKey">Cosmos Key</param>
        /// <param name="cosmosDatabase">Cosmos Database</param>
        /// <param name="cosmosCollection">Cosmos Collection</param>
        /// <param name="force">force reconnection even if no params changed</param>
        /// <returns>Task</returns>
        public async Task Reconnect(Uri cosmosUrl, string cosmosKey, string cosmosDatabase, string cosmosCollection, bool force = false)
        {
            if (cosmosUrl == null)
            {
                throw new ArgumentNullException(nameof(cosmosUrl));
            }

            if (force ||
                _cosmosDetails.CosmosCollection != cosmosCollection ||
                _cosmosDetails.CosmosDatabase != cosmosDatabase ||
                _cosmosDetails.CosmosKey != cosmosKey ||
                _cosmosDetails.CosmosUrl != cosmosUrl.AbsoluteUri)
            {
                CosmosDetails d = new CosmosDetails
                {
                    CosmosCollection = cosmosCollection,
                    CosmosDatabase   = cosmosDatabase,
                    CosmosKey        = cosmosKey,
                    CosmosUrl        = cosmosUrl.AbsoluteUri
                };

                // open and test a new client / container
                d.Client = await OpenAndTestCosmosClient(cosmosUrl, cosmosKey, cosmosDatabase, cosmosCollection).ConfigureAwait(false);

                d.Container = d.Client.GetContainer(cosmosDatabase, cosmosCollection);

                // set the current CosmosDetail
                _cosmosDetails = d;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Data Access Layer Constructor
        /// </summary>
        /// <param name="cosmosUrl">CosmosDB Url</param>
        /// <param name="cosmosKey">CosmosDB connection key</param>
        /// <param name="cosmosDatabase">CosmosDB Database</param>
        /// <param name="cosmosCollection">CosmosDB Collection</param>
        public DAL(Uri cosmosUrl, string cosmosKey, string cosmosDatabase, string cosmosCollection)
        {
            if (cosmosUrl == null)
            {
                throw new ArgumentNullException(nameof(cosmosUrl));
            }

            _cosmosDetails = new CosmosDetails
            {
                MaxRows          = MaxPageSize,
                Retries          = CosmosMaxRetries,
                Timeout          = CosmosTimeout,
                CosmosCollection = cosmosCollection,
                CosmosDatabase   = cosmosDatabase,
                CosmosKey        = cosmosKey,
                CosmosUrl        = cosmosUrl.AbsoluteUri
            };

            // create the CosmosDB client and container
            _cosmosDetails.Client    = OpenAndTestCosmosClient(cosmosUrl, cosmosKey, cosmosDatabase, cosmosCollection).GetAwaiter().GetResult();
            _cosmosDetails.Container = _cosmosDetails.Client.GetContainer(cosmosDatabase, cosmosCollection);
        }