private void CheckProxySafe(WebProxyToken proxyToken) { try { if (!proxiesList.ContainsKey(proxyToken.Proxy)) { proxiesList[proxyToken.Proxy] = proxyToken; } var checks = new[] { new { Uri = @"http://poe.trade/", Checker = new Func <string, bool>(x => x != null && x.Contains("Path of Exile")) }, new { Uri = @"http://exile.tools/", Checker = new Func <string, bool>(x => x != null && x.Contains("Path of Exile")) }, //new { Uri = @"http://www.google.com:80/", Checker = new Func<string, bool>(x => x != null && x.Contains("Google")) }, }; foreach (var check in checks) { var client = new WebClient { Proxy = proxyToken.Proxy }; var response = client.DownloadString(check.Uri); if (!check.Checker(response)) { throw new FormatException($"Failed to get expected result from proxy {proxyToken.Proxy}"); } } Log.Instance.Debug($"[GenericProxyProvider.CheckProxySafe] Proxy is active, {proxyToken.Proxy}"); proxyToken.ReportSuccess(); } catch (Exception ex) { Log.Instance.Debug($"[GenericProxyProvider.CheckProxySafe] Proxy failed({proxyToken.Proxy}), msg '{ex.Message}'"); proxyToken.ReportBroken(); } }
private void CheckProxySafe(WebProxyToken proxyToken) { try { if (!proxiesList.ContainsKey(proxyToken.Proxy)) { proxiesList[proxyToken.Proxy] = proxyToken; } var checks = new[] { new { Uri = @"http://poe.trade/", Checker = new Func<string, bool>(x => x != null && x.Contains("Path of Exile")) }, new { Uri = @"http://exile.tools/", Checker = new Func<string, bool>(x => x != null && x.Contains("Path of Exile")) }, //new { Uri = @"http://www.google.com:80/", Checker = new Func<string, bool>(x => x != null && x.Contains("Google")) }, }; foreach (var check in checks) { var client = new WebClient { Proxy = proxyToken.Proxy }; var response = client.DownloadString(check.Uri); if (!check.Checker(response)) { throw new FormatException($"Failed to get expected result from proxy {proxyToken.Proxy}"); } } Log.Instance.Debug($"[GenericProxyProvider.CheckProxySafe] Proxy is active, {proxyToken.Proxy}"); proxyToken.ReportSuccess(); } catch (Exception ex) { Log.Instance.Debug($"[GenericProxyProvider.CheckProxySafe] Proxy failed({proxyToken.Proxy}), msg '{ex.Message}'"); proxyToken.ReportBroken(); } }