Esempio n. 1
0
		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();				
			}

		}
Esempio n. 2
0
        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();
            }
        }
Esempio n. 3
0
        public static EntryForApiContract Create(IEntryWithNames entry, ContentLanguagePreference languagePreference,
                                                 IEntryThumbPersister thumbPersister, IEntryImagePersisterOld imagePersisterOld, bool ssl,
                                                 EntryOptionalFields includedFields)
        {
            ParamIs.NotNull(() => entry);

            switch (entry.EntryType)
            {
            case EntryType.Album:
                return(new EntryForApiContract((Album)entry, languagePreference, thumbPersister, ssl, includedFields));

            case EntryType.Artist:
                return(new EntryForApiContract((Artist)entry, languagePreference, thumbPersister, ssl, includedFields));

            case EntryType.DiscussionTopic:
                return(new EntryForApiContract((DiscussionTopic)entry, languagePreference));

            case EntryType.ReleaseEvent:
                return(new EntryForApiContract((ReleaseEvent)entry, thumbPersister, ssl, includedFields));

            case EntryType.Song:
                return(new EntryForApiContract((Song)entry, languagePreference, includedFields));

            case EntryType.SongList:
                return(new EntryForApiContract((SongList)entry, imagePersisterOld, ssl, includedFields));

            case EntryType.Tag:
                return(new EntryForApiContract((Tag)entry, languagePreference, imagePersisterOld, ssl, includedFields));
            }

            return(new EntryForApiContract(entry, languagePreference, includedFields));
        }
Esempio n. 4
0
        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();
            }
        }
Esempio n. 5
0
        public static EntryForApiContract Create(IEntryWithNames entry, ContentLanguagePreference languagePreference,
                                                 IEntryThumbPersister thumbPersister, IEntryImagePersisterOld imagePersisterOld, bool ssl,
                                                 EntryOptionalFields includedFields)
        {
            ParamIs.NotNull(() => entry);

            if (entry is Album)
            {
                return(new EntryForApiContract((Album)entry, languagePreference, thumbPersister, ssl, includedFields));
            }
            else if (entry is Artist)
            {
                return(new EntryForApiContract((Artist)entry, languagePreference, thumbPersister, ssl, includedFields));
            }
            else if (entry is DiscussionTopic)
            {
                return(new EntryForApiContract((DiscussionTopic)entry, languagePreference));
            }
            else if (entry is Song)
            {
                return(new EntryForApiContract((Song)entry, languagePreference, includedFields));
            }
            else if (entry is Tag)
            {
                return(new EntryForApiContract((Tag)entry, imagePersisterOld, ssl, includedFields));
            }

            throw new ArgumentException("Unsupported entry type: " + entry, "entry");
        }
Esempio n. 6
0
 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);
     }
 }
