Пример #1
0
        private void wizard_Load(object sender, EventArgs e)
        {
            mysql = new SQLMethods(Settings.Default.MySQLHost, Settings.Default.MySQLPort, Settings.Default.MySQLUsername, Settings.Default.MySQLPassword);

            if (!editor)
            {
                qualityComboBoxEX.SelectedIndex = 0;
                itemTypeComboBoxEX.SelectedIndex = 0;
                itemBindsComboBoxEX.SelectedIndex = 0;

                skillProfressionComboBoxEX.SelectedIndex = 0;

                //Test MySQL Connection

                wizardPage1.NextButtonEnabled = eWizardButtonState.False;

                MySQLConnProgressBarX.Enabled = true;
                MySQLConnProgressBarX.Visible = true;

                MySQLConnLabelX.Visible = true;

                MySQLConnBackgroundWorker.RunWorkerAsync();

            }
            else
            {
                //Get Item Information

                wizardPage1.NextButtonEnabled = eWizardButtonState.False;

                MySQLConnProgressBarX.Enabled = true;
                MySQLConnProgressBarX.Visible = true;

                MySQLConnLabelX.Visible = true;
                MySQLConnLabelX.Text = "Getting Item Information...";

                itemInfoBackgroundWorker.RunWorkerAsync();

            }
        }
Пример #2
0
        public static void Crawl(string[] args, Website website)
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            log4net.Config.XmlConfigurator.Configure();

            //A list of (generic) shopping items we will search for during crawl
            List <Uri>    URLList             = new List <Uri>();
            List <string> genericProductNames = SQLMethods.GetGenericProductNames();

            //Testing
            //List<string> genericProductNames = new List<string>();
            //genericProductNames.Add( "Juice" );

            foreach (string genericProductName in genericProductNames)
            {
                //0 items have been added for this product
                addCounter = 0;

                //Product category that will be stored in db = the generic item
                category = genericProductName;

                //Some sites can't handle spaces in URL, so replace with a '+'
                Uri siteUri = new Uri(website.Root + genericProductName.Replace(" ", "+"));

                Uri uriToCrawl = siteUri;

                IWebCrawler crawler;

                //Walmart works well with the manually configured webcrawler
                if (website.Root.Contains("walmart"))
                {
                    crawler = GetManuallyConfiguredWebCrawler(siteToCrawl);
                }

                //Loblaw owned sites need some extra 'checks' in each URL, so use custom crawler in this case
                else
                {
                    crawler = GetCustomBehaviorUsingLambdaWebCrawler();
                }

                //Subscribe to any of these asynchronous events, there are also sychronous versions of each.
                //This is where you process data about specific events of the crawl
                crawler.PageCrawlStartingAsync        += crawler_ProcessPageCrawlStarting;
                crawler.PageCrawlCompletedAsync       += crawler_ProcessPageCrawlCompleted;
                crawler.PageCrawlDisallowedAsync      += crawler_PageCrawlDisallowed;
                crawler.PageLinksCrawlDisallowedAsync += crawler_PageLinksCrawlDisallowed;

                //This is a synchronous call
                CrawlResult result = crawler.Crawl(uriToCrawl);

                //If we haven't added at least 3 items, recrawl double the number of sites
                if (addCounter <= 2)
                {
                    Console.WriteLine("Recrawling: " + category);
                    website.NumberOfSitesToCrawl = website.NumberOfSitesToCrawl + 10;

                    //Walmart works well with the manually configured webcrawler
                    if (website.Root.Contains("walmart"))
                    {
                        crawler = GetManuallyConfiguredWebCrawler(siteToCrawl);
                    }

                    //Loblaw owned sites need some extra 'checks' in each URL, so use custom crawler in this case
                    else
                    {
                        crawler = GetCustomBehaviorUsingLambdaWebCrawler();
                    }

                    crawler.PageCrawlStartingAsync        += crawler_ProcessPageCrawlStarting;
                    crawler.PageCrawlCompletedAsync       += crawler_ProcessPageCrawlCompleted;
                    crawler.PageCrawlDisallowedAsync      += crawler_PageCrawlDisallowed;
                    crawler.PageLinksCrawlDisallowedAsync += crawler_PageLinksCrawlDisallowed;

                    result = crawler.Crawl(uriToCrawl);
                }

                //Console.Read();
            }
        }
