Ejemplo n.º 1
0
        public static IPhotoMetadata Create(JsonObject value)
        {
            var photos = new List <IPhoto>();

            if (value.ContainsKey("sizes") && (value["sizes"].ValueType == JsonValueType.Array))
            {
                foreach (var item in value["sizes"].GetArray())
                {
                    var photo = VkPhoto.Create(item.GetObject());
                    if (photo != null)
                    {
                        photos.Add(photo);
                    }
                }
            }

            var instance = new VkPhotoMetadata();

            if (value.ContainsKey("id"))
            {
                instance.Id = (UInt32)value["id"].GetNumber();
            }
            if (value.ContainsKey("owner_id"))
            {
                var owner = value["owner_id"].GetNumber();
                instance.Owner = (owner < 0) ? OwnerId.Create((UInt32)Math.Abs(owner), OwnerId.OwnerType.Group) : OwnerId.Create((UInt32)owner, OwnerId.OwnerType.User);
            }
            if (value.ContainsKey("lat"))
            {
                instance.Latitude = value["lat"].GetNumber();
            }
            if (value.ContainsKey("long"))
            {
                instance.Longitude = value["long"].GetNumber();
            }
            if (value.ContainsKey("date"))
            {
                instance.Date = DateTimeExtensions.FromUnixTimestamp((Int32)value["date"].GetNumber());
            }
            if (value.ContainsKey("text"))
            {
                instance.Text = value["text"].GetString();
            }
            instance.Photos = photos;
            return(instance);
        }
Ejemplo n.º 2
0
        public static IPhoto Create(JsonObject value)
        {
            if (!value.ContainsKey("width") || !value.ContainsKey("height") || !value.ContainsKey("src") || !value.ContainsKey("type"))
            {
                return(null);
            }

            var instance = new VkPhoto();

            instance.Size = new Size((UInt16)value["width"].GetNumber(), (UInt16)value["height"].GetNumber());
            if (!instance.Size.IsVisible())
            {
                return(null);
            }
            instance.Source = new Uri(value["src"].GetString());
            instance.Type   = value["type"].GetString();
            return(instance);
        }