Beispiel #1
1
        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;
                }
            }
        }
Beispiel #2
0
        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 = "******",
                            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);*/
            Console.ReadLine();
       

            int n = 19;
            try
            {
                while (n < 10)
                {
                    n++;
                    var timestamp=(long) (DateTime.UtcNow.AddHours(-1).Subtract(new DateTime(1970, 1, 1))).TotalMilliseconds;
                    PostMessage x = new PostMessage
                    {
                        Type = "Post",
                        Info = new Info
                        {
                            user = "******",
                            uid = "1210808",
                            message = "java",
                            timestamp = timestamp
                        },
                        Path = new PostPath
                        {
                            District = "tst-azhang" 
                        }
                    };

                    await client.CreateDocumentAsync(database.SelfLink, x);
                }
            }
            catch (Exception e)
            {
                var t = e;
            }

            var z = 4;
        }