コード例 #1
0
        static void Main(string[] args)
        {
            try
            {
                _documentDbClient = new Db.Client.DocumentClient(
                    new Uri(ConfigurationManager.AppSettings["DocumentDbUri"]),
                    ConfigurationManager.AppSettings["DocumentDbKey"]);

                _documentDatabase = _documentDbClient.CreateDatabaseQuery()
                    .Where(db => db.Id == DatabaseStore).AsEnumerable().FirstOrDefault();

                //Create database and collection if not present
                CreateDatabaseIfNotExistsAsync().Wait();

                //Create Seed Data
                CreateDocumentsAsync(_customerCollection.SelfLink).Wait();

                //Query inserted customers
                QueryAllDocuments(_customerCollection.SelfLink);

                //Query subdocuments(orders)
                QueryWithSubdocuments(_customerCollection.SelfLink);

                //Query all customer first and last name with order number with amount greate than $300.00
                QueryWithTwoJoinsAndFilter(_customerCollection.SelfLink);

                //Create partitions
                InitializeRangeResolverAsync().Wait();

                //Run queries agianst different partitions and see where the documents are stored
                QueryPartitionAsync().Wait();

                //Update and delete the document
                UpdateAndDeleteDocumentAsync().Wait();
            }
            catch (Db.DocumentClientException de)
            {
                var baseException = de.GetBaseException();
                Console.WriteLine("{0} error occurred: {1}, Message: {2}", de.StatusCode, de.Message,
                    baseException.Message);
            }
            catch (Exception e)
            {
                var baseException = e.GetBaseException();
                Console.WriteLine("Error: {0}, Message: {1}", e.Message, baseException.Message);
            }
            finally
            {
                //Cleanup
                CleanUpAsync().Wait();
                Console.WriteLine("End of demo, press any key to exit.");
                Console.ReadKey();
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            try
            {
                _documentDbClient = new Db.Client.DocumentClient(
                    new Uri(ConfigurationManager.AppSettings["DocumentDbUri"]),
                    ConfigurationManager.AppSettings["DocumentDbKey"]);

                _documentDatabase = _documentDbClient.CreateDatabaseQuery()
                                    .Where(db => db.Id == DatabaseStore).AsEnumerable().FirstOrDefault();

                //Create database and collection if not present
                CreateDatabaseIfNotExistsAsync().Wait();

                //Create Seed Data
                CreateDocumentsAsync(_customerCollection.SelfLink).Wait();

                //Query inserted customers
                QueryAllDocuments(_customerCollection.SelfLink);

                //Query subdocuments(orders)
                QueryWithSubdocuments(_customerCollection.SelfLink);

                //Query all customer first and last name with order number with amount greate than $300.00
                QueryWithTwoJoinsAndFilter(_customerCollection.SelfLink);

                //Create partitions
                InitializeRangeResolverAsync().Wait();

                //Run queries agianst different partitions and see where the documents are stored
                QueryPartitionAsync().Wait();

                //Update and delete the document
                UpdateAndDeleteDocumentAsync().Wait();
            }
            catch (Db.DocumentClientException de)
            {
                var baseException = de.GetBaseException();
                Console.WriteLine("{0} error occurred: {1}, Message: {2}", de.StatusCode, de.Message,
                                  baseException.Message);
            }
            catch (Exception e)
            {
                var baseException = e.GetBaseException();
                Console.WriteLine("Error: {0}, Message: {1}", e.Message, baseException.Message);
            }
            finally
            {
                //Cleanup
                CleanUpAsync().Wait();
                Console.WriteLine("End of demo, press any key to exit.");
                Console.ReadKey();
            }
        }
コード例 #3
0
        private async Task <Microsoft.Azure.Documents.Database> GetOrCreateDatabaseAsync(Microsoft.Azure.Documents.Client.DocumentClient client, string databaseId)
        {
            var database = client.CreateDatabaseQuery().Where(db => db.Id == databaseId).ToArray().FirstOrDefault();

            if (database == null)
            {
                // Create the database.
                database = await client.CreateDatabaseAsync(new Microsoft.Azure.Documents.Database {
                    Id = databaseId
                });
            }

            return(database);
        }