Beispiel #1
0
        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);
            }));
        }
Beispiel #2
0
        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);
            }));
        }
Beispiel #3
0
        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);
            }));
        }
Beispiel #4
0
 /// <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)));
 }
Beispiel #5
0
 public EntryForPictureDisplayContract GetArchivedArtistPicture(int archivedVersionId)
 {
     return(HandleQuery(session =>
                        EntryForPictureDisplayContract.Create(
                            session.Load <ArchivedArtistVersion>(archivedVersionId), LanguagePreference)));
 }
Beispiel #6
0
 public EntryForPictureDisplayContract GetArchivedAlbumPicture(int archivedVersionId)
 {
     return(HandleQuery(session =>
                        EntryForPictureDisplayContract.Create(
                            session.Load <ArchivedAlbumVersion>(archivedVersionId), PermissionContext.LanguagePreference)));
 }
Beispiel #7
0
 public EntryForPictureDisplayContract GetCoverPicture(int id)
 {
     return(HandleQuery(session =>
                        EntryForPictureDisplayContract.Create(session.Load <Album>(id), PermissionContext.LanguagePreference)));
 }