public async Task ScrobbleTrack(Track track)
        {
            if (track == null)
            {
                throw new ArgumentNullException(nameof(track));
            }
            if (_lastFmClient == null || !_lastFmClient.Auth.Authenticated)
            {
                throw new InvalidOperationException("User is not authenticated.");
            }

            // skip if already scrobbled recently
            if (_lastScrobbledTracks.Contains(track))
            {
                return;
            }

            // scrobble
            var response = await _lastFmClient.Scrobbler.ScrobbleAsync(
                new Scrobble(track.Artist, string.Empty, track.Title, track.TimeAired));

            if (response.Success)
            {
                // add to last scrobbled tracks
                _lastScrobbledTracks.Enqueue(track);
            }
        }
示例#2
0
        private void TestWithSize(FixedSizeQueue <string> fixedSizeQueue, int size)
        {
            Assert.AreEqual(size, fixedSizeQueue.MaximumCapacity);
            Assert.AreEqual(0, fixedSizeQueue.Count);
            Assert.IsFalse(fixedSizeQueue.Contains(null));

            for (int i = 0; i < size; i++)
            {
                fixedSizeQueue.Push(i.ToString());
                Assert.AreEqual(i + 1, fixedSizeQueue.Count);
                Assert.IsFalse(fixedSizeQueue.Contains((i + 1).ToString()));

                for (int j = 0; j < i; j++)
                {
                    Assert.AreEqual((i - j).ToString(), fixedSizeQueue[j]);
                    Assert.IsTrue(fixedSizeQueue.Contains((i - j).ToString()));
                }
            }

            int index = size;

            for (int i = 0; i < size * 3 + 11; i++)
            {
                fixedSizeQueue.Push(index++.ToString());
                Assert.AreEqual(size, fixedSizeQueue.Count);

                for (int j = 0; j < size; j++)
                {
                    Assert.AreEqual((index - j - 1).ToString(), fixedSizeQueue[j]);
                }
            }

            foreach (string s in fixedSizeQueue)
            {
                Assert.AreEqual((--index).ToString(), s);
            }

            fixedSizeQueue.Clear();

            Assert.AreEqual(0, fixedSizeQueue.Count);
        }