当前位置: 首页>>代码示例>>C#>>正文


C# DocumentClient.CreateDatabaseQuery方法代码示例

本文整理汇总了C#中Microsoft.Azure.Documents.Client.DocumentClient.CreateDatabaseQuery方法的典型用法代码示例。如果您正苦于以下问题:C# DocumentClient.CreateDatabaseQuery方法的具体用法?C# DocumentClient.CreateDatabaseQuery怎么用?C# DocumentClient.CreateDatabaseQuery使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Azure.Documents.Client.DocumentClient的用法示例。


在下文中一共展示了DocumentClient.CreateDatabaseQuery方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DocumentDBDataReader

        public DocumentDBDataReader()
        {
            var dict = new Dictionary<HighchartsHelper.DocumentTypes, IEnumerable<Document>>();
            _documentClient = new DocumentClient(new Uri(ConfigurationManager.AppSettings["DocumentServiceEndpoint"]), ConfigurationManager.AppSettings["DocumentKey"]);

            _database = _documentClient.CreateDatabaseQuery().Where(db => db.Id == ConfigurationManager.AppSettings["DocumentDatabase"]).AsEnumerable().FirstOrDefault();

            if (_database == null)
                throw new ApplicationException("Error: DocumentDB database does not exist");

            // Check to verify a document collection with the id=FamilyCollection does not exist
            _documentCollection = _documentClient.CreateDocumentCollectionQuery(_database.CollectionsLink).Where(c => c.Id == ConfigurationManager.AppSettings["DocumentCollection"]).AsEnumerable().FirstOrDefault();

            if (_documentCollection == null)
                throw new ApplicationException("Error: DocumentDB collection does not exist");


            try
            {
                _documentClient.CreateUserDefinedFunctionAsync(_documentCollection.SelfLink, new UserDefinedFunction
                {
                    Id = "ISDEFINED",
                    Body = @"function ISDEFINED(doc, prop) {
                            return doc[prop] !== undefined;
                        }"
                });  
            }
            catch (Exception)
            {
                //fail silently for now..
            }
        }
开发者ID:Rodrigossz,项目名称:CloudDataCamp,代码行数:32,代码来源:DocumentDBDataReader.cs

示例2: GetStart

        //new add
        private static async Task GetStart()
        {
            var client = new DocumentClient(new Uri(EndpointURL), AuthorizationKey);
            
            database = client.CreateDatabaseQuery().Where(d => d.Id == "ppweict").AsEnumerable().FirstOrDefault();
            collection = client.CreateDocumentCollectionQuery(database.SelfLink).Where(c => c.Id == "Exam_Pool").AsEnumerable().FirstOrDefault();


            var EfDs = client.CreateDocumentQuery(collection.DocumentsLink, "SELECT * FROM Exam_pool f WHERE f.verify = \"true\" ");
            foreach (exam_pool EfD in EfDs)
            {
                Console.WriteLine(EfD);
                exams.Add(new exam_pool
                {
                    id = EfD.id,
                    exam_catrgory = EfD.exam_catrgory,
                    exam_level = EfD.exam_level,
                    questions = EfD.questions,
                    answer_A = EfD.answer_A,
                    answer_B = EfD.answer_B,
                    answer_C = EfD.answer_C,
                    answer_D = EfD.answer_D,
                    answer_E = EfD.answer_E,
                    C_answer = EfD.C_answer,
                    exam_link = EfD.exam_link,
                    lang = EfD.lang,
                    verify = EfD.verify,
                });
            }
        }
开发者ID:Steven-Tsai,项目名称:ppweict_Web_API,代码行数:31,代码来源:exam_pool_1_Repository.cs

