示例#1
0
        public AlbumDetailsContract(Album album, ContentLanguagePreference languagePreference, IUserPermissionContext userContext, IEntryThumbPersister thumbPersister,
                                    IEntryImagePersister imageStoreOld, Func <Song, SongVoteRating?> getSongRating = null)
            : base(album, languagePreference)
        {
            ArtistLinks = album.Artists.Select(a => new ArtistForAlbumContract(a, languagePreference)).OrderBy(a => a.Name).ToArray();
            CanEditPersonalDescription = EntryPermissionManager.CanEditPersonalDescription(userContext, album);
            CanRemoveTagUsages         = EntryPermissionManager.CanRemoveTagUsages(userContext, album);
            Description     = album.Description;
            Discs           = album.Songs.Any(s => s.DiscNumber > 1) ? album.Discs.Select(d => new AlbumDiscPropertiesContract(d)).ToDictionary(a => a.DiscNumber) : new Dictionary <int, AlbumDiscPropertiesContract>(0);
            OriginalRelease = (album.OriginalRelease != null ? new AlbumReleaseContract(album.OriginalRelease, languagePreference) : null);
            Pictures        = album.Pictures.Select(p => new EntryPictureFileContract(p, imageStoreOld)).ToArray();
            PVs             = album.PVs.Select(p => new PVContract(p)).ToArray();
            Songs           = album.Songs
                              .OrderBy(s => s.DiscNumber).ThenBy(s => s.TrackNumber)
                              .Select(s => new SongInAlbumContract(s, languagePreference, false, rating: getSongRating?.Invoke(s.Song)))
                              .ToArray();
            Tags     = album.Tags.ActiveUsages.Select(u => new TagUsageForApiContract(u, languagePreference)).OrderByDescending(t => t.Count).ToArray();
            WebLinks = album.WebLinks.Select(w => new WebLinkContract(w)).OrderBy(w => w.DescriptionOrUrl).ToArray();

            PersonalDescriptionText = album.PersonalDescriptionText;
            var author = album.PersonalDescriptionAuthor;

            PersonalDescriptionAuthor = author != null ? new ArtistForApiContract(author, languagePreference, thumbPersister, true, ArtistOptionalFields.MainPicture) : null;

            TotalLength = Songs.All(s => s.Song != null && s.Song.LengthSeconds > 0) ? TimeSpan.FromSeconds(Songs.Sum(s => s.Song.LengthSeconds)) : TimeSpan.Zero;
        }
示例#2
0
        /// <summary>
        /// Initializes image data.
        /// </summary>
        /// <param name="image">Image information. Cannot be null.</param>
        /// <param name="thumbPersister">Thumb persister. Cannot be null.</param>
        /// <param name="ssl">Whether to generate SSL URLs.</param>
        /// <param name="sizes">Sizes to generate. If Nothing, no image URLs will be generated.</param>
        public EntryThumbForApiContract(IEntryImageInformation image, IEntryImagePersister thumbPersister, bool ssl,
                                        ImageSizes sizes = ImageSizes.All)
        {
            ParamIs.NotNull(() => image);
            ParamIs.NotNull(() => thumbPersister);

            if (string.IsNullOrEmpty(image.Mime) && sizes != ImageSizes.Nothing)
            {
                return;
            }

            if (sizes.HasFlag(ImageSizes.SmallThumb))
            {
                UrlSmallThumb = thumbPersister.GetUrlAbsolute(image, ImageSize.SmallThumb, ssl);
            }

            if (sizes.HasFlag(ImageSizes.Thumb))
            {
                UrlThumb = thumbPersister.GetUrlAbsolute(image, ImageSize.Thumb, ssl);
            }

            if (sizes.HasFlag(ImageSizes.TinyThumb))
            {
                UrlTinyThumb = thumbPersister.GetUrlAbsolute(image, ImageSize.TinyThumb, ssl);
            }
        }
		public ImageThumbGenerator(IEntryImagePersister persister) {
			
			ParamIs.NotNull(() => persister);

			this.persister = persister;

		}
示例#4
0
 public static byte[] ReadBytes(this IEntryImagePersister persister, IEntryImageInformation imageInfo, ImageSize size)
 {
     using (var stream = persister.GetReadStream(imageInfo, size))
     {
         return(StreamHelper.ReadStream(stream));
     }
 }
示例#5
0
        public static string GetUrlAbsolute(this IEntryImagePersister persister, IEntryImageInformation picture, ImageSize size, bool checkExists)
        {
            if (checkExists && !persister.HasImage(picture, size))
            {
                return(null);
            }

            return(persister.GetUrlAbsolute(picture, size));
        }