Пример #3
0
        private void WeaponCreator_Load(object sender, EventArgs e)
        {
            //Set Default Values

            qualityComboBoxEx.SelectedIndex = 0;
            equipComboBoxEx.SelectedIndex = 0;
            materialComboBoxEx.SelectedIndex = 0;
            bindsComboBoxEx.SelectedIndex = 0;

            mysql = new SQLMethods(Settings.Default.MySQLHost, Settings.Default.MySQLPort, Settings.Default.MySQLUsername, Settings.Default.MySQLPassword);

            if (!editor)
            {
                //Test MySQL Connection

                wizardPage1.NextButtonEnabled = eWizardButtonState.False;

                MySQLConnProgressBarX.Enabled = true;
                MySQLConnProgressBarX.Visible = true;

                MySQLConnLabelX.Visible = true;

                MySQLConnBackgroundWorker.RunWorkerAsync();
            }
            else
            {
                //Get Item Information

                wizardPage1.NextButtonEnabled = eWizardButtonState.False;

                MySQLConnProgressBarX.Enabled = true;
                MySQLConnProgressBarX.Visible = true;

                MySQLConnLabelX.Visible = true;
                MySQLConnLabelX.Text = "Getting Armor Information...";

                armorInfoBackgroundWorker.RunWorkerAsync();
            }
        }
Пример #4
0
        private void SetProgramType(bool start = true)
        {
            mysql = new SQLMethods(Settings.Default.MySQLHost, Settings.Default.MySQLPort,
            Settings.Default.MySQLUsername, Settings.Default.MySQLPassword);

            if (Settings.Default.raEnabled)
            {
                startServerButtonItem.Enabled = false;
                stopServerButtonItem.Enabled = false;

                backupDBButtonItem.Enabled = false;
                restoreDBButtonItem.Enabled = false;

                compileButtonItem.Enabled = false;

                if (Settings.Default.raHost == String.Empty || Settings.Default.raPort == 0 ||
                Settings.Default.raUsername == String.Empty || Settings.Default.raPassword == String.Empty ||
                Settings.Default.MySQLHost == String.Empty || Settings.Default.MySQLPort == 0 ||
                Settings.Default.MySQLUsername == String.Empty || Settings.Default.MySQLPassword == String.Empty)
                {
                    using (var uSettings = new UserSettings())
                    {
                        uSettings.WizardFinished += uSettings_WizardFinished;

                        uSettings.ShowDialog();
                    }
                }
                else
                {
                    if (start)
                        SetupRAConnection();

                    refreshValuesTimer.Enabled = true;
                }
            }
            else
            {
                backupDBButtonItem.Enabled = true;
                restoreDBButtonItem.Enabled = true;

                startServerButtonItem.Enabled = true;
                stopServerButtonItem.Enabled = false;

                compileButtonItem.Enabled = true;

                if (Settings.Default.trinityFolder == String.Empty || Settings.Default.MySQLHost == String.Empty ||
                Settings.Default.MySQLPort == 0 || Settings.Default.MySQLUsername == String.Empty ||
                Settings.Default.MySQLPassword == String.Empty)
                {
                    using (var uSettings = new UserSettings())
                    {
                        uSettings.WizardFinished += uSettings_WizardFinished;

                        uSettings.ShowDialog();
                    }
                }
                else
                {
                    refreshValuesTimer.Enabled = true;
                }
            }
        }