示例3: GetDocumentDbClient

        private async Task<DocumentClient> GetDocumentDbClient()
        {
            var client = new DocumentClient(new Uri(_endPointUrl), _authorizationKKry);

            var database = client.CreateDatabaseQuery().
                Where(db => db.Id == DocumentDbId).AsEnumerable().FirstOrDefault();

            if (database == null)
            {
                database = await client.CreateDatabaseAsync(
                    new Database
                    {
                        Id = DocumentDbId
                    });    
            }

            DocumentCollection = client.CreateDocumentCollectionQuery
                ("dbs/" + database.Id).Where(c => c.Id == _collectionId).AsEnumerable().FirstOrDefault();

            if (DocumentCollection == null)
            {
                DocumentCollection = await client.CreateDocumentCollectionAsync("dbs/" + DocumentDbId,
                new DocumentCollection
                {
                    Id = _collectionId
                });

            }
           

            return client;
        }
开发者ID:sogeti,项目名称:Site-provisioning,代码行数:32,代码来源:SiteTemplateRepository.cs

示例4: FindDatabase

 static Database FindDatabase(DocumentClient client, string name)
 {
     return client.CreateDatabaseQuery()
         .Where(x => x.Id == name)
         .ToList()
         .SingleOrDefault();
 }
开发者ID:korz,项目名称:IntroductionToDocumentDB,代码行数:7,代码来源:Program.cs

示例5: Dichotomy

 public Dichotomy(string endpointUrl, string authorizationKey)
 {
     _client = new DocumentClient(new Uri(endpointUrl), authorizationKey);
     _database =
         _client.CreateDatabaseQuery().Where(db => db.SelfLink == ConfigurationManager.AppSettings["DBSelfLink"])
             .AsEnumerable().FirstOrDefault();
     _iDbService = new DbService();
 }
开发者ID:tzkwizard,项目名称:Azure,代码行数:8,代码来源:Dichotomy.cs

示例6: GetOrCreateDatabase

        private static Database GetOrCreateDatabase(DocumentClient client, string databaseName)
        {
            // Try to retrieve the database (Microsoft.Azure.Documents.Database) whose Id is equal to databaseName            
            var database = client.CreateDatabaseQuery().Where(db => db.Id == databaseName).ToArray().FirstOrDefault()
                           ?? client.CreateDatabaseAsync(new Database { Id = databaseName }).Result;

            return database;
        }
开发者ID:spederiva,项目名称:AzureOss,代码行数:8,代码来源:UsersController.cs

示例7: Dichotomy

 public Dichotomy(string endpointUrl, string authorizationKey)
 {
     _client = new DocumentClient(new Uri(endpointUrl), authorizationKey);
     _database =
         _client.CreateDatabaseQuery().Where(db => db.Id == CloudConfigurationManager.GetSetting("Database"))
             .AsEnumerable().FirstOrDefault();
     _iDbService = new DbService();
 }
开发者ID:tzkwizard,项目名称:ELS,代码行数:8,代码来源:Dichotomy.cs

示例8: GetDatabase

 private static Database GetDatabase(DocumentClient client)
 {
     var database = client
         .CreateDatabaseQuery()
         .Where(x => x.Id == "TestDocumentDatabase")
         .AsEnumerable()
         .FirstOrDefault();
     return database;
 }
开发者ID:keesschollaart81,项目名称:DocumentDbSerializationTest,代码行数:9,代码来源:Program.cs

示例9: Initialise

        public DocumentClient Initialise()
        {
            var configuration = (Configuration)ConfigurationManager.GetSection("DocumentDbProvider");
            _documentClient = new DocumentClient(new Uri(configuration.Endpoint), configuration.Key);
            Database = _documentClient.CreateDatabaseQuery()
                .Where(d => d.Id == _databaseName).AsEnumerable().FirstOrDefault()
                ?? _documentClient.CreateDatabaseAsync(new Database { Id = _databaseName }).Result;

            return _documentClient;
        }
开发者ID:ritasker,项目名称:TechTest,代码行数:10,代码来源:DocumentDbContext.cs

示例10: CollectionManager

		/// <summary>
		///     Constructor
		/// </summary>
		/// <param name="documentClient"></param>
		/// <param name="databaseId"></param>
		/// <param name="createDatabaseIfNonexistent"></param>
		public CollectionManager( DocumentClient documentClient ,
								  string databaseId ,
								  bool createDatabaseIfNonexistent = false ) {
			DocumentClient = documentClient;
			DatabaseId = databaseId;

			Database =
				DocumentClient.CreateDatabaseQuery().Where( item => item.Id == databaseId ).AsEnumerable().FirstOrDefault();

			Initialize( createDatabaseIfNonexistent ).Wait();
		}