示例#6
0
 public EntryThumbForApiContract(IEntryImageInformation image, IEntryImagePersister thumbPersister, bool ssl)
 {
     if (!string.IsNullOrEmpty(image.Mime))
     {
         UrlSmallThumb = thumbPersister.GetUrlAbsolute(image, ImageSize.SmallThumb, ssl);
         UrlThumb      = thumbPersister.GetUrlAbsolute(image, ImageSize.Thumb, ssl);
         UrlTinyThumb  = thumbPersister.GetUrlAbsolute(image, ImageSize.TinyThumb, ssl);
     }
 }
		public EntryThumbForApiContract(IEntryImageInformation image, IEntryImagePersister thumbPersister, bool ssl) {

			if (!string.IsNullOrEmpty(image.Mime)) {
				UrlSmallThumb = thumbPersister.GetUrlAbsolute(image, ImageSize.SmallThumb, ssl);
				UrlThumb = thumbPersister.GetUrlAbsolute(image, ImageSize.Thumb, ssl);
				UrlTinyThumb = thumbPersister.GetUrlAbsolute(image, ImageSize.TinyThumb, ssl);				
			}

		}
示例#8
0
        public static EntryThumbForApiContract Create(IEntryImageInformation image, IEntryImagePersister thumbPersister, bool ssl,
                                                      ImageSizes sizes = ImageSizes.All)
        {
            if (thumbPersister == null || string.IsNullOrEmpty(image?.Mime))
            {
                return(null);
            }

            return(new EntryThumbForApiContract(image, thumbPersister, ssl, sizes));
        }
示例#9
0
        public EntryPictureFileContract(EntryPictureFile picture, IEntryImagePersister imageStore)
        {
            ParamIs.NotNull(() => picture);

            EntryType    = picture.EntryType;
            Id           = picture.Id;
            Mime         = picture.Mime;
            Name         = picture.Name;
            OwnerEntryId = picture.OwnerEntryId;
            ThumbUrl     = imageStore.GetUrlAbsolute(picture, ImageSize.Thumb, true);
        }
示例#10
0
        public SongListForApiContract(SongList list, IUserIconFactory userIconFactory, IEntryImagePersister imagePersister,
                                      bool ssl, SongListOptionalFields fields) : base(list)
        {
            ParamIs.NotNull(() => list);

            Author    = new UserForApiContract(list.Author, userIconFactory, UserOptionalFields.None);
            EventDate = list.EventDate;

            if (fields.HasFlag(SongListOptionalFields.MainPicture))
            {
                MainPicture = (list.Thumb != null ? new EntryThumbForApiContract(list.Thumb, imagePersister, ssl) : null);
            }
        }
示例#11
0
        public ImageThumbGenerator(IEntryImagePersister persister)
        {
            ParamIs.NotNull(() => persister);

            _persister = persister;
        }
示例#12
0
 public AlbumForEditContract(Album album, ContentLanguagePreference languagePreference, IEntryImagePersister imageStore)
     : base(album, languagePreference)
 {
     ArtistLinks         = album.Artists.Select(a => new ArtistForAlbumContract(a, languagePreference)).OrderBy(a => a.Name).ToArray();
     DefaultNameLanguage = album.TranslatedName.DefaultLanguage;
     Description         = new EnglishTranslatedStringContract(album.Description);
     Discs           = album.Discs.Select(d => new AlbumDiscPropertiesContract(d)).ToArray();
     Identifiers     = album.Identifiers.Select(i => i.Value).ToArray();
     Names           = album.Names.Select(n => new LocalizedStringWithIdContract(n)).ToArray();
     OriginalRelease = (album.OriginalRelease != null ? new AlbumReleaseContract(album.OriginalRelease, languagePreference) : null);
     Pictures        = album.Pictures.Select(p => new EntryPictureFileContract(p, imageStore)).ToList();
     PVs             = album.PVs.Select(p => new PVContract(p)).ToArray();
     Songs           = album.Songs
                       .OrderBy(s => s.DiscNumber).ThenBy(s => s.TrackNumber)
                       .Select(s => new SongInAlbumEditContract(s, languagePreference)).ToArray();
     UpdateNotes = string.Empty;
     WebLinks    = album.WebLinks.Select(w => new WebLinkContract(w)).OrderBy(w => w.DescriptionOrUrl).ToArray();
 }
