public EntryForApiContract(Album album, ContentLanguagePreference languagePreference, IEntryThumbPersister thumbPersister, bool ssl, EntryOptionalFields includedFields) : this(album, languagePreference, includedFields) { ActivityDate = album.OriginalReleaseDate.IsFullDate ? (DateTime?)album.OriginalReleaseDate.ToDateTime() : null; ArtistString = album.ArtistString[languagePreference]; CreateDate = album.CreateDate; DiscType = album.DiscType; Status = album.Status; if (includedFields.HasFlag(EntryOptionalFields.MainPicture) && album.CoverPictureData != null) { MainPicture = new EntryThumbForApiContract(new EntryThumb(album, album.CoverPictureMime), thumbPersister, ssl); } if (includedFields.HasFlag(EntryOptionalFields.Names)) { Names = album.Names.Select(n => new LocalizedStringContract(n)).ToArray(); } if (includedFields.HasFlag(EntryOptionalFields.PVs)) { PVs = album.PVs.Select(p => new PVContract(p)).ToArray(); } if (includedFields.HasFlag(EntryOptionalFields.Tags)) { Tags = album.Tags.ActiveUsages.Select(u => new TagUsageForApiContract(u, languagePreference)).ToArray(); } if (includedFields.HasFlag(EntryOptionalFields.WebLinks)) { WebLinks = album.WebLinks.Select(w => new ArchivedWebLinkContract(w)).ToArray(); } }
public EntryForApiContract(Artist artist, ContentLanguagePreference languagePreference, IEntryThumbPersister thumbPersister, bool ssl, EntryOptionalFields includedFields) : this(artist, languagePreference, includedFields) { ArtistType = artist.ArtistType; CreateDate = artist.CreateDate; Status = artist.Status; if (includedFields.HasFlag(EntryOptionalFields.MainPicture) && artist.Picture != null) { MainPicture = new EntryThumbForApiContract(new EntryThumb(artist, artist.PictureMime), thumbPersister, ssl); } if (includedFields.HasFlag(EntryOptionalFields.Names)) { Names = artist.Names.Select(n => new LocalizedStringContract(n)).ToArray(); } if (includedFields.HasFlag(EntryOptionalFields.Tags)) { Tags = artist.Tags.ActiveUsages.Select(u => new TagUsageForApiContract(u, languagePreference)).ToArray(); } if (includedFields.HasFlag(EntryOptionalFields.WebLinks)) { WebLinks = artist.WebLinks.Select(w => new ArchivedWebLinkContract(w)).ToArray(); } }
public EntryThumbForApiContract GetIcons(IUserWithEmail user, ImageSizes sizes = ImageSizes.All) { var contract = new EntryThumbForApiContract(); if (string.IsNullOrEmpty(user.Email)) { return(contract); } if (sizes.HasFlag(ImageSizes.Thumb)) { contract.UrlThumb = GetUrl(user, ImageHelper.UserThumbSize); } if (sizes.HasFlag(ImageSizes.SmallThumb)) { contract.UrlSmallThumb = GetUrl(user, ImageHelper.UserSmallThumbSize); } if (sizes.HasFlag(ImageSizes.TinyThumb)) { contract.UrlTinyThumb = GetUrl(user, ImageHelper.UserTinyThumbSize); } return(contract); }
public AlbumForApiContract( Album album, AlbumMergeRecord mergeRecord, ContentLanguagePreference languagePreference, IEntryThumbPersister thumbPersister, bool ssl, AlbumOptionalFields fields) : this(album, mergeRecord, languagePreference, fields.HasFlag(AlbumOptionalFields.Artists), fields.HasFlag(AlbumOptionalFields.Names), fields.HasFlag(AlbumOptionalFields.PVs), fields.HasFlag(AlbumOptionalFields.Tags), fields.HasFlag(AlbumOptionalFields.WebLinks)) { if (languagePreference != ContentLanguagePreference.Default || fields.HasFlag(AlbumOptionalFields.AdditionalNames)) { AdditionalNames = album.Names.GetAdditionalNamesStringForLanguage(languagePreference); } if (fields.HasFlag(AlbumOptionalFields.Identifiers)) { Identifiers = album.Identifiers.Select(i => new AlbumIdentifierContract(i)).ToArray(); } if (thumbPersister != null && fields.HasFlag(AlbumOptionalFields.MainPicture) && !string.IsNullOrEmpty(album.CoverPictureMime)) { MainPicture = new EntryThumbForApiContract(new EntryThumb(album, album.CoverPictureMime), thumbPersister, ssl); } }
public EntryForApiContract(Song song, ContentLanguagePreference languagePreference, EntryOptionalFields includedFields) : this((IEntryWithNames)song, languagePreference) { ArtistString = song.ArtistString[languagePreference]; CreateDate = song.CreateDate; SongType = song.SongType; Status = song.Status; var thumb = VideoServiceHelper.GetThumbUrl(song.PVs.PVs); if (includedFields.HasFlag(EntryOptionalFields.MainPicture) && !string.IsNullOrEmpty(thumb)) { MainPicture = new EntryThumbForApiContract { UrlSmallThumb = thumb, UrlThumb = thumb, UrlTinyThumb = thumb }; } if (includedFields.HasFlag(EntryOptionalFields.Names)) { Names = song.Names.Select(n => new LocalizedStringContract(n)).ToArray(); } if (includedFields.HasFlag(EntryOptionalFields.Tags)) { Tags = song.Tags.Usages.Select(u => new TagUsageForApiContract(u)).ToArray(); } if (includedFields.HasFlag(EntryOptionalFields.WebLinks)) { WebLinks = song.WebLinks.Select(w => new ArchivedWebLinkContract(w)).ToArray(); } }
public AlbumForApiContract(TranslatedAlbumContract album, ContentLanguagePreference languagePreference, IEntryThumbPersister thumbPersister, AlbumOptionalFields fields) { ParamIs.NotNull(() => album); ArtistString = album.TranslatedArtistString.GetBestMatch(languagePreference); CreateDate = album.CreateDate; Deleted = album.Deleted; DiscType = album.DiscType; Id = album.Id; Name = album.Names.SortNames[languagePreference]; RatingAverage = album.RatingAverage; RatingCount = album.RatingCount; ReleaseDate = album.ReleaseDate; Status = album.Status; Version = album.Version; if (fields.HasFlag(AlbumOptionalFields.AdditionalNames)) { AdditionalNames = album.Names.GetAdditionalNamesStringForLanguage(languagePreference); } if (fields.HasFlag(AlbumOptionalFields.MainPicture)) { MainPicture = new EntryThumbForApiContract(new EntryThumb(album, album.CoverPictureMime), thumbPersister); } if (fields.HasFlag(AlbumOptionalFields.ReleaseEvent)) { ReleaseEvent = album.ReleaseEvent; } }
public TagForApiContract(Tag tag, IEntryImagePersisterOld thumbPersister, ContentLanguagePreference languagePreference, TagOptionalFields optionalFields) { ParamIs.NotNull(() => tag); CategoryName = tag.CategoryName; CreateDate = tag.CreateDate; DefaultNameLanguage = tag.TranslatedName.DefaultLanguage; Id = tag.Id; Name = tag.TranslatedName[languagePreference]; Status = tag.Status; Targets = (int)tag.Targets; UrlSlug = tag.UrlSlug; UsageCount = tag.UsageCount; Version = tag.Version; var includeAdditionalNames = optionalFields.HasFlag(TagOptionalFields.AdditionalNames); if (includeAdditionalNames) { AdditionalNames = tag.Names.GetAdditionalNamesStringForLanguage(languagePreference); } if (optionalFields.HasFlag(TagOptionalFields.Description)) { Description = tag.Description[languagePreference]; } if (optionalFields.HasFlag(TagOptionalFields.MainPicture) && tag.Thumb != null && thumbPersister != null) { MainPicture = new EntryThumbForApiContract(tag.Thumb, thumbPersister); } if (optionalFields.HasFlag(TagOptionalFields.Names)) { Names = tag.Names.Select(n => new LocalizedStringWithIdContract(n)).ToArray(); } if (optionalFields.HasFlag(TagOptionalFields.Parent) && tag.Parent != null) { Parent = new TagBaseContract(tag.Parent, languagePreference, includeAdditionalNames); } if (optionalFields.HasFlag(TagOptionalFields.RelatedTags)) { RelatedTags = tag.RelatedTags.Select(t => new TagBaseContract(t.LinkedTag, languagePreference, includeAdditionalNames)).ToArray(); } if (optionalFields.HasFlag(TagOptionalFields.TranslatedDescription)) { TranslatedDescription = new EnglishTranslatedStringContract(tag.Description); } if (optionalFields.HasFlag(TagOptionalFields.WebLinks)) { WebLinks = tag.WebLinks.Links.Select(w => new WebLinkForApiContract(w)).ToArray(); } }
public EntryForApiContract(Album album, ContentLanguagePreference languagePreference, IEntryThumbPersister thumbPersister, bool ssl, EntryOptionalFields includedFields) : this(album, languagePreference) { ArtistString = album.ArtistString[languagePreference]; CreateDate = album.CreateDate; DiscType = album.DiscType; Status = album.Status; if (includedFields.HasFlag(EntryOptionalFields.MainPicture) && album.CoverPictureData != null) { MainPicture = new EntryThumbForApiContract(new EntryThumb(album, album.CoverPictureMime), thumbPersister, ssl); } if (includedFields.HasFlag(EntryOptionalFields.Names)) { Names = album.Names.Select(n => new LocalizedStringContract(n)).ToArray(); } if (includedFields.HasFlag(EntryOptionalFields.Tags)) { Tags = album.Tags.Usages.Select(u => new TagUsageForApiContract(u)).ToArray(); } if (includedFields.HasFlag(EntryOptionalFields.WebLinks)) { WebLinks = album.WebLinks.Select(w => new ArchivedWebLinkContract(w)).ToArray(); } }
public ReleaseEventForApiContract(ReleaseEvent rel, ContentLanguagePreference languagePreference, ReleaseEventOptionalFields fields, IEntryThumbPersister thumbPersister) { Category = rel.Category; Date = rel.Date; EndDate = rel.EndDate; Id = rel.Id; Name = rel.TranslatedName[languagePreference]; SeriesNumber = rel.SeriesNumber; SeriesSuffix = rel.SeriesSuffix; Status = rel.Status; UrlSlug = rel.UrlSlug; VenueName = rel.VenueName; Version = rel.Version; if (rel.HasSeries) { SeriesId = rel.Series.Id; } if (fields.HasFlag(ReleaseEventOptionalFields.AdditionalNames)) { AdditionalNames = rel.Names.GetAdditionalNamesStringForLanguage(languagePreference); } if (fields.HasFlag(ReleaseEventOptionalFields.Artists)) { Artists = rel.Artists.Select(a => new ArtistForEventContract(a, languagePreference)).ToArray(); } if (fields.HasFlag(ReleaseEventOptionalFields.Description)) { Description = rel.Description; } if (thumbPersister != null && fields.HasFlag(ReleaseEventOptionalFields.MainPicture)) { MainPicture = EntryThumbForApiContract.Create(EntryThumb.Create(rel) ?? EntryThumb.Create(rel.Series), thumbPersister); } if (fields.HasFlag(ReleaseEventOptionalFields.Names)) { Names = rel.Names.Select(n => new LocalizedStringContract(n)).ToArray(); } if (fields.HasFlag(ReleaseEventOptionalFields.Series) && rel.HasSeries) { Series = new ReleaseEventSeriesContract(rel.Series, languagePreference); } if (fields.HasFlag(ReleaseEventOptionalFields.SongList) && rel.SongList != null) { SongList = new SongListBaseContract(rel.SongList); } if (fields.HasFlag(ReleaseEventOptionalFields.WebLinks)) { WebLinks = rel.WebLinks.Select(w => new WebLinkForApiContract(w)).ToArray(); } }
public ArtistForApiContract(Artist artist, ContentLanguagePreference languagePreference, IEntryThumbPersister thumbPersister, bool ssl, ArtistOptionalFields includedFields) { ArtistType = artist.ArtistType; BaseVoicebank = artist.BaseVoicebank != null ? new ArtistContract(artist.BaseVoicebank, languagePreference) : null; CreateDate = artist.CreateDate; DefaultName = artist.DefaultName; DefaultNameLanguage = artist.Names.SortNames.DefaultLanguage; Id = artist.Id; Name = artist.Names.SortNames[languagePreference]; PictureMime = artist.PictureMime; Status = artist.Status; Version = artist.Version; if (includedFields.HasFlag(ArtistOptionalFields.AdditionalNames)) { AdditionalNames = artist.Names.GetAdditionalNamesStringForLanguage(languagePreference); } if (includedFields.HasFlag(ArtistOptionalFields.ArtistLinks)) { ArtistLinks = artist.Groups.Select(g => new ArtistForArtistForApiContract(g, LinkDirection.ManyToOne, languagePreference)).ToArray(); } if (includedFields.HasFlag(ArtistOptionalFields.ArtistLinksReverse)) { ArtistLinksReverse = artist.Members.Select(m => new ArtistForArtistForApiContract(m, LinkDirection.OneToMany, languagePreference)).ToArray(); } if (includedFields.HasFlag(ArtistOptionalFields.Description)) { Description = artist.Description[languagePreference]; } if (includedFields.HasFlag(ArtistOptionalFields.Names)) { Names = artist.Names.Select(n => new LocalizedStringContract(n)).ToArray(); } if (includedFields.HasFlag(ArtistOptionalFields.Tags)) { Tags = artist.Tags.ActiveUsages.Select(u => new TagUsageForApiContract(u, languagePreference)).ToArray(); } if (thumbPersister != null && includedFields.HasFlag(ArtistOptionalFields.MainPicture) && !string.IsNullOrEmpty(artist.PictureMime)) { MainPicture = new EntryThumbForApiContract(new EntryThumb(artist, artist.PictureMime), thumbPersister, ssl); } if (includedFields.HasFlag(ArtistOptionalFields.WebLinks)) { WebLinks = artist.WebLinks.Select(w => new WebLinkForApiContract(w)).ToArray(); } }
public EntryForApiContract(Tag tag, IEntryImagePersisterOld thumbPersister, bool ssl, EntryOptionalFields includedFields) : this(tag, ContentLanguagePreference.Default) { if (includedFields.HasFlag(EntryOptionalFields.MainPicture) && tag.Thumb != null) { MainPicture = new EntryThumbForApiContract(tag.Thumb, thumbPersister, ssl); } }
public EntryForApiContract(ReleaseEvent releaseEvent, IEntryThumbPersister thumbPersister, bool ssl, EntryOptionalFields includedFields) : this(releaseEvent, ContentLanguagePreference.Default, includedFields) { ActivityDate = releaseEvent.Date.DateTime; ReleaseEventSeriesName = releaseEvent.Series != null ? releaseEvent.Series.Name : null; if (includedFields.HasFlag(EntryOptionalFields.MainPicture) && releaseEvent.Series != null && !string.IsNullOrEmpty(releaseEvent.Series.PictureMime)) { MainPicture = new EntryThumbForApiContract(new EntryThumb(releaseEvent.Series, releaseEvent.Series.PictureMime), thumbPersister, ssl); } }
public EntryForApiContract(SongList songList, IEntryImagePersisterOld thumbPersister, bool ssl, EntryOptionalFields includedFields) : this(songList, ContentLanguagePreference.Default, includedFields) { ActivityDate = songList.EventDate; CreateDate = songList.CreateDate; SongListFeaturedCategory = songList.FeaturedCategory; if (includedFields.HasFlag(EntryOptionalFields.MainPicture) && songList.Thumb != null) { MainPicture = new EntryThumbForApiContract(songList.Thumb, thumbPersister, ssl, SongList.ImageSizes); } }
public ArtistForApiContract(Artist artist, ContentLanguagePreference languagePreference, IEntryThumbPersister thumbPersister, bool ssl, ArtistOptionalFields includedFields) { ArtistType = artist.ArtistType; BaseVoicebank = artist.BaseVoicebank != null ? new ArtistContract(artist.BaseVoicebank, languagePreference) : null; CreateDate = artist.CreateDate; DefaultName = artist.DefaultName; DefaultNameLanguage = artist.Names.SortNames.DefaultLanguage; Id = artist.Id; Name = artist.Names.SortNames[languagePreference]; PictureMime = artist.PictureMime; Status = artist.Status; Version = artist.Version; if (languagePreference != ContentLanguagePreference.Default || includedFields.HasFlag(ArtistOptionalFields.AdditionalNames)) { AdditionalNames = artist.Names.GetAdditionalNamesStringForLanguage(languagePreference); } if (languagePreference != ContentLanguagePreference.Default) { LocalizedName = artist.Names.SortNames[languagePreference]; } if (includedFields.HasFlag(ArtistOptionalFields.Description)) Description = artist.Description; if (includedFields.HasFlag(ArtistOptionalFields.Groups)) Groups = artist.Groups.Select(g => new ArtistContract(g.Group, languagePreference)).ToArray(); if (includedFields.HasFlag(ArtistOptionalFields.Members)) Members = artist.Members.Select(m => new ArtistContract(m.Member, languagePreference)).ToArray(); if (includedFields.HasFlag(ArtistOptionalFields.Names)) Names = artist.Names.Select(n => new LocalizedStringContract(n)).ToArray(); if (includedFields.HasFlag(ArtistOptionalFields.Tags)) Tags = artist.Tags.Usages.Select(u => new TagUsageForApiContract(u)).ToArray(); if (thumbPersister != null && includedFields.HasFlag(ArtistOptionalFields.MainPicture) && !string.IsNullOrEmpty(artist.PictureMime)) { MainPicture = new EntryThumbForApiContract(new EntryThumb(artist, artist.PictureMime), thumbPersister, ssl); } if (includedFields.HasFlag(ArtistOptionalFields.WebLinks)) WebLinks = artist.WebLinks.Select(w => new ArchivedWebLinkContract(w)).ToArray(); }
public EntryForApiContract(Tag tag, ContentLanguagePreference languagePreference, IEntryImagePersisterOld thumbPersister, bool ssl, EntryOptionalFields includedFields) : this(tag, languagePreference, includedFields) { CreateDate = tag.CreateDate; TagCategoryName = tag.CategoryName; if (includedFields.HasFlag(EntryOptionalFields.MainPicture) && tag.Thumb != null) { MainPicture = new EntryThumbForApiContract(tag.Thumb, thumbPersister, ssl, Tag.ImageSizes); } UrlSlug = tag.UrlSlug; }
public UserForApiContract(User user, IUserIconFactory iconFactory, UserOptionalFields optionalFields) : base(user) { Active = user.Active; GroupId = user.GroupId; MemberSince = user.CreateDate; if (optionalFields.HasFlag(UserOptionalFields.MainPicture) && !string.IsNullOrEmpty(user.Email)) { var thumbUrl = iconFactory.GetIconUrl(user); MainPicture = new EntryThumbForApiContract { UrlThumb = thumbUrl, }; } }
public TagForApiContract(Tag tag, IEntryImagePersisterOld thumbPersister, bool ssl, TagOptionalFields optionalFields) { CategoryName = tag.CategoryName; Id = tag.Id; Name = tag.Name; if (optionalFields.HasFlag(TagOptionalFields.Description)) { Description = tag.Description; } if (optionalFields.HasFlag(TagOptionalFields.MainPicture) && tag.Thumb != null) { MainPicture = new EntryThumbForApiContract(tag.Thumb, thumbPersister, ssl); } }
public EntryForApiContract(ReleaseEvent releaseEvent, ContentLanguagePreference languagePreference, IEntryThumbPersister thumbPersister, EntryOptionalFields includedFields) : this(releaseEvent, languagePreference, includedFields) { ActivityDate = releaseEvent.Date.DateTime; EventCategory = releaseEvent.InheritedCategory; ReleaseEventSeriesName = releaseEvent.Series?.TranslatedName[languagePreference]; Status = releaseEvent.Status; UrlSlug = releaseEvent.UrlSlug; if (includedFields.HasFlag(EntryOptionalFields.MainPicture)) { MainPicture = EntryThumbForApiContract.Create(EntryThumb.Create(releaseEvent) ?? EntryThumb.Create(releaseEvent.Series), thumbPersister); } if (includedFields.HasFlag(EntryOptionalFields.WebLinks)) { WebLinks = releaseEvent.WebLinks.Select(w => new ArchivedWebLinkContract(w)).ToArray(); } }
public EntryForApiContract(Tag tag, ContentLanguagePreference languagePreference, IEntryImagePersisterOld thumbPersister, EntryOptionalFields includedFields) : this(tag, languagePreference, includedFields) { CreateDate = tag.CreateDate; Status = tag.Status; TagCategoryName = tag.CategoryName; if (includedFields.HasFlag(EntryOptionalFields.MainPicture) && tag.Thumb != null) { MainPicture = new EntryThumbForApiContract(tag.Thumb, thumbPersister, Tag.ImageSizes); } if (includedFields.HasFlag(EntryOptionalFields.WebLinks)) { WebLinks = tag.WebLinks.Links.Select(w => new ArchivedWebLinkContract(w)).ToArray(); } UrlSlug = tag.UrlSlug; }
public ReleaseEventSeriesForApiContract(ReleaseEventSeries series, ContentLanguagePreference languagePreference, ReleaseEventSeriesOptionalFields fields, IAggregatedEntryImageUrlFactory thumbPersister) { Category = series.Category; Id = series.Id; Name = series.TranslatedName[languagePreference]; Status = series.Status; UrlSlug = series.UrlSlug; Version = series.Version; if (fields.HasFlag(ReleaseEventSeriesOptionalFields.AdditionalNames)) { AdditionalNames = series.Names.GetAdditionalNamesStringForLanguage(languagePreference); } if (fields.HasFlag(ReleaseEventSeriesOptionalFields.Description)) { Description = series.Description; } if (fields.HasFlag(ReleaseEventSeriesOptionalFields.Events)) { Events = series.Events.Select(e => new ReleaseEventForApiContract(e, languagePreference, ReleaseEventOptionalFields.None, thumbPersister)).ToArray(); } if (thumbPersister != null && fields.HasFlag(ReleaseEventSeriesOptionalFields.MainPicture)) { MainPicture = EntryThumbForApiContract.Create(EntryThumb.Create(series), thumbPersister); } if (fields.HasFlag(ReleaseEventSeriesOptionalFields.Names)) { Names = series.Names.Select(n => new LocalizedStringContract(n)).ToArray(); } if (fields.HasFlag(ReleaseEventSeriesOptionalFields.WebLinks)) { WebLinks = series.WebLinks.Select(w => new WebLinkForApiContract(w)).ToArray(); } }
public TagForApiContract(Tag tag, IEntryImagePersisterOld thumbPersister, bool ssl, TagOptionalFields optionalFields) { AlisedToName = tag.AliasedTo != null ? tag.AliasedTo.Name : null; CategoryName = tag.CategoryName; Id = tag.Id; Name = tag.Name; ParentName = tag.Parent != null ? tag.Parent.Name : null; Status = tag.Status; if (optionalFields.HasFlag(TagOptionalFields.Description)) { Description = tag.Description; } if (optionalFields.HasFlag(TagOptionalFields.MainPicture) && tag.Thumb != null) { MainPicture = new EntryThumbForApiContract(tag.Thumb, thumbPersister, ssl); } }
private void SetAlbumCover(EntryThumbForApiContract albumMainPicture, int id) { if (setAlbumCover == null) { setAlbumCover = connection.CreateCommand(); setAlbumCover.CommandText = "UPDATE dump_vocadb.albums SET cover=@cover, scrapedcover = TRUE WHERE id=@id"; setAlbumCover.Parameters.Add("@cover", NpgsqlDbType.Bytea); setAlbumCover.Parameters.Add("@id", NpgsqlDbType.Integer); } try { setAlbumCover.Parameters["@cover"].Value = vocadb.DownloadImage(albumMainPicture.UrlThumb); } catch (Exception) { setAlbumCover.Parameters["@cover"].Value = DBNull.Value; logger.Error("Download failed: " + albumMainPicture.UrlThumb); } setAlbumCover.Parameters["@id"].Value = id; setAlbumCover.ExecuteNonQuery(); }
/// <summary> /// Returns an URL to entry thumbnail image, or placeholder if no image if specified. /// </summary> /// <param name="urlHelper">URL helper. Cannot be null.</param> /// <param name="imageInfo">Image information. Cannot be null.</param> /// <param name="size">Requested image size.</param> /// <returns>URL to the image thumbnail (may be placeholder).</returns> public static string ImageThumb(this UrlHelper urlHelper, EntryThumbForApiContract imageInfo, ImageSize size) { return(imageInfo?.GetSmallestThumb(size).EmptyToNull() ?? GetUnknownImageUrl(urlHelper).Url); }
public AlbumForApiContract( Album album, AlbumMergeRecord mergeRecord, ContentLanguagePreference languagePreference, IAggregatedEntryImageUrlFactory thumbPersister, AlbumOptionalFields fields, SongOptionalFields songFields) { ArtistString = album.ArtistString[languagePreference]; CatalogNumber = album.OriginalRelease != null ? album.OriginalRelease.CatNum : null; CreateDate = album.CreateDate; DefaultName = album.DefaultName; DefaultNameLanguage = album.Names.SortNames.DefaultLanguage; DiscType = album.DiscType; Id = album.Id; Name = album.Names.SortNames[languagePreference]; RatingAverage = album.RatingAverage; RatingCount = album.RatingCount; ReleaseDate = new OptionalDateTimeContract(album.OriginalReleaseDate); Status = album.Status; Version = album.Version; if (fields.HasFlag(AlbumOptionalFields.AdditionalNames)) { AdditionalNames = album.Names.GetAdditionalNamesStringForLanguage(languagePreference); } if (fields.HasFlag(AlbumOptionalFields.Artists)) { Artists = album.Artists.Select(a => new ArtistForAlbumForApiContract(a, languagePreference)).ToArray(); } if (fields.HasFlag(AlbumOptionalFields.Description)) { Description = album.Description[languagePreference]; } if (fields.HasFlag(AlbumOptionalFields.Discs)) { Discs = album.Discs.Select(d => new AlbumDiscPropertiesContract(d)).ToArray(); } if (fields.HasFlag(AlbumOptionalFields.Identifiers)) { Identifiers = album.Identifiers.Select(i => new AlbumIdentifierContract(i)).ToArray(); } if (thumbPersister != null && fields.HasFlag(AlbumOptionalFields.MainPicture) && album.Thumb != null) { MainPicture = new EntryThumbForApiContract(album.Thumb, thumbPersister); } if (fields.HasFlag(AlbumOptionalFields.Names)) { Names = album.Names.Select(n => new LocalizedStringContract(n)).ToArray(); } if (fields.HasFlag(AlbumOptionalFields.PVs)) { PVs = album.PVs.Select(p => new PVContract(p)).ToArray(); } if (fields.HasFlag(AlbumOptionalFields.ReleaseEvent)) { ReleaseEvent = album.OriginalReleaseEvent != null ? new ReleaseEventForApiContract(album.OriginalReleaseEvent, languagePreference, ReleaseEventOptionalFields.None, thumbPersister) : null; } if (fields.HasFlag(AlbumOptionalFields.Tags)) { Tags = album.Tags.ActiveUsages.Select(u => new TagUsageForApiContract(u, languagePreference)).ToArray(); } if (fields.HasFlag(AlbumOptionalFields.Tracks)) { Tracks = album.Songs.Select(s => new SongInAlbumForApiContract(s, languagePreference, songFields)).ToArray(); } if (fields.HasFlag(AlbumOptionalFields.WebLinks)) { WebLinks = album.WebLinks.Select(w => new WebLinkForApiContract(w)).ToArray(); } if (mergeRecord != null) { MergedTo = mergeRecord.Target.Id; } }
public SongForApiContract(Song song, SongMergeRecord mergeRecord, ContentLanguagePreference languagePreference, SongOptionalFields fields) { ArtistString = song.ArtistString[languagePreference]; CreateDate = song.CreateDate; DefaultName = song.DefaultName; DefaultNameLanguage = song.Names.SortNames.DefaultLanguage; FavoritedTimes = song.FavoritedTimes; Id = song.Id; LengthSeconds = song.LengthSeconds; Name = song.Names.SortNames[languagePreference]; PublishDate = song.PublishDate; PVServices = song.PVServices; RatingScore = song.RatingScore; SongType = song.SongType; Status = song.Status; Version = song.Version; if (fields.HasFlag(SongOptionalFields.AdditionalNames)) { AdditionalNames = song.Names.GetAdditionalNamesStringForLanguage(languagePreference); } if (fields.HasFlag(SongOptionalFields.Albums)) { Albums = song.OnAlbums.Select(a => new AlbumContract(a, languagePreference)).ToArray(); } if (fields.HasFlag(SongOptionalFields.Artists)) { Artists = song.Artists.Select(a => new ArtistForSongContract(a, languagePreference)).ToArray(); } if (fields.HasFlag(SongOptionalFields.Lyrics)) { Lyrics = song.Lyrics.Select(l => new LyricsForSongContract(l)).ToArray(); } if (fields.HasFlag(SongOptionalFields.MainPicture)) { var thumb = song.GetThumbUrl(); if (!string.IsNullOrEmpty(thumb)) { MainPicture = new EntryThumbForApiContract { UrlThumb = thumb }; } } if (fields.HasFlag(SongOptionalFields.Names)) { Names = song.Names.Select(n => new LocalizedStringContract(n)).ToArray(); } if (song.HasOriginalVersion) { OriginalVersionId = song.OriginalVersion.Id; } if (fields.HasFlag(SongOptionalFields.PVs)) { PVs = song.PVs.Select(p => new PVContract(p)).ToArray(); } if (fields.HasFlag(SongOptionalFields.ReleaseEvent) && song.ReleaseEvent != null) { ReleaseEvent = new ReleaseEventForApiContract(song.ReleaseEvent, languagePreference, ReleaseEventOptionalFields.None, null, true); } if (fields.HasFlag(SongOptionalFields.Tags)) { Tags = song.Tags.ActiveUsages.Select(u => new TagUsageForApiContract(u, languagePreference)).ToArray(); } if (fields.HasFlag(SongOptionalFields.ThumbUrl)) { ThumbUrl = song.GetThumbUrl(); } if (fields.HasFlag(SongOptionalFields.WebLinks)) { WebLinks = song.WebLinks.Select(w => new WebLinkForApiContract(w)).ToArray(); } if (mergeRecord != null) { MergedTo = mergeRecord.Target.Id; } }
public EntryForApiContract(Song song, ContentLanguagePreference languagePreference, EntryOptionalFields includedFields) : this((IEntryWithNames)song, languagePreference) { ArtistString = song.ArtistString[languagePreference]; CreateDate = song.CreateDate; SongType = song.SongType; Status = song.Status; var thumb = VideoServiceHelper.GetThumbUrl(song.PVs.PVs); if (includedFields.HasFlag(EntryOptionalFields.MainPicture) &&!string.IsNullOrEmpty(thumb)) { MainPicture = new EntryThumbForApiContract { UrlSmallThumb = thumb, UrlThumb = thumb, UrlTinyThumb = thumb }; } if (includedFields.HasFlag(EntryOptionalFields.Names)) { Names = song.Names.Select(n => new LocalizedStringContract(n)).ToArray(); } if (includedFields.HasFlag(EntryOptionalFields.Tags)) { Tags = song.Tags.Usages.Select(u => new TagUsageForApiContract(u)).ToArray(); } if (includedFields.HasFlag(EntryOptionalFields.WebLinks)) { WebLinks = song.WebLinks.Select(w => new ArchivedWebLinkContract(w)).ToArray(); } }