Esempio n. 7
0
        public PartialFindResult <ActivityEntryForApiContract> GetList(
            DateTime?before                    = null,
            DateTime?since                     = null,
            int?userId                         = null,
            EntryEditEvent?editEvent           = null,
            int maxResults                     = defaultMax,
            bool getTotalCount                 = false,
            ActivityEntryOptionalFields fields = ActivityEntryOptionalFields.None,
            EntryOptionalFields entryFields    = EntryOptionalFields.None,
            ContentLanguagePreference lang     = ContentLanguagePreference.Default)
        {
            maxResults = Math.Min(maxResults, absoluteMax);
            bool ssl = WebHelper.IsSSL(Request);

            return(repository.HandleQuery(ctx => {
                var query = ctx.Query <ActivityEntry>();

                if (before.HasValue && !since.HasValue)
                {
                    query = query.Where(a => a.CreateDate < before.Value);
                }

                if (!before.HasValue && since.HasValue)
                {
                    query = query.Where(a => a.CreateDate > since.Value);
                }

                if (before.HasValue && since.HasValue)
                {
                    query = query.Where(a => a.CreateDate > since.Value && a.CreateDate < before.Value);
                }

                if (userId.HasValue)
                {
                    query = query.Where(a => a.Author.Id == userId.Value);
                }

                if (editEvent.HasValue)
                {
                    query = query.Where(a => a.EditEvent == editEvent.Value);
                }

                var activityEntries = query
                                      .OrderByDescending(a => a.CreateDate)
                                      .Take(maxResults)
                                      .ToArray()
                                      .Where(a => !a.EntryBase.Deleted)
                                      .Select(a => new ActivityEntryForApiContract(a,
                                                                                   fields.HasFlag(ActivityEntryOptionalFields.Entry) ? entryForApiContractFactory.Create(a.EntryBase, entryFields, lang, ssl) : null,
                                                                                   userIconFactory, permissionContext, fields))
                                      .ToArray();

                var count = getTotalCount ? query.Count() : 0;

                return PartialFindResult.Create(activityEntries, count);
            }));
        }
 public PartialFindResult <ActivityEntryForApiContract> GetList(
     DateTime?before                    = null,
     DateTime?since                     = null,
     int?userId                         = null,
     EntryEditEvent?editEvent           = null,
     int maxResults                     = defaultMax,
     bool getTotalCount                 = false,
     ActivityEntryOptionalFields fields = ActivityEntryOptionalFields.None,
     EntryOptionalFields entryFields    = EntryOptionalFields.None,
     ContentLanguagePreference lang     = ContentLanguagePreference.Default) => queries.GetList(before, since, userId, editEvent, maxResults, getTotalCount, fields, entryFields, lang);
Esempio n. 9
0
 private PartialFindResult <EntryForApiContract> CallGetList(
     string query                   = null,
     int[] tag                      = null,
     EntryStatus?status             = null,
     int start                      = 0, int maxResults = 10, bool getTotalCount = true,
     NameMatchMode nameMatchMode    = NameMatchMode.Words,
     EntryOptionalFields fields     = EntryOptionalFields.None,
     ContentLanguagePreference lang = ContentLanguagePreference.Default)
 {
     return(queries.GetList(query, tag, null, false, status, start, maxResults, getTotalCount, EntrySortRule.Name, nameMatchMode, fields, lang));
 }
Esempio n. 10
0
 public PartialFindResult <CommentForApiContract> GetList(
     DateTime?before                 = null,
     DateTime?since                  = null,
     int?userId                      = null,
     EntryType entryType             = EntryType.Undefined,
     int maxResults                  = CommentQueries.DefaultMax,
     bool getTotalCount              = false,
     CommentOptionalFields fields    = CommentOptionalFields.None,
     EntryOptionalFields entryFields = EntryOptionalFields.None,
     ContentLanguagePreference lang  = ContentLanguagePreference.Default,
     CommentSortRule sortRule        = CommentSortRule.CreateDateDescending
     ) => _queries.GetList(before, since, userId, entryType, maxResults, getTotalCount, fields, entryFields, lang, sortRule);
Esempio n. 11
0
        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);
            }
        }
Esempio n. 12
0
		private PartialFindResult<EntryForApiContract> CallGetList(
			string query = null, 
			string tag = null,
			EntryStatus? status = null,
			int start = 0, int maxResults = 10, bool getTotalCount = true,
			NameMatchMode nameMatchMode = NameMatchMode.Words,
			EntryOptionalFields fields = EntryOptionalFields.None,
			ContentLanguagePreference lang = ContentLanguagePreference.Default,
			bool ssl = false) {
			
			return queries.GetList(query, tag, status, start, maxResults, getTotalCount, nameMatchMode, fields, lang, ssl);

		}
Esempio n. 13
0
        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;
        }
