private static Nhl_Games_Rtss_RosterParticipantItem ParseLinesman(HtmlNode row) { Nhl_Games_Rtss_RosterParticipantItem official = NhlGamesRtssRoster.ParseOfficial(row); official.Designation = Designation.Linesman; return(official); }
private static Nhl_Games_Rtss_RosterParticipantItem ParseCoach(HtmlNode row) { HtmlNode columnNode = row.SelectSingleNode(@"./td"); Nhl_Games_Rtss_RosterParticipantItem coach = new Nhl_Games_Rtss_RosterParticipantItem(); coach.ParticipantType = ParticipantType.Coach; coach.Designation = Designation.HeadCoach; coach.Name = columnNode.InnerText.Trim(); return(coach); }
private static Nhl_Games_Rtss_RosterParticipantItem ParseOfficial(HtmlNode row) { HtmlNode columnNode = row.SelectSingleNode(@"./td"); string nameText = columnNode.InnerText.Trim(); Nhl_Games_Rtss_RosterParticipantItem official = new Nhl_Games_Rtss_RosterParticipantItem(); official.ParticipantType = ParticipantType.Official; int officialsNumber = 0; string officialsName = String.Empty; NhlBaseClass.ParseNameText(nameText, out officialsNumber, out officialsName); official.Number = officialsNumber; official.Name = officialsName; return(official); }
private static Nhl_Games_Rtss_RosterParticipantItem ParsePlayer(HtmlNode row) { Nhl_Games_Rtss_RosterParticipantItem player = new Nhl_Games_Rtss_RosterParticipantItem(); // Assume it is a Player player.ParticipantType = ParticipantType.Player; HtmlNodeCollection columnNodes = row.SelectNodes(@"./td"); string numberText = columnNodes[0].InnerText; if (!String.IsNullOrWhiteSpace(numberText)) { player.Number = Convert.ToInt32(numberText); } player.Position = columnNodes[1].InnerText; // Parse out the name, captaincy, starting lineup string nameText = columnNodes[2].InnerText; if (columnNodes[2].Attributes["class"].Value.IndexOf("bold", StringComparison.InvariantCultureIgnoreCase) >= 0) { player.StartingLineup = true; } if (nameText.IndexOf("(C)", StringComparison.InvariantCultureIgnoreCase) >= 0) { player.Designation = Designation.Captain; player.Name = nameText.Replace("(C)", String.Empty).Trim(); } else if (nameText.IndexOf("(A)", StringComparison.InvariantCultureIgnoreCase) >= 0) { player.Designation = Designation.AssistantCaptain; player.Name = nameText.Replace("(A)", String.Empty).Trim(); } else { player.Name = nameText.Trim(); } return(player); }
private static List <Nhl_Games_Rtss_RosterParticipantItem> ParsePlayers(HtmlNodeCollection rows) { if (null == rows) { return(null); } List <Nhl_Games_Rtss_RosterParticipantItem> players = new List <Nhl_Games_Rtss_RosterParticipantItem>(); foreach (HtmlNode row in rows) { Nhl_Games_Rtss_RosterParticipantItem player = NhlGamesRtssRoster.ParsePlayer(row); if (null != player) { players.Add(player); } } return(players); }
public static Nhl_Games_Rtss_Roster ParseHtmlBlob(int rtssReportId, string html) { if (String.IsNullOrWhiteSpace(html) || html.Equals("404")) { return(null); } Nhl_Games_Rtss_Roster model = new Nhl_Games_Rtss_Roster(); model.NhlRtssReportModelId = rtssReportId; HtmlDocument htmlDocument = new HtmlDocument(); htmlDocument.LoadHtml(html); HtmlNode documentNode = htmlDocument.DocumentNode; // Special Case // The html for this game doesn't follow the same format as the other games if (null != documentNode.SelectSingleNode(@"./html/head/link[@href='RO010002_files/editdata.mso']")) { return(NhlGamesRtssRoster.BruinsRangersSpecialCase(rtssReportId)); } // Get the teams HtmlNodeCollection teamNodes = documentNode.SelectNodes(@".//tr/td[contains(@class,'teamHeading + border')]"); string team1 = teamNodes[0].InnerText; string team2 = teamNodes[1].InnerText; // Get the tables that contain a header with '#' HtmlNodeCollection rosterTables = documentNode.SelectNodes(@".//table[tbody/tr/td[text()='#'] or tr/td[text()='#']]"); // Pull out the rows for rosters and scratches. Assume the order of: // 1. visitor roster // 2. home roster // 3. visitor scratches // 4. home scratches // Also, ignore the first rows because they are header fields. HtmlNodeCollection team1RosterNodes = null; HtmlNodeCollection team2RosterNodes = null; if (null != rosterTables && rosterTables.Count >= 2) { team1RosterNodes = rosterTables[0].SelectNodes(@".//tr[position() > 1]"); team2RosterNodes = rosterTables[1].SelectNodes(@".//tr[position() > 1]"); Assert.IsTrue(team1RosterNodes.Count > 10, "team1Roster count"); Assert.IsTrue(team2RosterNodes.Count > 10, "team2Roster count"); } HtmlNodeCollection scratchesNodes = documentNode.SelectNodes(@".//tr[@id='Scratches']/td"); HtmlNodeCollection team1ScratchesNodes = null; HtmlNodeCollection team2ScratchesNodes = null; if (null != scratchesNodes) { team1ScratchesNodes = scratchesNodes[0].SelectNodes(@"./table/tr[position() > 1] | ./table/tbody/tr[position() > 1]"); team2ScratchesNodes = scratchesNodes[1].SelectNodes(@"./table/tr[position() > 1] | ./table/tbody/tr[position() > 1]"); } // Parse the players out of the lists List <Nhl_Games_Rtss_RosterParticipantItem> team1Roster = NhlGamesRtssRoster.ParsePlayers(team1RosterNodes); List <Nhl_Games_Rtss_RosterParticipantItem> team2Roster = NhlGamesRtssRoster.ParsePlayers(team2RosterNodes); List <Nhl_Games_Rtss_RosterParticipantItem> team1Scratches = NhlGamesRtssRoster.ParsePlayers(team1ScratchesNodes); List <Nhl_Games_Rtss_RosterParticipantItem> team2Scratches = NhlGamesRtssRoster.ParsePlayers(team2ScratchesNodes); // Find the head coaches HtmlNodeCollection coachNodes = documentNode.SelectNodes(@".//tr[@id='HeadCoaches']/td/table/tbody/tr | .//tr[@id='HeadCoaches']/td/table/tr"); Nhl_Games_Rtss_RosterParticipantItem coach1 = NhlGamesRtssRoster.ParseCoach(coachNodes[0]); Nhl_Games_Rtss_RosterParticipantItem coach2 = NhlGamesRtssRoster.ParseCoach(coachNodes[1]); // Find the officials HtmlNode officialsTableNode = documentNode.SelectSingleNode(@".//table[tbody/tr/td[contains(text(),'Referee')] or tr/td[contains(text(),'Referee')]]"); HtmlNodeCollection officialsSubTableNodes = officialsTableNode.SelectNodes(@".//table"); HtmlNodeCollection refereesNodes = officialsSubTableNodes[0].SelectNodes(@".//tr"); HtmlNodeCollection linesmenNodes = officialsSubTableNodes[1].SelectNodes(@".//tr"); Nhl_Games_Rtss_RosterParticipantItem referee1 = null; if (refereesNodes != null && refereesNodes.Count >= 1) { referee1 = NhlGamesRtssRoster.ParseReferee(refereesNodes[0]); } Nhl_Games_Rtss_RosterParticipantItem referee2 = null; if (refereesNodes != null && refereesNodes.Count >= 2) { referee2 = NhlGamesRtssRoster.ParseReferee(refereesNodes[1]); } Nhl_Games_Rtss_RosterParticipantItem linesman1 = null; if (linesmenNodes != null && linesmenNodes.Count >= 1) { linesman1 = NhlGamesRtssRoster.ParseLinesman(linesmenNodes[0]); } Nhl_Games_Rtss_RosterParticipantItem linesman2 = null; if (linesmenNodes != null && linesmenNodes.Count >= 2) { linesman2 = NhlGamesRtssRoster.ParseLinesman(linesmenNodes[1]); } // Check for standby officials HtmlNodeCollection standbyOfficialsNodes1 = officialsSubTableNodes[2].SelectNodes(@".//tr"); HtmlNodeCollection standbyOfficialsNodes2 = officialsSubTableNodes[3].SelectNodes(@".//tr"); if (null != standbyOfficialsNodes1 || null != standbyOfficialsNodes2) { Console.WriteLine("Encountered potential standby officials in RTSS report {0}", rtssReportId); } // Fill out the model model.VisitorHeadCoach = new List <Nhl_Games_Rtss_RosterParticipantItem> { coach1 }; model.HomeHeadCoach = new List <Nhl_Games_Rtss_RosterParticipantItem> { coach2 }; model.VisitorRoster = team1Roster; model.HomeRoster = team2Roster; model.VisitorScratches = team1Scratches; model.HomeScratches = team2Scratches; model.Linesman = new List <Nhl_Games_Rtss_RosterParticipantItem> { linesman1, linesman2 }; model.Referees = new List <Nhl_Games_Rtss_RosterParticipantItem> { referee1, referee2 }; return(model); }