コード例 #1
0
        /// <summary>
        /// Extracts the account endpoint and key from the connection string.
        /// </summary>
        /// <example>"AccountEndpoint=https://mytestcosmosaccount.documents.azure.com:443/;AccountKey={SecretAccountKey};"</example>
        /// <param name="connectionString">The connection string must contain AccountEndpoint and AccountKey.</param>
        public CosmosConfiguration(string connectionString)
        {
            if (string.IsNullOrWhiteSpace(connectionString))
            {
                throw new ArgumentNullException(nameof(connectionString));
            }

            DbConnectionStringBuilder builder = new DbConnectionStringBuilder {
                ConnectionString = connectionString
            };

            this.AccountEndPoint = new Uri(CosmosConfiguration.GetValueFromSqlConnectionString(builder,
                                                                                               CosmosConfiguration.ConnectionStringAccountEndpoint));
            this.AccountKey = CosmosConfiguration.GetValueFromSqlConnectionString(builder, CosmosConfiguration.ConnectionStringAccountKey);
            Initialize();
        }
コード例 #2
0
        /// <summary>
        /// Used for unit testing only.
        /// </summary>
        internal CosmosClient(
            CosmosConfiguration cosmosConfiguration,
            DocumentClient documentClient)
        {
            if (cosmosConfiguration == null)
            {
                throw new ArgumentNullException(nameof(cosmosConfiguration));
            }

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

            this.Init(cosmosConfiguration, documentClient);
        }
コード例 #3
0
        /// <summary>
        /// Create a new CosmosClient with the cosmosConfiguration
        /// </summary>
        /// <param name="cosmosConfiguration">The <see cref="CosmosConfiguration"/> used to initialize the cosmos client.</param>
        /// <example>
        /// This example creates a CosmosClient
        /// <code language="c#">
        /// <![CDATA[
        /// CosmosConfiguration configuration = new CosmosConfiguration("accountEndpoint", "accountkey");
        /// using (CosmosClient cosmosClient = new CosmosClient(configuration)
        /// {
        ///     // Create a database and other CosmosClient operations
        /// }
        ///]]>
        /// </code>
        /// </example>
        public CosmosClient(CosmosConfiguration cosmosConfiguration)
        {
            if (cosmosConfiguration == null)
            {
                throw new ArgumentNullException(nameof(cosmosConfiguration));
            }

            DocumentClient documentClient = new DocumentClient(
                cosmosConfiguration.AccountEndPoint,
                cosmosConfiguration.AccountKey,
                apitype: cosmosConfiguration.ApiType,
                sendingRequestEventArgs: cosmosConfiguration.SendingRequestEventArgs,
                transportClientHandlerFactory: cosmosConfiguration.TransportClientHandlerFactory,
                connectionPolicy: cosmosConfiguration.GetConnectionPolicy());

            this.Init(
                cosmosConfiguration,
                documentClient);
        }
コード例 #4
0
        internal void Init(
            CosmosConfiguration configuration,
            DocumentClient documentClient)
        {
            this.CosmosConfiguration = configuration;
            this.DocumentClient      = documentClient;

            //Request pipeline
            ClientPipelineBuilder clientPipelineBuilder = new ClientPipelineBuilder(
                this,
                this.DocumentClient.RetryPolicy,
                this.CosmosConfiguration.CustomHandlers
                );

            // DocumentClient is not initialized with any consistency overrides so default is backend consistency
            this.AccountConsistencyLevel = this.DocumentClient.ConsistencyLevel;

            this.RequestHandler = clientPipelineBuilder.Build();
            this.Databases      = new CosmosDatabases(this);
            this.offerSet       = new Lazy <CosmosOffers>(() => new CosmosOffers(this.DocumentClient), LazyThreadSafetyMode.PublicationOnly);
        }