/// <summary> /// Synchronously processes all scrobbles and now playing notifications that are in the Queues, and returns the results /// </summary> /// <param name="throwExceptionDuringProcess">When true, will throw the first Exception encountered during Scrobbling (and cease to process). /// When false, any exceptions raised will be attached to the corresponding <see cref="ScrobbleResponse"/>, but will not be thrown. Default is false.</param> /// <returns><see cref="ScrobbleResponses"/>, a list of <see cref="ScrobbleResponse"/> </returns> /// <remarks>This method will complete synchronously and may take some time. This should be invoked by a single timer. This /// method may not be thread safe</remarks> public List <Response> Process(bool throwExceptionDuringProcess = false) { if (string.IsNullOrEmpty(SessionKey)) { return(null); } var results = new List <Response>(); Track track; while (NowPlayingQueue.TryDequeue(out track)) { try { results.Add(_scrobbler.NowPlaying(track)); } catch (Exception exception) { if (throwExceptionDuringProcess) { throw; } results.Add(new NowPlayingResponse { Track = track, Exception = exception }); } } while (ScrobbleQueue.TryDequeue(out track)) { //TODO: Implement bulk scrobble try { results.Add(_scrobbler.Scrobble(track)); } catch (Exception exception) { if (throwExceptionDuringProcess) { throw; } results.Add(new ScrobbleResponse { Track = track, Exception = exception }); } } RatingObject rating; while (RatingQueue.TryDequeue(out rating)) { try { switch (rating.RatingType) { case Rating.love: results.Add(_scrobbler.Love(rating.Track)); break; case Rating.ban: results.Add(_scrobbler.Ban(rating.Track)); break; case Rating.unlove: results.Add(_scrobbler.UnLove(rating.Track)); break; case Rating.unban: results.Add(_scrobbler.UnBan(rating.Track)); break; } } catch (Exception exception) { if (throwExceptionDuringProcess) { throw; } results.Add(new RatingResponse { ErrorCode = -1, Exception = exception, Track = rating.Track }); } } return(results); }
/// <summary> /// Enqueues a Srobble request but does not send it. Call <see cref="Process"/> to send /// </summary> /// <param name="track">The <see cref="Track"/> that has played</param> /// <remarks>This method is thread-safe. Will not check for invalid tracks until Processed. You should validate the Track before calling Scrobble</remarks> public void Scrobble(Track track) { ScrobbleQueue.Enqueue(track); }