예제 #1
0
        private async void LoadReleaseNotes(List <AppCastItem> items)
        {
            AppCastItem latestVersion = items.OrderByDescending(p => p.Version).FirstOrDefault();
            string      releaseNotes  = await _releaseNotesGrabber.DownloadAllReleaseNotes(items, latestVersion, _cancellationToken);

            wbChangeLog.Invoke((MethodInvoker) delegate
            {
                // see https://stackoverflow.com/a/15209861/3938401
                wbChangeLog.Navigate("about:blank");
                wbChangeLog.Document.OpenNew(true);
                wbChangeLog.Document.Write(releaseNotes);
                wbChangeLog.DocumentText = releaseNotes;
            });
        }
예제 #2
0
 private void timeOutDo()
 {
     if (webBrowser.InvokeRequired)
     {
         webBrowser.Invoke(new MyJsBridgeForm.InNoneOutVoidDelegate(timeOutDo));
         return;
     }
     else
     {
         //  webBrowser.Stop();
         if (MyJsBridgeForm.isShowErrHtml)
         {
             webBrowser.Navigate(errHtml);
         }
     }
 }
예제 #3
0
        public DocBrowser()
        {
            InitializeComponent();

            // Create the webBrowser control on the UserControl.
            // This code was moved from the designer for cut and paste
            // ease.
            webBrowser1             = new System.Windows.Forms.WebBrowser();
            webBrowser1.Dock        = System.Windows.Forms.DockStyle.Fill;
            webBrowser1.Location    = new System.Drawing.Point(0, 0);
            webBrowser1.MinimumSize = new System.Drawing.Size(200, 200);
            webBrowser1.Name        = "webBrowser1";
            webBrowser1.Size        = new System.Drawing.Size(532, 514);
            webBrowser1.TabIndex    = 0;
            Controls.Add(webBrowser1);
            webBrowser1.Invoke(new Action(delegate() { Controls.Add(webBrowser1); }));


            // set up an event handler to delete our temp file when we're done with it.
            webBrowser1.DocumentCompleted += webBrowser1_DocumentCompleted;
        }
예제 #4
0
        private void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            string urlAdd  = "https://rd.tencent.com/top/ptlogin/ptlogins/login?site=";
            string urlAdd2 = "https://tapd.tencent.com/ptlogin/ptlogins/login?";

            if ((webBrowser.Url != null && webBrowser.Url.ToString().Contains(urlAdd)) || (webBrowser.Url != null && webBrowser.Url.ToString().Contains(urlAdd2)))
            {
                //判断是否已加载完网页
                if (webBrowser.ReadyState == WebBrowserReadyState.Complete)
                {
                    //获取网页文档对象,相当于获取网页的全部源码
                    HtmlDocument htmlDoc = this.webBrowser.Document;
                    //设置帐号
                    HtmlElement id = htmlDoc.GetElementById("username");
                    id.SetAttribute("value", FrmSet.UserName);
                    //设置密码
                    HtmlElement pwd = htmlDoc.GetElementById("password_input");
                    pwd.SetAttribute("value", FrmSet.PassWord);
                    //登录
                    HtmlElement btn = htmlDoc.GetElementById("login_button");
                    if (btn != null)
                    {
                        btn.InvokeMember("click");
                    }
                }
            }
            // 根据id找到对应的元素
            HtmlElement htmlEle = webBrowser.Document.GetElementById("checkout_btn");

            if (htmlEle != null)
            {
                // 激活html元素的 click 成员
                if (search)
                {
                    htmlEle.InvokeMember("click");
                }

                System.Threading.Thread submitT = new Thread(() =>
                {
                    Thread.Sleep(1000);

                    try
                    {
                        while (search)
                        {
                            webBrowser.Invoke(new Action(() =>
                            {
                                HtmlDocument cd           = webBrowser.Document;
                                HtmlElementCollection dhl = cd.GetElementsByTagName("BUTTON");

                                foreach (HtmlElement item in dhl)
                                {
                                    if (item.InnerText == "提交" || item.InnerText == "Submit")
                                    {
                                        item.InvokeMember("click");
                                        search = false;
                                        Share.wFiles.WriteString("WCO", "LastCheckOutTime", string.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now));

                                        showTipsDelegate();

                                        webBrowser.Dispose();
                                    }
                                }
                            }));

                            Thread.Sleep(1000);
                        }
                    }
                    catch (Exception ex)
                    {
                        LogUtil.WriteError(ex);
                    }
                });
                submitT.Start();
            }
        }
