private HttpResponse LibraryItems() { var filter = new FilterExpression <ITrack>(Request.QueryString["query"]); var includeSortHeaders = "1".Equals(Request.QueryString["include-sort-headers"]); var sort = new SortExpression(Request.QueryString["sort"]); using (Player.MediaLibrary.BeginRead()) { var rawItems = sort.Sort(filter.Filter(Player.MediaLibrary.Tracks)); Func <ITrack, string> selector; switch (Request.QueryString["sort"]) { case "album": case "albums": selector = x => x.AlbumArtistName; break; case "artist": case "artists": selector = x => x.AlbumName; break; default: selector = x => x.Title; break; } var items = rawItems.Select <ITrack, object>(GetTrackItem).ToArray(); if (items.Length == 0 && !includeSortHeaders) { // album not in library, and this is not search using (Player.BeginRead()) { if (filter.IsMatch(Player.CurrentTrack)) { items = new[] { GetTrackItem(Player.CurrentTrack, 0) } } ; } } return(new DmapResponse(new { apso = new { mstt = 200, muty = (byte)0, mlcl = items, //mshl = includeSortHeaders ? rawItems.GetShortcuts(selector) : null } })); } }
public void IsMatch_returns_expected_result(string id, string filterType, string filterScope, string entryType, string entryScope, bool expected) { _ = id; // ARRANGE var sut = new FilterExpression(type: filterType, scope: filterScope); var entry = GetChangeLogEntry(type: entryType, scope: entryScope); // ACT var actual = sut.IsMatch(entry); // ASSERT Assert.Equal(expected, actual); }
private HttpResponse LibraryItems() { var filter = new FilterExpression<ITrack>(Request.QueryString["query"]); var includeSortHeaders = "1".Equals(Request.QueryString["include-sort-headers"]); var sort = new SortExpression(Request.QueryString["sort"]); using (Player.MediaLibrary.BeginRead()) { var rawItems = sort.Sort(filter.Filter(Player.MediaLibrary.Tracks)); Func<ITrack, string> selector; switch (Request.QueryString["sort"]) { case "album": case "albums": selector = x => x.AlbumArtistName; break; case "artist": case "artists": selector = x => x.AlbumName; break; default: selector = x => x.Title; break; } var items = rawItems.Select<ITrack, object>(GetTrackItem).ToArray(); if (items.Length == 0 && !includeSortHeaders) { // album not in library, and this is not search using (Player.BeginRead()) { if (filter.IsMatch(Player.CurrentTrack)) items = new[] { GetTrackItem(Player.CurrentTrack, 0) }; } } return new DmapResponse(new { apso = new { mstt = 200, muty = (byte)0, mlcl = items, //mshl = includeSortHeaders ? rawItems.GetShortcuts(selector) : null } }); } }