Exemplo n.º 1
0
        private void ParseData(recenttracks recent)
        {
            var latestTrack = recent.tracks[0];

            OutputMoodMessage(latestTrack);
            if (logger.IsDebugEnabled)
            {
                // If we have "cached" data just write the most recent track
                if (_lastTracks != null)
                {
                    var track = recent.tracks[0];
                    LogDebug(String.Format(@"Played ""{0}"" by {1} from the album ""{2}"" on {3}", track.name, track.artist, track.album, track.date));
                    return;
                }

                // Log 'em all
                foreach (var track in recent.tracks)
                {
                    LogDebug(String.Format(@"Played ""{0}"" by {1} from the album ""{2}"" on {3}", track.name, track.artist, track.album, track.date));
                }
            }
        }
Exemplo n.º 2
0
        internal void GetData()
        {
            var recent    = new recenttracks();
            var serialize = new XmlSerializer(typeof(recenttracks));
            var request   = WebRequest.Create(String.Format(lastFmUrl, LastFmUserName));

            using (var response = request.GetResponse())
                using (var stream = response.GetResponseStream()) {
                    recent = (recenttracks)serialize.Deserialize(stream);
                }

            // See if the data has changed
            if (_lastTracks == recent)
            {
                _lastTracks = recent;
                return;
            }

            // Parse
            ParseData(recent);

            // Set cached value
            _lastTracks = recent;
        }