/// <summary> /// Change the state of the connection. /// </summary> /// <param name="newstate">new state</param> internal StateSnapshot ChangeState(VPNConnectionState newstate) { StateSnapshot ev = null; StateSnapshot ret; lock (this) { ret = createSnapshotNoLock(); if (ConnectionState != newstate) { ConnectionState = newstate; ev = createSnapshotNoLock(); } } #if DEBUG Debug.WriteLine("ChangeState: " + newstate); #endif if (ev != null) { raiseEvents(ev); } return(ret); }
/// <summary> /// notepad exited <br /> /// reload configuration /// </summary> /// <param name="sender">ignored</param> /// <param name="e">ignored</param> private void p_Exited(object sender, EventArgs e) { // was a connection established? bool wasConnected = false; VPNConnectionState state = m_vpn.State.CreateSnapshot().ConnectionState; if (m_vpn != null) { wasConnected = state == VPNConnectionState.Initializing || state == VPNConnectionState.Running; } // close the connection if needed, reload the configuration Disconnect(); init(); // reconnect, if the user wants it if (wasConnected && m_error_message == null) { if (RTLMessageBox.Show(m_parent, Program.res.GetString("BOX_Reconnect"), MessageBoxButtons.YesNoCancel, MessageBoxDefaultButton.Button1, MessageBoxIcon.Question) == DialogResult.Yes) { Connect(); } } }
internal void ChangeVPNState(string[] p) { StateSnapshot res; lock (this) { Array.Copy(p, m_vpnstate, 4); if (p[1].Equals("CONNECTED", StringComparison.OrdinalIgnoreCase) || p[1].Equals("ASSIGN_IP", StringComparison.OrdinalIgnoreCase)) { m_connection.IP = p[3]; if (p[1].Equals("CONNECTED", StringComparison.OrdinalIgnoreCase)) { ConnectionState = VPNConnectionState.Running; } } else if (p[1].Equals("RECONNECTING", StringComparison.OrdinalIgnoreCase)) { m_connection.IP = null; if (p[2].ToUpperInvariant() != "SIGHUP" && p[2].ToUpperInvariant() != "INIT_INSTANCE") { ConnectionState = VPNConnectionState.Initializing; } } else if (p[1].Equals("EXITING", StringComparison.OrdinalIgnoreCase)) { m_connection.IP = null; } res = createSnapshotNoLock(); } raiseEvents(res); }
/// <summary> /// disconnect was selected in the context menu /// </summary> /// <param name="sender">ignored</param> /// <param name="e">ignored</param> private void m_menu_disconnect_Click(object sender, EventArgs e) { VPNConnectionState state = m_vpn.State.CreateSnapshot().ConnectionState; if (state == VPNConnectionState.Initializing || state == VPNConnectionState.Running) { Disconnect(); } }
/// <summary> /// Checks wheather the requested state can be reached. If not, the methods throws an error. /// </summary> /// <param name="newState"></param> protected void CheckState(VPNConnectionState newState) { switch (newState) { case VPNConnectionState.Initializing: if (m_state.ConnectionState != VPNConnectionState.Stopped && m_state.ConnectionState != VPNConnectionState.Error) { throw new InvalidOperationException("Already connected"); } break; } }
private void btnConnect_Click(object sender, EventArgs e) { VPNConnectionState state = m_config.VPNConnection.State.CreateSnapshot().ConnectionState; // connect only if we are disconnected, clear the list if (state == VPNConnectionState.Stopped || state == VPNConnectionState.Error) { m_config.VPNConnection.Connect(); } // disconnect only if we are connected else if (state == VPNConnectionState.Initializing || state == VPNConnectionState.Running) { m_config.Disconnect(); } }
/// <summary> /// Change the state of the connection. /// </summary> /// <param name="newstate">new state</param> internal StateSnapshot ChangeState(VPNConnectionState newstate) { StateSnapshot ev = null; StateSnapshot ret; lock (this) { ret = createSnapshotNoLock(); if (ConnectionState != newstate) { ConnectionState = newstate; ev = createSnapshotNoLock(); } } #if DEBUG Debug.WriteLine("ChangeState: " + newstate); #endif if (ev != null) raiseEvents(ev); return ret; }
/// <summary> /// Checks wheather the requested state can be reached. If not, the methods throws an error. /// </summary> /// <param name="newState"></param> protected void CheckState(VPNConnectionState newState) { switch (newState) { case VPNConnectionState.Initializing: if (m_state.ConnectionState != VPNConnectionState.Stopped && m_state.ConnectionState != VPNConnectionState.Error) throw new InvalidOperationException("Already connected"); break; } }
internal void ChangeVPNState(string[] p) { StateSnapshot res; lock (this) { Array.Copy(p, m_vpnstate, 4); if (p[1].Equals("CONNECTED",StringComparison.OrdinalIgnoreCase) || p[1].Equals("ASSIGN_IP", StringComparison.OrdinalIgnoreCase)) { m_connection.IP = p[3]; if (p[1].Equals("CONNECTED", StringComparison.OrdinalIgnoreCase)) ConnectionState = VPNConnectionState.Running; } else if (p[1].Equals("RECONNECTING", StringComparison.OrdinalIgnoreCase)) { m_connection.IP = null; if(p[2].ToUpperInvariant() != "SIGHUP" && p[2].ToUpperInvariant() != "INIT_INSTANCE") ConnectionState = VPNConnectionState.Initializing; } else if (p[1].Equals("EXITING", StringComparison.OrdinalIgnoreCase)) { m_connection.IP = null; } res = createSnapshotNoLock(); } raiseEvents(res); }
private void setState(StateSnapshot ss) { string text = ss.VPNState[1]; text = Program.res.GetString("VPNSTATE_" + text); if (text != null) { if (text.StartsWith("VPNSTATE_", StringComparison.OrdinalIgnoreCase)) { text = ss.VPNState[1]; } lblVPNState.Text = text; } else { lblVPNState.Text = ""; } llIP.SetIP(m_config.VPNConnection.IP); lblVPNState.Left = llIP.Left - lblVPNState.Width - 16; llIP.SetIP(m_config.VPNConnection.IP); if(ss.ConnectionState != lastConnectionState) { lastConnectionState = ss.ConnectionState; switch (ss.ConnectionState) { case VPNConnectionState.Initializing: lstLog.Items.Clear(); lblState.Text = Program.res.GetString("STATE_Initializing"); pbStatus.Image = Properties.Resources.STATE_Initializing; toolTip.SetToolTip(btnConnect, Program.res.GetString("QUICKINFO_Disconnect")); btnConnect.Image = Properties.Resources.BUTTON_Disconnect; btnConnect.Enabled = true; break; case VPNConnectionState.Running: lblState.Text = Program.res.GetString("STATE_Connected"); pbStatus.Image = Properties.Resources.STATE_Running; toolTip.SetToolTip(btnConnect, Program.res.GetString("QUICKINFO_Disconnect")); btnConnect.Image = Properties.Resources.BUTTON_Disconnect; btnConnect.Enabled = true; break; case VPNConnectionState.Stopped: lblState.Text = Program.res.GetString("STATE_Stopped"); pbStatus.Image = Properties.Resources.STATE_Stopped; toolTip.SetToolTip(btnConnect, Program.res.GetString("QUICKINFO_Connect")); btnConnect.Image = Properties.Resources.BUTTON_Connect; btnConnect.Enabled = true; lblVPNState.Text = ""; break; case VPNConnectionState.Stopping: lblState.Text = Program.res.GetString("STATE_Stopping"); pbStatus.Image = Properties.Resources.STATE_Stopping; toolTip.SetToolTip(btnConnect, Program.res.GetString("QUICKINFO_Connect")); btnConnect.Image = Properties.Resources.BUTTON_Connect; btnConnect.Enabled = false; break; case VPNConnectionState.Error: default: lblState.Text = Program.res.GetString("STATE_Error"); pbStatus.Image = Properties.Resources.STATE_Error; toolTip.SetToolTip(btnConnect, Program.res.GetString("QUICKINFO_Connect")); btnConnect.Image = Properties.Resources.BUTTON_Connect; btnConnect.Enabled = true; lblVPNState.Text = ""; break; } } }
private void setState(StateSnapshot ss) { string text = ss.VPNState[1]; text = ProgramVPN.res.GetString("VPNSTATE_" + text); if (text != null) { if (text.StartsWith("VPNSTATE_", StringComparison.OrdinalIgnoreCase)) { text = ss.VPNState[1]; } lblVPNState.Text = text; } else { lblVPNState.Text = ""; } llIP.SetIP(m_config.VPNConnection.IP); lblVPNState.Left = llIP.Left - lblVPNState.Width - 16; llIP.SetIP(m_config.VPNConnection.IP); if (ss.ConnectionState != lastConnectionState) { lastConnectionState = ss.ConnectionState; switch (ss.ConnectionState) { case VPNConnectionState.Initializing: lstLog.Items.Clear(); lblState.Text = ProgramVPN.res.GetString("STATE_Initializing"); pbStatus.Image = Properties.Resources.STATE_Initializing; toolTip.SetToolTip(btnConnect, ProgramVPN.res.GetString("QUICKINFO_Disconnect")); btnConnect.Image = Properties.Resources.BUTTON_Disconnect; btnConnect.Enabled = true; break; case VPNConnectionState.Running: lblState.Text = ProgramVPN.res.GetString("STATE_Connected"); pbStatus.Image = Properties.Resources.STATE_Running; toolTip.SetToolTip(btnConnect, ProgramVPN.res.GetString("QUICKINFO_Disconnect")); btnConnect.Image = Properties.Resources.BUTTON_Disconnect; btnConnect.Enabled = true; if (m_isTemporary) { m_isTemporary = false; Hide(); } break; case VPNConnectionState.Stopped: lblState.Text = ProgramVPN.res.GetString("STATE_Stopped"); pbStatus.Image = Properties.Resources.STATE_Stopped; toolTip.SetToolTip(btnConnect, ProgramVPN.res.GetString("QUICKINFO_Connect")); btnConnect.Image = Properties.Resources.BUTTON_Connect; btnConnect.Enabled = true; lblVPNState.Text = ""; break; case VPNConnectionState.Stopping: lblState.Text = ProgramVPN.res.GetString("STATE_Stopping"); pbStatus.Image = Properties.Resources.STATE_Stopping; toolTip.SetToolTip(btnConnect, ProgramVPN.res.GetString("QUICKINFO_Connect")); btnConnect.Image = Properties.Resources.BUTTON_Connect; btnConnect.Enabled = false; break; case VPNConnectionState.Error: default: lblState.Text = ProgramVPN.res.GetString("STATE_Error"); pbStatus.Image = Properties.Resources.STATE_Error; toolTip.SetToolTip(btnConnect, ProgramVPN.res.GetString("QUICKINFO_Connect")); btnConnect.Image = Properties.Resources.BUTTON_Connect; btnConnect.Enabled = true; lblVPNState.Text = ""; break; } } }