public static Dictionary <string, Player> GetPlayerInfoFromParticipants(ICarnoServiceSink sink, string s) { List <WikiNode> nodes = WikiParser.Parse(s).ToList(); var participants = new Dictionary <string, Player>(); bool taking = false; foreach (var node in nodes) { if (node.IsSection()) { taking = ((node as WikiTextNode).Text == "Participants"); } if (taking && node is WikiTableNode) { foreach (var cell in (node as WikiTableNode).Cells) { var cellnodes = (from cellnode in cell where cellnode is WikiTemplateNode let nodetemplate = cellnode as WikiTemplateNode orderby nodetemplate.Name select nodetemplate).ToList(); if (cellnodes.Count == 0 || cellnodes.Count > 2 || cellnodes[0].Name.ToLower() != "player") { continue; } WikiTemplateNode player = cellnodes[0]; string playerId = GetPlayerId(player); string team = "noteam"; if (cellnodes.Count == 2) { WikiTemplateNode temppart = cellnodes[1]; team = temppart.Name.From("TeamPart/"); team = sink.ConformTeamId(team); } Player info = new Player(); info.Id = player.GetParamText("1"); info.Flag = player.GetParamText("flag"); info.Team = team; info.Link = LiquipediaUtils.NormaliseLink(GetPlayerLink(player.GetParamText("link"))); participants[playerId] = info; if (!string.IsNullOrEmpty(info.Link)) { sink.SetIdLinkMap(info.Id, info.Link); } } } } return(participants); }
private static string GetPlayerId(WikiTemplateNode template) { if (template.Name != "Player" && template.Name != "Playersp") { throw new ArgumentOutOfRangeException("template"); } string playerId = template.GetParamText("1"); if (!string.IsNullOrEmpty(GetPlayerLink(template.GetParamText("link")))) { playerId = LiquipediaUtils.NormaliseLink(template.GetParamText("link")); } return(playerId); }
void ICarnoServiceSink.SetIdLinkMap(string id, string link) { idLinkMap[id] = LiquipediaUtils.NormaliseLink(link); }