本文整理汇总了C#中Options.ContainsKey方法的典型用法代码示例。如果您正苦于以下问题:C# Options.ContainsKey方法的具体用法?C# Options.ContainsKey怎么用?C# Options.ContainsKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Options
的用法示例。
在下文中一共展示了Options.ContainsKey方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildContents
/// <summary>
/// Builds the contents object
/// </summary>
/// <param name="tracks">The tracks source</param>
/// <param name="filter">The filter object which contains the parameters with which to query for items</param>
/// <param name="container">The container the tracks are sources from</param>
/// <returns>A filled contents object</returns>
Contents BuildContents(IEnumerable<Track> tracks, Options filter, IContainer container)
{
// Get type
var type = (filter.ContainsKey("type") ? filter["type"] : container.ViewTypes.FirstOrDefault()) ?? Types.Track;
// Create contents instance
var contents = new Contents(container);
// Set meta data
dynamic meta = new ExpandoObject();
contents.Meta = meta;
meta.Shuffable = type == Types.Track;
meta.SortedByAlpha = container is MasterPlaylist || container is WebcastContainer;
// Get the data for the given type
switch(type) {
case Types.Track:
contents.Data = GetTracksData(tracks, meta.SortedByAlpha);
contents.Keys = new string[] { "id", "name", "artist", "album", "albumArtist", "number", "duration", "index" };
if (filter.ContainsKey("albumid")) {
meta.Albumid = filter["albumid"];
meta.TotalDuration = (int)(tracks.Aggregate(TimeSpan.Zero, (total, t) => total + t.Duration).TotalSeconds);
}
break;
case Types.Album:
contents.Data = GetAlbumsData(tracks);
contents.Keys = new string[] { "id", "album", "artist", "artworkid", "index" };
break;
case Types.Artist:
contents.Data = GetArtistsData(tracks);
contents.Keys = new string[] { "artist", "albums", "tracks", "index" };
break;
case Types.Genre:
contents.Data = GetGenresData(tracks);
contents.Keys = new string[] { "genre", "index" };
break;
case Types.Webcast:
contents.Data = GetWebcastsData(tracks);
contents.Keys = new string[] { "id", "name", "index" };
break;
}
return contents;
}
示例2: GetArtwork
public Image GetArtwork(Container container, Options filter)
{
// For now, wo only get images based on album ID
if (!filter.ContainsKey("album")) return null;
// Get tracks by albumID
string albumID = filter["album"];
var tracks = Track.GetTracksOfAlbum(albumID);
if (tracks.Count() == 0) return null;
// Get the artwork from one of the tracks of the album
Image artwork = null;
tracks.FirstOrDefault(t => (artwork = t.Artwork) != null);
return artwork;
}
示例3: BuildContents
/// <summary>
/// Builds the contents object
/// </summary>
/// <param name="channels">The channels source</param>
/// <param name="filter">The filter object which contains the parameters with which to query for items</param>
/// <param name="channelsContainer">The radio channels container the tracks are sources from</param>
/// <returns>A filled contents object</returns>
Contents BuildContents(IEnumerable<RadioChannel> channels, Options filter, RadioChannels channelsContainer)
{
// Create contents instance
var contents = new Contents(channelsContainer);
var type = (filter.ContainsKey("type") ? filter["type"] : channelsContainer.ViewTypes.FirstOrDefault()) ?? Types.Channel;
// Set meta data
dynamic meta = new ExpandoObject();
contents.Meta = meta;
meta.SortedByAlpha = true;
// Get the data for the given type
switch (type) {
case Types.Channel:
contents.Data = GetChannelsData(channels);
contents.Keys = new string[] { "id", "name", "index" };
break;
case Types.Genre:
contents.Data = GetGenresData(channels);
contents.Keys = new string[] { "genre", "index" };
break;
}
return contents;
}
示例4: GetItems
/// <summary>
///
/// </summary>
/// <param name="container"></param>
/// <param name="filter"></param>
/// <returns></returns>
public IEnumerable<IItem> GetItems(Container container, Options filter)
{
if (!(container is Playlist)) return null;
IEnumerable<ITrack> ret = null;
var allTracks = ((Playlist)container).Tracks;
string view = filter.ContainsKey("view") ? filter["view"] : null;
string group = view == null ? null : (filter.ContainsKey(view) ? filter[view] : null);
switch (view) {
// All tracks for the given artist or genre
case "artist":
case "genre":
if (group == null) return null;
group = group.ToLower();
switch (view) {
case "artist": ret = allTracks.Where(t => t.IsByArtist(group)); break;
case "genre": ret = allTracks.Where(t => t.IsOfGenre(group)); break;
}
ret = ret
.OrderByOrdinal(t => t.AlbumArtistSort)
.ThenByOrdinal(t => t.AlbumSort);
break;
// All tracks for the given album
case "album":
if (group == null) return null;
ret = Track.Where(t => t.AlbumID == group);
break;
// All tracks
case "track":
ret = allTracks
.OrderByOrdinal(t => t.TitleSort)
.ThenByOrdinal(t => t.ArtistSort);
break;
// No default sorting
default:
ret = allTracks;
break;
}
// Order by disc number, track number and track name
// TODO: do not sort non-masterplaylist
if (view is String && view != "track") {
if (ret is IOrderedEnumerable<ITrack>)
ret = ((IOrderedEnumerable<ITrack>)ret).ThenBy(t => t.DiscNumber == 0);
else
ret = ret.OrderBy(t => t.DiscNumber == 0);
ret = ((IOrderedEnumerable<ITrack>)ret)
.ThenBy(t => t.DiscNumber == 0)
.ThenBy(t => t.DiscNumber)
.ThenBy(t => t.TrackNumber == 0)
.ThenBy(t => t.TrackNumber)
.ThenByOrdinal(t => t.TitleSort);
}
return ret;
}
示例5: SortTracks
/// <summary>
/// Sorts the given tracks collection based on the filter and sortByName parameters
/// </summary>
/// <param name="tracks">The tracks to sort</param>
/// <param name="filter">The filter used</param>
/// <param name="master">Whether the tracks are from the master playlist</param>
/// <returns>The sorted track collection</returns>
IEnumerable<Track> SortTracks(IEnumerable<Track> tracks, Options filter, bool master)
{
if (filter.ContainsKey("albumid") || filter.ContainsKey("artist"))
tracks = SortTracksByAlbum(tracks);
else if (master && filter.ContainsKey("type") && filter["type"] == Types.Track)
tracks = SortTracksByName(tracks);
return tracks;
}