Пример #5
0
        static void crawler_ProcessPageCrawlCompleted(object sender, PageCrawlCompletedArgs e)
        {
            {
                string      productName;
                string      productNameTwo = "";
                string      productPrice;
                string      productCategory;
                string      site;
                CrawledPage crawledPage = e.CrawledPage;

                //If the URL we're searching has a Food Item URL identifier, scrape the data
                var title = crawledPage.AngleSharpHtmlDocument.GetElementsByClassName(siteToCrawl.ProductTitleIdentifier);
                var price = crawledPage.AngleSharpHtmlDocument.GetElementsByClassName(siteToCrawl.ProductPriceIdentifier);
                if (title.Length < 1)
                {
                    return;
                }

                /*if (crawledPage.WebException != null || crawledPage.HttpWebResponse.StatusCode != HttpStatusCode.OK)
                 *  Console.WriteLine("Crawl of page failed {0}", crawledPage.Uri.AbsoluteUri);
                 * else
                 *  Console.WriteLine(  );
                 *  Console.WriteLine("Crawl of page succeeded {0}", crawledPage.Uri.AbsoluteUri);*/

                if (crawledPage.Uri.AbsoluteUri.Contains("walmart"))
                {
                    productName  = title[0].TextContent;
                    price        = crawledPage.AngleSharpHtmlDocument.GetElementsByClassName(siteToCrawl.ProductPriceIdentifier);
                    productPrice = price[0].ParentElement.TextContent;
                }
                else
                {
                    productName    = title[1].Children[1].TextContent;
                    productNameTwo = title[1].Children[0].InnerHtml;
                    price          = crawledPage.AngleSharpHtmlDocument.GetElementsByClassName(siteToCrawl.ProductPriceIdentifier);
                    productPrice   = price[0].InnerHtml;
                }

                var pluralCategory   = category + "s";
                var singularCategory = category.Remove(category.Length - 1);

                if (productNameTwo.ToLower().Contains(category.ToLower()))
                {
                    productName = productNameTwo;
                }

                if (crawledPage.Uri.ToString().Contains(singularCategory.Replace(" ", "+")) &&
                    (productName.ToLower().Contains(category.ToLower()) ||
                     productName.ToLower().Contains(singularCategory.ToLower()) ||
                     productName.ToLower().Contains(pluralCategory.ToLower())))
                {
                    Console.WriteLine("Crawling: " + crawledPage.Uri.ToString() + " for: " + category);
                    site            = crawledPage.ParentUri.Host;
                    productCategory = category;

                    /*Console.WriteLine();
                     * Console.WriteLine("********************************");
                     * Console.WriteLine("Would insert:");
                     * Console.WriteLine(productName);
                     * Console.WriteLine(productPrice);
                     * Console.WriteLine("********************************");
                     * Console.WriteLine();
                     * Console.Read();*/

                    //Item added!
                    addCounter++;

                    //Send the scraped data for this specific listing to the SQL Database
                    SQLMethods.InsertProductRecord(productName, productCategory, productPrice, site);
                }
            }
        }
Пример #6
0
        private void SendMail_Load(object sender, EventArgs e)
        {
            mysql = new SQLMethods(Settings.Default.MySQLHost, Settings.Default.MySQLPort, Settings.Default.MySQLUsername, Settings.Default.MySQLPassword);

            mysqlBackgroundWorker.RunWorkerAsync();
        }
Пример #7
0
 private void SearchNPCID_Load(object sender, EventArgs e)
 {
     mysql = new SQLMethods(Settings.Default.MySQLHost, Settings.Default.MySQLPort, Settings.Default.MySQLUsername, Settings.Default.MySQLPassword);
 }
