static private void watcher_Disconnected(object sender, RasConnectionEventArgs e) { // A connection has disconnected successfully. Log.ProcessDebug("Event " + VpnSelectorLibRes.A_connection_has_disconnected_successfully_ + e.Connection.EntryName); if (VpnDisconnectedEvent != null) { VpnDisconnectedEvent(null, new VpnDisconnectedEventArgs()); } if (IsSynchMode == false) { AppManager.Instance.ProcessNotification(VpnSelectorLibRes.VPN_disconnected); BaseProxyServer oldProxy = NetConnUtils.CurrentProxyServer; NetConnUtils.CurrentProxyServer = null; if (oldProxy != null) { //proxy changed NetConnUtils.ConfirmIpAddressAsync(); } //reconnect //https://stackoverflow.com/questions/23950702/reconnect-vpn-windows-service if (NetConnUtils.CurrentProxyServer != null && IsReconnect == true) { OpenConnectLocal(NetConnUtils.CurrentProxyServer, true); } } }
static private void watcher_Connected(object sender, RasConnectionEventArgs e) { // A connection has successfully connected. Log.ProcessDebug("Event " + VpnSelectorLibRes.A_connection_has_successfully_connected_ + e.Connection.EntryName); BaseProxyServer oldProxy = NetConnUtils.CurrentProxyServer; if (IsSynchMode == false) { NetConnUtils.CurrentProxyServer = BaseProxyServer.FindFromNames(NetConnUtils.GetActiveConnectionsNames()); } if (VpnConnectedEvent != null) { VpnConnectedEvent(null, new VpnConnectedEventArgs()); } if (IsSynchMode == false) { if ((oldProxy == null && NetConnUtils.CurrentProxyServer != null) || (oldProxy != null && oldProxy != NetConnUtils.CurrentProxyServer)) { //proxy changed NetConnUtils.ConfirmIpAddressAsync(); } } }
protected void CreateVPNSupport() { NetConnUtils.InitSettings(); // // vpnButton // this.vpnButton = new System.Windows.Forms.ToolStripSplitButton(); this.vpnButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; this.vpnButton.Enabled = true; this.vpnButton.ImageTransparentColor = System.Drawing.Color.Magenta; this.vpnButton.Name = "vpnButton"; this.vpnButton.Size = new System.Drawing.Size(19, 23); this.vpnButton.Text = "VPN"; this.vpnButton.ToolTipText = "VPN"; vpnButton.Image = VpnSelectorLibRes.network_off; //vpnButton.DoubleClick += VpnButton_DoubleClick; - do not working // // ipAddressLabel // this.ipAddressLabel = new System.Windows.Forms.ToolStripStatusLabel(); this.ipAddressLabel.AutoToolTip = true; this.ipAddressLabel.Enabled = false; this.ipAddressLabel.Name = "ipAddressLabel"; this.ipAddressLabel.Size = new System.Drawing.Size(66, 20); this.ipAddressLabel.Text = "127.0.0.1"; this.ipAddressLabel.ToolTipText = "127.0.0.1"; this.statusBar.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.eventWarrningButton, this.vpnButton, this.ipAddressLabel }); if (useMainTrayIconForVPN && BaseApplicationContext.NotifyIcon != null) { vpnNotifyIcon = BaseApplicationContext.NotifyIcon; } else { vpnNotifyIcon = new NotifyIcon(components) { ContextMenuStrip = new ContextMenuStrip(), Icon = vpnOffIcon, Text = "VPN", Visible = true }; } vpnButton.MouseDown += VpnButton_MouseDown; vpnNotifyIcon.ContextMenuStrip.Opening += VpnNotifyIconContextMenuStrip_Opening; vpnNotifyIcon.DoubleClick += VpnNotifyIcon_DoubleClick; NetConnUtils.OnNetworkChekComplatedEvent += JustNetworkUtils_OnNetworkChekComplatedEvent; NetConnUtils.VpnDisconnectedEvent += VpnSelector_OnVpnDisconnectedEvent; NetConnUtils.VpnConnectedEvent += VpnSelector_OnVpnConnectedEvent; NetConnUtils.VpnDialerErrorEvent += VpnSelector_OnVpnDialerErrorEvent; NetConnUtils.CreateDialerAndBeginWatch(); bool _isActiveConnectionPresent = NetConnUtils.IsActiveConnectionPresent(); if (_isActiveConnectionPresent) { NetConnUtils.CurrentProxyServer = BaseProxyServer.FindFromNames(NetConnUtils.GetActiveConnectionsNames()); ProcessVpnConnectedEvent(); //DotRasUtils.CurrentProxyServer = DotRasUtils.CurrentProxyServer; } else { NetConnUtils.ConfirmIpAddressAsync(); } }