/// <summary> /// Creates an instance of <see cref="CacheItemMedia" /> from <paramref name="go" />. This instance is suitable for storing in cache. /// </summary> /// <param name="go">The media object.</param> /// <returns>An instance of <see cref="CacheItemMedia" />.</returns> public static CacheItemMedia CreateFrom(IGalleryObject go) { return(new CacheItemMedia(go.Id, go.GalleryId, go.Parent.Id, CacheItemDisplayObject.CreateFrom(go.Thumbnail, go.Optimized, go.Original), go.GalleryObjectType, go.Sequence, go.DateAdded, CacheItemMetaItem.FromMetaItems(go.MetadataItems, go.Id, go.GalleryObjectType), go.CreatedByUserName, go.LastModifiedByUserName, go.DateLastModified, go.IsPrivate)); }
/// <summary> /// Creates an instance of <see cref="CacheItemAlbum" /> from <paramref name="album" />. This instance is suitable for storing in cache. /// If <paramref name="album" /> is not inflated, a call to the data store is made to retrieve the child albums and media assets. /// </summary> /// <param name="album">The album.</param> /// <returns>An instance of <see cref="CacheItemAlbum" />.</returns> public static CacheItemAlbum CreateFrom(IAlbum album) { ConcurrentDictionary <int, byte> childAlbumIds; ConcurrentDictionary <int, byte> childMediaObjectIds; if (album.AreChildrenInflated) { childAlbumIds = new ConcurrentDictionary <int, byte>(album.GetChildGalleryObjects(GalleryObjectType.Album).ToDictionary(k => k.Id, v => (byte)0)); childMediaObjectIds = new ConcurrentDictionary <int, byte>(album.GetChildGalleryObjects(GalleryObjectType.MediaObject).ToDictionary(k => k.Id, v => (byte)0)); } else { using (var repo = new AlbumRepository()) { childAlbumIds = new ConcurrentDictionary <int, byte>(repo.Where(a => a.FKAlbumParentId == album.Id).ToDictionary(k => k.AlbumId, v => (byte)0)); } using (var repo = new MediaObjectRepository()) { childMediaObjectIds = new ConcurrentDictionary <int, byte>(repo.Where(a => a.FKAlbumId == album.Id).ToDictionary(k => k.MediaObjectId, v => (byte)0)); } } return(new CacheItemAlbum(album.Id, album.GalleryId, album.Parent.Id, album.GalleryObjectType, album.Sequence, album.DateAdded, CacheItemMetaItem.FromMetaItems(album.MetadataItems, album.Id, album.GalleryObjectType), album.CreatedByUserName, album.LastModifiedByUserName, album.DateLastModified, album.IsPrivate, album.DirectoryName, album.ThumbnailMediaObjectId, album.SortByMetaName, album.SortAscending, album.OwnerUserName, album.OwnerRoleName, childAlbumIds, childMediaObjectIds)); }