private Playlist(IEnumerable <ITrack> tracks, ITracksSource source) { var notYetPlayed = tracks.Where(track => { var now = DateTime.UtcNow.AddHours(2); return(track.Stop >= now); }); foreach (var track in notYetPlayed) { _tracks.AddLast(track); } _tracksSource = source; _current = _tracks.First; }
public static async Task <Playlist> CreateFrom(ITracksSource source) { if (source == null) { throw new ArgumentNullException(nameof(source)); } var tracks = await source.GetAsync(); var tracksList = tracks.ToList(); if (!tracksList.Any()) { throw new ApplicationException("Tracks source has not returned any tracks"); } var playlist = new Playlist(tracksList, source); return(playlist); }