예제 #1
0
        public DocumentDB(IAzureEndpoints AzureEndpoints)
        {
            var documentClient        = new DocumentClient(new Uri(AzureEndpoints.GetDocumentDBUrl()), AzureEndpoints.GetDocumentDBKey());
            var documentRetryStrategy = new DocumentDbRetryStrategy(RetryStrategy.DefaultExponential)
            {
                FastFirstRetry = true
            };

            dbClient = documentClient.AsReliable(documentRetryStrategy);
        }
        internal static IReliableReadWriteDocumentClient CreateClient(ConnectionSettings settings)
        {
            var client = new DocumentClient(new Uri(settings.EndpointUri), settings.AuthorizationKey, new ConnectionPolicy
            {
                ConnectionMode     = ConnectionMode.Direct,
                ConnectionProtocol = Protocol.Tcp
            });
            var documentRetryStrategy = new DocumentDbRetryStrategy(RetryStrategy.DefaultExponential)
            {
                FastFirstRetry = true
            };

            return(client.AsReliable(documentRetryStrategy));
        }
예제 #3
0
        private static IReliableReadWriteDocumentClient CreateClient(string uri, string key)
        {
            ConnectionPolicy policy = new ConnectionPolicy()
            {
                ConnectionMode     = ConnectionMode.Direct,
                ConnectionProtocol = Protocol.Tcp
            };
            var documentClient        = new DocumentClient(new Uri(uri), key, policy);
            var documentRetryStrategy = new DocumentDbRetryStrategy(RetryStrategy.DefaultExponential)
            {
                FastFirstRetry = true
            };

            return(documentClient.AsReliable(documentRetryStrategy));
        }
예제 #4
0
        public IReliableReadWriteDocumentClient GetClient(string endpointUrl, string authorizationKey, ConnectionPolicy connectionPolicy = null)
        {
            if (string.IsNullOrWhiteSpace(endpointUrl))
            {
                throw new ArgumentNullException("endpointUrl");
            }

            if (string.IsNullOrWhiteSpace(authorizationKey))
            {
                throw new ArgumentNullException("authorizationKey");
            }

            var documentClient = new DocumentClient(new Uri(endpointUrl), authorizationKey, connectionPolicy ?? new ConnectionPolicy());

            var documentRetryStrategy = new DocumentDbRetryStrategy(DocumentDbRetryStrategy.DefaultExponential)
            {
                FastFirstRetry = true
            };

            return(documentClient.AsReliable(documentRetryStrategy));
        }
예제 #5
0
    IReliableReadWriteDocumentClient IAzureDocumentDBBuilder.GetIReliableReadWriteDocumentClient(
        string endpoint,
        string auth,
        ConnectionPolicy connPolicy,
        DocumentDbRetryStrategy retryStrategy)
    {
        if (string.IsNullOrWhiteSpace(endpoint))
        {
            throw new ArgumentNullException("endpoint");
        }

        if (string.IsNullOrWhiteSpace(auth))
        {
            throw new ArgumentNullException("auth");
        }

        if (connPolicy == null)
        {
            connPolicy = new ConnectionPolicy()
            {
                ConnectionMode = ConnectionMode.Direct
            }
        }
        ;

        if (retryStrategy == null)
        {
            retryStrategy = new DocumentDbRetryStrategy(DocumentDbRetryStrategy.DefaultExponential)
            {
                FastFirstRetry = true
            }
        }
        ;

        return(new DocumentClient(new Uri(endpoint), auth, connPolicy).AsReliable(retryStrategy));
    }

    Database IAzureDocumentDBBuilder.GetDatabase(
        IReliableReadWriteDocumentClient client,
        string databaseId,
        bool createIfNotExist)
    {
        if (client == null)
        {
            throw new ArgumentNullException("client");
        }

        if (string.IsNullOrWhiteSpace(databaseId))
        {
            throw new ArgumentNullException("databaseId");
        }

        Database database = client.CreateDatabaseQuery().Where(u => u.Id.ToString() == databaseId)
                            .AsEnumerable()
                            .FirstOrDefault();

        if (database == null && createIfNotExist)
        {
            database = client.CreateDatabaseAsync(new Database {
                Id = databaseId
            }).Result;
        }
        else if (database == null && !createIfNotExist)
        {
            throw new InvalidOperationException("The database does not exist and you are not creating it at runtime");
        }

        return(database);
    }
}