Ejemplo n.º 1
0
        public static void UpdatePhotos()
        {
            using (var ctx = new JamieEntityModelContainer())
            {
                foreach (var owner in ctx.Owners)
                {
                    var service = GetService(owner);
                    if (ctx.Albums.Count() > 0)
                    {
                        owner.Albums.Run(album =>
                        {
                            var googleAlbum = GetAlbum(service, album.Id);
                            if (googleAlbum.Updated != album.LastUpdated)
                            {
                                var query = new PhotoQuery(PicasaQuery.CreatePicasaUri(owner.Name, album.Id)) { ExtraParameters = "imgmax=1280" };
                                var googlePhotos = service.Query(query).Entries.Select(entry => new Google.Picasa.Photo { AtomEntry = entry }).ToArray();
                                var albumPhotos = album.Photos.ToArray();

                                albumPhotos.Run(photo =>
                                {
                                    if (googlePhotos.FirstOrDefault(gPhoto => gPhoto.Id == photo.Id) != null)
                                        return;

                                    album.Photos.Remove(photo);
                                    ctx.Photos.DeleteObject(photo);
                                });

                                googlePhotos.Run(photo =>
                                {
                                    if (albumPhotos.FirstOrDefault(p => p.Id == photo.Id) != null || ctx.Photos.FirstOrDefault(p => p.Id == photo.Id) != null)
                                        return;

                                    var newPhoto = new Photo
                                    {
                                        Id = photo.Id,
                                        TimeTaken = FromUnixTimeStamp(photo.Timestamp),
                                        ThumbUri = ((PicasaEntry)photo.AtomEntry).Media.Thumbnails.Last().Url,
                                        FullUri = photo.AtomEntry.Content.AbsoluteUri
                                    };

                                    album.Photos.Add(newPhoto);
                                });

                                album.LastUpdated = googleAlbum.Updated;
                            }
                        });
                    }
                }

                ctx.SaveChanges();
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Create a new Photo object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="timeTaken">Initial value of the TimeTaken property.</param>
 /// <param name="thumbUri">Initial value of the ThumbUri property.</param>
 public static Photo CreatePhoto(global::System.String id, global::System.DateTime timeTaken, global::System.String thumbUri)
 {
     Photo photo = new Photo();
     photo.Id = id;
     photo.TimeTaken = timeTaken;
     photo.ThumbUri = thumbUri;
     return photo;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Photos EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToPhotos(Photo photo)
 {
     base.AddObject("Photos", photo);
 }