Ejemplo n.º 1
0
        private static Player Create(XmlNode node, NSMgr nsmgr)
        {
            string positionType = nsmgr.GetValue(node, "position_type");
            string playerKey    = nsmgr.GetValue(node, "player_key");
            string playerId     = nsmgr.GetValue(node, "player_id");
            string status       = nsmgr.GetValue(node, "status");
            string firstName    = nsmgr.GetValue(node, "name", "ascii_first");
            string lastName     = nsmgr.GetValue(node, "name", "ascii_last");

            List <string> positions         = new List <string>();
            XmlNode       eligiblePositions = node["eligible_positions"];

            if (eligiblePositions != null)
            {
                foreach (XmlNode position in eligiblePositions.SelectNodes(NSMgr.GetNodeName("position"), nsmgr))
                {
                    positions.Add(position.InnerText);
                }
            }

            Dictionary <int, string> stats = new Dictionary <int, string>();

            foreach (XmlNode stat in node.SelectNodes(nsmgr.GetXPath("player_stats", "stats", "stat"), nsmgr))
            {
                string keyString = nsmgr.GetValue(stat, "stat_id").Trim();
                string value     = nsmgr.GetValue(stat, "value").Trim();
                int    key;
                if (int.TryParse(keyString, out key) && !string.IsNullOrEmpty(value))
                {
                    stats[key] = value;
                }
            }

            return(new Player(playerKey, playerId, positionType == "B", firstName, lastName, status, positions, stats));
        }
Ejemplo n.º 2
0
        public static async Task <List <Player> > GetAllPlayers(string leagueId)
        {
            List <Player> players = new List <Player>();
            int           start   = 1;

            while (true)
            {
                string playerXml = await Services.Http.GetRawDataAsync(UrlGen.PaginatedPlayers(leagueId, start));

                XmlDocument doc = new XmlDocument();
                doc.LoadXml(playerXml);
                NSMgr nsmgr = new NSMgr(doc);

                XmlNodeList playerRoots = doc.SelectNodes("//" + NSMgr.GetNodeName("player"), nsmgr);
                if (playerRoots.Count == 0)
                {
                    break;
                }

                start += playerRoots.Count;
                foreach (XmlNode playerRoot in playerRoots)
                {
                    players.Add(Player.Create(playerRoot, nsmgr));
                }
            }

            return(players);
        }