internal ConnectionStateInterceptor(IAdsSession session) : base("ConnectionStateObserverInterceptor") { this._synchronizer = new object(); this._connectionState = TwinCAT.ConnectionState.Disconnected; this._lastSucceeded = DateTime.MinValue; this._lastAccess = DateTime.MinValue; this._session = session; }
private void setState(TwinCAT.ConnectionState newState) { TwinCAT.ConnectionState none = TwinCAT.ConnectionState.None; object obj2 = this._synchronizer; lock (obj2) { none = this._connectionState; this._connectionState = newState; } if (none != this._connectionState) { this.OnConnectionStatusChanged(none, newState); } }
protected virtual void OnConnectionStatusChanged(TwinCAT.ConnectionState oldState, TwinCAT.ConnectionState newState) { if (this.ConnectionStateChanged != null) { ConnectionStateChangedReason error = ConnectionStateChangedReason.Error; if ((newState == TwinCAT.ConnectionState.Connected) && ((oldState == TwinCAT.ConnectionState.Disconnected) || (oldState == TwinCAT.ConnectionState.None))) { error = ConnectionStateChangedReason.Established; } else if ((newState == TwinCAT.ConnectionState.Connected) && (oldState == TwinCAT.ConnectionState.Lost)) { error = ConnectionStateChangedReason.Resurrected; } else if (newState == TwinCAT.ConnectionState.Lost) { error = ConnectionStateChangedReason.Lost; } else if (newState == TwinCAT.ConnectionState.Disconnected) { error = ConnectionStateChangedReason.Closed; } this.ConnectionStateChanged(this, new SessionConnectionStateChangedEventArgs(error, newState, oldState, this._session, this._session.Connection, null)); } }