public void ParseUnitsInVillage(ServerInfo serverInfo, int villageId) { /* <tr> <td><a href="build.php?gid=16"><img class="unit u15" src="img/x.gif" alt="Paladinov" title="Paladinov" /></a></td> <td class="u_count"><b>747</b></td> <td class="u_name">Paladinov</td> </tr> */ const string patternUnits = @"<td class=""u_count""><b>(\d+)</b></td>(.|[\r\n])*?<td class=""u_name"">((\w*)(\s*)(\w*))</td>"; //const string patternUnits = @"<b>(\d+)</b></td><td>((\w*)(\s*)(\w*))</td>"; MatchCollection unitsCollection = Regex.Matches(pageSource, patternUnits); //Console.WriteLine("unitsCollection.Count=" + unitsCollection.Count); Village village = serverInfo.GetVillage(villageId); village.RemoveVillageUnits(); for (int i = 0; i < unitsCollection.Count; i++) { //Console.WriteLine("0" + unitsCollection[i].Groups[0].Value.Trim()); //Console.WriteLine("1" + unitsCollection[i].Groups[1].Value.Trim()); //Console.WriteLine("2" + unitsCollection[i].Groups[2].Value.Trim()); //Console.WriteLine("3" + unitsCollection[i].Groups[3].Value.Trim()); //Console.WriteLine("4" + unitsCollection[i].Groups[4].Value.Trim()); string unitName = unitsCollection[i].Groups[4].Value.Trim(); int unitCount = Int32.Parse(unitsCollection[i].Groups[1].Value.Trim()); Unit unit = new Unit(unitCount, unitName); village.AddVillageUnit(unit); } }
public void AddVillageUnit(Unit unit) { villageUnits.Add(unit); }