示例#13
0
        public ArtistDetailsContract(Artist artist, ContentLanguagePreference languagePreference, IUserPermissionContext userContext, IEntryImagePersister imageStore)
            : base(artist, languagePreference)
        {
            AllNames           = string.Join(", ", artist.AllNames.Where(n => n != Name));
            BaseVoicebank      = artist.BaseVoicebank != null ? new ArtistContract(artist.BaseVoicebank, languagePreference) : null;
            CanRemoveTagUsages = EntryPermissionManager.CanRemoveTagUsages(userContext, artist);
            CreateDate         = artist.CreateDate;
            Description        = artist.Description;
            Draft          = artist.Status == EntryStatus.Draft;
            TranslatedName = new TranslatedStringContract(artist.TranslatedName);
            LatestAlbums   = new AlbumForApiContract[] {};
            LatestSongs    = new SongForApiContract[] {};
            OwnerUsers     = artist.OwnerUsers.Select(u => new UserContract(u.User)).ToArray();
            Pictures       = artist.Pictures.Select(p => new EntryPictureFileContract(p, imageStore)).ToArray();
            TopAlbums      = new AlbumForApiContract[] {};
            TopSongs       = new SongForApiContract[] {};
            WebLinks       = artist.WebLinks.Select(w => new WebLinkContract(w)).OrderBy(w => w.DescriptionOrUrl).ToArray();

            CharacterDesigner = artist.ArtistLinksOfType(ArtistLinkType.CharacterDesigner, LinkDirection.ManyToOne, allowInheritance: true)
                                .Select(g => new ArtistContract(g, languagePreference)).FirstOrDefault();

            CharacterDesignerOf = artist.ArtistLinksOfType(ArtistLinkType.CharacterDesigner, LinkDirection.OneToMany)
                                  .Select(g => new ArtistContract(g, languagePreference)).OrderBy(a => a.Name).ToArray();

            if (artist.CanHaveChildVoicebanks)
            {
                var children = artist.ChildVoicebanks
                               .Where(c => !c.Deleted)
                               .Select(c => new ArtistContract(c, languagePreference))
                               .ToArray();

                // Show child voicebanks with release date first
                ChildVoicebanks = children
                                  .Where(c => c.ReleaseDate.HasValue)
                                  .OrderBy(c => c.ReleaseDate)
                                  .Concat(children.Where(c => !c.ReleaseDate.HasValue))
                                  .ToArray();
            }
            else
            {
                ChildVoicebanks = new ArtistContract[0];
            }

            Groups = artist.ArtistLinksOfType(ArtistLinkType.Group, LinkDirection.ManyToOne)
                     .Select(g => new ArtistContract(g, languagePreference)).OrderBy(g => g.Name).ToArray();

            Illustrators = artist.ArtistLinksOfType(ArtistLinkType.Illustrator, LinkDirection.ManyToOne, allowInheritance: true)
                           .Select(g => new ArtistContract(g, languagePreference)).ToArray();

            IllustratorOf = artist.ArtistLinksOfType(ArtistLinkType.Illustrator, LinkDirection.OneToMany)
                            .Select(g => new ArtistContract(g, languagePreference)).OrderBy(a => a.Name).ToArray();

            Manager = artist.ArtistLinksOfType(ArtistLinkType.Manager, LinkDirection.ManyToOne, allowInheritance: true)
                      .Select(g => new ArtistContract(g, languagePreference)).FirstOrDefault();

            Members = artist.ArtistLinksOfType(ArtistLinkType.Group, LinkDirection.OneToMany)
                      .Select(g => new ArtistContract(g, languagePreference)).OrderBy(g => g.Name).ToArray();

            Tags = artist.Tags.ActiveUsages
                   .Select(u => new TagUsageForApiContract(u, languagePreference))
                   .OrderByDescending(t => t.Count).ToArray();

            VoiceProviders = artist.ArtistLinksOfType(ArtistLinkType.VoiceProvider, LinkDirection.ManyToOne, allowInheritance: true)
                             .Select(g => new ArtistContract(g, languagePreference)).OrderBy(a => a.Name).ToArray();

            Voicebanks = artist.ArtistLinksOfType(ArtistLinkType.VoiceProvider, LinkDirection.OneToMany)
                         .Select(g => new ArtistContract(g, languagePreference)).OrderBy(a => a.Name).ToArray();
        }
示例#14
0
        public ArtistForEditContract(Artist artist, ContentLanguagePreference languagePreference, IEntryImagePersister imageStore)
            : base(artist, languagePreference)
        {
            BaseVoicebank       = artist.BaseVoicebank != null ? new ArtistContract(artist.BaseVoicebank, languagePreference) : null;
            DefaultNameLanguage = artist.TranslatedName.DefaultLanguage;
            Description         = new EnglishTranslatedStringContract(artist.Description);
            Groups        = artist.Groups.Where(g => g.LinkType == ArtistLinkType.Group).Select(g => new ArtistForArtistContract(g, languagePreference)).OrderBy(g => g.Parent.Name).ToArray();
            Illustrator   = artist.ArtistLinksOfType(ArtistLinkType.Illustrator, Domain.LinkDirection.ManyToOne).Select(g => new ArtistContract(g, languagePreference)).FirstOrDefault();
            Names         = artist.Names.Select(n => new LocalizedStringWithIdContract(n)).ToArray();
            Pictures      = artist.Pictures.Select(p => new EntryPictureFileContract(p, imageStore)).ToList();
            UpdateNotes   = string.Empty;
            VoiceProvider = artist.ArtistLinksOfType(ArtistLinkType.VoiceProvider, Domain.LinkDirection.ManyToOne).Select(g => new ArtistContract(g, languagePreference)).FirstOrDefault();
            WebLinks      = artist.WebLinks.Select(w => new WebLinkContract(w)).OrderBy(w => w.DescriptionOrUrl).ToArray();

            AssociatedArtists = artist.Groups
                                .Where(a => a.LinkType != ArtistLinkType.Group &&
                                       (a.Parent.Id != Illustrator?.Id || a.LinkType != ArtistLinkType.Illustrator) &&
                                       (a.Parent.Id != VoiceProvider?.Id || a.LinkType != ArtistLinkType.VoiceProvider))
                                .Select(g => new ArtistForArtistContract(g, languagePreference))
                                .ToArray();
        }