示例#1
0
        public Boolean RefreshIEProxySettings()
        {
            System.Windows.Forms.WebBrowser oBrowser = new System.Windows.Forms.WebBrowser();
            oBrowser.ScriptErrorsSuppressed = true;
            CountedWait oCWTimer = new CountedWait(ref oBrowser, 4000);
            while (true)
            {
                try
                {
                    const int INTERNET_OPTION_PROXY_SETTINGS_CHANGED = 95;
                    const int INTERNET_OPTION_PROXY = 38;
                    const int INTERNET_OPEN_TYPE_PROXY = 3;

                    Struct_INTERNET_PROXY_INFO struct_IPI;
                    if (iProxyPos >= BlackSEOps.Properties.Settings.Default.Proxies.Count)
                        iProxyPos = 0;
                    String sProxy = BlackSEOps.Properties.Settings.Default.Proxies[iProxyPos];
                    iProxyPos++;
                    // Filling in structure
                    struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_PROXY;
                    struct_IPI.proxy = Marshal.StringToHGlobalAnsi(sProxy);
                    struct_IPI.proxyBypass = Marshal.StringToHGlobalAnsi("local");

                    // Allocating memory
                    IntPtr intptrStruct = Marshal.AllocCoTaskMem(Marshal.SizeOf(struct_IPI));

                    // Converting structure to IntPtr
                    Marshal.StructureToPtr(struct_IPI, intptrStruct, true);

                    InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY, intptrStruct, Marshal.SizeOf(struct_IPI));
                    Marshal.FreeHGlobal(struct_IPI.proxy);
                    Marshal.FreeHGlobal(struct_IPI.proxyBypass);
                    Marshal.FreeCoTaskMem(intptrStruct);
                    InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY_SETTINGS_CHANGED, IntPtr.Zero, 0);

                    oBrowser.Navigate("http://kreuzerkrieg.dyndns.info/SiteMap.xml");
                    if (oCWTimer.Wait(15))
                    {
                        return true;
                    }
                    else
                    {
                        //System.Console.WriteLine("Proxy \"" + sProxy + "\" appears to be dead trying next one.");
                    }
                }
                catch (UnauthorizedAccessException uex)
                {
                    throw new UnauthorizedAccessException("RefreshIEProxySettings thrown an exception", uex);
                }
                catch (AccessViolationException ex)
                {
                    throw new AccessViolationException("RefreshIEProxySettings has thrown an exception", ex);
                }
                catch (Exception ex)
                {
                    throw new Exception("RefreshIEProxySettings thrown an exception", ex);
                }
            }
        }
示例#2
0
 public HtmlDocument loadDocument(ref System.Windows.Forms.WebBrowser oBrowser, String sURL)
 {
     CountedWait oCWTimer = new CountedWait(ref oBrowser, 3000);
     while (true)
     {
         try
         {
             oBrowser.Navigate(sURL);
             if (oCWTimer.Wait(10))
             {
                 return oBrowser.Document;
             }
             else
             {
                 //System.Console.WriteLine("Proxy timeout, switching to next one.");
                 oWININET.RefreshIEProxySettings();
             }
         }
         catch (UnauthorizedAccessException uex)
         {
             throw new UnauthorizedAccessException("..::" + this.GetType().Name + "::..loadDocument has thrown an exception.", uex);
         }
         catch (AccessViolationException ex)
         {
             throw new AccessViolationException("..::" + this.GetType().Name + "::..loadDocument has thrown an exception.", ex);
         }
         catch (Exception ex)
         {
             System.Console.WriteLine("..::" + this.GetType().Name + "::..loadDocument thrown an exception, reason:  " + ex.Message + "\n" + ex.StackTrace + ", switching proxy");
             oWININET.RefreshIEProxySettings();
         }
     }
 }
示例#3
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();
         }
     }
 }
示例#4
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...");
                    }
                }
            }
        }
示例#5
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();
                }
            }
        }