Пример #8
0
        private bool ParseServerDetails(IPEndPoint remote, byte[] data)
        {
            string key          = String.Format("{0}:{1}", remote.Address, remote.Port);
            string receivedData = Encoding.UTF8.GetString(data);

            //Console.WriteLine(receivedData.Replace("\x00", "\\x00").Replace("\x02", "\\x02"));

            // split by 000 (info/player separator) and 002 (players/teams separator)
            // the players/teams separator is really 00, but because 00 may also be used elsewhere (an empty value for example), we hardcode it to 002
            // the 2 is the size of the teams, for BF2 this is always 2.
            string[] sections = receivedData.Split(new string[] { "\x00\x00\x00", "\x00\x00\x02" }, StringSplitOptions.None);

            //Console.WriteLine(sections.Length);

            if (sections.Length != 3 && !receivedData.EndsWith("\x00\x00"))
            {
                return(true);                // true means we don't send back a response
            }
            string serverVars = sections[0];

            //string playerVars = sections[1];
            //string teamVars = sections[2];

            string[] serverVarsSplit = serverVars.Split(new string[] { "\x00" }, StringSplitOptions.None);

            GameServer server = new GameServer()
            {
                Valid         = false,
                IPAddress     = remote.Address.ToString(),
                QueryPort     = remote.Port,
                LastRefreshed = DateTime.UtcNow,
                LastPing      = DateTime.UtcNow
            };

            // set the country based off ip address
            if (GeoIP.Instance == null || GeoIP.Instance.Reader == null)
            {
                server.country = "??";
            }
            else
            {
                try {
                    server.country = GeoIP.Instance.Reader.Omni(server.IPAddress).Country.IsoCode.ToUpperInvariant();
                } catch (Exception e) {
                    LogError(Category, e.ToString());
                    server.country = "??";
                }
            }

            for (int i = 0; i < serverVarsSplit.Length - 1; i += 2)
            {
                PropertyInfo property = server.GetType().GetProperty(serverVarsSplit[i]);

                if (property == null)
                {
                    continue;
                }

                if (property.Name == "hostname")
                {
                    // strip consecutive whitespace from hostname
                    property.SetValue(server, Regex.Replace(serverVarsSplit[i + 1], @"\s+", " ").Trim(), null);
                }
                else if (property.Name == "bf2_plasma")
                {
                    // set plasma to true if the ip is in plasmaservers.txt
                    if (PlasmaServers.Any(x => x.Equals(remote.Address)))
                    {
                        property.SetValue(server, true, null);
                    }
                    else
                    {
                        property.SetValue(server, false, null);
                    }
                }
                else if (property.Name == "bf2_ranked")
                {
                    // we're always a ranked server (helps for mods with a default bf2 main menu, and default filters wanting ranked servers)
                    property.SetValue(server, true, null);
                }
                else if (property.Name == "bf2_pure")
                {
                    // we're always a pure server
                    property.SetValue(server, true, null);
                }
                else if (property.PropertyType == typeof(Boolean))
                {
                    // parse string to bool (values come in as 1 or 0)
                    int value;
                    if (Int32.TryParse(serverVarsSplit[i + 1], NumberStyles.Integer, CultureInfo.InvariantCulture, out value))
                    {
                        property.SetValue(server, value != 0, null);
                    }
                }
                else if (property.PropertyType == typeof(Int32))
                {
                    // parse string to int
                    int value;
                    if (Int32.TryParse(serverVarsSplit[i + 1], NumberStyles.Integer, CultureInfo.InvariantCulture, out value))
                    {
                        property.SetValue(server, value, null);
                    }
                }
                else if (property.PropertyType == typeof(Double))
                {
                    // parse string to double
                    double value;
                    if (Double.TryParse(serverVarsSplit[i + 1], NumberStyles.Float, CultureInfo.InvariantCulture, out value))
                    {
                        property.SetValue(server, value, null);
                    }
                }
                else if (property.PropertyType == typeof(String))
                {
                    // parse string to string
                    property.SetValue(server, serverVarsSplit[i + 1], null);
                }
            }

            if (String.IsNullOrWhiteSpace(server.gamename) || !server.gamename.Equals("battlefield2", StringComparison.InvariantCultureIgnoreCase))
            {
                // only allow servers with a gamename of battlefield2
                return(true);                // true means we don't send back a response
            }
            else if (String.IsNullOrWhiteSpace(server.gamevariant) || !ModWhitelist.ToList().Any(x => SQLMethods.EvaluateIsLike(server.gamevariant, x)))
            {
                // only allow servers with a gamevariant of those listed in modwhitelist.txt, or (pr || pr_*) by default
                return(true);                // true means we don't send back a response
            }

            // you've got to have all these properties in order for your server to be valid
            if (!String.IsNullOrWhiteSpace(server.hostname) &&
                !String.IsNullOrWhiteSpace(server.gamevariant) &&
                !String.IsNullOrWhiteSpace(server.gamever) &&
                !String.IsNullOrWhiteSpace(server.gametype) &&
                !String.IsNullOrWhiteSpace(server.mapname) &&
                server.hostport > 1024 && server.hostport <= UInt16.MaxValue &&
                server.maxplayers > 0)
            {
                server.Valid = true;
            }

            // if the server list doesn't contain this server, we need to return false in order to send a challenge
            // if the server replies back with the good challenge, it'll be added in AddValidServer
            if (!Servers.ContainsKey(key))
            {
                return(false);
            }

            Servers.AddOrUpdate(key, server, (k, old) => {
                if (!old.Valid && server.Valid)
                {
                    Log(Category, String.Format("Added new server at: {0}:{1} ({2}) ({3})", server.IPAddress, server.QueryPort, server.country, server.gamevariant));
                }

                return(server);
            });

            return(true);
        }