예제 #5
0
        private void pobierz(object browser)
        {
            System.Windows.Forms.WebBrowser bro = browser as System.Windows.Forms.WebBrowser;

            HtmlElementCollection coll = null;
            bool gotowy = false;

loop:
            try
            {
                bro.Invoke(new Action(() => { coll = bro.Document.GetElementsByTagName("span"); }));
                foreach (HtmlElement h in coll)
                {
                    if (h.InnerText == "DOKUMENT WYGENEROWANY")
                    {
                        gotowy = true;
                    }
                }
            }
            catch { goto loop; }
            if (gotowy == false)
            {
                goto loop;
            }

            HtmlElementCollection colls = null;


            bro.Invoke(new Action(() =>
            {
                try
                {
                    colls = bro.Document.GetElementsByTagName("a");
                    HtmlElementCollection szukajNazwy = bro.Document.GetElementsByTagName("span");
                    string nazwa = null;
                    foreach (HtmlElement span in szukajNazwy)
                    {
                        if (span.InnerText.ToString().Contains(".SWX"))
                        {
                            nazwa = span.InnerText.Substring(0, span.InnerText.Length - 4);
                        }
                    }

                    foreach (HtmlElement h in colls)
                    {
                        if (h.InnerText == "pobierz plik")
                        {
                            progressBar.Value++;

                            Uri url = new Uri(h.GetAttribute("href").ToString());

                            HttpWebRequest wr  = (HttpWebRequest)WebRequest.Create(url);
                            wr.Credentials     = CredentialCache.DefaultCredentials;
                            wr.CookieContainer = new CookieContainer();
                            Cookie cookie      = getCookie(bro.Document.Cookie);
                            wr.CookieContainer.Add(cookie);


                            HttpWebResponse ws = (HttpWebResponse)wr.GetResponse();

                            Stream stream = ws.GetResponseStream();

                            Stream output = new FileStream(sciezkaZapisu + "\\" + nazwa + ".SWZ", FileMode.OpenOrCreate);

                            stream.CopyTo(output);

                            stream.Close();
                            output.Close();


                            HtmlElementCollection inputs = bro.Document.GetElementsByTagName("input");

                            foreach (HtmlElement ht in inputs)
                            {
                                if (ht.GetAttribute("value").ToString() == "Zakończ →")
                                {
                                    webBrowser1.DocumentCompleted += webBrowser1_DocumentCompleted6;
                                    ht.InvokeMember("Click");
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MyMessageBox.Show("Treść błędu:\n" + ex.Message, "Błąd", MyMessageBoxButtons.Ok);
                    progressLabel.Content = "";
                    return;
                }
            }
                                  ));
        }
예제 #6
0
 private void setWbDocumentText(WebBrowser wb, string str)
 {
     if (wb.InvokeRequired)
     {
         wb.Invoke(setWbDT, wb, str);
     }
     else {
         wb.DocumentText = str;
     }
 }
예제 #7
0
        public string Navigate(string url, int timeout)
        {
            string gethtml = string.Empty;
            try
            {
                int interval = 500;
                using (WebBrowser browser = new WebBrowser())
                {
                    browser.ScriptErrorsSuppressed = false;
                    DateTime startTime = DateTime.Now;
                    bool isbusy = true;
                    int length = 0;
                    //browser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(browser_DocumentCompleted);
                    //browser.Navigating += new WebBrowserNavigatingEventHandler(browser_Navigating);
                    browser.Navigate(url);
                    while (browser.ReadyState != WebBrowserReadyState.Complete)
                    {
                        Application.DoEvents();
                        System.Diagnostics.Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss") + " Still Loading");
                    }

                    while (hitCount < 10)
                    {
                        double t = Math.Ceiling((DateTime.Now - startTime).TotalSeconds);
                        if (t >= timeout)
                        {
                            throw new Exception("Visiting about new exception delay, since the setting is timeout");
                        }

                        BrowserEventHandler browserEventHanler = delegate() { isbusy = !browser.IsBusy; };
                        browser.Invoke(browserEventHanler);

                        if (browser.Document.All["flight-info"] != null)
                        {
                            int len = 0;
                            if (!string.IsNullOrEmpty(browser.Document.All["flight-info"].InnerHtml))
                                len = browser.Document.All["flight-info"].InnerHtml.Length;
                            if (len == length)
                            {
                                hitCount++;
                            }
                            else
                            {
                                hitCount = 0; length = len;
                            }

                            //System.Diagnostics.Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss") + "->flight-info-:InnerHtml" + browser.Document.All["flight-info"].InnerHtml);
                        }

                        if (!string.IsNullOrEmpty(browser.Document.All["flight-info"].InnerHtml))
                            length = browser.Document.All["flight-info"].InnerHtml.Length;
                        Application.DoEvents();
                        System.Threading.Thread.Sleep(interval);
                    }

                    if (browser.Document.All["flight-info"] != null)
                    {
                        System.Diagnostics.Debug.Write("=".PadLeft(50, '='));
                        System.Diagnostics.Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss") + "->flight-info-:InnerHtml" + browser.Document.All["flight-info"].InnerHtml);
                        gethtml = browser.Document.All["flight-info"].InnerHtml;
                    }

                    //var htmldocument = (mshtml.HTMLDocument)browser.Document.DomDocument; System.Diagnostics.Debug.Write("=".PadLeft(50, '='));
                    //System.Diagnostics.Debug.WriteLine(htmldocument.documentElement.outerHTML); System.Diagnostics.Debug.Write("=".PadLeft(50, '='));
                    //System.Diagnostics.Debug.WriteLine(browser.Document.Body.OuterHtml);
                }
            }
            catch (Exception ex)
            {
                Log.LogErr(ex);
            }

            return gethtml;
        }
예제 #8
0
        public string Navigate(string url, int timeout, string flightHtmlElementID)
        {
            string gethtml = string.Empty;
            try
            {
                int interval = 500;
                using (WebBrowser browser = new WebBrowser())
                {
                    browser.ScriptErrorsSuppressed = false;

                    DateTime startTime = DateTime.Now;
                    bool isbusy = true;
                    int length = 0;
                    browser.Navigate(url);
                    while (browser.ReadyState != WebBrowserReadyState.Complete)
                    {
                        Application.DoEvents();
                        System.Diagnostics.Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss") + " Still Loading");
                        System.Threading.Thread.Sleep(interval);
                        double t = Math.Ceiling((DateTime.Now - startTime).TotalSeconds);
                        if (t >= timeout)
                        {
                            throw new Exception("Visiting about new exception delay, since the setting is timeout");
                        }
                    }

                    while (hitCount < 4)
                    {
                        double t = Math.Ceiling((DateTime.Now - startTime).TotalSeconds);
                        if (t >= timeout)
                        {
                            throw new Exception("Visiting about new exception delay, since the setting is timeout");
                        }

                        BrowserEventHandler browserEventHanler = delegate() { isbusy = !browser.IsBusy; };
                        browser.Invoke(browserEventHanler);

                        if (browser.Document.All[flightHtmlElementID] != null)
                        {
                            int len = 0;
                            if (!string.IsNullOrEmpty(browser.Document.All[flightHtmlElementID].InnerHtml))
                                len = browser.Document.All[flightHtmlElementID].InnerHtml.Length;
                            System.Diagnostics.Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss") + string.Format(" hitCnt:{0};len:{1};length:{2}", hitCount, len, length));

                            if (len == length)
                            {
                                hitCount++;
                            }
                            else
                            {
                                hitCount = 0; length = len;
                            }
                        }

                        if (!string.IsNullOrEmpty(browser.Document.All[flightHtmlElementID].InnerHtml))
                            length = browser.Document.All[flightHtmlElementID].InnerHtml.Length;
                        System.Diagnostics.Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss") + " begin DoEvents and Sleep");
                        //Application.DoEvents();
                        System.Threading.Thread.Sleep(interval);
                        System.Diagnostics.Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss") + " end DoEvents and Sleep");
                    }

                    if (browser.Document.All[flightHtmlElementID] != null)
                    {
                        gethtml = browser.Document.All[flightHtmlElementID].InnerHtml;
                    }
                }
            }
            catch (Exception ex)
            {
                Log.LogErr(ex);
            }

            return gethtml;
        }
예제 #9
0
        public void Navigate()
        {
            try
            {
                this.TextAsync = string.Empty;
                this.HTMLSourceCode = string.Empty;
                int interval = 500;
                Thread thread = new Thread(delegate()
                {
                    using (WebBrowser browser = new WebBrowser())
                    {
                        browser.ScriptErrorsSuppressed = false;
                        browser.ScrollBarsEnabled = false;
                        browser.AllowNavigation = true;
                        DateTime startTime = DateTime.Now;
                        bool isbusy = true;
                        bool isRefresh = false;
                        // bool completed = false;
                        int count = 6;
                        int index = 0;
                        int length = 0;
                        browser.DocumentCompleted += new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(wb_DocumentCompleted);
                        do
                        {
                            //browser.DocumentCompleted += delegate(object sender, WebBrowserDocumentCompletedEventArgs e)
                            //{
                            //    this.HTMLSourceCode = browser.Document.Body.OuterHtml;
                            //    string url0 = browser.Document.Url.ToString();
                            //    completed = url0.Equals(e.Url.ToString());
                            //};

                            if (!isRefresh)
                                browser.Navigate(url);
                            while (browser.ReadyState != WebBrowserReadyState.Complete || !browser.StatusText.Equals("Done"))
                                System.Windows.Forms.Application.DoEvents();
                            if (this.completed)
                                this.TextAsync = browser.Document.Body.OuterHtml;
                            string strRegex = "(?<ITEM><figure class=\"flight-info none\" id=\"flight-info\" style=\"display: block;\">)[\\S\\s]*?(?=</figure>)";
                            Regex re = new Regex(strRegex, RegexOptions.IgnoreCase | RegexOptions.Multiline);
                            Match mc = re.Match(this.TextAsync);
                            if (mc.Length > 0)
                            {
                                System.Diagnostics.Debug.WriteLine(mc.Value);
                                break;
                            }
                            else
                                isRefresh = true;

                            if (browser.ReadyState == WebBrowserReadyState.Complete && browser.StatusText.Equals("Done"))
                            {
                                System.Windows.Forms.Application.DoEvents();
                                BrowserEventHandler browserEventHanler = delegate() { isbusy = !browser.IsBusy; };
                                browser.Invoke(browserEventHanler);

                                //try
                                //{
                                //    browser.Document.InvokeScript("flight.submit()");
                                //    isRefresh = true;
                                //    completed = false;
                                //}
                                //catch (Exception ex)
                                //{
                                //    System.Diagnostics.Debug.Write(ex);
                                //}
                            }

                            if (!isbusy)
                            {
                                int len = browser.Document.Body.OuterHtml.Length;
                                if (len == length) { index++; }
                                else { index = 0; length = len; }
                                if (index == count) { isbusy = false; }
                            }

                            if (this.completed)
                                length = browser.Document.Body.OuterHtml.Length;
                            System.Threading.Thread.Sleep(interval);
                            double t = Math.Ceiling((DateTime.Now - startTime).TotalSeconds);
                            if (t >= this.timeout)
                            {
                                this.Error = new Exception("Visiting about new exception delay, since the setting is timeout");
                                break;
                            }
                        } while (isbusy);
                    }
                });
                thread.SetApartmentState(ApartmentState.STA);
                thread.Start();
                thread.Join();
            }
            catch (Exception ex) { throw ex; }
        }
예제 #10
0
        public static object WaitForCondition(WebBrowser browser, Func<object> check_condition, int mss)
        {
            if (browser.InvokeRequired)
                return browser.Invoke(new delegateWaitForCondition(WaitForCondition), browser, check_condition, mss);

            DateTime timeout = DateTime.Now.AddMilliseconds(mss);
            while(DateTime.Now < timeout)
            {
                if (browser.Document != null && browser.Document.Body != null)
                {
                    object o = check_condition();
                    if (o != null)
                        return o;
                }
                ThreadRoutines.Wait(20);
            }
            return null;
        }
예제 #11
0
        private void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            try
            {
                string urlAdd = "https://api.weibo.com/oauth2/authorize";

                if ((webBrowser.Url != null && webBrowser.Url.ToString().Contains(urlAdd)))
                {
                    //判断是否已加载完网页
                    if (webBrowser.ReadyState == WebBrowserReadyState.Complete)
                    {
                        try
                        {
                            //获取网页文档对象,相当于获取网页的全部源码
                            HtmlDocument htmlDoc = webBrowser.Document;
                            //设置帐号
                            HtmlElement id = htmlDoc.GetElementById("userId");
                            id.SetAttribute("value", passport);
                            //设置密码
                            HtmlElement pwd = htmlDoc.GetElementById("passwd");
                            pwd.SetAttribute("value", password);
                            //登录

                            HtmlDocument          cd  = webBrowser.Document;
                            HtmlElementCollection dhl = cd.GetElementsByTagName("a");

                            foreach (HtmlElement item in dhl)
                            {
                                if (item.GetAttribute("action-type").Equals("submit"))
                                {
                                    item.InvokeMember("click");
                                    break;
                                }
                            }
                            HtmlElement btn = htmlDoc.GetElementById("submit");
                            if (btn != null)
                            {
                                btn.InvokeMember("click");
                            }
                        }
                        catch (Exception ex)
                        {
                            LogUtil.WriteError(ex);
                        }
                    }
                }
                // 根据id找到对应的元素
                string oauth2Url = "https://api.weibo.com/oauth2/default.html?code=";

                if ((webBrowser.Url != null && webBrowser.Url.ToString().Contains(oauth2Url)))
                {
                    //MessageBox.Show(webBrowser.Url.ToString());
                    var      url  = webBrowser.Url.ToString();
                    char[]   cha  = { '=' };
                    string[] strs = url.Split(cha, StringSplitOptions.RemoveEmptyEntries);
                    if (strs.Count() == 2)
                    {
                        Code = strs[1];
                        try
                        {
                            AccessToken accessToken = o.GetAccessTokenByAuthorizationCode(strs[1]); //请注意这里返回的是AccessToken对象,不是string
                            Share.wFiles.WriteString("WCO", "AcessToken", CryptHelper.EncryptString(oauth.AccessToken));
                            if (submitT != null && submitT.IsAlive)
                            {
                                submitT.Abort();
                            }
                            webBrowser.Dispose();
                        }
                        catch (WeiboException ex)
                        {
                            Console.WriteLine(ex.Message);
                            if (submitT != null && submitT.IsAlive)
                            {
                                submitT.Abort();
                            }
                            webBrowser.Dispose();
                        }
                    }
                }
                string authorizeUrl = "https://api.weibo.com/oauth2/authorize";
                submitT = new Thread(() =>
                {
                    Thread.Sleep(1000);
                    bool search = true;
                    while (search)
                    {
                        if (!webBrowser.IsHandleCreated)
                        {
                            return;
                        }
                        webBrowser.Invoke(new Action(() =>
                        {
                            if (webBrowser.Url != null && webBrowser.Url.ToString() == authorizeUrl)
                            {
                                HtmlDocument cd           = webBrowser.Document;
                                HtmlElementCollection dhl = cd.GetElementsByTagName("a");

                                foreach (HtmlElement item in dhl)
                                {
                                    if (item.GetAttribute("action-type").Equals("submit"))
                                    {
                                        item.InvokeMember("click");
                                        search = false;
                                        break;
                                    }
                                }
                            }
                        }));

                        Thread.Sleep(500);
                    }
                });
                submitT.Start();
            }
            catch (Exception ex)
            {
                LogUtil.WriteError(ex);
            }
        }