Example #1
0
 public virtual void SetStatus(TestProxyResult result)
 {
     this.Working         = result.Success;
     this.LastChecked     = DateTime.Now;
     this.LastElapsedTime = result.ElapsedTime;
     this.LastException   = result.Error;
 }
Example #2
0
        public static TestProxyResult TestProxy(IWebProxyWithStatus wp, int timeoutInMs = 10000)
        {
            TestProxyResult result = new TestProxyResult();
            var             sw     = new Stopwatch();

            using (Devmasters.Net.HttpClient.URLContent url = new Devmasters.Net.HttpClient.URLContent("http://api.devmasters.cz/ip.ashx"))
            {
                try
                {
                    sw.Start();
                    url.Timeout = timeoutInMs;
                    url.Proxy   = wp;

                    string content = url.GetContent().Text;

                    result.Success = (content == wp.GetProxy(apiHost).Host);
                }
                catch (Exception ex)
                {
                    result.Success = false;
                    result.Error   = ex;
                }
                finally
                {
                    sw.Stop();
                    result.ElapsedTime = sw.Elapsed;
                }
                return(result);
            }
        }
Example #3
0
        public static void TestProxies(List <IWebProxyWithStatus> proxiesToCheck)
        {
            var results = new List <TestProxyResult>();

            Parallel.ForEach(proxiesToCheck,
#if DEBUG
                             //new ParallelOptions() { MaxDegreeOfParallelism = 1 },// for DEBUG set 1
#else
#endif
                             wp =>
            {
                TestProxyResult res = TestProxy(wp);
                wp.SetStatus(res);
                System.Diagnostics.Debug.WriteLine(wp.GetProxy(new Uri("http://www.seznam.cz")).AbsoluteUri + " " + res.ElapsedTime.Milliseconds.ToString() + " " + res.Success);
            });
        }