Пример #1
0
        private static bool isAddable(HtmlAgilityPack.HtmlDocument doc, List <string> categories, int i, HtmlNode itemPriceNode, HtmlNode itemStrengthNode)
        {
            bool pageExists = DwarAPI.pageExists("http://w1.dwar.ru/artifact_info.php?artikul_id=" + i);

            if (!pageExists)
            {
                return(false);
            }

            bool notNullPrice = ((itemPriceNode != null) && (itemPriceNode.SelectNodes("span") != null));

            if (!notNullPrice)
            {
                return(false);
            }

            bool itemIsInCategories = categories.Contains(doc.DocumentNode.SelectSingleNode("//*[@title='Тип предмета']").InnerText);

            if (!itemIsInCategories)
            {
                return(false);
            }

            bool itemIsTransportable = !doc.DocumentNode.Descendants("td").Where(d => d.Attributes.Contains("class") && d.Attributes["class"].Value.Contains("redd") && d.InnerText == "Предмет нельзя передать").Any <HtmlNode>();

            if (!itemIsTransportable)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Пример #2
0
        private static void addItems(List <HtmlNode> nodes, MySqlCommand command)
        {
            DateTime localDateTime;
            DateTime lotExpiration;
            string   localDateTimeStr;

            foreach (HtmlNode item in nodes)
            {
                try
                {
                    localDateTime        = DateTime.UtcNow.ToUniversalTime();
                    localDateTimeStr     = localDateTime.ToString("yyyy-MM-dd HH:mm:ss");
                    lotExpiration        = lotEndTime(item, localDateTime);
                    command.CommandText += "('" + Convert.ToInt64(item.SelectSingleNode("td[7]/descendant::input[2]").GetAttributeValue("aid", "")) + "','" + item.SelectSingleNode("td[2]/a").InnerText + "','"
                                           + item.SelectSingleNode("td[2]/span[1]").InnerText.TrimStart() + "','" + item.SelectSingleNode("td[2]/span[2]").InnerText.Remove(0, item.SelectSingleNode("td[2]/span[2]").InnerText.IndexOf('/') + 1) + "','" + item.SelectSingleNode("td[5]").InnerText + "','"
                                           + DwarAPI.getMoney(item.SelectSingleNode("td[6]")) + "','" + DwarAPI.getMoney(item.SelectSingleNode("td[7]")) + "','" + DwarAPI.getMoney(item.SelectSingleNode("td[8]")) + "','"
                                           + localDateTimeStr + "','" + lotExpiration.ToString("yyyy-MM-dd HH:mm:ss") + "','" + localDateTimeStr + "','"
                                           + (int)(lotExpiration - localDateTime).TotalSeconds + "','" + "1" + "'),";
                }
                catch (NullReferenceException exception)
                {
                    // globals.dwarLog.Error(exception.Message + " " + exception.StackTrace + " " + Thread.CurrentThread.ManagedThreadId);
                }
            }
        }
Пример #3
0
 private void button2_Click(object sender, EventArgs e)
 {
     try
     {
         DwarAPI.getCategories();
     }
     catch (Exception exception)
     {
         MessageBox.Show(exception.ToString());
     }
 }
Пример #4
0
 private void loginButton_Click(object sender, EventArgs e)
 {
     try
     {
         DwarAPI.login();
     }
     catch (Exception exception)
     {
         MessageBox.Show(exception.ToString());
     }
 }
Пример #5
0
        public static void scanItems()
        {
            globals.dwarLog.Trace("Сканирование началось; " + "ThreadID = " + Thread.CurrentThread.ManagedThreadId);
            MySqlConnection connection  = new MySqlConnection(globals.connectionString);
            MySqlConnection connection2 = new MySqlConnection(globals.connectionString);
            MySqlDataReader reader      = null;

            try
            {
                MySqlCommand command  = new MySqlCommand();
                MySqlCommand command2 = new MySqlCommand();

                string html;

                connection.Open();
                connection2.Open();
                command.Connection   = connection;
                command2.Connection  = connection2;
                command2.CommandText = "CREATE TABLE IF NOT EXISTS items (lotID BIGINT PRIMARY KEY, itemName NVARCHAR(50), itemCategory NVARCHAR(50), itemStrength INT(3), itemCount NVARCHAR(10), pricePerPiece NVARCHAR(50), itemBid NVARCHAR(50), itemBuyOut NVARCHAR(50), detectionTime DATETIME, lotEndTime DATETIME, lastUpdateTime DATETIME, secondsLeft INT, buyedOut TINYINT, subsists TINYINT);";
                command2.ExecuteNonQuery();
                command.CommandText = "SELECT browserValue FROM categories";
                reader = command.ExecuteReader();
                command2.CommandText = "INSERT INTO items (lotID, itemName, itemCategory, itemStrength, itemCount, pricePerPiece, itemBid, itemBuyOut, detectionTime, lotEndTime, lastUpdateTime, secondsLeft, subsists) VALUES";
                HtmlAgilityPack.HtmlDocument doc;
                while (reader.Read())
                {
                    html = DwarRequest.getRequest("http://" + globals.gameWorld + ".dwar.ru/area_auction.php?&_filter%5Btitle%5D=&_filter%5Bcount_min%5D=&_filter%5Bcount_max%5D=&_filter%5Blevel_min%5D=&_filter%5Blevel_max%5D=&_filter%5Bkind%5D=" + reader[0] + "&_filter%5Bquality%5D=-1&_filterapply=%D0%9E%D0%BA&page=0", ref cookie);
                    doc  = new HtmlAgilityPack.HtmlDocument();
                    doc.LoadHtml(html);
                    List <HtmlNode> items = getItemNodes(doc);
                    if (items == null)
                    {
                        continue;
                    }
                    int number = DwarAPI.pageCount(doc);

                    addItems(items, command2);

                    for (int i = 1; i < number; i++)
                    {
                        html = DwarRequest.getRequest("http://" + globals.gameWorld + ".dwar.ru/area_auction.php?&_filter%5Btitle%5D=&_filter%5Bcount_min%5D=&_filter%5Bcount_max%5D=&_filter%5Blevel_min%5D=&_filter%5Blevel_max%5D=&_filter%5Bkind%5D=" + reader[0] + "&_filter%5Bquality%5D=-1&_filterapply=%D0%9E%D0%BA&page=" + i, ref cookie);
                        doc  = new HtmlAgilityPack.HtmlDocument();
                        doc.LoadHtml(html);

                        items = getItemNodes(doc);
                        addItems(items, command2);
                    }
                }
                connection.Close();
                reader.Close();
                command2.CommandText = command2.CommandText.TrimEnd(',') + " ON DUPLICATE KEY UPDATE itemBid = VALUES(itemBid), lastUpdateTime = VALUES(lastUpdateTime), secondsLeft = TIMESTAMPDIFF(SECOND,'" + DateTime.UtcNow.ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ss") + "',lotEndTime);";
                command2.ExecuteNonQuery();
                command2.CommandText = "UPDATE items SET buyedOut = IF ('" + DateTime.UtcNow.ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ss") + "'>DATE_ADD(lotEndTime, INTERVAL " + globals.expectedAuctionScanningTime + " MINUTE),'2',IF('" + DateTime.UtcNow.ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ss") + "'>DATE_ADD(lastUpdateTime, INTERVAL " + globals.expectedAuctionScanningTime + " MINUTE),'1','0')) WHERE subsists='1'; UPDATE items SET subsists = '0' WHERE DATE_ADD(lastUpdateTime, INTERVAL " + globals.expectedAuctionScanningTime + " MINUTE)<'" + DateTime.UtcNow.ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ss") + "';";
                command2.ExecuteNonQuery();
                globals.dwarLog.Trace("Сканирование завершено; " + "ThreadID = " + Thread.CurrentThread.ManagedThreadId);
            }
            catch (Exception exception)
            {
                globals.dwarLog.Error(exception.Message + " " + exception.StackTrace + " " + Thread.CurrentThread.ManagedThreadId);
                MessageBox.Show(exception.Message + " " + exception.StackTrace + " " + Thread.CurrentThread.ManagedThreadId);
            }
            finally
            {
                if (connection.State != System.Data.ConnectionState.Closed)
                {
                    connection.Close();
                }
                if (connection2.State != System.Data.ConnectionState.Closed)
                {
                    connection2.Close();
                }
                if (reader != null && reader.IsClosed == false)
                {
                    reader.Close();
                }
            }
        }