public EntryForPictureDisplayContract GetCoverPictureThumb(int albumId) { var size = ImageSize.Thumb; // TODO: this all should be moved to DynamicImageUrlFactory return(repository.HandleQuery(ctx => { var album = ctx.Load(albumId); // If there is no picture, return empty. if (album.CoverPictureData == null || string.IsNullOrEmpty(album.CoverPictureMime)) { return EntryForPictureDisplayContract.Create(album, PermissionContext.LanguagePreference); } // Try to read thumbnail from file system. var data = album.Thumb; if (imagePersister.HasImage(data, size)) { var bytes = imagePersister.ReadBytes(data, size); return EntryForPictureDisplayContract.Create(album, data.Mime, bytes, PermissionContext.LanguagePreference); } // This should return the original image. return EntryForPictureDisplayContract.Create(album, PermissionContext.LanguagePreference); })); }
public EntryForPictureDisplayContract GetCoverPictureThumb(int albumId) { var size = new Size(ImageHelper.DefaultThumbSize, ImageHelper.DefaultThumbSize); return(repository.HandleQuery(ctx => { var album = ctx.Load(albumId); if (album.CoverPictureData == null || string.IsNullOrEmpty(album.CoverPictureMime) || album.CoverPictureData.HasThumb(size)) { return EntryForPictureDisplayContract.Create(album, PermissionContext.LanguagePreference, size); } var data = new EntryThumb(album, album.CoverPictureMime); if (imagePersister.HasImage(data, ImageSize.Thumb)) { using (var stream = imagePersister.GetReadStream(data, ImageSize.Thumb)) { var bytes = StreamHelper.ReadStream(stream); return EntryForPictureDisplayContract.Create(album, data.Mime, bytes, PermissionContext.LanguagePreference); } } return EntryForPictureDisplayContract.Create(album, PermissionContext.LanguagePreference, size); })); }
protected ActionResult Picture(EntryForPictureDisplayContract contract) { ParamIs.NotNull(() => contract); Response.Cache.SetETag(string.Format("{0}{1}v{2}", contract.EntryType, contract.EntryId, contract.Version)); return(Picture(contract.Picture, contract.Name)); }
protected ActionResult Picture(EntryForPictureDisplayContract contract) { ParamIs.NotNull(() => contract); // Allow images to be cached by public proxies, images shouldn't contain anything sensitive so this should be ok. Response.Cache.SetCacheability(HttpCacheability.Public); Response.Cache.SetETag(string.Format("{0}{1}v{2}", contract.EntryType, contract.EntryId, contract.Version)); // Cached version indicated by the "v" request parameter. // If no version is specified, assume no caching. if (contract.Version > 0 && !string.IsNullOrEmpty(Request.Params["v"])) { Response.Cache.SetMaxAge(pictureCacheDuration); } return(Picture(contract.Picture, contract.Name)); }
public EntryForPictureDisplayContract GetPictureThumb(int artistId) { var size = ImageSize.Thumb; return(repository.HandleQuery(ctx => { var artist = ctx.Load(artistId); if (artist.Picture == null || string.IsNullOrEmpty(artist.PictureMime)) { return EntryForPictureDisplayContract.Create(artist, PermissionContext.LanguagePreference); } var data = artist.Thumb; if (imagePersister.HasImage(data, size)) { var bytes = imagePersister.ReadBytes(data, size); return EntryForPictureDisplayContract.Create(artist, data.Mime, bytes, PermissionContext.LanguagePreference); } return EntryForPictureDisplayContract.Create(artist, PermissionContext.LanguagePreference); })); }
protected ActionResult Picture(EntryForPictureDisplayContract contract) { ParamIs.NotNull(() => contract); var cacheControl = new CacheControlHeaderValue { // Allow images to be cached by public proxies, images shouldn't contain anything sensitive so this should be ok. Public = true, }; Response.Headers[HeaderNames.ETag] = $"{contract.EntryType}{contract.EntryId}v{contract.Version}"; // Cached version indicated by the "v" request parameter. // If no version is specified, assume no caching. if (contract.Version > 0 && !string.IsNullOrEmpty(Request.Query["v"])) { cacheControl.MaxAge = PictureCacheDuration; } Response.GetTypedHeaders().CacheControl = cacheControl; return(Picture(contract.Picture, contract.Name)); }
/// <summary> /// Gets the picture for a <see cref="Artist"/>. /// </summary> /// <param name="id">Artist Id.</param> /// <param name="requestedSize">Requested size. If Empty, original size will be returned.</param> /// <returns>Data contract for the picture. Can be null if there is no picture.</returns> public EntryForPictureDisplayContract GetArtistPicture(int id, Size requestedSize) { return(HandleQuery(session => EntryForPictureDisplayContract.Create(session.Load <Artist>(id), PermissionContext.LanguagePreference, requestedSize))); }
public EntryForPictureDisplayContract GetArchivedArtistPicture(int archivedVersionId) { return(HandleQuery(session => EntryForPictureDisplayContract.Create( session.Load <ArchivedArtistVersion>(archivedVersionId), LanguagePreference))); }
public EntryForPictureDisplayContract GetArchivedAlbumPicture(int archivedVersionId) { return(HandleQuery(session => EntryForPictureDisplayContract.Create( session.Load <ArchivedAlbumVersion>(archivedVersionId), PermissionContext.LanguagePreference))); }
public EntryForPictureDisplayContract GetCoverPicture(int id) { return(HandleQuery(session => EntryForPictureDisplayContract.Create(session.Load <Album>(id), PermissionContext.LanguagePreference))); }