public ConnectionHandler(string host, int port) { Host = host ?? throw new ArgumentNullException(nameof(host)); Port = port; Connection = new IPConnection(); Connection.SetAutoReconnect(true); Connection.Connected += (s, e) => { IsConnceted = true; Connection.Enumerate(); var reason = e switch { IPConnection.CONNECT_REASON_REQUEST => ConnectedReason.Requested, IPConnection.CONNECT_REASON_AUTO_RECONNECT => ConnectedReason.Reconnect, _ => ConnectedReason.Unknown, }; Connected?.Invoke(this, new ConnectedEventArgs(reason)); }; Connection.Disconnected += (s, e) => { IsConnceted = false; var reason = e switch { IPConnection.DISCONNECT_REASON_REQUEST => DisconnectedReason.RequestedFromSelf, IPConnection.DISCONNECT_REASON_SHUTDOWN => DisconnectedReason.RequestedFromEndpoint, IPConnection.DISCONNECT_REASON_ERROR => DisconnectedReason.Timeout, _ => DisconnectedReason.Unknown, }; Disconnected?.Invoke(this, new DisconnectedEventArgs(reason)); }; Connection.EnumerateCallback += (s, uid, cu, p, hV, fV, dI, eT) => { Enumerate?.Invoke(this, new EnumerateEventArgs( new TinkerforgeDeviceInfo(uid, cu, p, hV, fV, dI), eT)); }; }