示例#1
0
        /// <summary>
        /// Gets the available routes.
        /// </summary>
        /// <returns></returns>
        private IEnumerable <Route> GetRoutes()
        {
            var testTargetUri = TestTargetUri;

            // if remote is optional, whenever we have a remote proxy configured or not,
            // the short route (local only) is returned
            if (OptionalRemoteProxy)
            {
                var shortRoute = ProxyClient.CreateRoute(LocalProxy);
                if (testTargetUri != null)
                {
                    ProxyValidator.Validate(shortRoute, testTargetUri);
                }
                yield return(shortRoute);
            }
            // then, if there is a remote proxy or it is not optional
            // (in which case we skipped the first step above)
            // the full route is returned
            if (!OptionalRemoteProxy || RemoteProxy != null)
            {
                var fullRoute = ProxyClient.CreateRoute(LocalProxy, RemoteProxy);
                if (testTargetUri != null)
                {
                    ProxyValidator.Validate(fullRoute, testTargetUri);
                }
                yield return(fullRoute);
            }
        }
 private void CheckProxyServers()
 {
     try
     {
         Loading = true;
         ProxyServers.Clear();
         var testTargetUri = TestTargetUri;
         if (testTargetUri != null)
         {
             var route = ProxyClient.CreateRoute(LocalProxy);
             foreach (var hostEndPoint in ProxyPageScanner.ScanPage(ProxyPage.PageUri, ProxyPage.ParseAsText, ProxyPage.HostPortEx, route, testTargetUri))
             {
                 var ipEndPoint = hostEndPoint.IPEndPoint;
                 if (ipEndPoint == null)
                 {
                     continue;
                 }
                 var location = Geolocation.Locate(ipEndPoint.Address, route);
                 var p        = ProxyAnalyzer.MeasurePerformance(route, testTargetUri);
                 if (p == null)
                 {
                     continue;
                 }
                 var proxy = new Proxy(hostEndPoint, location, (int)p.Ping.TotalMilliseconds, (int)(p.DownloadSpeed / 1024));
                 ProxyServers.Add(proxy);
             }
         }
     }
     finally
     {
         Loading = false;
     }
 }
示例#3
0
        private void FirstLoad()
        {
            var diagnostic = SystemProxyAnalyzer.Diagnose();

            // if there is a local proxy, use it
            LocalProxy = diagnostic.DefaultProxy;
            // find a remote proxy
            if (!diagnostic.SensitiveHttpConnectRoute.HasFlag(RouteStatus.ProxyAcceptsAddress))
            {
                var firstProxy = ProxyPageScanner.ScanPage(ProxyPage.Default.First(), ProxyClient.CreateRoute(LocalProxy), TestTargetUri).FirstOrDefault();
                if (firstProxy != null)
                {
                    RemoteProxy = new Uri(string.Format("http://{0}:{1}", firstProxy.Host, firstProxy.Port));
                }
            }
            else
            {
                RemoteProxy = null;
            }
        }