Esempio n. 14
0
        public PartialFindResult<EntryForApiContract> GetList(
            string query,
            string tag = null,
            EntryStatus? status = null,
            int start = 0, int maxResults = defaultMax, bool getTotalCount = false,
            NameMatchMode nameMatchMode = NameMatchMode.Exact,
            EntryOptionalFields fields = EntryOptionalFields.None,
            ContentLanguagePreference lang = ContentLanguagePreference.Default
            )
        {
            var ssl = WebHelper.IsSSL(Request);
            maxResults = GetMaxResults(maxResults);

            return queries.GetList(query, tag, status, start, maxResults, getTotalCount, nameMatchMode, fields, lang, ssl);
        }
Esempio n. 15
0
        public PartialFindResult <EntryForApiContract> GetList(
            string query,
            string tag                     = null,
            EntryStatus?status             = null,
            int start                      = 0, int maxResults = defaultMax, bool getTotalCount = false,
            NameMatchMode nameMatchMode    = NameMatchMode.Exact,
            EntryOptionalFields fields     = EntryOptionalFields.None,
            ContentLanguagePreference lang = ContentLanguagePreference.Default
            )
        {
            var ssl = WebHelper.IsSSL(Request);

            maxResults = GetMaxResults(maxResults);

            return(queries.GetList(query, tag, status, start, maxResults, getTotalCount, nameMatchMode, fields, lang, ssl));
        }
Esempio n. 16
0
        public PartialFindResult <EntryForApiContract> GetList(
            string query = "",
            [FromUri] string[] tagName = null,
            [FromUri] int[] tagId      = null,
            bool childTags             = false,
            EntryStatus?status         = null,
            int start                      = 0, int maxResults = defaultMax, bool getTotalCount = false,
            EntrySortRule sort             = EntrySortRule.Name,
            NameMatchMode nameMatchMode    = NameMatchMode.Exact,
            EntryOptionalFields fields     = EntryOptionalFields.None,
            ContentLanguagePreference lang = ContentLanguagePreference.Default
            )
        {
            maxResults = GetMaxResults(maxResults);

            return(queries.GetList(query, tagId, tagName, childTags, status, start, maxResults, getTotalCount, sort, nameMatchMode, fields, lang, searchEvents: true));
        }
Esempio n. 17
0
        public static EntryForApiContract Create(IEntryWithNames entry, ContentLanguagePreference languagePreference,
                                                 IAggregatedEntryImageUrlFactory thumbPersister,
                                                 EntryOptionalFields includedFields)
        {
            ParamIs.NotNull(() => entry);

            return(entry.EntryType switch
            {
                EntryType.Album => new EntryForApiContract((Album)entry, languagePreference, thumbPersister, includedFields),
                EntryType.Artist => new EntryForApiContract((Artist)entry, languagePreference, thumbPersister, includedFields),
                EntryType.DiscussionTopic => new EntryForApiContract((DiscussionTopic)entry, languagePreference),
                EntryType.ReleaseEvent => new EntryForApiContract((ReleaseEvent)entry, languagePreference, thumbPersister, includedFields),
                EntryType.Song => new EntryForApiContract((Song)entry, languagePreference, includedFields),
                EntryType.SongList => new EntryForApiContract((SongList)entry, thumbPersister, includedFields),
                EntryType.Tag => new EntryForApiContract((Tag)entry, languagePreference, thumbPersister, includedFields),
                _ => new EntryForApiContract(entry, languagePreference, includedFields),
            });
Esempio n. 18
0
        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;
        }
Esempio n. 19
0
        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();
            }
        }
