public async Task Send(string m) { try { dynamic x = JsonConvert.DeserializeObject(m); var path = x.url.ToString().Split('/'); if (_sp != null) { PostMessage mess = new PostMessage { Type = "Post", Path = new PostPath() { District = path[1], School = path[2], Classes = path[3] }, Info = new Info() { user = x.body.user, uid = x.body.uid, timestamp = x.body.timestamp, message = x.body.message } }; var res = await _documentClient.ExecuteStoredProcedureAsync<Document>( _sp.SelfLink, mess, _documentCollection.SelfLink); //After save in DB success, save in Firebase if (res.StatusCode == HttpStatusCode.OK) { FirebaseResponse response = await _client.PushAsync(x.url.ToString(), x.body); } } } catch (Exception e) { Console.WriteLine(e.Message); } }
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; }
public PostMessage PostData(dynamic data, string[] path) { Random r = new Random(); PostMessage message = new PostMessage { Type = "Post", Path = new PostPath() { District = path[1] + r.Next(1, 51), School = path[2], Classes = path[3] }, Info = new Info() { user = data.body.user, uid = data.body.uid, timestamp = data.body.timestamp, message = data.body.message } }; return message; }