/// <summary>
        /// Gets the closed achievements from http://steamcommunity.com/id/[customurl]/[game]/?xml=1.
        /// </summary>
        /// <param name="steamUserId">The steam user id.</param>
        /// <returns></returns>
        public ICollection <UserAchievement> GetAchievements(string steamUserId)
        {
            if (steamUserId == null)
            {
                throw new ArgumentNullException("steamUserId");
            }

            List <UserAchievement> achievements = new List <UserAchievement>();

            IEnumerable <Game> games = GetGames(steamUserId);

            foreach (Game game in games.Where(g => g.PlayedRecently))
            {
                string xmlStatsUrl = game.StatsUrl + "/?xml=1";

                string xml = _webClient.DownloadString(xmlStatsUrl);

                IEnumerable <UserAchievement> gameAchievements;
                try
                {
                    gameAchievements = _achievementParser.ParseClosed(xml);
                }
                catch (XmlException ex)
                {
                    // log and ignore invalid achievement xml
                    HttpContext context = HttpContext.Current;
                    if (context != null)
                    {
                        ErrorSignal signal = ErrorSignal.FromContext(context);
                        if (signal != null)
                        {
                            string    message   = "Invalid xml for " + game.Name + " stats: " + game.StatsUrl;
                            Exception exception = new InvalidOperationException(message, ex);
                            signal.Raise(exception);
                        }
                    }

                    continue;
                }

                if (!gameAchievements.Any())
                {
                    continue;
                }

                List <UserAchievement> achievementList = gameAchievements.ToList();
                Game game1 = game;
                achievementList.ForEach(a => a.Game = game1);

                achievements.AddRange(achievementList);
            }

            return(achievements);
        }
Example #2
0
        /// <summary>
        /// Gets the closed achievements from http://steamcommunity.com/id/[customurl]/statsfeed/[game]/?xml=1.
        /// </summary>
        /// <param name="steamUserId">The steam user id.</param>
        /// <returns></returns>
        public IEnumerable <Achievement> GetAchievements(string steamUserId)
        {
            if (steamUserId == null)
            {
                throw new ArgumentNullException("steamUserId");
            }

            List <Achievement> achievements = new List <Achievement>();

            IEnumerable <Game> games = GetGames(steamUserId);

            foreach (Game game in games)
            {
                string statsUrl    = game.StatsUrl.ToString();
                string xmlStatsUrl = statsUrl + "/?xml=1";

                string xml = _webClient.DownloadString(xmlStatsUrl);

                IEnumerable <Achievement> gameAchievements;
                try
                {
                    gameAchievements = _achievementParser.ParseClosed(xml);
                }
                catch (XmlException ex)
                {
                    ErrorSignal signal = ErrorSignal.FromCurrentContext();
                    if (signal != null)
                    {
                        string    message   = "Invalid xml for " + game.Name + " stats: " + statsUrl;
                        Exception exception = new InvalidOperationException(message, ex);
                        signal.Raise(exception);
                    }

                    continue;
                }

                if (gameAchievements.Any())
                {
                    List <Achievement> achievementList = gameAchievements.ToList();
                    Game game1 = game;
                    achievementList.ForEach(a => a.Game = game1);

                    achievements.AddRange(achievementList);
                }
            }

            return(achievements);
        }