Пример #1
0
        /// <summary>
        /// Scrobbles the given <paramref name="scrobbles"/>.
        /// </summary>
        /// <param name="scrobbles">Collection of scrobble objects to scrobble.</param>
        /// <param name="needCaching">If true, scrobbles should be cached
        /// if they can't be scrobbled.</param>
        /// <returns>Response.</returns>
        public async Task <ScrobbleResponse> ScrobbleAsync(IEnumerable <Scrobble> scrobbles, bool needCaching = false)
        {
            User.UpdateRecentScrobbles();
            if (User.RecentScrobbles.Count + scrobbles.Count() > User.MAXSCROBBLESPERDAY)
            {
                throw new InvalidOperationException(string.Format("Scrobbling these tracks would break the daily scrobble cap! ({0})\r\nYou have scrobbled {1} tracks in the past 24 hours.",
                                                                  User.MAXSCROBBLESPERDAY, User.RecentScrobbles.Count));
            }

            ScrobbleResponse response;

            if (needCaching)
            {
                response = await _cachingScrobbler.ScrobbleAsync(scrobbles);
            }
            else
            {
                response = await _scrobbler.ScrobbleAsync(scrobbles);
            }

            if (response.Success && response.Status == LastResponseStatus.Successful)
            {
                User.AddScrobbles(scrobbles, DateTime.Now);
            }
            return(response);
        }
Пример #2
0
        /// <summary>
        /// Scrobbles the given <paramref name="scrobbles"/>.
        /// </summary>
        /// <param name="scrobbles">Collection of scrobble objects to scrobble.</param>
        /// <param name="needCaching">If true, scrobbles should be cached
        /// if they can't be scrobbled.</param>
        /// <returns>Response.</returns>
        public async Task <ScrobbleResponse> ScrobbleAsync(IEnumerable <Scrobble> scrobbles, bool needCaching = false)
        {
            await User.UpdateRecentScrobbles();

            int recentScrobblesCount = User.RecentScrobblesCache.Count();

            if (recentScrobblesCount + scrobbles.Count() > User.MAXSCROBBLESPERDAY)
            {
                throw new InvalidOperationException($"Scrobbling these tracks would break the daily scrobble cap! " +
                                                    $"({User.MAXSCROBBLESPERDAY})\r\nYou have scrobbled {recentScrobblesCount} tracks in the past 24 hours.");
            }

            ScrobbleResponse response = needCaching ? await _cachingScrobbler.ScrobbleAsync(scrobbles) : await _scrobbler.ScrobbleAsync(scrobbles);

            if (response.Success && response.Status == LastResponseStatus.Successful)
            {
                await User.UpdateRecentScrobbles();
            }
            return(response);
        }