public void CalculatorSourceOverPercent()
        {
            DeserializeLanguage();
            Language language = Languages.GetLanguage("sl-SI");
            Assert.IsNotNull(language, "Language is null!");

            HtmlDocument htmlDocument = new HtmlDocument();
            htmlDocument.Load("..\\..\\Test Files\\Marketplace.php.html");
            HtmlParser htmlParser = new HtmlParser(htmlDocument, language);
            MarketPlace marketPlaceDestination = htmlParser.MarketPlace();
            Assert.IsNotNull(marketPlaceDestination, "NULL");
            Village destinationVillage = new Village();
            destinationVillage.AddId(123).AddName("01");
            Production productionDestination = htmlParser.GetProduction();
            Assert.IsNotNull(productionDestination, "NULL");
            destinationVillage.UpdateProduction(productionDestination);

            htmlDocument = new HtmlDocument();
            htmlDocument.Load("..\\..\\Test Files\\Marketplace.idle.php.html");
            htmlParser = new HtmlParser(htmlDocument, language);
            MarketPlace marketPlaceSource = htmlParser.MarketPlace();
            Assert.IsNotNull(marketPlaceSource, "NULL");
            Village sourceVillage = new Village();
            sourceVillage.AddId(321).AddName("02");
            Production productionSource = htmlParser.GetProduction();
            Assert.IsNotNull(productionSource, "NULL");
            sourceVillage.UpdateProduction(productionSource);

            DateTime dt = new DateTime(DateTime.Now.Ticks);
            MarketPlaceQueue queue = new MarketPlaceQueue
            {
                DestinationVillage = destinationVillage,
                SourceVillage = sourceVillage,
                Goods = 50,
                GoodsToSend = 750,
                SendWood = true,
                SendClay = true,
                SendIron = true,
                SendCrop = true,
                SendGoodsType = SendGoodsType.SourceOverPercent,
                LastSend = dt.AddHours(-2),
                RepeatMinutes = 10,
            };

            MarketPlaceCalculator calculator = new MarketPlaceCalculator
            {
                Destination = destinationVillage,
                Source = sourceVillage,
                MarketPlaceDestination = marketPlaceDestination,
                MarketPlaceSource = marketPlaceSource,
                Queue = queue,
            };
            calculator.CalculateSourceOver();
            Assert.AreEqual("&r1=750&r2=750&r3=0&r4=750", calculator.PostParameters, "PostParameters");
            Assert.IsTrue(calculator.TimeToSend(dt), "Last send time");
        }
Beispiel #2
0
 /// <summary>
 /// Sends the resources ifmarketplace queue is active.
 /// </summary>
 private void SendResources()
 {
     List<MarketPlaceQueue> newQueue = new List<MarketPlaceQueue>();
     DateTime dt = new DateTime(DateTime.Now.Ticks);
     foreach (MarketPlaceQueue queue in actions.MarketPlaceQueue)
     {
         MarketPlaceCalculator calculator = new MarketPlaceCalculator(account, htmlDocument, htmlWeb, queue,
                                                                      settings, languages);
         if (queue.SendGoodsType == SendGoodsType.Repeat)
         {
             if (calculator.TimeToSendRepeat(dt))
             {
                 calculator.ParseUnknownDestination();
                 calculator.CalculateUnknownDestination();
                 string process = calculator.Process();
                 if (process.Length > 5)
                 {
                     UpdateStatus(process);
                 }
                 MarketPlaceQueue updated = queue;
                 updated.LastSend = dt;
                 newQueue.Add(updated);
             }
             else
             {
                 newQueue.Add(queue);
             }
         }
         else
         {
             if (calculator.TimeToSend(dt))
             {
                 calculator.Parse();
                 if (queue.SendGoodsType == SendGoodsType.DestinationBellowPercent)
                 {
                     calculator.Calculate();
                 }
                 if (queue.SendGoodsType == SendGoodsType.SourceOverPercent)
                 {
                     calculator.CalculateSourceOver();
                 }
                 string process = calculator.Process();
                 if (process.Length > 5)
                 {
                     UpdateStatus(process);
                     MarketPlaceQueue updated = queue;
                     updated.LastSend = dt;
                     newQueue.Add(updated);
                 }
                 else
                 {
                     newQueue.Add(queue);
                 }
             }
             else
             {
                 newQueue.Add(queue);
             }
         }
         //wait 2-5 seconds before processing with the next action
         Thread.Sleep(new Random().Next(2000, 5000));
     }
     actions.MarketPlaceQueue.Clear();
     actions.MarketPlaceQueue.AddRange(newQueue);
     SerializeActions();
 }