/// <summary> /// Adds the given <paramref name="scrobbles"/> to /// the <see cref="RecentScrobbles"/>. /// </summary> /// <param name="scrobbles">Scrobbles to add.</param> /// <param name="timeScrobbled">The time this scrobble was scrobbled. /// Leave null if you want to use the TimePlayed of the scrobble.</param> public void AddScrobbles(IEnumerable <Scrobble> scrobbles, DateTime?timeScrobbled = null) { foreach (var scrobble in scrobbles) { _recentScrobbles.Add(new Tuple <Scrobble, DateTime>(scrobble, timeScrobbled ?? scrobble.TimePlayed.DateTime)); } RecentScrobblesChanged?.Invoke(this, EventArgs.Empty); }
/// <summary> /// Updates the <see cref="RecentScrobbles"/>, /// removing scrobbles older than 1 day. /// </summary> public void UpdateRecentScrobbles() { int oldCount = RecentScrobbles.Count; _recentScrobbles = RecentScrobbles.Where(i => (DateTime.Now - i.Item2) <= TimeSpan.FromDays(1)).ToList(); if (oldCount != RecentScrobbles.Count) { RecentScrobblesChanged?.Invoke(this, EventArgs.Empty); } }
/// <summary> /// Adds the given <paramref name="scrobbles"/> to /// the <see cref="RecentScrobbles"/>. /// </summary> /// <param name="scrobbles">Scrobbles to add.</param> /// <param name="timeScrobbled">The time this scrobble was scrobbled. /// Leave null if you want to use the TimePlayed of the scrobble.</param> public void AddScrobbles(IEnumerable <Scrobble> scrobbles, DateTime?timeScrobbled = null) { if (scrobbles == null) { throw new ArgumentNullException(nameof(scrobbles)); } foreach (var scrobble in scrobbles) { _recentScrobbles.Add(new Tuple <Scrobble, DateTime>(scrobble, timeScrobbled ?? scrobble.TimePlayed.DateTime)); } RecentScrobblesChanged?.Invoke(this, EventArgs.Empty); }