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); }
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)); }
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)); }
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)); }