internal DocumentClient BindForClient(DocumentDBAttribute attribute)
        {
            string             resolvedConnectionString = ResolveConnectionString(attribute.ConnectionStringSetting);
            IDocumentDBService service = GetService(resolvedConnectionString);

            return(service.GetClient());
        }
 private static DocumentDBContext CreateContext(IDocumentDBService service)
 {
     return(new DocumentDBContext
     {
         Service = service,
         ResolvedDatabaseName = DatabaseName,
         ResolvedCollectionName = CollectionName
     });
 }
示例#3
0
        internal static async Task <Database> CreateDatabaseIfNotExistsAsync(IDocumentDBService service, string databaseName)
        {
            Uri      databaseUri = UriFactory.CreateDatabaseUri(databaseName);
            Database database    = service.CreateDatabaseQuery().Where(db => db.Id == databaseName).AsEnumerable().FirstOrDefault();

            if (database == null)
            {
                database = await service.CreateDatabaseAsync(new Database { Id = databaseName });
            }

            return(database);
        }
        public DocumentClient Convert(DocumentDBAttribute attribute)
        {
            if (attribute == null)
            {
                throw new ArgumentNullException(nameof(attribute));
            }

            string             resolvedConnectionString = _config.ResolveConnectionString(attribute.ConnectionStringSetting);
            IDocumentDBService service = _config.GetService(resolvedConnectionString);

            return(service.GetClient());
        }
        internal DocumentDBContext CreateContext(DocumentDBAttribute attribute, TraceWriter trace)
        {
            string resolvedConnectionString = ResolveConnectionString(attribute.ConnectionStringSetting);

            IDocumentDBService service = GetService(resolvedConnectionString);

            return(new DocumentDBContext
            {
                Service = service,
                Trace = trace,
                ResolvedAttribute = attribute
            });
        }
示例#6
0
        private static DocumentDBContext CreateContext(IDocumentDBService service, bool createIfNotExists = false,
                                                       string partitionKeyPath = null, int throughput = 0)
        {
            DocumentDBAttribute attribute = new DocumentDBAttribute(DatabaseName, CollectionName)
            {
                CreateIfNotExists    = createIfNotExists,
                PartitionKey         = partitionKeyPath,
                CollectionThroughput = throughput
            };

            return(new DocumentDBContext
            {
                Service = service,
                ResolvedAttribute = attribute
            });
        }
        public static async Task CreateIfNotExistAsync(IDocumentDBService service, string databaseName, string documentCollectionName)
        {
            Uri      databaseUri = UriFactory.CreateDatabaseUri(databaseName);
            Database database    = new Database {
                Id = databaseName
            };
            DocumentCollection documentCollection = new DocumentCollection
            {
                Id = documentCollectionName
            };

            // If we queried for the Database or Collection before creation, we may hit a race condition
            // if multiple instances are running the same code. So let's just create and ignore a Conflict.
            await DocumentDBUtility.ExecuteAndIgnoreStatusCodeAsync(HttpStatusCode.Conflict,
                                                                    () => service.CreateDatabaseAsync(database));

            await DocumentDBUtility.ExecuteAndIgnoreStatusCodeAsync(HttpStatusCode.Conflict,
                                                                    () => service.CreateDocumentCollectionAsync(databaseUri, documentCollection));
        }
 public TestDocumentDBServiceFactory(IDocumentDBService service)
 {
     _service = service;
 }
示例#9
0
 public TodoItemManager(IDocumentDBService service)
 {
     documentDBService = service;
 }
 public UserService(IDocumentDBService cosmosDBService)
 {
     _cosmosDBService = cosmosDBService;
 }
示例#11
0
 public TripsManager(IDocumentDBService service)
 {
     documentDBService = service;
 }
 public ProductController(ILogger <ProductController> logger, IDocumentDBService docService, IBlobService blobStorageService)
 {
     _logger             = logger;
     _blobStorageService = blobStorageService;
     _docService         = docService;
 }
 public LoginItemManager(IDocumentDBService service)
 {
     documentDBService = service;
 }
示例#14
0
        internal static async Task <DocumentCollection> CreateDocumentCollectionIfNotExistsAsync(IDocumentDBService service, string databaseName, string collectionName, string partitionKey, int throughput)
        {
            Uri databaseUri = UriFactory.CreateDatabaseUri(databaseName);
            DocumentCollection collection = service.CreateDocumentCollectionQuery(databaseUri).Where(c => c.Id == collectionName).AsEnumerable().FirstOrDefault();

            if (collection == null)
            {
                DocumentCollection documentCollection = new DocumentCollection
                {
                    Id = collectionName
                };

                if (!string.IsNullOrEmpty(partitionKey))
                {
                    documentCollection.PartitionKey.Paths.Add(partitionKey);
                }

                // If there is any throughput specified, pass it on. DocumentClient will throw with a
                // descriptive message if the value does not meet the collection requirements.
                RequestOptions collectionOptions = null;
                if (throughput != 0)
                {
                    collectionOptions = new RequestOptions
                    {
                        OfferThroughput = throughput
                    };
                }
                collection = await service.CreateDocumentCollectionAsync(databaseUri, documentCollection, collectionOptions);
            }

            return(collection);
        }
示例#15
0
 public StoreInfoManager(IDocumentDBService service)
 {
     documentDBService = service;
 }
示例#16
0
 public ProductController(IDocumentDBService documentDBService, IBlobService blobStorageService)
 {
     docService  = documentDBService;
     blobService = blobStorageService;
 }
示例#17
0
 public DocumentDBController(IDocumentDBService dbService)
 {
     this.dbService = dbService;
 }