Пример #1
0
 public DocumentClient GetSampleDocumentDbClient()
 {
     try
     {
         var    SourceCosmosDBSettings = CloneSettings.GetSourceSettings("Sample");
         string SourceEndpointUrl      = SourceCosmosDBSettings.EndpointUrl;
         string SourceAccessKey        = SourceCosmosDBSettings.AccessKey;
         var    sourceDocumentClient   = new DocumentClient(new Uri(SourceEndpointUrl), SourceAccessKey, ConnectionPolicy);
         return(sourceDocumentClient);
     }
     catch (Exception ex)
     {
         logger.LogError(ex);
         throw;
     }
 }
Пример #2
0
        public async Task <DocumentCollection> CreateSampleDocumentCollection(DocumentClient sampleClient, bool IsFixedCollection = false)
        {
            try
            {
                var    sampleCosmosDBSettings = CloneSettings.GetSourceSettings("Sample");
                string sampleDatabaseName     = sampleCosmosDBSettings.DatabaseName;;
                string sampleCollectionName   = sampleCosmosDBSettings.CollectionName;
                int    offerThroughput        = sampleCosmosDBSettings.OfferThroughputRUs;

                await sampleClient.CreateDatabaseIfNotExistsAsync(new Database { Id = sampleDatabaseName });

                DocumentCollection newDocumentCollection;
                if (!IsFixedCollection)
                {
                    var partitionKeyDefinition = new PartitionKeyDefinition();
                    partitionKeyDefinition.Paths.Add("/CompositeName");
                    newDocumentCollection = (DocumentCollection)await sampleClient.CreateDocumentCollectionIfNotExistsAsync
                                                (UriFactory.CreateDatabaseUri(sampleDatabaseName),
                                                new DocumentCollection { Id = sampleCollectionName, PartitionKey = partitionKeyDefinition },
                                                new RequestOptions { OfferThroughput = offerThroughput });
                }
                else
                {
                    //no partition key if it is a fixed collection
                    newDocumentCollection = (DocumentCollection)await sampleClient.CreateDocumentCollectionIfNotExistsAsync
                                                (UriFactory.CreateDatabaseUri(sampleDatabaseName),
                                                new DocumentCollection { Id = sampleCollectionName },
                                                new RequestOptions { OfferThroughput = offerThroughput });
                }
                return(newDocumentCollection);
            }
            catch (Exception ex)
            {
                logger.LogError(ex);
                throw;
            }
        }