/// <summary> /// Initializes a new instance of the <see cref="InstanceRepository"/> class /// </summary> /// <param name="cosmosSettings">the configuration settings for cosmos database</param> /// <param name="logger">the logger</param> /// <param name="dataRepository">the data repository to fetch data elements from</param> public InstanceRepository( IOptions <AzureCosmosSettings> cosmosSettings, ILogger <InstanceRepository> logger, IDataRepository dataRepository) { _logger = logger; _dataRepository = dataRepository; _settings = cosmosSettings.Value; CosmosDatabaseHandler database = new CosmosDatabaseHandler(cosmosSettings.Value); _client = database.CreateDatabaseAndCollection(CollectionId); _collectionUri = database.CollectionUri; Uri databaseUri = database.DatabaseUri; _databaseId = database.DatabaseName; DocumentCollection documentCollection = database.CreateDocumentCollection(CollectionId, PartitionKey); _client.CreateDocumentCollectionIfNotExistsAsync( databaseUri, documentCollection).GetAwaiter().GetResult(); _client.OpenAsync(); }
/// <summary> /// Initializes a new instance of the <see cref="DataRepository"/> class /// </summary> /// <param name="cosmosettings">the configuration settings for azure cosmos database</param> /// <param name="storageConfiguration">the storage configuration for azure blob storage</param> public DataRepository(IOptions <AzureCosmosSettings> cosmosettings, IOptions <AzureStorageConfiguration> storageConfiguration) { var database = new CosmosDatabaseHandler(cosmosettings.Value); _client = database.CreateDatabaseAndCollection(_collectionId); _collectionUri = database.CollectionUri; Uri databaseUri = database.DatabaseUri; _databaseId = database.DatabaseName; DocumentCollection documentCollection = database.CreateDocumentCollection(_collectionId, _partitionKey); _client.CreateDocumentCollectionIfNotExistsAsync( databaseUri, documentCollection).GetAwaiter().GetResult(); _client.OpenAsync(); _storageConfiguration = storageConfiguration.Value; // connect to azure blob storage StorageCredentials storageCredentials = new StorageCredentials(_storageConfiguration.AccountName, _storageConfiguration.AccountKey); CloudStorageAccount storageAccount = new CloudStorageAccount(storageCredentials, true); _blobClient = CreateBlobClient(storageCredentials, storageAccount); _container = _blobClient.GetContainerReference(_storageConfiguration.StorageContainer); }
/// <summary> /// Initializes a new instance of the <see cref="TextRepository"/> class /// </summary> /// <param name="cosmosettings">the configuration settings for cosmos database</param> /// <param name="generalSettings">the general configurations settings</param> /// <param name="logger">the logger</param> /// <param name="memoryCache">the memory cache</param> public TextRepository( IOptions <AzureCosmosSettings> cosmosettings, IOptions <GeneralSettings> generalSettings, ILogger <ITextRepository> logger, IMemoryCache memoryCache) { var database = new CosmosDatabaseHandler(cosmosettings.Value); _logger = logger; _client = database.CreateDatabaseAndCollection(_collectionId); _collectionUri = database.CollectionUri; _databaseId = database.DatabaseName; DocumentCollection documentCollection = database.CreateDocumentCollection(_collectionId, _partitionKey); _client.CreateDocumentCollectionIfNotExistsAsync( database.DatabaseUri, documentCollection).GetAwaiter().GetResult(); _client.OpenAsync(); _memoryCache = memoryCache; _cacheEntryOptions = new MemoryCacheEntryOptions() .SetPriority(CacheItemPriority.High) .SetAbsoluteExpiration(new TimeSpan(0, 0, generalSettings.Value.TextResourceCacheLifeTimeInSeconds)); }
/// <summary> /// Initializes a new instance of the <see cref="DataRepository"/> class /// </summary> /// <param name="sasTokenProvider">A provider that can be asked for SAS tokens.</param> /// <param name="cosmosSettings">the configuration settings for azure cosmos database</param> /// <param name="storageConfiguration">the storage configuration for azure blob storage</param> /// <param name="logger">The logger to use when writing to logs.</param> public DataRepository( ISasTokenProvider sasTokenProvider, IOptions <AzureCosmosSettings> cosmosSettings, IOptions <AzureStorageConfiguration> storageConfiguration, ILogger <DataRepository> logger) { _storageConfiguration = storageConfiguration.Value; _sasTokenProvider = sasTokenProvider; _logger = logger; CosmosDatabaseHandler database = new CosmosDatabaseHandler(cosmosSettings.Value); _documentClient = database.CreateDatabaseAndCollection(_collectionId); _collectionUri = database.CollectionUri; Uri databaseUri = database.DatabaseUri; _databaseId = database.DatabaseName; DocumentCollection documentCollection = database.CreateDocumentCollection(_collectionId, _partitionKey); _documentClient.CreateDocumentCollectionIfNotExistsAsync( databaseUri, documentCollection).GetAwaiter().GetResult(); _documentClient.OpenAsync(); }
/// <summary> /// Initializes a new instance of the <see cref="TextRepository"/> class /// </summary> /// <param name="cosmosettings">the configuration settings for cosmos database</param> public TextRepository(IOptions <AzureCosmosSettings> cosmosettings) { var database = new CosmosDatabaseHandler(cosmosettings.Value); _client = database.CreateDatabaseAndCollection(_collectionId); _collectionUri = database.CollectionUri; _databaseId = database.DatabaseName; DocumentCollection documentCollection = database.CreateDocumentCollection(_collectionId, _partitionKey); _client.CreateDocumentCollectionIfNotExistsAsync( database.DatabaseUri, documentCollection).GetAwaiter().GetResult(); _client.OpenAsync(); }
/// <summary> /// Initializes a new instance of the <see cref="ApplicationRepository"/> class. /// </summary> /// <param name="cosmosettings">the configuration settings for cosmos database</param> /// <param name="logger">dependency injection of logger</param> public ApplicationRepository(IOptions <AzureCosmosSettings> cosmosettings, ILogger <ApplicationRepository> logger) { _logger = logger; var database = new CosmosDatabaseHandler(cosmosettings.Value); _client = database.CreateDatabaseAndCollection(collectionId); _collectionUri = database.CollectionUri; databaseUri = database.DatabaseUri; databaseId = database.DatabaseName; DocumentCollection documentCollection = database.CreateDocumentCollection(collectionId, partitionKey); _client.CreateDocumentCollectionIfNotExistsAsync( databaseUri, documentCollection).GetAwaiter().GetResult(); _client.OpenAsync(); }