Exemple #1
0
 public static TableChat TableChatData(dynamic room, dynamic message)
 {
     TableChat item = new TableChat(room.Value.room.ID.ToString(), message.Name.ToString())
     {
         roomName = room.Value.room.Name,
         timestamp = message.Value.timestamp,
         user = message.Value.user,
         uid = message.Value.uid,
         message = message.Value.message
     };
     return item;
 }
Exemple #2
0
        private static async Task Backup(dynamic u, CloudTable table)
        {
            try
            {
                if (u.Value.messages.Value != "")
                {
                    var origin = new List<dynamic>();
                    foreach (var s in u.Value.messages)
                    {
                        origin.Add(s);
                    }

                    var sorted = origin.OrderBy(o => o.Value.timestamp).ToList();

                    if (sorted.Count <= RecordRemained) return;

                    for (int i = 0; i < sorted.Count - RecordRemained; i++)
                    {
                        var s = sorted[i];
                        TableChat c = new TableChat(u.Value.room.ID.ToString(), s.Name.ToString())
                        {
                            roomName = u.Value.room.Name,
                            timestamp = s.Value.timestamp,
                            user = s.Value.user,
                            uid = s.Value.uid,
                            message = s.Value.message
                        };
                        TableOperation insertOperation = TableOperation.Insert(c);
                        // Execute the insert operation.
                        var res = await table.ExecuteAsync(insertOperation);
                        if (res.HttpStatusCode == 204)
                        {
                            string url = "ChatRoom/" + u.Name + "/messages/" + s.Name;
                            await _firebaseClient.DeleteAsync(url);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }