本文整理汇总了C#中FilterExpression.Filter方法的典型用法代码示例。如果您正苦于以下问题:C# FilterExpression.Filter方法的具体用法?C# FilterExpression.Filter怎么用?C# FilterExpression.Filter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FilterExpression
的用法示例。
在下文中一共展示了FilterExpression.Filter方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BrowseGenres
private HttpResponse BrowseGenres()
{
var filter = new FilterExpression<ITrack>(Request.QueryString["filter"]);
var includeSortHeaders = "1".Equals(Request.QueryString["include-sort-headers"]);
using (Player.MediaLibrary.BeginRead())
{
var rawItems = filter.Filter(Player.MediaLibrary.Tracks);
var items = rawItems.Where(x => !string.IsNullOrEmpty(x.GenreName))
.GroupBy(x => x.GenreName, StringComparer.InvariantCultureIgnoreCase)
.Select(x => x.Key)
.OrderBy(x => x, LatinFirstSortComparer.Instance)
.ToArray();
return new DmapResponse(new
{
abro = new
{
mstt = 200,
muty = (byte)0,
abgn = items,
mshl = includeSortHeaders ? items.GetShortcuts(x => x) : null
}
});
}
}
示例2: AddTracks
private HttpResponse AddTracks()
{
// source is set by filter
var editParams = Request.QueryString["edit-params"];
if (!string.IsNullOrEmpty(editParams))
{
var filter = new FilterExpression<ITrack>(editParams);
using (Player.BeginWrite())
{
var playlist = Player.Playlists.Where(x => x.Id == id2.Value).FirstOrDefault() as IEditablePlaylist;
if (playlist != null)
{
using (Player.MediaLibrary.BeginRead())
{
var items = filter.Filter(Player.MediaLibrary.Tracks).Except(playlist.Tracks).ToArray();
if (items.Length > 0)
playlist.AddTrackRange(items);
}
}
}
return new NoContentResponse();
}
// source is set by playlist id
var addSrc = Request.QueryString["edit-add-src"];
int playlistId;
if (!string.IsNullOrEmpty(addSrc) && int.TryParse(addSrc, out playlistId))
{
using (Player.BeginWrite())
{
var source = Player.Playlists.Where(x => x.Id == playlistId).FirstOrDefault();
if (source != null)
{
var playlist = Player.Playlists.Where(x => x.Id == id2.Value).FirstOrDefault() as IEditablePlaylist;
if (playlist != null)
{
using (Player.MediaLibrary.BeginRead())
{
var items = source.Tracks.Except(playlist.Tracks).ToArray();
if (items.Length > 0)
playlist.AddTrackRange(items);
}
}
}
}
return new NoContentResponse();
}
return null;
}
示例3: ContainerItems
private HttpResponse ContainerItems()
{
if (!id2.HasValue || id2.Value == 100)
return 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 pl = Player.GetContainers().FirstOrDefault(x => x.Id == id2.Value);
if (pl != null)
{
lock (pl)
{
var rawItems = filter.Filter(pl.Tracks);
var items = rawItems.Select<ITrack, object>(GetTrackItem).ToArray();
return new DmapResponse(new
{
apso = new
{
mstt = 200,
muty = (byte)0,
mlcl = items
}
});
}
}
}
return new DmapResponse(new
{
apso = new
{
mstt = 200,
muty = (byte)0,
mlcl = new object[0]
}
});
}
示例4: LibraryItems
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
}
});
}
}
示例5: Groups
private HttpResponse Groups()
{
var groupType = Request.QueryString["group-type"];
var filter = new FilterExpression<ITrack>(Request.QueryString["query"]);
var includeSortHeaders = ("1".Equals(Request.QueryString["include-sort-headers"]));
using (Player.MediaLibrary.BeginRead())
{
var rawItems = filter.Filter(Player.MediaLibrary.Tracks);
switch (groupType)
{
case "artist":
case "artists":
{
var items = rawItems.Where(x => x.AlbumArtist != null).GroupBy(x => x.AlbumArtist).OrderBy(x => x.Key.Name, LatinFirstSortComparer.Instance);
return new DmapResponse(new
{
agar = new
{
mstt = 200,
muty = (byte)0,
mlcl = items.Select(x => new
{
miid = x.Key.Id,
mper = x.Key.PersistentId,
minm = x.Key.Name,
agac = x.Where(t => t.Album != null).Select(t => t.Album).Distinct().Count(), // albums count
mimc = x.Count(), // tracks count
asri = x.Key.PersistentId // required to queue an album
}).ToArray(),
mshl = includeSortHeaders ? items.Select(x => x.Key.Name).GetShortcuts(x => x) : null
}
});
}
case "album":
case "albums":
{
var items = rawItems.Where(x => x.Album != null).GroupBy(x => x.Album).OrderBy(x => x.Key.Title, LatinFirstSortComparer.Instance).ThenBy(x => x.Key.Artist);
return new DmapResponse(new
{
agal = new
{
mstt = 200,
muty = (byte)0,
mlcl = items.Select(x => new
{
miid = x.Key.Id,
mper = x.Key.PersistentId,
minm = x.Key.Title,
asaa = x.Key.Artist.Name,
asai = x.Key.PersistentId,
mgds = true,
astm = (uint)x.Sum(t => t.Duration.TotalMilliseconds),
mimc = x.Count()
}).ToArray(),
mshl = includeSortHeaders ? items.Select(x => x.Key.Title).GetShortcuts(x => x) : null
}
});
}
default:
break;
}
}
return new NotFoundResponse();
}
示例6: CueResponse
private HttpResponse CueResponse()
{
switch (Request.QueryString["command"])
{
case "clear":
{
Player.ClearPlaybackSource();
return new DmapResponse(new
{
cacr = new
{
mstt = 200,
miid = (Player.ActivePlaylist ?? Player.MediaLibrary).Id
}
});
}
case "play":
{
if (!string.IsNullOrEmpty(Request.QueryString["query"]))
{
var filter = new FilterExpression<ITrack>(Request.QueryString["query"]);
var sort = new SortExpression(Request.QueryString["sort"]);
using (Player.MediaLibrary.BeginRead())
{
var items = sort.Sort(filter.Filter(Player.MediaLibrary.Tracks)).ToArray();
Player.SetPlaybackSource(items);
}
}
int index;
if (string.IsNullOrEmpty(Request.QueryString["index"]) || !int.TryParse(Request.QueryString["index"], out index))
index = -1;
var track = Player.Play(index);
return new DmapResponse(new
{
cacr = new
{
mstt = 200,
miid = (Player.ActivePlaylist ?? Player.MediaLibrary).Id
}
});
}
case "add":
{
if (!string.IsNullOrEmpty(Request.QueryString["query"]))
{
var filter = new FilterExpression<ITrack>(Request.QueryString["query"]);
var sort = new SortExpression(Request.QueryString["sort"]);
using (Player.MediaLibrary.BeginRead())
{
var items = new List<ITrack>();
var oldItems = Player.GetPlaybackSource();
if (oldItems != null)
items.AddRange(oldItems);
var oldCount = items.Count;
items.AddRange(sort.Sort(filter.Filter(Player.MediaLibrary.Tracks)));
if (items.Count != oldCount)
{
Player.SetPlaybackSource(items.ToArray());
}
}
}
return new DmapResponse(new
{
cacr = new
{
mstt = 200,
miid = (Player.ActivePlaylist ?? Player.MediaLibrary).Id
}
});
}
default:
return new NotFoundResponse();
}
}
示例7: DeleteTracks
private HttpResponse DeleteTracks()
{
var editParams = Request.QueryString["edit-params"];
if (string.IsNullOrEmpty(editParams)) return null;
// HACK to use itemid instead of containeritemid
var match = containerItemIdMask.Match(editParams);
if (match.Success)
editParams = string.Format("'dmap.itemid:{0}'", match.Groups[1].Value);
var filter = new FilterExpression<ITrack>(editParams);
using (Player.BeginWrite())
{
var playlist = Player.Playlists.Where(x => x.Id == id2.Value).FirstOrDefault() as IEditablePlaylist;
if (playlist != null)
{
using (Player.MediaLibrary.BeginRead())
playlist.RemoveTrackRange(filter.Filter(playlist.Tracks).ToArray());
}
}
return new NoContentResponse();
}
示例8: QueueEditResponse
private HttpResponse QueueEditResponse()
{
var command = Request.QueryString["command"];
int mode = int.Parse(Request.QueryString["mode"]);
switch (command)
{
case "clear":
// todo: clear
return new NoContentResponse();
case "add":
// todo: add
if (!string.IsNullOrEmpty(Request.QueryString["query"]))
{
var filter = new FilterExpression<ITrack>(Request.QueryString["query"]);
var queuefilter = Request.QueryString["queuefilter"];
var sort = new SortExpression(Request.QueryString["sort"]);
using (Player.MediaLibrary.BeginRead())
{
var items = new List<ITrack>();
var oldCount = 0;
if (mode == 3)
{
// next
var oldItems = Player.GetPlaybackSource();
if (oldItems != null)
items.AddRange(oldItems);
oldCount = items.Count;
}
if (string.IsNullOrEmpty(queuefilter))
{
items.AddRange(sort.Sort(filter.Filter(Player.MediaLibrary.Tracks)));
}
else if (queuefilter.StartsWith("playlist:"))
{
var playlist = Player.Playlists.FirstOrDefault(x => x.Id == int.Parse(queuefilter.Substring(9)));
if (playlist != null)
items.AddRange(sort.Sort(filter.Filter(playlist.Tracks)));
else
throw new InvalidOperationException("Playlist with id " + queuefilter.Substring(9) + " not found");
}
else
throw new InvalidOperationException("Unknown queuefilter: " + queuefilter);
if (items.Count != oldCount)
{
Player.SetPlaybackSource(items.ToArray());
}
}
}
if (mode == 1)
{
int index;
if (string.IsNullOrEmpty(Request.QueryString["index"]) || !int.TryParse(Request.QueryString["index"], out index))
index = -1;
var track = Player.Play(index);
}
return new DmapResponse(new
{
cacr = new
{
mstt = 200,
miid = (Player.ActivePlaylist ?? Player.MediaLibrary).Id
}
});
default:
return new NotFoundResponse();
}
}
示例9: VoteForTrack
private void VoteForTrack()
{
var itemSpec = Request.QueryString["item-spec"];
if (string.IsNullOrEmpty(itemSpec)) return;
using (Player.MediaLibrary.BeginRead())
{
var jb = Player.MediaLibrary.Jukebox as IJukeboxPlaylist;
if (jb != null)
{
var filter = new FilterExpression<ITrack>(itemSpec);
var tracks = filter.Filter(Player.MediaLibrary.Tracks);
foreach (var track in tracks)
{
jb.Vote(track);
}
}
}
}