private static void SetIEModeInRegistry(UserAgentSelector.MainWindow.RegistryMode regMode, IEMode mode) { string userAgentPath = UserAgentSelector.MainWindow.Wow64Path; if (regMode == UserAgentSelector.MainWindow.RegistryMode.Normal) { userAgentPath = UserAgentSelector.MainWindow.NormalPath; } RegistryKey regKey = Registry.LocalMachine.OpenSubKey(userAgentPath, true); if (regKey == null) { regKey = Registry.LocalMachine.CreateSubKey(userAgentPath); } using (regKey) { if (string.IsNullOrEmpty(mode.Version) == true) { regKey.DeleteValue("Version"); } else { regKey.SetValue("Version", mode.Version); } } }
private async Task <bool> CheckProxy(string proxyUrl) { var uri = new Uri(_baseUrl); var builder = new UriBuilder(uri) { Path = String.Empty }; uri = builder.Uri; var handler = new HttpClientHandler { Proxy = new WebProxy(new Uri(proxyUrl)), AllowAutoRedirect = true }; var client = new HttpClient(handler) { Timeout = TimeSpan.FromSeconds(_requestTimeout) }; try { var req = new HttpRequestMessage(HttpMethod.Head, uri); req.Headers.UserAgent.ParseAdd(UserAgentSelector.GetRandomAgent()); var resp = await client.SendAsync(req); return(resp.IsSuccessStatusCode); } catch (Exception) { return(false); } }
internal static void SetIEMode(UserAgentSelector.MainWindow.RegistryMode regMode, IEMode mode) { string exePath = typeof(App).Assembly.Location; if (IsAdministrator() == false) { try { ProcessStartInfo procInfo = new ProcessStartInfo(); procInfo.UseShellExecute = true; procInfo.FileName = exePath; procInfo.WorkingDirectory = Environment.CurrentDirectory; procInfo.Verb = "runas"; procInfo.Arguments = string.Format("{0} \"{1}\"", regMode, mode.Version); Process.Start(procInfo); } catch (Exception) { } Application.Current.Shutdown(0); return; } SetIEModeInRegistry(regMode, mode); }
private async Task InitializeHttpClient() { var userAgent = UserAgentSelector.GetRandomAgent(); var httpHandler = new HttpClientHandler(); var httpClient = new HttpClient(httpHandler) { BaseAddress = new Uri(_baseUrl), Timeout = TimeSpan.FromSeconds(_requestTimeout) }; if (_proxyProvider != null) { var proxyUrl = await _proxyProvider.GetProxyAsync(CheckProxy); if (!String.IsNullOrEmpty(proxyUrl)) { httpHandler.Proxy = new WebProxy(new Uri(proxyUrl)); _logger.Info("UzService uses proxy " + proxyUrl); } else { _logger.Warning("Cannot obtain proxy, requesting unproxied"); } } _httpClient = httpClient; _httpHandler = httpHandler; _userAgent = userAgent; }