예제 #1
0
        public static List <VkAttachment> FromJson(JToken json)
        {
            var result = new List <VkAttachment>();

            foreach (var a in json)
            {
                switch (a["type"].Value <string>())
                {
                case "audio":
                    result.Add(VkAudioAttachment.FromJson(a["audio"]));
                    break;

                case "photo":
                    result.Add(VkPhotoAttachment.FromJson(a["photo"]));
                    break;

                case "sticker":
                    result.Add(VkStickerAttachment.FromJson(a["sticker"]));
                    break;

                case "gift":
                    result.Add(VkGiftAttachment.FromJson(a["gift"]));
                    break;

                case "link":
                    result.Add(VkLinkAttachment.FromJson(a["link"]));
                    break;

                case "doc":
                    result.Add(VkDocumentAttachment.FromJson(a["doc"]));
                    break;

                case "video":
                    result.Add(VkVideoAttachment.FromJson(a["video"]));
                    break;

                case "wall":
                    result.Add(VkWallPostAttachment.FromJson(a["wall"]));
                    break;
                }
            }

            return(result);
        }
예제 #2
0
        public static new VkWallPostAttachment FromJson(JToken json)
        {
            if (json == null)
            {
                throw new ArgumentException("Json can not be null.");
            }

            var result = new VkWallPostAttachment();

            result.Id = (long)json["id"];

            if (json["owner_id"] != null)
            {
                result.OwnerId = (long)json["owner_id"];
            }

            if (json["from_id"] != null)
            {
                result.FromId = (long)json["from_id"];
            }

            if (json["to_id"] != null)
            {
                result.ToId = (long)json["to_id"];
            }

            if (json["date"] != null)
            {
                result.Date = DateTimeExtensions.UnixTimeStampToDateTime(json["date"].Value <long>());
            }

            if (json["post_type"] != null)
            {
                result.PostType = (string)json["post_type"];
            }

            if (json["text"] != null)
            {
                result.Text = (string)json["text"];
            }

            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);
                    }
                }
            }


            if (json["can_delete"] != null)
            {
                result.CanDelete = (int)json["can_delete"] == 1;
            }

            return(result);
        }