Esempio n. 1
0
        protected void __Go2FormNSubmitQuery(ref System.Windows.Forms.WebBrowser oBrowser, String sQuery, String sUrl, String sInputId, String sBtnId)
        {
            CountedWait oCWTimer = new CountedWait(ref oBrowser, 3000);
            Int32 iErrorCount = 0;
            while (true)
            {
                try
                {
                    HtmlDocument oDocument = oDocLoader.loadDocument(ref oBrowser, sUrl);
                    HtmlElement oQueryInput = oDocument.GetElementById(sInputId);
                    HtmlElement oQuerySubmit = oDocument.GetElementById(sBtnId);
                    if (oQueryInput == null || oQuerySubmit == null)
                    {
                        throw new Exception("Submition form elements not found, retrying");
                    }
                    oQueryInput.InvokeMember("click");
                    oQueryInput.InvokeMember("focus");
                    oQueryInput.SetAttribute("value", sQuery);
                    oQuerySubmit.InvokeMember("click");

                    if (oCWTimer.Wait(10))
                    {
                        TimedWait oTimedWait = new TimedWait(oRandomizer.Next(10000, 30000));
                        oTimedWait.Wait();
                        return;
                    }
                    else
                    {
                        //System.Console.WriteLine("Proxy timeout, switching to next one.");
                        wininet.RefreshIEProxySettings();
                    }
                    iErrorCount = 0;
                }
                catch (UnauthorizedAccessException ex)
                {
                    throw new UnauthorizedAccessException("Unauthorized access to HTML properties, aborting operation", ex);
                }
                catch (AccessViolationException ex)
                {
                    throw new AccessViolationException("Access Violation, aborting operation", ex);
                }
                catch (Exception ex)
                {
                    System.Console.WriteLine("..::" + this.GetType().Name + "::..__Go2FormNSubmitQuery thrown an exception, reason:  " + ex.Message + ", switching proxy");
                    wininet.RefreshIEProxySettings();
                }
                finally
                {
                    iErrorCount++;
                    if (iErrorCount > 10)
                    {
                        throw new Exception("Too much errors in __Go2FormNSubmitQuery, aborting...");
                    }
                }
            }
        }
Esempio n. 2
0
 protected void NavigateToSite(HtmlElement oLink, ref WebBrowser oBrowser)
 {
     CountedWait oCWTimer = new CountedWait(ref oBrowser, 3000);
     while (true)
     {
         try
         {
             sSiteToNavigate = oLink.GetAttribute("href");
             oLink.InvokeMember("click");
             if (oCWTimer.Wait(10))
             {
                 bSiteFound = true;
                 TimedWait oTimedWait = new TimedWait(oRandomizer.Next(10000, 30000));
                 oTimedWait.Wait();
                 return;
             }
             else
             {
                 //System.Console.WriteLine("Proxy timeout, switching to next one.");
                 wininet.RefreshIEProxySettings();
             }
         }
         catch (UnauthorizedAccessException ex)
         {
             throw new UnauthorizedAccessException("..::" + this.GetType().Name + "::..NavigateToSite thrown an exception", ex);
         }
         catch (AccessViolationException ex)
         {
             throw new AccessViolationException("..::" + this.GetType().Name + "::..NavigateToSite thrown an exception", ex);
         }
         catch (Exception ex)
         {
             System.Console.WriteLine("..::" + this.GetType().Name + "::..NavigateToSite thrown an exception, reason:  " + ex.Message + ", switching proxy");
             wininet.RefreshIEProxySettings();
         }
     }
 }
Esempio n. 3
0
        protected void OpenNewWindow(object sender, CancelEventArgs e)
        {
            System.Windows.Forms.WebBrowser oTmpBrowser = (System.Windows.Forms.WebBrowser)sender;
            oDocLoader.loadDocument(ref oTmpBrowser, sSiteToNavigate);
            e.Cancel = true;

            bSiteFound = true;
            TimedWait oTimer = new TimedWait(oRandomizer.Next(10000, 30000));
            oTimer.Wait();
            return;
        }
Esempio n. 4
0
        protected void GoToNextPage(HtmlElement oLink, ref WebBrowser oBrowser)
        {
            CountedWait oCWTimer = new CountedWait(ref oBrowser, 3000);
            while (true)
            {
                try
                {
                    // Below line added to rise UnauthorizedAccessException in case something went wrong
                    String sHREF = oLink.GetAttribute("href");

                    oLink.InvokeMember("click");
                    if (oCWTimer.Wait(10))
                    {
                        TimedWait oTimedWait = new TimedWait(oRandomizer.Next(8000, 14000));
                        oTimedWait.Wait();
                        return;
                    }
                    else
                    {
                        //System.Console.WriteLine("Proxy timeout, switching to next one.");
                        wininet.RefreshIEProxySettings();
                    }
                }
                catch (UnauthorizedAccessException ex)
                {
                    throw new UnauthorizedAccessException("Unauthorized access to HTML properties, aborting operation", ex);
                }
                catch (AccessViolationException ex)
                {
                    throw new AccessViolationException("Access Violation, aborting operation", ex);
                }
                catch (Exception ex)
                {
                    System.Console.WriteLine("..::" + this.GetType().Name + "::..GoToNextPage thrown an exception, reason:  " + ex.Message + ", switching proxy");
                    wininet.RefreshIEProxySettings();
                }
            }
        }