Exemplo n.º 1
0
        public void ParseAvailableVillages()
        {
            HtmlDocument htmlDocument = new HtmlDocument();
            htmlDocument.Load("..\\..\\Test Files\\dorf1.php.html");
            HtmlParser htmlParser = new HtmlParser(htmlDocument);
            List<Village> villages = htmlParser.GetAvailableVillages();
            Assert.IsNotNull(villages, "villages is null!");
            Assert.AreEqual(2, villages.Count, "Villages count!");
            Assert.AreEqual(-82, villages[0].CoordinateX, "CoordinateX!");
            Assert.AreEqual(64, villages[0].CoordinateY, "CoordinateY!");

            htmlDocument.Load("..\\..\\Test Files\\dorf1.php.1.village.html");
            htmlParser = new HtmlParser(htmlDocument);
            villages = htmlParser.GetAvailableVillages();
            Assert.IsNotNull(villages, "villages is null!");
            Assert.AreEqual(1, villages.Count, "Villages count!");
            Assert.AreEqual(0, villages[0].CoordinateX, "CoordinateX!");
            Assert.AreEqual(0, villages[0].CoordinateY, "CoordinateY!");
        }
Exemplo n.º 2
0
 /// <summary>
 /// Updates the account info.
 /// </summary>
 private void UpdateAccountInfo()
 {
     UpdateStatus("UpdateAccountInfo");
     HtmlParser htmlParser = new HtmlParser(htmlDocument);
     List<Village> villages = htmlParser.GetAvailableVillages();
     string servername = settings.LoginData.Servername;
     if (villages.Count == 1)
     {
         string url = String.Format(CultureInfo.InvariantCulture, "{0}karte.php", servername);
         htmlDocument = htmlWeb.Load(url);
         //<h1>Zemljevid(<span id="x">-31</span>|<span id="y">-25</span>)</h1>
         HtmlNode htmlNode = htmlDocument.DocumentNode.SelectSingleNode("//h1");
         if (htmlNode != null)
         {
             HtmlNode nodeX = htmlDocument.DocumentNode.SelectSingleNode("//span[@id='x']");
             if (nodeX != null)
             {
                 villages[0].CoordinateX = Misc.String2Number(nodeX.InnerText.Trim());
             }
             HtmlNode nodeY = htmlDocument.DocumentNode.SelectSingleNode("//span[@id='y']");
             if (nodeY != null)
             {
                 villages[0].CoordinateY = Misc.String2Number(nodeY.InnerText.Trim());
             }
         }
     }
     account.UpdateVillages(villages);
     foreach (Village village in villages)
     {
         string url = String.Format(CultureInfo.InvariantCulture, "{0}dorf1.php?newdid={1}",
                                    servername, village.Id);
         htmlDocument = htmlWeb.Load(url);
         htmlParser = new HtmlParser(htmlDocument);
         Production production = htmlParser.GetProduction();
         village.UpdateProduction(production);
         Troops availableTroops = htmlParser.GetAvailableTroops();
         village.UpdateTroopsInVillage(availableTroops);
     }
     List<BuildQueue> list = new List<BuildQueue>();
     foreach (BuildQueue buildQueue in actions.BuildQueue)
     {
         string url = String.Format(CultureInfo.InvariantCulture, "{0}build.php?newdid={1}&id={2}",
                                    servername, buildQueue.VillageId, buildQueue.BuildingId);
         htmlDocument = htmlWeb.Load(url);
         htmlParser = new HtmlParser(htmlDocument);
         buildQueue.Resources = htmlParser.GetResourcesForNextLevel();
         if (buildQueue.Level > buildQueue.Resources.CurrentLevel)
         {
             list.Add(buildQueue);
         }
         else
         {
             UpdateStatus("Removing " + buildQueue);
         }
     }
     actions.BuildQueue = list;
     SerializeActions();
     UpdateListBoxBuildQueues(listBoxBuildQueues);
     UpdateComboBoxVillages(comboBoxMapVillages);
     UpdateComboBoxVillages(comboBoxRallyPointVillages);
     UpdateComboBoxVillages(comboBoxBuildQueueVillages);
     UpdateComboBoxVillages(comboBoxMarketPlaceSourceVillage);
     UpdateComboBoxVillages(comboBoxMarketPlaceDestinationVillage);
     UpdateComboBoxVillages(comboBoxMarketPlaceRepeatSourceVillage);
 }