Esempio n. 1
0
        private async Task <IPhotoMetadata> GetPhotoMetadataAsync(UInt32 photoId, Double latitude, Double longitude, String uri)
        {
            var storageFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri(uri));

            var fileBuffer = await FileIO.ReadBufferAsync(storageFile);

            var imageProperties = await storageFile.Properties.GetImagePropertiesAsync();

            await App.Model.LocalFiles.StoreAsync(photoId, fileBuffer);

            var photo = new ScreenshotsDataPhoto(new Size(imageProperties.Width, imageProperties.Height), new Uri(uri), "m");

            return(new ScreenshotsPhotoMetadata(photoId, OwnerId.Create(1, OwnerId.OwnerType.User), latitude, longitude, DateTime.Now, null, new IPhoto[] { photo }));
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        private static Tuple <IReadOnlyCollection <IPhotoMetadata>, DateTime?, DateTime?> ParseItemsUsingNewton(JsonTextReader reader)
        {
            var items = new List <IPhotoMetadata>();

            while (reader.TokenType != JsonToken.StartArray)
            {
                reader.Read();
            }

            var startDate = (DateTime?)null;
            var endDate   = (DateTime?)null;

            while (reader.Read() && (reader.TokenType != JsonToken.EndArray))
            {
                while (reader.TokenType != JsonToken.StartObject)
                {
                    reader.Read();
                }

                var id     = (UInt32?)null;
                var owner  = (OwnerId)null;
                var lat    = (Double?)null;
                var lon    = (Double?)null;
                var date   = (DateTime?)null;
                var text   = (String)null;
                var photos = new List <IPhoto>();
                while (reader.Read() && (reader.TokenType != JsonToken.EndObject))
                {
                    if (reader.TokenType == JsonToken.PropertyName)
                    {
                        if ("id".Equals(reader.Value))
                        {
                            reader.Read();
                            id = Convert.ToUInt32(reader.Value);
                        }
                        else if ("owner_id".Equals(reader.Value))
                        {
                            reader.Read();
                            owner = OwnerId.Create(Convert.ToInt32(reader.Value));
                        }
                        else if ("lat".Equals(reader.Value))
                        {
                            reader.Read();
                            lat = Convert.ToDouble(reader.Value);
                        }
                        else if ("long".Equals(reader.Value))
                        {
                            reader.Read();
                            lon = Convert.ToDouble(reader.Value);
                        }
                        else if ("date".Equals(reader.Value))
                        {
                            reader.Read();
                            date = DateTimeExtensions.FromUnixTimestamp(Convert.ToInt32(reader.Value));
                            if (!endDate.HasValue)
                            {
                                endDate = date;
                            }
                            startDate = date;
                        }
                        else if ("text".Equals(reader.Value))
                        {
                            reader.Read();
                            text = Convert.ToString(reader.Value);
                        }
                        else if ("sizes".Equals(reader.Value))
                        {
                            while (reader.Read() && (reader.TokenType != JsonToken.EndArray))
                            {
                                var src    = (String)null;
                                var width  = (UInt32?)null;
                                var height = (UInt32?)null;
                                var type   = (String)null;
                                while (reader.Read() && (reader.TokenType != JsonToken.EndObject))
                                {
                                    if (reader.TokenType == JsonToken.PropertyName)
                                    {
                                        if ("src".Equals(reader.Value))
                                        {
                                            reader.Read();
                                            src = Convert.ToString(reader.Value);
                                        }
                                        else if ("width".Equals(reader.Value))
                                        {
                                            reader.Read();
                                            width = Convert.ToUInt32(reader.Value);
                                        }
                                        else if ("height".Equals(reader.Value))
                                        {
                                            reader.Read();
                                            height = Convert.ToUInt32(reader.Value);
                                        }
                                        else if ("type".Equals(reader.Value))
                                        {
                                            reader.Read();
                                            type = Convert.ToString(reader.Value);
                                        }
                                    }
                                }
                                if ((src != null) && width.HasValue && (width.Value > 0) && height.HasValue && (height.Value > 0) && (type != null))
                                {
                                    photos.Add(new VkPhoto(new Windows.Foundation.Size(width.Value, height.Value), new Uri(src), type));
                                }
                            }
                        }
                    }
                }
                items.Add(new VkPhotoMetadata(id, owner, lat, lon, date, text, photos));
            }
            return(new Tuple <IReadOnlyCollection <IPhotoMetadata>, DateTime?, DateTime?>(items, startDate, endDate));
        }