示例#1
0
        public bool CheckIfTimestampAlreadyProcessed(long timestamp)
        {
            Pulls pulls = new Pulls(timestamp, 0, 0);

            if (pulls.Unixtime > pulls.getLastPull(sqlConn.CreateCommand()))
            {
                return(false);
            }
            return(true);
        }
示例#2
0
        private void insertAhItem(WowAPI.AhItem[] items, long unixtime)
        {
            // Insert into pulls the info
            Pulls pulls = new Pulls(unixtime, newItems.Count, items.Length);

            if (pulls.Unixtime > pulls.getLastPull(sqlConn.CreateCommand()))
            {
                pulls.InsertData(sqlConn.CreateCommand());

                int itemCount   = 0;
                int itemQueries = 0;

                StringBuilder sbAuctions = new StringBuilder();
                StringBuilder sbItems    = new StringBuilder();

                sbAuctions.Append("INSERT IGNORE INTO auctions (auctionId, itemId, owner, realm, bid, buyout, ppu_bid, ppu_buyout, quantity) VALUES ");
                sbItems.Append("INSERT IGNORE INTO items (itemId, name, class, subClass) VALUES ");

                Logger.Write(LogType.INFO, "Creating SQL query for " + items.Length.ToString() + " auctions.");

                for (int i = 0; i < items.Length; i++)
                {
                    // Check if we are having a new item which doesn't exist in database yet
                    if (!(checkIfItemExists(items[i].ItemID)) && !(newItemIds.Contains(items[i].ItemID)))
                    {
                        newItemIds.Add(items[i].ItemID);

                        // If we want to ignore queries... Ignore :-D
                        if (Config.GetString("ignoreNewItemQueries") != "true")
                        {
                            WowAPI.WowItem newItem = itemQuery.getItemFromBlizzard(items[i].ItemID);
                            itemQueries++;

                            // If wow api doesn't know the ID, report it and skip it
                            if (newItem == null)
                            {
                                insertInvalidItemId(items[i].ItemID);
                            }
                            else
                            {
                                newItems.Add(newItem);
                            }
                        }
                        else
                        {
                            Logger.Write(LogType.WARNING, "ignoreNewItemQueries = true, ignoring Blizzard Web Api queries and not adding new items to database!");
                        }


                        if (Config.GetString("logToConsole") == "true")
                        {
                            Console.SetCursorPosition(0, Console.CursorTop);
                            Console.Write("Itemqueries from Blizzard API: " + newItems.Count.ToString());
                        }
                    }

                    sbAuctions.Append("('");
                    sbAuctions.Append(items[i].AuctionID.ToString());
                    sbAuctions.Append("', ");

                    sbAuctions.Append("");
                    sbAuctions.Append(items[i].ItemID);
                    sbAuctions.Append(", ");

                    sbAuctions.Append("'");
                    sbAuctions.Append(items[i].Owner.ToString());
                    sbAuctions.Append("', ");

                    sbAuctions.Append("'");
                    sbAuctions.Append(items[i].Realm.ToString());
                    sbAuctions.Append("', ");

                    sbAuctions.Append("'");
                    sbAuctions.Append(items[i].Bid.ToString());
                    sbAuctions.Append("', ");

                    sbAuctions.Append("'");
                    sbAuctions.Append(items[i].Buyout.ToString());
                    sbAuctions.Append("', ");

                    sbAuctions.Append("'");
                    sbAuctions.Append(items[i].PricePerUnitBid.ToString());
                    sbAuctions.Append("', ");

                    sbAuctions.Append("'");
                    sbAuctions.Append(items[i].PricePerUnitBuyout.ToString());
                    sbAuctions.Append("', ");

                    sbAuctions.Append("'");
                    sbAuctions.Append(items[i].Quantity.ToString());

                    if (items.Length - 1 == i)
                    {
                        sbAuctions.Append("');");
                    }
                    else
                    {
                        sbAuctions.Append("'), ");
                    }

                    itemCount++;
                }

                // Insert new items if any
                if (newItems.Count != 0)
                {
                    Logger.Write(LogType.INFO, "Creating SQL query for " + newItems.Count.ToString() + " new items.");

                    for (int i = 0; i < newItems.Count; i++)
                    {
                        sbItems.Append("(");
                        sbItems.Append(newItems[i].ItemID);
                        sbItems.Append(", ");

                        sbItems.Append("'");
                        sbItems.Append(newItems[i].Name);
                        sbItems.Append("', ");

                        sbItems.Append("");
                        sbItems.Append(newItems[i].Class);
                        sbItems.Append(", ");

                        sbItems.Append("");
                        sbItems.Append(newItems[i].SubClass);


                        if (newItems.Count - 1 == i)
                        {
                            sbItems.Append(");");
                        }
                        else
                        {
                            sbItems.Append("), ");
                        }
                    }
                }

                MySqlCommand sqlCommand = sqlConn.CreateCommand();

                Logger.Write(LogType.INFO, "Adding " + itemCount.ToString() + " auctions to the database.");
                sqlCommand.CommandText = sbAuctions.ToString();


                try
                {
                    sqlCommand.ExecuteNonQuery();
                }
                catch (MySqlException ex)
                {
                    // Packet too big, max_allowed_packet
                    if (ex.Number == 1153)
                    {
                        Logger.Write(LogType.FATAL, "Unable to insert query of size " + sqlCommand.CommandText.Length + " to database. Make sure to set max_allowed_packet high enough from my.ini.");
                    }
                    else
                    {
                        Logger.Write(LogType.ERROR, "Unable to insert auctions to database: " + ex.Message);
                    }
                }
                finally
                {
                    sqlCommand.Dispose();
                }


                if (newItems.Count != 0)
                {
                    Logger.Write(LogType.INFO, "Adding " + newItems.Count.ToString() + " new items to the database.");

                    try
                    {
                        sqlCommand             = sqlConn.CreateCommand();
                        sqlCommand.CommandText = sbItems.ToString();
                        sqlCommand.ExecuteNonQuery();
                    }
                    catch (MySqlException ex)
                    {
                        Logger.Write(LogType.ERROR, "Unable to add new items to database: " + ex.Message);
                    }
                    finally
                    {
                        sqlCommand.Dispose();
                    }
                }
                else
                {
                    Logger.Write(LogType.INFO, "No new items.");
                }
            }
            else
            {
                Logger.Write(LogType.WARNING, string.Format("Auctiondata timestamped {0} is already added to database. Not adding twice.", pulls.Unixtime));
            }
        }