private void ReloadResolver(DnsCryptProxyType dnsCryptProxyType) { if (dnsCryptProxyType == DnsCryptProxyType.Primary) { if (_primaryResolver != null) { PrimaryDnsCryptProxyManager.DnsCryptProxy.Parameter = ConvertProxyEntryToParameter( _primaryResolver, DnsCryptProxyType.Primary); if (PrimaryDnsCryptProxyManager.WriteRegistry(DnsCryptProxyType.Primary)) { if (PrimaryDnsCryptProxyManager.IsDnsCryptProxyInstalled()) { RestartService(DnsCryptProxyType.Primary); } } } } else { if (_secondaryResolver != null) { SecondaryDnsCryptProxyManager.DnsCryptProxy.Parameter = ConvertProxyEntryToParameter(_secondaryResolver, DnsCryptProxyType.Secondary); if (SecondaryDnsCryptProxyManager.WriteRegistry(DnsCryptProxyType.Secondary)) { if (SecondaryDnsCryptProxyManager.IsDnsCryptProxyInstalled()) { RestartService(DnsCryptProxyType.Secondary); } } } } }
private async void HandleService(DnsCryptProxyType dnsCryptProxyType) { if (dnsCryptProxyType == DnsCryptProxyType.Primary) { IsWorkingOnPrimaryService = true; if (IsPrimaryResolverRunning) { // service is running, stop it await Task.Run(() => { PrimaryDnsCryptProxyManager.Stop(); }).ConfigureAwait(false); Thread.Sleep(Global.ServiceStopTime); _isPrimaryResolverRunning = PrimaryDnsCryptProxyManager.IsDnsCryptProxyRunning(); NotifyOfPropertyChange(() => IsPrimaryResolverRunning); } else { if (PrimaryDnsCryptProxyManager.IsDnsCryptProxyInstalled()) { // service is installed, just start them await Task.Run(() => { PrimaryDnsCryptProxyManager.Start(); }).ConfigureAwait(false); Thread.Sleep(Global.ServiceStartTime); _isPrimaryResolverRunning = PrimaryDnsCryptProxyManager.IsDnsCryptProxyRunning(); NotifyOfPropertyChange(() => IsPrimaryResolverRunning); } else { //install and start the service var installResult = await Task.Run(() => { return(PrimaryDnsCryptProxyManager.Install()); }).ConfigureAwait(false); Thread.Sleep(Global.ServiceStartTime); _isPrimaryResolverRunning = PrimaryDnsCryptProxyManager.IsDnsCryptProxyRunning(); NotifyOfPropertyChange(() => IsPrimaryResolverRunning); } } IsWorkingOnPrimaryService = false; } else { IsWorkingOnSecondaryService = true; if (IsSecondaryResolverRunning) { // service is running, stop it await Task.Run(() => { SecondaryDnsCryptProxyManager.Stop(); }).ConfigureAwait(false); Thread.Sleep(Global.ServiceStopTime); _isSecondaryResolverRunning = SecondaryDnsCryptProxyManager.IsDnsCryptProxyRunning(); NotifyOfPropertyChange(() => IsSecondaryResolverRunning); } else { if (SecondaryDnsCryptProxyManager.IsDnsCryptProxyInstalled()) { // service is installed, just start them await Task.Run(() => { SecondaryDnsCryptProxyManager.Start(); }).ConfigureAwait(false); Thread.Sleep(Global.ServiceStartTime); _isSecondaryResolverRunning = SecondaryDnsCryptProxyManager.IsDnsCryptProxyRunning(); NotifyOfPropertyChange(() => IsSecondaryResolverRunning); } else { //install and start the service var installResult = await Task.Run(() => { return(SecondaryDnsCryptProxyManager.Install()); }) .ConfigureAwait(false); Thread.Sleep(Global.ServiceStartTime); _isSecondaryResolverRunning = SecondaryDnsCryptProxyManager.IsDnsCryptProxyRunning(); NotifyOfPropertyChange(() => IsSecondaryResolverRunning); } } IsWorkingOnSecondaryService = false; } }