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


C# DocumentClient.ReadDatabaseAsync方法代码示例

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


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

示例1: CreateDatabase

        private static void CreateDatabase(DocumentClient documentClient)
        {
            //create a document collection if it doesn't exist.

            try
            {
                documentClient.ReadDatabaseAsync(UriFactory.CreateDatabaseUri(DatabaseName)).GetAwaiter().GetResult();
            }
            catch (DocumentClientException de)
            {
                // If the database does not exist, create it
                if (de.StatusCode == HttpStatusCode.NotFound)
                {
                    documentClient.CreateDatabaseAsync(new Database { Id = DatabaseName }).GetAwaiter().GetResult();
                }
                else
                {
                    throw;
                }
            }
        }
开发者ID:XpiritBV,项目名称:mini-hacks,代码行数:21,代码来源:Program.cs

示例2: sp2

        private static async Task sp2(DocumentCollection dc, DocumentClient client, Database database)
        {
            DocumentCollection dc2 = client.CreateDocumentCollectionQuery(database.SelfLink)
                .Where(c => c.Id == "LMSCollection1444075919174")
                .AsEnumerable()
                .FirstOrDefault();
            await client.OpenAsync();
            //await _iDbService.CollectionTransfer(client, dc2, dc);
            var mn=await client.ReadDatabaseAsync(database.SelfLink);

          /*  await client.CreateDocumentAsync(dc.SelfLink, new CurrentCollection
            {
                id = "CurrentCollection",
                name=dc.Id
            });*/
          /*  var resolver = _iDbService.GetResolver(client, dc);
            foreach (var d in resolver.PartitionMap)
            {
                Console.WriteLine(d.Value);
                Offer offer = client.CreateOfferQuery()
                                      .Where(r => r.ResourceLink == d.Value)
                                      .AsEnumerable()
                                      .SingleOrDefault();
            }*/




           /* HashPartitionResolver hashResolver = new HashPartitionResolver(
                u => ((PostMessage) u).Path.District,
                new string[] {dc.SelfLink, dc2.SelfLink});

            client.PartitionResolvers[database.SelfLink] = hashResolver;*/

            var rangeResolver = _iDbService.GetResolver(client);
            client.PartitionResolvers[database.SelfLink] = rangeResolver;

            
            var created = await _iDbService.InitResolver("");
          
            
            while (true)
            {
                var re2 = await _iDbService.UpdateResolver(dc2);
                var p = re2;
                await Task.Delay(TimeSpan.FromSeconds(4));
            }

            var z1 = rangeResolver.GetPartitionKey(new PostMessage
                    {
                        Type = "Post",
                        Info = new Info
                        {
                            user = "tzk",
                            uid = "1210808",
                            message = "java",
                            timestamp = 7
                        },
                        Path = new PostPath
                        {
                            District = "tst-azhang" 
                        }
                    });

            //search global
            IQueryable<PostMessage> query = client.CreateDocumentQuery<PostMessage>(database.SelfLink)
                .Where(u => u.Info.timestamp>1);

            var now = (long)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalMilliseconds;

            //search on partition

            var t1 = DateTime.Now;
            var query2 = client.CreateDocumentQuery<PostMessage>(database.SelfLink, new FeedOptions
            {
                MaxItemCount = 1200
            }, now);
            var query3 = client.CreateDocumentQuery<PostMessage>(dc2.SelfLink).AsDocumentQuery();



            var t2 = DateTime.Now;
            Console.WriteLine(t2-t1);
              //.Where(u => u.Path.District=="tst-azhang");
          
            foreach (PostMessage a in query2)
            {
                Console.WriteLine(a.Info.timestamp);
            }

          /*  double totalRequestCharge = 0;
            
            while (query3.HasMoreResults)
            {
                FeedResponse<dynamic> queryResponse = await query3.ExecuteNextAsync<dynamic>();
                Console.WriteLine("Query batch consumed {0} request units {1} doc", queryResponse.RequestCharge, queryResponse.Count);
                totalRequestCharge += queryResponse.RequestCharge;
            }
            Console.WriteLine(DateTime.Now - t2);
            Console.WriteLine("Query consumed {0} request units in total", totalRequestCharge);*/
//.........这里部分代码省略.........
开发者ID:tzkwizard,项目名称:ELS,代码行数:101,代码来源:DocumentDB.cs


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