Beispiel #1
0
        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);
            }
        }
Beispiel #2
0
 public static 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;
 }
Beispiel #3
0
        private static async Task AddTestData(DocumentClient client, Database database, int number)
        {
            int n = 0;
            try
            {
                while (n < number)
                {
                    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;
            }
        }