Esempio n. 1
0
        internal static Standings Create(XmlNode node, NSMgr nsmgr)
        {
            string teamKey = nsmgr.GetValue(node, "team_key");

            string rankStr = nsmgr.GetValue(node, "team_standings", "rank");
            int rank;
            if (!Int32.TryParse(rankStr, out rank))
            {
                return null;
            }

            Dictionary<string, string> stats = new Dictionary<string, string>();
            foreach (XmlNode stat in node.SelectNodes(nsmgr.GetXPath("team_stats", "stats", "stat"), nsmgr))
            {
                string key = nsmgr.GetValue(stat, "stat_id");
                string value = nsmgr.GetValue(stat, "value");
                if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(value))
                {
                    stats[key] = value;
                }
            }

            Dictionary<string, string> points = new Dictionary<string, string>();
            foreach (XmlNode stat in node.SelectNodes(nsmgr.GetXPath("team_points", "stats", "stat"), nsmgr))
            {
                string key = nsmgr.GetValue(stat, "stat_id");
                string value = nsmgr.GetValue(stat, "value");
                if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(value))
                {
                    points[key] = value;
                }
            }

            return new Standings(teamKey, stats, points, rank);
        }
Esempio n. 2
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));
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        internal static RosterPosition Create(XmlNode node, NSMgr nsmgr)
        {
            string position     = nsmgr.GetValue(node, "position");
            string positionType = nsmgr.GetValue(node, "position_type");
            string countString  = nsmgr.GetValue(node, "count");

            int  count            = int.Parse(countString);
            bool accumulatesStats = (position != "BN" && position != "DL" && position != "NA");

            return(new RosterPosition(position, positionType, count, accumulatesStats));
        }
Esempio n. 5
0
        internal static StatDefinition Create(XmlNode node, NSMgr nsmgr)
        {
            string idString     = nsmgr.GetValue(node, "stat_id");
            string name         = nsmgr.GetValue(node, "name");
            string sortOrder    = nsmgr.GetValue(node, "sort_order");           // 1 -> more is better
            string positionType = nsmgr.GetValue(node, "position_type");
            string displayOnly  = nsmgr.GetValue(node, "is_only_display_stat"); // !1 -> counts for points

            int  id              = int.Parse(idString);
            bool moreIsBetter    = sortOrder == "1";
            bool countsForPoints = (displayOnly != "1");

            return(new StatDefinition(id, name, moreIsBetter, positionType, countsForPoints));
        }
Esempio n. 6
0
        internal static Team Create(XmlNode node, NSMgr nsmgr)
        {
            string        key          = nsmgr.GetValue(node, "team_key");
            string        id           = nsmgr.GetValue(node, "team_id");
            string        name         = nsmgr.GetValue(node, "name");
            string        managerName  = nsmgr.GetValue(node, "managers", "manager", "nickname");
            string        managerEmail = nsmgr.GetValue(node, "managers", "manager", "email");
            List <string> playerKeys   = new List <string>();

            foreach (XmlNode player in node.SelectNodes(nsmgr.GetXPath("roster", "players", "player"), nsmgr))
            {
                playerKeys.Add(nsmgr.GetValue(player, "player_key"));
            }

            return(new Team(key, id, name, managerName, managerEmail, playerKeys));
        }
Esempio n. 7
0
        public static async Task <League> 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 key  = nsmgr.GetValue(league, "league_key");
            string name = nsmgr.GetValue(league, "name");
            Dictionary <int, StatDefinition> stats = new Dictionary <int, StatDefinition>();

            foreach (XmlNode node in league.SelectNodes(nsmgr.GetXPath("settings", "stat_categories", "stats", "stat"), nsmgr))
            {
                StatDefinition stat = StatDefinition.Create(node, nsmgr);
                stats[stat.Id] = stat;
            }

            List <RosterPosition> rosterPositions = new List <RosterPosition>();

            foreach (XmlNode node in league.SelectNodes(nsmgr.GetXPath("settings", "roster_positions", "roster_position"), nsmgr))
            {
                rosterPositions.Add(RosterPosition.Create(node, nsmgr));
            }

            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))
            {
                teams.Add(Team.Create(team, nsmgr));
            }

            Dictionary <string, Player> players = new Dictionary <string, Player>();

            foreach (Player player in await Player.GetAllPlayers(leagueId))
            {
                player.SetStatValues(stats);
                players[player.Key] = player;
            }

            string leagueStandings = await Services.Http.GetRawDataAsync(UrlGen.LeagueStandings(leagueId));

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

            List <Standings> standings = new List <Standings>();

            foreach (XmlNode node in league.SelectNodes(nsmgr.GetXPath("standings", "teams", "team"), nsmgr))
            {
                standings.Add(Standings.Create(node, nsmgr));
            }

            return(new League(key, name, stats, rosterPositions, teams, players, standings));
        }