Пример #9
0
        private void LootCreator_Load(object sender, EventArgs e)
        {
            mysql = new SQLMethods(Settings.Default.MySQLHost, Settings.Default.MySQLPort, Settings.Default.MySQLUsername, Settings.Default.MySQLPassword);

            bool testMySQL = mysql.TestMySQLConnection();

            if (!testMySQL)
            {
                TaskDialog.Show(new TaskDialogInfo("Error", eTaskDialogIcon.Stop, "Could Not Connect To MySQL", String.Empty, eTaskDialogButton.Ok));

                finished = true;

                this.Close();
            }

            if (editor)
            {
                lootInfoBackgroundWorker.RunWorkerAsync();
            }
        }
Пример #10
0
        private void restoreDBBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            string loc = String.Empty;

            foreach (string f in Directory.GetFiles(String.Format("{0}\\TrinityCore Manager\\backups", Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments))))
            {
                if (String.Format("{0:T}", GetDate(f)) == e.Argument.ToString())
                {
                    loc = f;
                }
            }

            if (loc != String.Empty && File.Exists(loc))
            {
                mysql = new SQLMethods(Settings.Default.MySQLHost, Settings.Default.MySQLPort, Settings.Default.MySQLUsername, Settings.Default.MySQLPassword);

                if (mysql != null)
                {
                    try
                    {
                        mysql.ExecuteMySQLScript(loc);

                        restoreSuccess = true;

                    }
                    catch (Exception ex)
                    {
                        TaskDialog.Show(new TaskDialogInfo("Error", eTaskDialogIcon.Stop, "Error!", ex.Message, eTaskDialogButton.Ok));
                    }
                }

            }
        }
Пример #11
0
        private void NPCCreator_Load(object sender, EventArgs e)
        {
            //Set Default Values

            rankComboBoxEx.SelectedIndex = 0;
            factionComboBoxEx.SelectedIndex = 0;
            typeComboBoxEx.SelectedIndex = 0;
            familyComboItemEx.SelectedIndex = 0;
            classComboBoxEx.SelectedIndex = 0;
            aiNameComboBoxEx.SelectedIndex = 0;
            movementTypeComboBoxEx.SelectedIndex = 0;
            inhabitComboBoxEx.SelectedIndex = 0;

            mysql = new SQLMethods(Settings.Default.MySQLHost, Settings.Default.MySQLPort, Settings.Default.MySQLUsername, Settings.Default.MySQLPassword);

            if (!editor)
            {
                //Test MySQL Connection

                wizardPage1.NextButtonEnabled = eWizardButtonState.False;

                MySQLConnProgressBarX.Enabled = true;
                MySQLConnProgressBarX.Visible = true;

                MySQLConnLabelX.Visible = true;

                MySQLConnBackgroundWorker.RunWorkerAsync();
            }
            else
            {
                //Get Item Information

                wizardPage1.NextButtonEnabled = eWizardButtonState.False;

                MySQLConnProgressBarX.Enabled = true;
                MySQLConnProgressBarX.Visible = true;

                MySQLConnLabelX.Visible = true;
                MySQLConnLabelX.Text = "Getting NPC Information...";

                npcInfoBackgroundWorker.RunWorkerAsync();
            }
        }
Пример #12
0
        private void SearchDisplayID_Load(object sender, EventArgs e)
        {
            itemsListBox.SelectedIndexChanged += new EventHandler(itemsListBox_SelectedIndexChanged);

            mysql = new SQLMethods(Settings.Default.MySQLHost, Settings.Default.MySQLPort, Settings.Default.MySQLUsername, Settings.Default.MySQLPassword);
        }