private async void ConnectButton_Click(object sender, RoutedEventArgs e) { try { VPN vpn = _service.VPN_UPV; if (!vpn.IsReachable()) { bool exists = !string.IsNullOrEmpty(vpn.Name) || await CreateVPN(vpn, "la UPV desde fuera del campus"); if (exists) { _service.SaveChanges(); await vpn.ConnectAsync(); } else { throw new OperationCanceledException(); } } OnStarted(EventArgs.Empty); } catch (OperationCanceledException) { // The user canceled the connection } }
public async Task Start() { if (!started) { VPN vpn = _service.VPN_UPV; if (string.IsNullOrEmpty(vpn.Name)) { SelectVPN window = new SelectVPN(vpn); window.ShowDialog(); if (window.Canceled) { throw new OperationCanceledException(); } _service.SaveChanges(); } await vpn.ConnectAsync(); started = true; OnStarted(); } }