protected override async Task <IDataSinkAdapter> CreateAsync(DocumentDbClient client, IDataItemTransformation transformation, IDocumentDbBulkSinkAdapterConfiguration configuration, IEnumerable <string> collectionNames) { var sink = new DocumentDbBulkSinkAdapterDispatcher(client, transformation, GetInstanceConfiguration(configuration, collectionNames)); await sink.InitializeAsync(); return(sink); }
public async Task CreateIndex(IncludedPath index) { var collection = new DocumentCollection { Id = _configurationService.DocumentDb.Collection }; collection.IndexingPolicy.IncludedPaths.Add(index); await DocumentDbClient.ReplaceDocumentCollectionAsync(collection); }
public async Task SetIndexMode(IndexingMode mode) { var collection = new DocumentCollection { Id = _configurationService.DocumentDb.Collection }; collection.IndexingPolicy.IndexingMode = mode; await DocumentDbClient.ReplaceDocumentCollectionAsync(collection); }
public Document GetDocument(Expression <Func <Document, bool> > predicate) { Document doc = DocumentDbClient.CreateDocumentQuery <Document>(CollectionUri) .Where(predicate) .AsEnumerable() .SingleOrDefault(); return(doc); }
//public async Task CreateCollection(bool checkIfExists) //{ // await CreateCollection(_configurationService.DocumentDb.Collection, checkIfExists); //} //private Database Database // => // _database ?? // (_database = DocumentDbClient.CreateDatabaseQuery().Where(d => d.Id == _configurationService.DocumentDb.Database).AsEnumerable().FirstOrDefault()); //public async Task CreateCollection(string collectionName, bool checkIfExists) //{ // var collectionDefinition = new DocumentCollection // { // Id = collectionName, // IndexingPolicy = new IndexingPolicy(new RangeIndex(DataType.String) { Precision = -1 }) // }; // if (checkIfExists) // { // DocumentCollection dbCollection = // DocumentDbClient.CreateDocumentCollectionQuery(Database.SelfLink) // .Where(c => c.Id == collectionName) // .AsEnumerable() // .FirstOrDefault(); // if (dbCollection == null) // { // await DocumentDbClient.CreateDocumentCollectionAsync(Database.SelfLink, collectionDefinition, // new RequestOptions()); // } // } // else // { // await DocumentDbClient.CreateDocumentCollectionAsync(Database.SelfLink, collectionDefinition, new RequestOptions()); // } //} public async Task UpsertDocument <T>(T document) { //var doc = JsonConvert.SerializeObject(document, // new JsonSerializerSettings {ContractResolver = new CamelCasePropertyNamesContractResolver()}); //JObject.Parse(doc) ResourceResponse <Document> result = await DocumentDbClient.UpsertDocumentAsync( CollectionUri, document); }
public async Task <ResourceResponse <StoredProcedure> > GetStoredProcedure(string id) { StoredProcedure dbSp = DocumentDbClient.CreateStoredProcedureQuery(CollectionUri) .Where(c => c.Id == id) .AsEnumerable() .FirstOrDefault(); return(await DocumentDbClient.ReadStoredProcedureAsync(dbSp.SelfLink)); }
private async Task EnsureDatabaseExistsAsync() { try { await DocumentDbClient.CreateDatabaseIfNotExistsAsync(new Database { Id = _settings.DatabaseId }); } catch (Exception ex) { throw ex; } }
/// <summary> /// Execute stored procedure in this collection /// </summary> /// <typeparam name="TResult"></typeparam> /// <param name="procId"></param> /// <param name="partitionKey"></param> /// <param name="args"></param> /// <returns></returns> public async Task <TResult> ExecuteStoredProcedureAsync <TResult>(string procId, object partitionKey, object args) { var url = UriFactory.CreateStoredProcedureUri(_settings.DatabaseId, _settings.CollectionId, procId); RequestOptions options = new RequestOptions() { PartitionKey = new PartitionKey(partitionKey) }; return(await DocumentDbClient.ExecuteStoredProcedureAsync <TResult>(url, options, args)); }
public void Dispose() { if (_sourceClient != null) { _sourceClient.Dispose(); _sourceClient = null; } if (_targetClient != null) { _targetClient.Dispose(); _targetClient = null; } }
public IQueryable <T> GetItems <T>(Expression <Func <T, bool> > predicate) { if (predicate == null) { return(DocumentDbClient.CreateDocumentQuery <T>(CollectionUri, new FeedOptions { MaxItemCount = -1 })); } return(DocumentDbClient.CreateDocumentQuery <T>(CollectionUri, new FeedOptions { MaxItemCount = -1 }) .Where(predicate)); }
public IQueryable <T> GetItemsOrderByDescending <T>(Expression <Func <T, bool> > wherePredicate, Expression <Func <T, DateTime> > orderPredicate) { if (wherePredicate == null) { return(DocumentDbClient.CreateDocumentQuery <T>(CollectionUri, new FeedOptions { MaxItemCount = -1 })); } return(DocumentDbClient.CreateDocumentQuery <T>(CollectionUri, new FeedOptions { MaxItemCount = -1 }) .Where(wherePredicate).OrderByDescending(orderPredicate)); }
public async Task <T> ExecuteStoredProcedure <T>(string storedProcedureName, params dynamic[] parameters) { var storedProc = DocumentDbClient.CreateStoredProcedureQuery(CollectionUri).Where(p => p.Id == storedProcedureName).AsEnumerable().FirstOrDefault(); if (storedProc == null) { throw new ArgumentNullException($"Stored Procedure {storedProcedureName} does not exists on the database"); } StoredProcedureResponse <T> response = null; response = await DocumentDbClient.ExecuteStoredProcedureAsync <T>(storedProc.SelfLink, parameters); return(response); }
private async Task EnsureCollectionExistsAsync() { DocumentCollection myCollection = new DocumentCollection { Id = _settings.CollectionId }; if (!string.IsNullOrWhiteSpace(_settings.PartitionPath)) { myCollection.PartitionKey.Paths.Add(_settings.PartitionPath); } RequestOptions options = new RequestOptions() { OfferThroughput = _settings.InitialOfferThroughput ?? DefaultInitialOfferThroughput }; await DocumentDbClient.CreateDocumentCollectionIfNotExistsAsync(UriFactory.CreateDatabaseUri(_settings.DatabaseId), myCollection); }
protected override void Load(ContainerBuilder builder) { // register the DocumentClient for DocumentDB API builder.Register(c => { var cosmosDbClient = c.Resolve <IOptions <CosmosDbOptions> >().Value; return(new DocumentClient(cosmosDbClient.EndpointUri, cosmosDbClient.PrimaryKey)); }).SingleInstance(); // create the DocumentDB client and initialize it builder.Register(c => { var databaseClient = new DocumentDbClient( c.Resolve <IOptions <CosmosDbOptions> >(), c.Resolve <ILogger <DocumentDbClient> >(), c.Resolve <DocumentClient>()); databaseClient.Initialize().Wait(); return(databaseClient); }).As <IDatabaseClient>(); // services builder.Register(c => new UserService(c.Resolve <IOptions <CosmosDbOptions> >(), c.Resolve <IDatabaseClient>())) .As <IUserService>(); }
/// <summary> /// Creates the database if it does not exist using the database name from configuration setting /// </summary> /// <returns></returns> public async Task CreateDatabase() { var dbName = _configurationService.DocumentDb.Database; await DocumentDbClient.CreateDatabaseIfNotExistsAsync(new Database { Id = dbName }); }
public async Task DeleteDocuments(string documentLink) { ResourceResponse <Document> result = await DocumentDbClient.DeleteDocumentAsync(documentLink); }
private async Task CreateStoredProcedure(StoredProcedure storedProcedure) { await DocumentDbClient.CreateStoredProcedureAsync(CollectionUri, storedProcedure); }
public IQueryable <T> GetItemsByExpression <T>(string sqlExpression) { return(DocumentDbClient.CreateDocumentQuery <T>(CollectionUri, sqlExpression)); }
/// <summary> /// Execute stored procedure in this collection /// </summary> /// <typeparam name="TResult"></typeparam> /// <param name="procId"></param> /// <param name="args"></param> /// <returns></returns> public async Task <TResult> ExecuteStoredProcedureAsync <TResult>(string procId, object args) { var url = UriFactory.CreateStoredProcedureUri(_settings.DatabaseId, _settings.CollectionId, procId); return(await DocumentDbClient.ExecuteStoredProcedureAsync <TResult>(url, args)); }
public async Task UpsertDocument(object document) { ResourceResponse <Document> result = await DocumentDbClient.UpsertDocumentAsync(CollectionUri, JObject.FromObject(document)); }
public async Task CreateCollection() { await DocumentDbClient.CreateDocumentCollectionIfNotExistsAsync( UriFactory.CreateDatabaseUri(_configurationService.DocumentDb.Database), new DocumentCollection { Id = _configurationService.DocumentDb.Collection }); }
public async Task UpsertDocument <T>(T document) { ResourceResponse <Document> result = await DocumentDbClient.UpsertDocumentAsync( CollectionUri, document); }
protected abstract Task <IDataSinkAdapter> CreateAsync(DocumentDbClient client, IDataItemTransformation transformation, TConfiguration configuration, IEnumerable <string> collectionNames, CancellationToken cancellation);
protected abstract Task <IDataSinkAdapter> CreateAsync(DocumentDbClient client, IDataItemTransformation transformation, TConfiguration configuration);
public async Task <ResourceResponse <Document> > ReplaceDocument(object document) { ResourceResponse <Document> updated = await DocumentDbClient.UpsertDocumentAsync(CollectionUri, document); return(updated); }