Esempio n. 20
0
        public PartialFindResult <EntryForApiContract> GetList(
            string query,
            int[] tagIds,
            string[] tags,
            bool childTags,
            EntryStatus?status,
            int start, int maxResults, bool getTotalCount,
            EntrySortRule sort,
            NameMatchMode nameMatchMode,
            EntryOptionalFields fields,
            ContentLanguagePreference lang,
            bool ssl,
            bool searchTags = false
            )
        {
            var textQuery       = SearchTextQuery.Create(query, nameMatchMode);
            var artistTextQuery = ArtistSearchTextQuery.Create(query, nameMatchMode);             // Can't use the existing words collection here as they are noncanonized

            return(repository.HandleQuery(ctx => {
                // Get all applicable names per entry type
                var artistQuery = ctx.OfType <Artist>().Query()
                                  .Where(a => !a.Deleted)
                                  .WhereHasName_Canonized(artistTextQuery)
                                  .WhereHasTags(tagIds, childTags)
                                  .WhereHasTags(tags)
                                  .WhereStatusIs(status);

                var artistNames = artistQuery
                                  .OrderBy(sort, lang)
                                  .Take(start + maxResults)
                                  .SelectEntryBase(lang, EntryType.Artist)
                                  .ToArray();

                var albumQuery = ctx.OfType <Album>().Query()
                                 .Where(a => !a.Deleted)
                                 .WhereHasName(textQuery)
                                 .WhereHasTags(tagIds, childTags)
                                 .WhereHasTags(tags)
                                 .WhereStatusIs(status);

                var albumNames = albumQuery
                                 .OrderBy(sort, lang)
                                 .Take(start + maxResults)
                                 .SelectEntryBase(lang, EntryType.Album)
                                 .ToArray();

                var songQuery = ctx.OfType <Song>().Query()
                                .Where(a => !a.Deleted)
                                .WhereHasName(textQuery)
                                .WhereHasTags(tagIds, childTags)
                                .WhereHasTags(tags)
                                .WhereStatusIs(status);

                var songNames = songQuery
                                .OrderBy(sort, lang)
                                .Take(start + maxResults)
                                .SelectEntryBase(lang, EntryType.Song)
                                .ToArray();

                var tagQuery = searchTags ? ctx.OfType <Tag>().Query()
                               .WhereHasName(textQuery)
                               .WhereStatusIs(status) : null;

                var tagNames = searchTags ? tagQuery
                               .OrderBy(sort, lang)
                               .Take(start + maxResults)
                               .SelectEntryBase(lang, EntryType.Tag)
                               .ToArray() : null;

                // Get page of combined names
                var entryNames = artistNames.Concat(albumNames).Concat(songNames).Concat(tagNames ?? new DataContracts.EntryBaseContract[0])
                                 .OrderBy(e => e.DefaultName)
                                 .Skip(start)
                                 .Take(maxResults)
                                 .ToArray();

                var artistIds = entryNames.Where(e => e.EntryType == EntryType.Artist).Select(a => a.Id).ToArray();
                var albumIds = entryNames.Where(e => e.EntryType == EntryType.Album).Select(a => a.Id).ToArray();
                var songIds = entryNames.Where(e => e.EntryType == EntryType.Song).Select(a => a.Id).ToArray();
                var searchedTagIds = searchTags ? entryNames.Where(e => e.EntryType == EntryType.Tag).Select(a => a.Id).ToArray() : new int[0];

                // Get the actual entries in the page
                var artists = artistIds.Any() ? ctx.OfType <Artist>().Query()
                              .Where(a => artistIds.Contains(a.Id))
                              .ToArray()
                              .Select(a => new EntryForApiContract(a, lang, entryThumbPersister, ssl, fields)) : new EntryForApiContract[0];

                var albums = albumIds.Any() ? ctx.OfType <Album>().Query()
                             .Where(a => albumIds.Contains(a.Id))
                             .ToArray()
                             .Select(a => new EntryForApiContract(a, lang, entryThumbPersister, ssl, fields)) : new EntryForApiContract[0];

                var songs = songIds.Any() ? ctx.OfType <Song>().Query()
                            .Where(a => songIds.Contains(a.Id))
                            .ToArray()
                            .Select(a => new EntryForApiContract(a, lang, fields)) : new EntryForApiContract[0];

                var searchedTags = searchTags && searchedTagIds.Any() ? ctx.OfType <Tag>().Query()
                                   .Where(a => searchedTagIds.Contains(a.Id))
                                   .ToArray()
                                   .Select(a => new EntryForApiContract(a, lang, entryImagePersisterOld, ssl, fields)) : new EntryForApiContract[0];

                // Merge and sort the final list
                var entries = artists.Concat(albums).Concat(songs).Concat(searchedTags);

                if (sort == EntrySortRule.Name)
                {
                    entries = entries.OrderBy(a => a.Name);
                }

                if (sort == EntrySortRule.AdditionDate)
                {
                    entries = entries.OrderByDescending(a => a.CreateDate);
                }

                var count = 0;

                if (getTotalCount)
                {
                    var artistCount =
                        (artistNames.Length >= maxResults ? artistQuery.Count() : artistNames.Length);

                    var albumCount =
                        (albumNames.Length >= maxResults ? albumQuery.Count() : albumNames.Length);

                    var songCount =
                        (songNames.Length >= maxResults ? songQuery.Count() : songNames.Length);

                    var tagCount =
                        searchTags ? (tagNames.Length >= maxResults ? tagQuery.Count() : tagNames.Length) : 0;

                    count = artistCount + albumCount + songCount + tagCount;
                }

                return new PartialFindResult <EntryForApiContract>(entries.ToArray(), count);
            }));
        }
