public Task <string> GetOrCreateCollectionAsync(string collectionName, CollectionPricingTier collectionTier) { Assert.IsFalse(String.IsNullOrEmpty(collectionName), TestResources.MissingCollectionNameInGetOrCreateCollection); createdCollections.Add(collectionName); return(Task.FromResult(collectionName)); }
public Task <string> GetOrCreateCollectionAsync(string collectionName, CollectionPricingTier collectionTier, IndexingPolicy indexingPolicy) { return(GetOrCreateCollectionAsyncInternal(collectionName, null, new RequestOptions { OfferType = ToOfferType(collectionTier) }, indexingPolicy)); }
public async Task <string> GetOrCreateCollectionAsync(string collectionName, CollectionPricingTier collectionTier, IndexingPolicy indexingPolicy) { Guard.NotEmpty("collectionName", collectionName); var database = await GetOrCreateDatabase(databaseName); var collection = await TryGetCollection(database, collectionName); if (collection == null) { var alreadyExists = false; try { var collectionDefinition = new DocumentCollection { Id = collectionName }; if (indexingPolicy != null) { collectionDefinition.IndexingPolicy = indexingPolicy; } collection = await client.CreateDocumentCollectionAsync(database.SelfLink, collectionDefinition, new RequestOptions { OfferType = ToOfferType(collectionTier) }); } catch (DocumentClientException clientException) { if (clientException.StatusCode != HttpStatusCode.Conflict) { throw; } alreadyExists = true; } if (alreadyExists) { collection = await TryGetCollection(database, collectionName); } } if (collection == null) { throw Errors.FailedToCreateCollection(collectionName); } return(collection.SelfLink); }
private static string ToOfferType(CollectionPricingTier collectionTier) { return(Enum.GetName(typeof(CollectionPricingTier), collectionTier).ToUpperInvariant()); }