Exemplo n.º 1
0
        private void btnNike_Click(object sender, RoutedEventArgs e)
        {
            Timeout = int.Parse(txtTimeout.Text);
            BackgroundWorker worker = new BackgroundWorker();

            worker.WorkerReportsProgress = true;
            worker.DoWork             += worker_DoWork;
            worker.ProgressChanged    += worker_ProgressChanged;
            worker.RunWorkerCompleted += worker_RunWorkerCompleted;
            WorkerArgument arg = new WorkerArgument();

            arg.Timeout = int.Parse(txtTimeout.Text);
            arg.Vendor  = "Nike";
            DataView dv = gridProduct.DataContext as DataView;

            arg.RowFilter = "description like '%nike.com%'";
            arg.Table     = dv;// dv.ToTable();
            worker.RunWorkerAsync(arg);
        }
Exemplo n.º 2
0
        void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            //DataTable dt = e.Result as DataTable;
            //openDataTable(dt);
            WorkerArgument arg = e.Result as WorkerArgument;

            if (arg.Vendor == "All" && ckScheduleMinute.IsChecked == true)
            {
                string outFile = automationExport();
                if (outFile != null)
                {
                    importToGoStuff(outFile, "http://gostuffs.com/web#model=product.template&action=import&menu_id=138", Timeout);
                }
            }
            else
            {
                lbPriceChangedCount.Text = arg.PriceChangedCount + " rows";
                lbInvalidPriceCount.Text = arg.InvalidPriceCount + " rows";
                MessageBox.Show("Done " + arg.Vendor);
            }
        }
Exemplo n.º 3
0
        void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            WorkerArgument arg = e.Argument as WorkerArgument;
            //killWebDriver();

            var options = new ChromeOptions();

            // ("ignoreDefaultArgs");
            options.AddExcludedArgument("enable-automation");
            options.AddArgument("no-sandbox");
            options.Proxy            = null;
            options.PageLoadStrategy = PageLoadStrategy.Eager;
            //options.AddExtension("extension_1_1_0_0.crx");
            IWebDriver wdr = new ChromeDriver(options);

            //int countChanges = 0;
            //int countInvalidChanges = 0;
            try
            {
                //timeout = arg.Timeout;
                DataView dv2 = arg.Table;// new DataView(arg.Table);
                DataView dv  = new DataView(dv2.Table);
                dv.RowFilter = arg.RowFilter;
                if (arg.Vendor == "Costco")
                {
                    loginCostco(wdr);
                }


                for (int i = 0; i < dv.Count; i++)
                {
                    if (arg.IsClearCookies)
                    {
                        wdr.Manage().Cookies.DeleteAllCookies();
                    }
                    DataRow dr = dv[i].Row;

                    //support re-run
                    if (
                        !(toPrice(dr[Product.STANDARD_PRICE].ToString()) <= 0 ||
                          dr[Product.SYNC_STATE].ToString() == "error" ||
                          dr[Product.IS_SPECIAL_PRODUCT].ToString() == Product.TRUE
                          )
                        )
                    {
                        continue;
                    }

                    string url = dr[Product.DESCRIPTION].ToString();
                    if (url.Contains("amazon"))
                    {
                        getAmazonPrice(wdr, url, dr);
                    }
                    else if (url.Contains("costco"))
                    {
                        getCostcoPrice(wdr, url, dr);
                    }
                    else if (url.Contains("walmart"))
                    {
                        getWalmartPrice(wdr, url, dr);
                    }
                    else if (url.Contains("ebay.com"))
                    {
                        getEbayPrice(wdr, url, dr);
                    }
                    else if (url.Contains("macys.com"))
                    {
                        getMacysPrice(wdr, url, dr);
                    }
                    else if (url.Contains("nike.com"))
                    {
                        getNikePrice(wdr, url, dr);
                    }
                    // color rows
                    // var dgr = gridProduct.ItemContainerGenerator.ContainerFromItem(dr.Row) as DataGridRow;
                    if (toPrice(dr[Product.STANDARD_PRICE].ToString()) <= 0)
                    {
                        dr[Product.SYNC_STATE] = "error";
                        arg.InvalidPriceCount++;
                        // dgr.Background = Brushes.LightPink;
                    }
                    else if (dr[Product.STANDARD_PRICE].ToString() != dr[Product.OLD_STANDARD_PRICE].ToString())
                    {
                        dr[Product.SYNC_STATE] = "changed";
                        arg.PriceChangedCount++;
                        //dgr.Background = Brushes.LightSeaGreen;
                    }
                    else
                    {
                        dr[Product.SYNC_STATE] = "same";
                    }
                    dr[Product.SYNC_DATE] = DateTime.Now.ToString("g");
                    stopBrowsing(wdr);
                }

                //lbPriceChangedCount.Text = countChanges + " rows";
                //lbInvalidPriceCount.Text = countInvalidChanges + " rows";
            }
            catch (Exception ex)
            {
                //MessageBox.Show(ex.ToString());
            }
            finally
            {
                try
                {
                    e.Result = arg;
                    wdr.Close();
                    wdr.Quit();
                }
                catch
                {
                    //suppress
                }
            }
        }