Beispiel #1
0
        void browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            browser = (WebBrowser)sender;
            if (browser.ReadyState != System.Windows.Forms.WebBrowserReadyState.Complete)
                return;
            if (e.Url.ToString() != browser.Url.ToString())
                return;
            if (browser.Url.ToString() == searchProductUrl)
            {

                detailProductUrl = null;
                HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument();
                document.LoadHtml(browser.DocumentText);
                HtmlNodeCollection nodes = document.DocumentNode.SelectNodes(RankQueryer.PRODUCT_LINK_PATH);
                for (int k = 0; k < nodes.Count; k++)
                {
                    HtmlNode aLinkNode = nodes[k];
                    string proId = aLinkNode.Attributes["data-pid"].Value;
                    int rankProductId = Convert.ToInt32(proId);
                    if (rankProductId == item.ProductId)
                    {
                        detailProductUrl = aLinkNode.Attributes["href"].Value;
                        break;
                    }
                }

                if (detailProductUrl != null && detailProductUrl != string.Empty)
                {
                    IEHandleUtils.Navigate(browser, detailProductUrl, null, additionalHeaders);
                }
                else
                {
                    if (currentPage == maxQueryPage)
                    {
                        this.canInquiry = false;
                        ClickedEvent(item, "The system does not find the product you need to click.");
                        string productUrl = item.ProductUrl.Substring(item.ProductUrl.LastIndexOf("/"));
                        detailProductUrl = PURL_PREFIX + item.ProductId + productUrl;
                        ClickingEvent(item, "Enforce clicking " + detailProductUrl);
                        browser.Document.InvokeScript("onProductClick", new string[] { item.ProductId.ToString() });
                        IEHandleUtils.Navigate(browser, detailProductUrl, null, additionalHeaders);
                    }
                    else
                    {
                        currentPage++;
                        searchProductUrl = string.Format(SEARCH_URL2, clickKey.Replace(" ", "_"), currentPage);
                        Thread.Sleep(new Random().Next(1000, 10000));
                        ClickingEvent(item, @"Clicking " + searchProductUrl);
                        IEHandleUtils.Navigate(browser, searchProductUrl, null, additionalHeaders);
                    }
                }
            }
            if (detailProductUrl != null && browser.Url.ToString() == detailProductUrl)
            {
                item.Clicked = item.Clicked + 1;
                ClickedEvent(item, "This product has been successfully click.");
                if (this.canInquiry)
                {
                    string messageUrl = "http://message.alibaba.com/msgsend/contact.htm?action=contact_action&domain=1&id="+ this.item.ProductId +"&tracelog=tracedetailfeedback";
                    IEHandleUtils.Navigate(browser, messageUrl, null, additionalHeaders);

                }
                else
                {
                    browser.DocumentCompleted -= new WebBrowserDocumentCompletedEventHandler(browser_DocumentCompleted);
                    eventX.Set();
                }
            }
            if (browser.Url.ToString().StartsWith(SEND_MESSAGE))
            {
                string postUrl = "http://message.alibaba.com/msgsend/inquiry.htm";
                //string html = browser.Document.Body.InnerHtml;
                string html = browser.DocumentText;
                string msgContent = inquiryMessage.Content + "\r\n." + DateTime.Now.ToString("yyyyMMddHHmmss");
                int randomNumber = new Random().Next(1, 20) * 100;
                string token = "_csrf_token_=" + browser.Document.All["_csrf_token_"].GetAttribute("value");
                string action = "action=SendMemberInquiryAction";
                string sh = "_fmm.b._0.sh=false";
                string pageId = "pageId=" + GetDmtrackPageid(html);
                string chkProductIds = "chkProductIds="+ browser.Document.All["chkProductIds"].GetAttribute("value");
                string s = "_fmm.b._0.s=" + browser.Document.GetElementById("subject").GetAttribute("value");
                string c = "_fmm.b._0.c=<p>" + msgContent.Replace("\r\n", "<br>") + "<p>";
                string o = "_fmm.a._0.o=" + randomNumber + " Piece/Pieces";
                string attachs = "attachs=";
                string eventSubmitDoSend = "eventSubmitDoSend=Send";
                string postString = token + "&" + action + "&" + sh + "&" + pageId + "&" + chkProductIds + "&" + s + "&"
                       + c + "&" + o + "&" + attachs + "&" + eventSubmitDoSend;
                string headers = additionalHeaders + Environment.NewLine +
                       "Content-Type: application/x-www-form-urlencoded" + Environment.NewLine;
                IEHandleUtils.Navigate(browser, postUrl, postString, headers);
            }
            if (browser.Url.ToString().IndexOf(INQUIRY_SUCCESS) >= 0)
            {
                InquiryInfos info = new InquiryInfos();
                info.ProductId = item.ProductId;
                info.Account = aliAccount.Account;
                info.MsgId = inquiryMessage.MsgId;
                info.InquiryDate = Convert.ToInt32(DateTime.Now.ToString("yyyyMMdd"));
                info.Company = item.CompanyUrl;
                info.InquiryIp = aliAccount.LoginIp;
                InquiryEndEvent(info, "This product has been send a Rank Inquiry.");
                browser.DocumentCompleted -= new WebBrowserDocumentCompletedEventHandler(browser_DocumentCompleted);
                IEHandleUtils.Navigate(browser, LOGOUT_URL, null, additionalHeaders);
                eventX.Set();
            }
        }
Beispiel #2
0
 public void InsertInquiryInfos(InquiryInfos model)
 {
     string sql = @"INSERT INTO InquiryInfos(Account, ProductId, MsgId, Company, InquiryIp, InquiryDate)values(@Account,@ProductId,@MsgId,@Company,@InquiryIp,@InquiryDate)";
     SQLiteParameter[] parameter = new SQLiteParameter[]
     {
         new SQLiteParameter("@Account",model.Account),
         new SQLiteParameter("@ProductId", model.ProductId),
         new SQLiteParameter("@MsgId",model.MsgId),
         new SQLiteParameter("@Company",model.Company),
         new SQLiteParameter("@InquiryIp",model.InquiryIp),
         new SQLiteParameter("@InquiryDate",model.InquiryDate)
     };
     dbHelper.ExecuteNonQuery(sql, parameter);
 }
Beispiel #3
0
 public virtual void InquiryEndEvent(InquiryInfos kw, string msg)
 {
     if (OnInquiryEndEvent != null)
     {
         InquiryEventArgs e = new InquiryEventArgs(kw, msg);
         OnInquiryEndEvent(this, e);
     }
 }
Beispiel #4
0
 public InquiryEventArgs(InquiryInfos _obj, string _msg)
 {
     this.Item = _obj;
     this.Msg = _msg;
 }