Exemple #1
0
        private static Album MapAlbum(dynamic album)
        {
            var newAlbum = new Album();

            newAlbum.Id = album.id;
            newAlbum.Name = album.name ?? string.Empty;
            newAlbum.Description = album.description ?? string.Empty;
            newAlbum.FBLink = album.link;
            newAlbum.CoverPhoto = album.cover_photo;
            newAlbum.Type = album.type;
            newAlbum.Count = Convert.ToInt32(album.count ?? "0");

            newAlbum.CreatedTimeStamp = Convert.ToDateTime(album.created_time);
            newAlbum.UpdatedTimeStamp = Convert.ToDateTime(album.updated_time);
            newAlbum.Pictures = new EntityCollection<Picture>();
            return newAlbum;
        }
 /// <summary>
 /// Create a new Album object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="type">Initial value of the Type property.</param>
 /// <param name="coverPhoto">Initial value of the CoverPhoto property.</param>
 /// <param name="createdTimeStamp">Initial value of the CreatedTimeStamp property.</param>
 /// <param name="updatedTimeStamp">Initial value of the UpdatedTimeStamp property.</param>
 public static Album CreateAlbum(global::System.String id, global::System.String name, global::System.String type, global::System.String coverPhoto, global::System.DateTime createdTimeStamp, global::System.DateTime updatedTimeStamp)
 {
     Album album = new Album();
     album.Id = id;
     album.Name = name;
     album.Type = type;
     album.CoverPhoto = coverPhoto;
     album.CreatedTimeStamp = createdTimeStamp;
     album.UpdatedTimeStamp = updatedTimeStamp;
     return album;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Albums EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToAlbums(Album album)
 {
     base.AddObject("Albums", album);
 }
        public static void SyncPhotos(Album album)
        {
            var incomingPictureIds = new List<string>();
            string albumId = album.Id;
            using (var unitOfWork = UnitOfWorkFactory.BeginNew())
            {
                try
                {
                    var user =
                        unitOfWork.MemberRepository.FindMemberByFBId(AppConstants.AppSettings.MasterAdminFacebookId);
                    var client = new FacebookClient(user.FBAccessToken);

                    string photosFeedUrl = albumId + "/photos";
                    dynamic photosFeed = client.Get(photosFeedUrl);
                    bool haveAllPhotosBeenFetched = false;
                    do
                    {
                        if (photosFeed == null
                            || photosFeed.data == null)
                        {
                            haveAllPhotosBeenFetched = true;
                        }
                        else
                        {
                            List<Picture> pictures = Mapper.MapPictures(photosFeed);

                            if (pictures != null
                                && pictures.Any())
                            {
                                foreach (var picture in pictures)
                                {
                                    incomingPictureIds.Add(picture.Id);
                                    var existingPicture = unitOfWork.PictureRepository.FindById(picture.Id);
                                    if (existingPicture != null)
                                    {
                                        //This condition doesn't seem to working with change in description
                                        if (existingPicture.UpdatedTimeStamp != picture.UpdatedTimeStamp)
                                        {
                                            existingPicture.Description = picture.Description;
                                            existingPicture.UpdatedTimeStamp = picture.UpdatedTimeStamp;
                                        }
                                    }
                                    else
                                    {
                                        picture.AlbumId = albumId;
                                        unitOfWork.PictureRepository.Add(picture);
                                    }

                                    unitOfWork.Commit();
                                }
                            }

                            // Getting next page
                            if (photosFeed.paging != null
                                && photosFeed.paging.cursors != null
                                && photosFeed.paging.cursors.after != null)
                            {
                                var nextCursor = photosFeed.paging.cursors.after;
                                photosFeedUrl = albumId + "/photos?after=" + nextCursor;
                                photosFeed = client.Get(photosFeedUrl);
                            }
                            else
                            {
                                photosFeed = null;
                            }
                        }
                    } while (!haveAllPhotosBeenFetched);

                    //Clean removed photos
                    var storedPictures = unitOfWork.PictureRepository.Find(p => p.AlbumId == albumId).ToList();
                    foreach (var storedPicture in storedPictures)
                    {
                        if(!incomingPictureIds.Contains(storedPicture.Id))
                        {
                            unitOfWork.PictureRepository.Remove(storedPicture);
                            unitOfWork.Commit(); ;
                        }
                    }
                }
                catch (Exception exception)
                {

                }
            }
        }