Esempio n. 1
0
        internal CosmosStore(IDocumentClient documentClient,
                             string databaseName,
                             string authKey,
                             string endpoint,
                             string overriddenCollectionName,
                             IDatabaseCreator databaseCreator     = null,
                             ICollectionCreator collectionCreator = null,
                             bool scaleable = false)
        {
            CollectionName = overriddenCollectionName;
            DatabaseName   = databaseName;
            if (documentClient == null)
            {
                throw new ArgumentNullException(nameof(documentClient));
            }
            var cosmonautClient = new CosmonautClient(documentClient);

            Settings = new CosmosStoreSettings(databaseName, endpoint, authKey, documentClient.ConnectionPolicy,
                                               scaleCollectionRUsAutomatically: scaleable);
            if (string.IsNullOrEmpty(Settings.DatabaseName))
            {
                throw new ArgumentNullException(nameof(Settings.DatabaseName));
            }
            _collectionCreator = collectionCreator ?? new CosmosCollectionCreator(cosmonautClient);
            _databaseCreator   = databaseCreator ?? new CosmosDatabaseCreator(cosmonautClient);
            _cosmosScaler      = new CosmosScaler <TEntity>(this);
            InitialiseCosmosStore();
        }
Esempio n. 2
0
 internal CosmosStore(ICosmonautClient cosmonautClient,
                      string databaseName,
                      string overriddenCollectionName,
                      IDatabaseCreator databaseCreator     = null,
                      ICollectionCreator collectionCreator = null,
                      bool scaleable = false)
 {
     CollectionName  = overriddenCollectionName;
     DatabaseName    = databaseName;
     CosmonautClient = cosmonautClient ?? throw new ArgumentNullException(nameof(cosmonautClient));
     Settings        = new CosmosStoreSettings(databaseName, cosmonautClient.DocumentClient.ServiceEndpoint.ToString(), string.Empty, cosmonautClient.DocumentClient.ConnectionPolicy,
                                               scaleCollectionRUsAutomatically: scaleable);
     if (Settings.InfiniteRetries)
     {
         CosmonautClient.DocumentClient.SetupInfiniteRetries();
     }
     if (string.IsNullOrEmpty(Settings.DatabaseName))
     {
         throw new ArgumentNullException(nameof(Settings.DatabaseName));
     }
     _collectionCreator = collectionCreator ?? new CosmosCollectionCreator(CosmonautClient);
     _databaseCreator   = databaseCreator ?? new CosmosDatabaseCreator(CosmonautClient);
     _cosmosScaler      = new CosmosScaler <TEntity>(this);
     InitialiseCosmosStore();
 }
Esempio n. 3
0
 internal CosmosStore(IDocumentClient documentClient,
                      string databaseName,
                      IDatabaseCreator databaseCreator,
                      ICollectionCreator collectionCreator)
 {
     DocumentClient = documentClient ?? throw new ArgumentNullException(nameof(documentClient));
     Settings       = new CosmosStoreSettings(databaseName, documentClient.ServiceEndpoint, documentClient.AuthKey.ToString(), documentClient.ConnectionPolicy);
     if (string.IsNullOrEmpty(Settings.DatabaseName))
     {
         throw new ArgumentNullException(nameof(Settings.DatabaseName));
     }
     _databaseCreator   = databaseCreator ?? throw new ArgumentNullException(nameof(databaseCreator));
     _collectionCreator = collectionCreator ?? throw new ArgumentNullException(nameof(collectionCreator));
     InitialiseCosmosStore();
 }
Esempio n. 4
0
        public CosmosStore(CosmosStoreSettings settings, string overriddenCollectionName)
        {
            Settings     = settings ?? throw new ArgumentNullException(nameof(settings));
            DatabaseName = settings.DatabaseName;
            var documentClient = DocumentClientFactory.CreateDocumentClient(settings);

            CosmonautClient = new CosmonautClient(documentClient, Settings.InfiniteRetries);
            if (string.IsNullOrEmpty(Settings.DatabaseName))
            {
                throw new ArgumentNullException(nameof(Settings.DatabaseName));
            }
            _collectionCreator = new CosmosCollectionCreator(CosmonautClient);
            _databaseCreator   = new CosmosDatabaseCreator(CosmonautClient);
            InitialiseCosmosStore(overriddenCollectionName);
        }
Esempio n. 5
0
        public CosmosStore(CosmosStoreSettings settings,
                           IDatabaseCreator databaseCreator,
                           ICollectionCreator collectionCreator)
        {
            Settings = settings ?? throw new ArgumentNullException(nameof(settings));
            var endpointUrl = Settings.EndpointUrl ?? throw new ArgumentNullException(nameof(Settings.EndpointUrl));
            var authKey     = Settings.AuthKey ?? throw new ArgumentNullException(nameof(Settings.AuthKey));

            DocumentClient = DocumentClientFactory.CreateDocumentClient(endpointUrl, authKey);
            if (string.IsNullOrEmpty(Settings.DatabaseName))
            {
                throw new ArgumentNullException(nameof(Settings.DatabaseName));
            }
            _collectionCreator = collectionCreator ?? throw new ArgumentNullException(nameof(collectionCreator));
            _databaseCreator   = databaseCreator ?? throw new ArgumentNullException(nameof(databaseCreator));
            InitialiseCosmosStore();
        }
Esempio n. 6
0
 internal CosmosStore(ICosmonautClient cosmonautClient,
                      string databaseName,
                      string overriddenCollectionName,
                      IDatabaseCreator databaseCreator     = null,
                      ICollectionCreator collectionCreator = null)
 {
     DatabaseName    = databaseName;
     CosmonautClient = cosmonautClient ?? throw new ArgumentNullException(nameof(cosmonautClient));
     Settings        = new CosmosStoreSettings(databaseName, cosmonautClient.DocumentClient.ServiceEndpoint.ToString(), string.Empty, cosmonautClient.DocumentClient.ConnectionPolicy);
     if (Settings.InfiniteRetries)
     {
         CosmonautClient.DocumentClient.SetupInfiniteRetries();
     }
     if (string.IsNullOrEmpty(Settings.DatabaseName))
     {
         throw new ArgumentNullException(nameof(Settings.DatabaseName));
     }
     _collectionCreator = collectionCreator ?? new CosmosCollectionCreator(CosmonautClient);
     _databaseCreator   = databaseCreator ?? new CosmosDatabaseCreator(CosmonautClient);
     InitialiseCosmosStore(overriddenCollectionName);
 }
Esempio n. 7
0
 public CosmosStore(CosmosStoreSettings settings) : this(settings, string.Empty)
 {
 }
 internal static IDocumentClient CreateDocumentClient(CosmosStoreSettings settings)
 {
     return(new DocumentClient(settings.EndpointUrl, settings.AuthKey, settings.JsonSerializerSettings, settings.ConnectionPolicy ?? ConnectionPolicy.Default, settings.ConsistencyLevel));
 }
Esempio n. 9
0
 public static IDocumentClient CreateDocumentClient(CosmosStoreSettings settings)
 {
     return(new DocumentClient(settings.EndpointUrl, settings.AuthKey, settings.ConnectionPolicy ?? ConnectionPolicy.Default));
 }