Exemple #1
0
        public static void PopulateGoodBrowser(Mouser.Domain.ApplicationContext context, Good good)
        {
            Random rnd     = new Random();
            int    proxyId = rnd.Next(2, 5);
            Proxy  proxy   = context.Proxies.Find(proxyId);

            if (proxy == null)
            {
                return;
            }

            WebProxy wp = new WebProxy(proxy.IPAddress, true);

            if (proxy.UserName != "")
            {
                ICredentials credentials = new NetworkCredential(proxy.UserName, proxy.Password);
                wp.Credentials = credentials;
            }

            var    web1 = new HtmlWeb();
            string url  = good.ProductDetailUrl.Replace("ru.", "").Replace("eu.", "");

            //NetworkCredential networkCredential = new NetworkCredential(proxy.UserName, proxy.Password);
            //var doc2 = web1.Load(url, "GET", wp, networkCredential);

            var doc1 = web1.LoadFromBrowser(HttpUtility.UrlDecode(url), o =>
            {
                var webBrowser = (WebBrowser)o;
                // WAIT until the dynamic text is set
                return(!string.IsNullOrEmpty(webBrowser.Document.GetElementById("mlnkMailTo").InnerText));
            });

            if (
                !String.IsNullOrEmpty(doc1.Text) &&
                !doc1.Text.Contains("<meta name=\"ROBOTS\" content=\"NOINDEX, NOFOLLOW\">") &&
                !doc1.Text.Contains("{\"success\":false,\"error")
                )
            {
                good.IsWebDownloaded = true;
                GoodData goodData = context.GoodDatas.FirstOrDefault(g => g.Good.Id == good.Id);
                if (goodData != null)
                {
                    goodData.Response     = doc1.Text;
                    goodData.CreationDate = DateTime.Now;
                    goodData.Url          = url;
                }
                else
                {
                    context.GoodDatas.Add(new GoodData {
                        CreationDate = DateTime.Now, Good = good, Response = doc1.Text, Url = url
                    });
                }
            }
            else
            {
                context.GoodDataErrors.Add(new GoodDataError {
                    CreationDate = DateTime.Now, Good = good, Response = doc1.Text, Url = url
                });
            }
            context.SaveChangesAsync();
        }
Exemple #2
0
 private async void gridView1_RowUpdated(object sender, DevExpress.XtraGrid.Views.Base.RowObjectEventArgs e)
 {
     await dbContext.SaveChangesAsync();
 }