/// <summary> /// OVPN changes it status. /// Show or hide elements. /// </summary> /// <param name="sender">ignored</param> /// <param name="e">the new state</param> /// <seealso cref="stateChanged"/> void State_StateChanged(object sender, StateChangedEventArgs e) { try { if (m_parent.InvokeRequired) { m_parent.BeginInvoke( new EventHandler<StateChangedEventArgs>( State_StateChanged),sender, e); return; } } catch (ObjectDisposedException) { return; } switch (e.NewState.ConnectionState) { case VPNConnectionState.Initializing: m_menu_disconnect.Visible = true; m_menu_connect.Visible = false; m_menu.Image = Properties.Resources.STATE_Initializing; break; case VPNConnectionState.Running: m_menu_disconnect.Visible = true; m_menu_connect.Visible = false; m_menu.Image = Properties.Resources.STATE_Running; // show assigned ip if possible string text = Program.res.GetString("STATE_Connected"); if (m_vpn.IP != null) text += Environment.NewLine + "IP: " + m_vpn.IP; m_parent.ShowPopup(Name, text); break; case VPNConnectionState.Stopped: m_menu_disconnect.Visible = false; m_menu_connect.Visible = true; m_menu.Image = Properties.Resources.STATE_Stopped; break; case VPNConnectionState.Stopping: m_menu_disconnect.Visible = false; m_menu_connect.Visible = false; m_menu.Image = Properties.Resources.STATE_Stopping; break; case VPNConnectionState.Error: default: m_menu_disconnect.Visible = false; m_menu_connect.Visible = true; m_menu.Image = Properties.Resources.STATE_Error; if (!m_isService) { if (RTLMessageBox.Show(m_status, Program.res.GetString("BOX_VPN_Error"), MessageBoxButtons.YesNo, MessageBoxDefaultButton.Button2, MessageBoxIcon.Error) == DialogResult.Yes) { ProcessStartInfo pi = new ProcessStartInfo(); pi.Arguments = "\"" + m_tempLog + "\""; pi.ErrorDialog = true; pi.FileName = "notepad.exe"; pi.UseShellExecute = true; Process.Start(pi); } } else { RTLMessageBox.Show(m_status, Program.res.GetString("BOX_VPNS_Error"), MessageBoxButtons.OK, MessageBoxDefaultButton.Button2, MessageBoxIcon.Error); } break; } m_parent.StateChanged(); }
/// <summary> /// the connection state changed /// </summary> /// <param name="sender">ignored</param> /// <param name="e">the new state</param> private void State_StateChanged(object sender, StateChangedEventArgs e) { // wrong thred? revoke! if (this.InvokeRequired) { try { this.BeginInvoke(new helper.Action<StateSnapshot>(setState), e.NewState); } catch (ObjectDisposedException) { } catch (InvalidAsynchronousStateException) { } return; } else { setState(e.NewState); } }
/// <summary> /// vpn state has changed, refresh all buttons/texts /// </summary> /// <param name="sender">ignored</param> /// <param name="e">the new state</param> void State_StateChanged(object sender, StateChangedEventArgs e) { if (this.InvokeRequired) { try { this.BeginInvoke(new helper.Action<StateSnapshot>(setState), e.NewState); } catch (ObjectDisposedException) { } return; } else { setState(e.NewState); } }