Exemplo n.º 1
0
 private void WebBrowserOnLoadCompleted(object sender, NavigationEventArgs navigationEventArgs)
 {
     EasyAnalyze esAnalyze = new EasyAnalyze();
     esAnalyze.GoToPage(textBox.Text);
 }
Exemplo n.º 2
0
        private void MyAnalyze()
        {
            List<Product> listProductsSend;
            if (countProverok > 0 && listProducts == null)
            {
                countProverok++;
                textBlock.Dispatcher.BeginInvoke(new Action(delegate ()
                {
                    textBlock.DataContext = null;
                    textBlock.Text = "Идет проверка №" + countProverok;
                }));
                List<Product> listProducts2;
                EasyAnalyze esAnalyze = new EasyAnalyze();
                listProducts = esAnalyze.GoToPage(urlSite);

                if (!File.Exists("Products.json"))
                {
                    //первый запуск
                    try
                    {
                        File.WriteAllText(@"Products.json", JsonConvert.SerializeObject(listProducts));
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Ошибка записи файла. " + ex.Message);
                    }


                }
                else
                {
                    listProducts2 = JsonConvert.DeserializeObject<List<Product>>(File.ReadAllText("Products.json"));
                    

                    var differences = listProducts2.Where(l2 => listProducts.Any(l1 => l1.Id == l2.Id && l1.Price != l2.Price)).ToList();

                    listProductsSend = listProducts2.Except(listProducts, new ProductComparer()).ToList();
                    listProductsSend.AddRange(differences);
                    listProductsSend.AddRange(listProducts.Except(listProducts2, new ProductComparer()).ToList());
                    if (listProductsSend.Count > 0)
                    {
                        string allprod = "";
                        foreach (var prod in listProductsSend)
                        {
                            prod.Url = Regex.Replace(prod.Url, @"vk.com/wkview\.php\?act=show&al=1&loc=market-([0-9]{1,22}?)&w=product-([0-9)]{1,33})",
                                "vk.com/market-$1?w=product-$2");
                            allprod = allprod + " | " + prod.Name + " | " + prod.Price + " | " + prod.Url + " ; \n\r ";
                        }
                        Email.SendMail(login, pass, osn, allprod);
                        try
                        {
                            File.WriteAllText(@"Products.json", JsonConvert.SerializeObject(listProducts));
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Файл не записался. " + ex.Message);
                        }

                    }

                }
                

                listProducts = null;

                //Distinct(new ProductComparer()).ToList(); ;
            }
            else if (countProverok == 0 && listProducts == null)
            {
                textBlock.Dispatcher.BeginInvoke(new Action(delegate ()
                {
                    textBlock.DataContext = null;
                    textBlock.Text = "Первичный сбор информации";
                }));
                
                EasyAnalyze esAnalyze = new EasyAnalyze();
                listProducts = esAnalyze.GoToPage(urlSite);

                if (!File.Exists("Products.json"))
                {
                    File.WriteAllText(@"Products.json", JsonConvert.SerializeObject(listProducts));

                }

                countProverok++;
                listProducts = null;
            }
            
        }