internal void error() { m_state = OVPNState.ERROR; disconnectLogic(); m_state = OVPNState.STOPPED; changeState(OVPNState.ERROR); }
/// <summary> /// Connect the management logic to OpenVPN /// </summary> protected bool connectLogic() { m_ovpnMLogic.reset(); for (int i = 0; i < 8; ++i) { try { System.Threading.Thread.Sleep(500); // TODO: 500 m_ovpnMLogic.connect(); return(true); } catch (System.Net.Sockets.SocketException ex) { m_logs.logDebugLine(1, "Could not establish connection " + "to management interface:" + ex.Message); if (i != 5) { m_logs.logDebugLine(1, "Trying again in a second"); System.Threading.Thread.Sleep(500); } } } m_logs.logDebugLine(1, "Could not establish connection, abording"); m_state = OVPNState.RUNNING; disconnect(); while (m_state != OVPNState.STOPPED) { Thread.Sleep(200); } changeState(OVPNState.ERROR); return(false); }
/// <summary> /// change the state of the class /// </summary> /// <param name="newstate">new state</param> internal void changeState(OVPNState newstate) { if (m_state != newstate) { m_state = newstate; if (stateChanged != null && !noevents) { stateChanged(this, new EventArgs()); } } }
/// <summary> /// Checks wheather the requested state can be reached. If not, the methods throws an error. /// </summary> /// <param name="newState"></param> protected void checkState(OVPNState newState) { switch (newState) { case OVPNState.INITIALIZING: if (m_state != OVPNState.STOPPED && m_state != OVPNState.ERROR) { throw new InvalidOperationException("Already connected"); } break; case OVPNState.STOPPING: if (m_state == OVPNState.INITIALIZING) { throw new InvalidOperationException("Can't disconnect and connect at the same time"); } break; } }
/// <summary> /// change the state of the class /// </summary> /// <param name="newstate">new state</param> internal void changeState(OVPNState newstate) { if (m_state != newstate) { m_state = newstate; if(stateChanged != null && !noevents) stateChanged(this, new EventArgs()); } }
/// <summary> /// Connect the management logic to OpenVPN /// </summary> protected bool connectLogic() { m_ovpnMLogic.reset(); for(int i = 0; i < 8; ++i) { try { System.Threading.Thread.Sleep(500); // TODO: 500 m_ovpnMLogic.connect(); return true; } catch (System.Net.Sockets.SocketException ex) { m_logs.logDebugLine(1, "Could not establish connection " + "to management interface:" + ex.Message); if (i != 5) { m_logs.logDebugLine(1, "Trying again in a second"); System.Threading.Thread.Sleep(500); } } } m_logs.logDebugLine(1, "Could not establish connection, abording"); m_state = OVPNState.RUNNING; disconnect(); while (m_state != OVPNState.STOPPED) Thread.Sleep(200); changeState(OVPNState.ERROR); return false; }
/// <summary> /// Checks wheather the requested state can be reached. If not, the methods throws an error. /// </summary> /// <param name="newState"></param> protected void checkState(OVPNState newState) { switch (newState) { case OVPNState.INITIALIZING: if (m_state != OVPNState.STOPPED && m_state != OVPNState.ERROR) throw new InvalidOperationException("Already connected"); break; case OVPNState.STOPPING: if (m_state == OVPNState.INITIALIZING) throw new InvalidOperationException("Can't disconnect and connect at the same time"); break; } }