Esempio n. 21
0
        public PartialFindResult <EntryForApiContract> GetList(
            string query,
            string tag,
            EntryStatus?status,
            int start, int maxResults, bool getTotalCount,
            NameMatchMode nameMatchMode,
            EntryOptionalFields fields,
            ContentLanguagePreference lang,
            bool ssl
            )
        {
            var textQuery       = SearchTextQuery.Create(query, nameMatchMode);
            var artistTextQuery = ArtistSearchTextQuery.Create(query, textQuery.MatchMode);             // Can't use the existing words collection here as they are noncanonized

            return(repository.HandleQuery(ctx => {
                // Get all applicable names per entry type
                var artistNames = ctx.OfType <Artist>().Query()
                                  .Where(a => !a.Deleted)
                                  .WhereHasName_Canonized(artistTextQuery)
                                  .WhereHasTag(tag)
                                  .WhereStatusIs(status)
                                  .OrderBy(ArtistSortRule.Name, lang)
                                  .Take(start + maxResults)
                                  .SelectEntryBase(lang, EntryType.Artist)
                                  .ToArray();

                var albumNames = ctx.OfType <Album>().Query()
                                 .Where(a => !a.Deleted)
                                 .WhereHasName(textQuery)
                                 .WhereHasTag(tag)
                                 .WhereStatusIs(status)
                                 .OrderBy(AlbumSortRule.Name, lang)
                                 .Take(start + maxResults)
                                 .SelectEntryBase(lang, EntryType.Album)
                                 .ToArray();

                var songNames = ctx.OfType <Song>().Query()
                                .Where(a => !a.Deleted)
                                .WhereHasName(textQuery)
                                .WhereHasTag(tag)
                                .WhereStatusIs(status)
                                .OrderBy(SongSortRule.Name, lang)
                                .Take(start + maxResults)
                                .SelectEntryBase(lang, EntryType.Song)
                                .ToArray();

                // Get page of combined names
                var entryNames = artistNames.Concat(albumNames).Concat(songNames)
                                 .OrderBy(e => e.DefaultName)
                                 .Skip(start)
                                 .Take(maxResults)
                                 .ToArray();

                var artistIds = entryNames.Where(e => e.EntryType == EntryType.Artist).Select(a => a.Id).ToArray();
                var albumIds = entryNames.Where(e => e.EntryType == EntryType.Album).Select(a => a.Id).ToArray();
                var songIds = entryNames.Where(e => e.EntryType == EntryType.Song).Select(a => a.Id).ToArray();

                // Get the actual entries in the page
                var artists = artistIds.Any() ? ctx.OfType <Artist>().Query()
                              .Where(a => artistIds.Contains(a.Id))
                              .ToArray()
                              .Select(a => new EntryForApiContract(a, lang, entryThumbPersister, ssl, fields)) : new EntryForApiContract[0];

                var albums = albumIds.Any() ? ctx.OfType <Album>().Query()
                             .Where(a => albumIds.Contains(a.Id))
                             .ToArray()
                             .Select(a => new EntryForApiContract(a, lang, entryThumbPersister, ssl, fields)) : new EntryForApiContract[0];

                var songs = songIds.Any() ? ctx.OfType <Song>().Query()
                            .Where(a => songIds.Contains(a.Id))
                            .ToArray()
                            .Select(a => new EntryForApiContract(a, lang, fields)) : new EntryForApiContract[0];

                // Merge and sort the final list
                var entries = artists.Concat(albums).Concat(songs)
                              .OrderBy(a => a.Name);

                var count = 0;

                if (getTotalCount)
                {
                    count =
                        ctx.OfType <Artist>().Query()
                        .Where(a => !a.Deleted)
                        .WhereHasName_Canonized(artistTextQuery)
                        .WhereHasTag(tag)
                        .WhereStatusIs(status)
                        .Count() +
                        ctx.OfType <Album>().Query()
                        .Where(a => !a.Deleted)
                        .WhereHasName(textQuery)
                        .WhereHasTag(tag)
                        .WhereStatusIs(status)
                        .Count() +
                        ctx.OfType <Song>().Query()
                        .Where(a => !a.Deleted)
                        .WhereHasName(textQuery)
                        .WhereHasTag(tag)
                        .WhereStatusIs(status)
                        .Count();
                }

                return new PartialFindResult <EntryForApiContract>(entries.ToArray(), count);
            }));
        }
 public EntryForApiContract Create(IEntryWithNames entry, EntryOptionalFields includedFields, ContentLanguagePreference languagePreference, bool ssl)
 {
     return(EntryForApiContract.Create(entry, languagePreference, thumbPersister, imagePersisterOld, ssl, includedFields));
 }
