Exemplo n.º 1
0
        public static async Task <List <YahooPlayerData> > GetAllPlayers(string leagueId)
        {
            List <YahooPlayerData> players = new List <YahooPlayerData>();
            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(YahooPlayerData.Create(playerRoot, nsmgr));
                }
            }

            return(players);
        }
Exemplo n.º 2
0
        private static YahooPlayerData Create(XmlNode node, NSMgr nsmgr)
        {
            YahooPlayerData player = new YahooPlayerData();

            player.playerKey   = nsmgr.GetValue(node, "player_key");
            player.SourceID    = nsmgr.GetValue(node, "player_id");
            player.DisplayName = nsmgr.GetValue(node, "name", "full");

            XmlNode eligiblePositions = node["eligible_positions"];

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

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

            foreach (XmlNode stat in node.SelectNodes(nsmgr.GetXPath("player_stats", "stats", "stat"), nsmgr))
            {
                string statIdString = nsmgr.GetValue(stat, "stat_id").Trim();
                string statValue    = nsmgr.GetValue(stat, "value").Trim();
                int    statId;
                if (int.TryParse(statIdString, out statId))
                {
                    yahooStats[statId] = statValue;
                }
            }
            YConstants.Stats.MapYahooStatDictionaryToDataModelStatDictionary(yahooStats, player.Stats);

            return(player);
        }
Exemplo n.º 3
0
        public static async Task <YahooLeague> Create(string leagueId)
        {
            string leagueXml = await Services.Http.GetRawDataAsync(UrlGen.LeagueSettingsUrl(leagueId));

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(leagueXml);
            NSMgr   nsmgr  = new NSMgr(doc);
            XmlNode league = doc.SelectSingleNode(nsmgr.GetXPath("fantasy_content", "league"), nsmgr);

            string name = nsmgr.GetValue(league, "name");

            List <Constants.StatID> scoringStats = new List <Constants.StatID>();

            foreach (XmlNode node in league.SelectNodes(nsmgr.GetXPath("settings", "stat_categories", "stats", "stat"), nsmgr))
            {
                string displayOnly = nsmgr.GetValue(node, "is_only_display_stat"); // !1 -> counts for points
                if (displayOnly != "1")
                {
                    string idString = nsmgr.GetValue(node, "stat_id");
                    int    id       = int.Parse(idString);
                    scoringStats.Add(YConstants.Stats.ScoringStatIdFromYahooStatId(id));
                }
            }

            Dictionary <Position, int> positionCounts = new Dictionary <Position, int>();

            foreach (XmlNode node in league.SelectNodes(nsmgr.GetXPath("settings", "roster_positions", "roster_position"), nsmgr))
            {
                string position    = nsmgr.GetValue(node, "position");
                string countString = nsmgr.GetValue(node, "count");
                int    count       = int.Parse(countString);
                positionCounts[YConstants.Positions.PositionFromYahooPosition(position)] = count;
            }

            //List<YahooPlayerData> allPlayers = await YahooPlayerData.GetAllPlayers(leagueId);

            string leagueTeams = await Services.Http.GetRawDataAsync(UrlGen.TeamsWithRostersUrl(leagueId));

            doc.LoadXml(leagueTeams);
            nsmgr  = new NSMgr(doc);
            league = doc.SelectSingleNode(nsmgr.GetXPath("fantasy_content", "league"), nsmgr);

            List <Team> teams = new List <Team>();

            foreach (XmlNode team in league.SelectNodes(nsmgr.GetXPath("teams", "team"), nsmgr))
            {
            }

            return(null);
        }