public override async Task Contribute(DocumentClient client, IDocumentDbConfiguration configuration) { var attribute = typeof (TDocument).GetDocumentTypeAttribute(); if (attribute == null) { return; } try { await client.ReadDocumentCollectionAsync(UriFactory.CreateDocumentCollectionUri(configuration.DatabaseName, attribute.CollectionName)); } catch (DocumentClientException ex) { if (ex.StatusCode != HttpStatusCode.NotFound) { throw; } var collectionInfo = new DocumentCollection { Id = attribute.CollectionName, IndexingPolicy = new IndexingPolicy(new RangeIndex(DataType.String) { Precision = -1 }) }; await client.CreateDocumentCollectionAsync(UriFactory.CreateDatabaseUri(configuration.DatabaseName), collectionInfo); } }
private async Task OnPostCreate(DocumentClient client, IDocumentDbConfiguration configuration) { foreach (var contributor in contributors) { await contributor.OnPostCreate(client, configuration); } }
public DocumentDbRepository(string cosmosDatabase, IDocumentDbConfiguration configuration) { var resources = DocumentDbResources.CreateResources(configuration, typeof(T).Name); Client = resources.DocumentClient; DocumentCollection = resources.DocumentCollection; }
public DocumentDbRepository(IDocumentDbConfiguration configuration) { var resources = DocumentDbResources.CreateResources(configuration, typeof(T).Name); Client = resources.DocumentClient; DocumentCollection = resources.DocumentCollection; database = configuration.DatabaseName; }
public async Task Create(IDocumentDbConfiguration configuration) { var client = DocumentClientFactory.Create(configuration); await OnPreCreate(client, configuration); await CreateDatabase(client, configuration); await Contribute(client, configuration); await OnPostCreate(client, configuration); }
internal static DocumentDbRepositoryResources CreateResources(IDocumentDbConfiguration configuration, string collectionName) { var options = new DocumentDbConfigurationOptions { DatabaseName = configuration.DatabaseName, CollectionName = collectionName, Key = configuration.Key, DocumentDb = configuration.DocumentDb, CollectionPartitionKeyPaths = configuration.PartitionKeys.ContainsKey(collectionName) == true ? configuration.PartitionKeys[collectionName] : default,
private async Task CreateDatabase(DocumentClient client, IDocumentDbConfiguration configuration) { try { await client.ReadDatabaseAsync(UriFactory.CreateDatabaseUri(configuration.DatabaseName)); } catch (DocumentClientException ex) { if (ex.StatusCode == HttpStatusCode.NotFound) { await client.CreateDatabaseAsync(new Database { Id = configuration.DatabaseName }); } } }
public async override Task OnPreCreate(DocumentClient client, IDocumentDbConfiguration configuration) { try { await client.DeleteDatabaseAsync(UriFactory.CreateDatabaseUri(configuration.DatabaseName)); } catch (DocumentClientException ex) { if (ex.StatusCode != HttpStatusCode.NotFound) { throw; } } }
private static async Task CreateDatabase(IDocumentDbConfiguration configuration) { var creationStategy = new SampleDocumentDbCreationStrategy(); await creationStategy.Create(configuration); }
public virtual Task OnPreCreate(DocumentClient client, IDocumentDbConfiguration configuration) { return(Task.FromResult(default(object))); }
public DocumentRepository(IDocumentDbConfiguration configuration) { this.configuration = configuration; client = DocumentClientFactory.Create(configuration); }
public static IAsyncRepository <T> Create <T>(IDocumentDbConfiguration dbConfiguration) { return(new DocumentDbRepository <T>(dbConfiguration)); }
public static DocumentClient Create(IDocumentDbConfiguration configuration) { return(new DocumentClient(new Uri(configuration.EndpointUri), configuration.Key)); }
public DocumentDataRepository(IDocumentDbConfiguration documentDbConfiguration) { _documentDbConfiguration = documentDbConfiguration; _client = new DocumentClient(_documentDbConfiguration.Uri, _documentDbConfiguration.PrimaryKey); }