Esempio n. 23
0
        private EntryForApiContract(IEntryWithNames entry, ContentLanguagePreference languagePreference, EntryOptionalFields fields)
        {
            EntryType = entry.EntryType;
            Id        = entry.Id;

            DefaultName         = entry.DefaultName;
            DefaultNameLanguage = entry.Names.SortNames.DefaultLanguage;
            Name    = entry.Names.SortNames[languagePreference];
            Version = entry.Version;

            if (fields.HasFlag(EntryOptionalFields.AdditionalNames))
            {
                AdditionalNames = entry.Names.GetAdditionalNamesStringForLanguage(languagePreference);
            }
        }
Esempio n. 24
0
		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);					
			}

		}
Esempio n. 25
0
		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();				
			}

		}
Esempio n. 26
0
        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);
            }
        }
Esempio n. 27
0
        public EntryForApiContract(Song song, ContentLanguagePreference languagePreference, EntryOptionalFields includedFields)
            : this((IEntryWithNames)song, languagePreference, includedFields)
        {
            ActivityDate = song.PublishDate.DateTime;
            ArtistString = song.ArtistString[languagePreference];
            CreateDate   = song.CreateDate;
            SongType     = song.SongType;
            Status       = song.Status;

            if (includedFields.HasFlag(EntryOptionalFields.MainPicture))
            {
                var thumb = song.GetThumbUrl();

                if (!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.PVs))
            {
                PVs = song.PVs.Select(p => new PVContract(p)).ToArray();
            }

            if (includedFields.HasFlag(EntryOptionalFields.Tags))
            {
                Tags = song.Tags.ActiveUsages.Select(u => new TagUsageForApiContract(u, languagePreference)).ToArray();
            }

            if (includedFields.HasFlag(EntryOptionalFields.WebLinks))
            {
                WebLinks = song.WebLinks.Select(w => new ArchivedWebLinkContract(w)).ToArray();
            }
        }