Ejemplo n.º 1
0
 private ThreadSafeObservableCollection <Mediafile> GetPlayingCollection()
 {
     if (Shuffle)
     {
         return(_shuffledList);
     }
     else
     {
         if (PlaylistSongCollection?.IsPlayingCollection() == true || IsPlayingFromPlaylist)
         {
             return(PlaylistSongCollection);
         }
         else if (TracksCollection?.Elements?.IsPlayingCollection() == true)
         {
             return(TracksCollection.Elements);
         }
     }
     if (NowPlayingQueue?.Any() == true)
     {
         return(NowPlayingQueue);
     }
     return(null);
 }
Ejemplo n.º 2
0
        /// <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);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Enqueues a NowPlaying request but does not send it. Call <see cref="Process"/> to send
 /// </summary>
 /// <param name="track">The <see cref="Track"/> that is now playing</param>
 /// <remarks>This method is thread-safe. Will not check for invalid tracks until Processed. You should validate the Track before calling NowPlaying</remarks>
 public void NowPlaying(Track track)
 {
     NowPlayingQueue.Enqueue(track);
 }