public static VkWallEntry FromJson(JToken json) { if (json == null) { throw new ArgumentException("Json can not be null."); } var result = new VkWallEntry(); result.Id = json["id"].Value <double>(); if (json["text"] != null) { result.Text = WebUtility.HtmlDecode(json["text"].Value <string>()); result.Text = result.Text.Replace("<br>", Environment.NewLine); } if (json["from_id"] != null) { result.SourceId = json["from_id"].Value <long>(); } if (json["date"] != null) { result.Date = DateTimeExtensions.UnixTimeStampToDateTime(json["date"].Value <long>()); } if (json["attachments"] != null) { result.Attachments = VkAttachment.FromJson(json["attachments"]); } if (json["copy_history"] != null) { result.CopyHistory = new List <VkWallEntry>(); foreach (var p in json["copy_history"]) { try { var post = VkWallEntry.FromJson(p); if (post != null) { result.CopyHistory.Add(post); } } catch (Exception ex) { Debug.WriteLine(ex); } } } return(result); }
public static VkMessage FromJson(JToken json, string apiVersion = null) { if (json == null) { throw new Exception("Json can't be null"); } var result = new VkMessage(); if (json["id"] != null) { result.Id = (long)json["id"]; } if (json["user_id"] != null) { result.UserId = (long)json["user_id"]; } result.Date = DateTimeExtensions.UnixTimeStampToDateTime((long)json["date"]); if (json["read_state"] != null) { result.IsRead = (int)json["read_state"] == 1; } if (json["out"] != null) { result.IsOut = (int)json["out"] == 1; } result.Title = (string)json["title"]; result.Body = (string)json["body"]; if (json["deleted"] != null) { result.IsDeleted = (int)json["deleted"] == 1; } if (json["attachments"] != null) { result.Attachments = VkAttachment.FromJson(json["attachments"]); } if (json["geo"] != null) { result.Geo = VkGeo.FromJson(json["geo"]); } if (json["fwd_messages"] != null) { result.ForwardMessages = new List <VkMessage>(); foreach (var fwdMessage in json["fwd_messages"]) { var message = VkMessage.FromJson(fwdMessage); result.ForwardMessages.Add(message); } } if (json["emoji"] != null) { result.ContainsEmoji = (int)json["emoji"] == 1; } if (json["chat_id"] != null) { result.ChatId = (long)json["chat_id"]; } if (json["chat_active"] != null) { result.ChatUsers = json["chat_active"].Select(t => t.Value <long>()).ToList(); } if (json["users_count"] != null) { result.UsersCount = (int)json["users_count"]; } if (json["admin_id"] != null) { result.AdminId = (long)json["admin_id"]; } if (json["action"] != null) { result.Action = (string)json["action"]; } if (json["action_text"] != null) { result.ActionText = (string)json["action_text"]; } if (json["photo_50"] != null) { result.Photo50 = (string)json["photo_50"]; } if (json["photo_100"] != null) { result.Photo100 = (string)json["photo_100"]; } if (json["photo_200"] != null) { result.Photo200 = (string)json["photo_200"]; } return(result); }
public static VkMessage FromJson(JToken json, string apiVersion = null) { if (json == null) { throw new Exception("Json can't be null"); } var result = new VkMessage(); result.Id = (long)json["id"]; result.UserId = (long)json["user_id"]; result.Date = DateTimeExtensions.UnixTimeStampToDateTime((long)json["date"]); if (json["read_state"] != null) { result.IsRead = (int)json["read_state"] == 1; } if (json["out"] != null) { result.IsOut = (int)json["out"] == 1; } result.Title = (string)json["title"]; result.Body = (string)json["body"]; if (json["deleted"] != null) { result.IsDeleted = (int)json["deleted"] == 1; } if (json["attachments"] != null) { result.Attachments = VkAttachment.FromJson(json["attachments"], apiVersion); } //TODO forward messages if (json["emoji"] != null) { result.ContainsEmoji = (int)json["emoji"] == 1; } if (json["chat_id"] != null) { result.ChatId = (long)json["chat_id"]; } if (json["chat_active"] != null) { result.ChatUsers = json["chat_active"].Select(t => t.Value <long>()).ToList(); } if (json["users_count"] != null) { result.UsersCount = (int)json["users_count"]; } if (json["admin_id"] != null) { result.AdminId = (long)json["admin_id"]; } return(result); }