开发者ID:theuntitled,项目名称:JF.Azure.DocumentDB,代码行数:17,代码来源:CollectionManager.cs

示例11: ReadOrCreateDatabase

        internal static Database ReadOrCreateDatabase(DocumentClient client, string databaseId)
        {
            var databases = client.CreateDatabaseQuery()
                            .Where(db => db.Id == databaseId).ToArray();

            if (databases.Any())
            {
                return databases.First();
            }

            var database = new Database { Id = databaseId };
            return client.CreateDatabaseAsync(database).Result;
        }
开发者ID:alphio,项目名称:DocumentDB.AspNet.Identity,代码行数:13,代码来源:Utils.cs

示例12: Main

        static void Main(string[] args)
        {
            if (args.Count() < 4)
            {
                Console.WriteLine("You must specify the following parameters: Document DB endpoint URL, secret key, database name, and collection name.");
                Console.WriteLine("Program terminated. Press any key to exit");
                Console.ReadKey();
                return; // exit program

            }

            // setup DocumentDB client using passed parameters
            Uri endpoint = new Uri(args[0]);
            string authKey = args[1];
            string databaseId = args[2];
            string collectionId = args[3];

            var connectionPolicy = new ConnectionPolicy()
            {
                ConnectionProtocol = Protocol.Https,
                ConnectionMode = ConnectionMode.Gateway
            };
            client = new DocumentClient(endpoint, authKey, connectionPolicy);

            Database database = client.CreateDatabaseQuery().Where(db => db.Id == databaseId).ToArray().FirstOrDefault();
            DocumentCollection collection = client.CreateDocumentCollectionQuery(database.SelfLink).Where(c => c.Id == collectionId).ToArray().FirstOrDefault();

            // get list of SP files
            var currentDir = new DirectoryInfo(Directory.GetCurrentDirectory());
            foreach (FileInfo tmpFile in currentDir.GetFiles("SP_*.js"))
            {
                string storedProecureId = tmpFile.Name.Substring(3, (tmpFile.Name.Length - 6));
                Console.WriteLine("Found File: " + storedProecureId);

                var storedProc = new StoredProcedure()
                {
                    Id = storedProecureId,
                    Body = File.ReadAllText(tmpFile.FullName)
                };

                TryDeleteStoredProcedure(collection.SelfLink, storedProc.Id); 

                client.CreateStoredProcedureAsync(collection.SelfLink, storedProc, null).Wait();
            }

            Console.WriteLine("Stored Procedure Setup completed. Press any key to continue.");
            Console.ReadKey();
        }
开发者ID:hpatel98,项目名称:SCAMP,代码行数:48,代码来源:Program.cs

示例13: GetOrCreateDatabase

        public static Database GetOrCreateDatabase(DocumentClient client, string databaseId)
        {
            IQueryable<Database> dbQuery = from db in client.CreateDatabaseQuery()
                                           where db.Id == databaseId
                                           select db;

            IEnumerable<Database> enumerable = dbQuery.AsEnumerable();
            if (!enumerable.Any())
            {
                return client.CreateDatabaseAsync(new Database() { Id = databaseId }).Result.Resource;
            }
            else
            {
                return enumerable.First<Database>();
            }
        }
开发者ID:vikramadhav,项目名称:DocumentDB-MVA,代码行数:16,代码来源:DocumentDBUtils.cs

示例14: WriteDocument

        public async Task<bool>  WriteDocument(MessageType type, String jsonString)
        {
            var client = new DocumentClient(new Uri(ConfigurationManager.AppSettings["DocumentServiceEndpoint"]), ConfigurationManager.AppSettings["DocumentKey"]);

            var dbName = ConfigurationManager.AppSettings["DocumentDatabase"];
            var database = client.CreateDatabaseQuery().Where(db => db.Id == dbName).AsEnumerable().FirstOrDefault() ??
                           await client.CreateDatabaseAsync(new Database{ Id = dbName});


            // Check to verify a document collection with the does not exist
            var docCollection = ConfigurationManager.AppSettings["DocumentCollection"];
            var documentCollection = client.CreateDocumentCollectionQuery(database.CollectionsLink).Where(c => c.Id == docCollection).AsEnumerable().FirstOrDefault() ??
                                     await client.CreateDocumentCollectionAsync(database.CollectionsLink, new DocumentCollection { Id = docCollection });

            var id = Guid.NewGuid().ToString();

            var response = HttpStatusCode.Unused;
            switch (type)
            {
                case MessageType.Energy:
                    var energyDoc = JsonConvert.DeserializeObject<EnergyDocument>(jsonString);
                    energyDoc.id = id;
                    response = (await client.CreateDocumentAsync(documentCollection.DocumentsLink, energyDoc)).StatusCode;
                    break;
                case MessageType.Humidity:
                    var humidityDoc = JsonConvert.DeserializeObject<HumidityDocument>(jsonString);
                    humidityDoc.id = id;
                    response = (await client.CreateDocumentAsync(documentCollection.DocumentsLink, humidityDoc)).StatusCode;
                    break;
                case MessageType.Light:
                    var lightDoc = JsonConvert.DeserializeObject<LightDocument>(jsonString);
                    lightDoc.id = id;
                    response = (await client.CreateDocumentAsync(documentCollection.DocumentsLink, lightDoc)).StatusCode;
                    break;
                case MessageType.Temperature:
                    var tempDoc = JsonConvert.DeserializeObject<TemperatureDocument>(jsonString);
                    tempDoc.id = id;
                    response = (await client.CreateDocumentAsync(documentCollection.DocumentsLink, tempDoc)).StatusCode;
                    break;
            }

            return response == HttpStatusCode.Created;
        }
开发者ID:karalamalar,项目名称:CloudDataCamp,代码行数:43,代码来源:DocumentDBWriter.cs

示例15: Main

        static void Main(string[] args)
        {
            ConnectionPolicy policy = new ConnectionPolicy()
            {
                ConnectionMode = ConnectionMode.Direct,
                ConnectionProtocol = Protocol.Tcp
            };
            Uri endPoint = new Uri(EndpointUrl);
            using (DocumentClient client = new DocumentClient(endPoint, AuthKey, policy))
            {
                Database database =
                    client.CreateDatabaseQuery().Where(db => db.Id == DatabasebId).AsEnumerable().First();
                DocumentCollection collection =
                    client.CreateDocumentCollectionQuery(database.SelfLink)
                        .Where(c => c.Id == CollectionId)
                        .AsEnumerable()
                        .First();

                IEnumerable<DataClass> dataSet = GetDataObjects(100);

                Task<ResourceResponse<Document>>[] documentTasks =
                    dataSet.Select(d => client.CreateDocumentAsync(collection.DocumentsLink, d)).ToArray();

                Task.WaitAll(documentTasks);

                Document[] docs = documentTasks.Select(t => t.Result.Resource).ToArray();

                Document doc = docs.First();

                Task<ResourceResponse<Attachment>>[] attachmentTasks =
                    docs.Select(d => client.CreateAttachmentAsync(doc.AttachmentsLink, GetStream(1024))).ToArray();

                Task.WaitAll(attachmentTasks);

                DataClass[] data =
                    client.CreateDocumentQuery<DataClass>(collection.DocumentsLink).Select(d => d).ToArray();
                Attachment[] attachments = client.CreateAttachmentQuery(doc.AttachmentsLink).ToArray();

                string sql = "SELECT c.Name FROM c Where c.ObjectKey < 30 AND c.ObjectKey > 20";
                dynamic[] dataArray = client.CreateDocumentQuery(collection.DocumentsLink, sql).ToArray();
            }
        }
开发者ID:pospanet,项目名称:OpenAlt_2015,代码行数:42,代码来源:Program.cs


注:本文中的Microsoft.Azure.Documents.Client.DocumentClient.CreateDatabaseQuery方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。