//little bugs private void OnConnectionStateChanged(object sender, ConnectionStateChangedEventArgs e) { if (!String.IsNullOrEmpty(e.Username)) { ConnectionStateChanged?.Invoke(this, e); } }
private void InvokeConnectionStateChange() { if (ConnectionStateChanged != null) { ConnectionStateChanged.Invoke(this, new DroneConnectionStateChangedEventArgs(connected)); } }
public void HandleConnectionStateChanged(object sender, ConnectionStateChangedEventArgs e) { if (!String.IsNullOrEmpty(e.Client)) { ConnectionStateChanged?.Invoke(this, e); } }
private void Client_OnConnectionStateChanged(object sender) { VoipProviderConnectionState state; switch (Client.ConnectionState) { case ConnectionState.None: state = VoipProviderConnectionState.None; break; case ConnectionState.Connecting: state = VoipProviderConnectionState.Connecting; break; case ConnectionState.Open: state = VoipProviderConnectionState.Open; break; case ConnectionState.Closing: state = VoipProviderConnectionState.Closing; break; case ConnectionState.Closed: state = VoipProviderConnectionState.Closed; break; default: Console.WriteLine($"Asterisk: Received unknown connection state {Client.ConnectionState}"); return; } ConnectionStateChanged?.Invoke(this, state); }
public async Task Run(T host) { while (true) { var stream = CreateStream(); await stream.WaitForConnectionAsync(); _ = Task.Run(async() => { try { ConnectionStateChanged?.Invoke(this, true); this.rpc = JsonRpc.Attach(stream, host); await this.rpc.Completion; } catch (ObjectDisposedException) { } catch (IOException) { } catch (Exception ex) { Log.Exception(ex); } ConnectionStateChanged?.Invoke(this, false); this.rpc.Dispose(); await stream.DisposeAsync(); }); } }
private void ActiveWindowChanged(object sender, ActiveWindowChangedEventArgs eventArgs) { IsConnected = _sessionProvider.IsConnected && eventArgs.Window != null; IsRunning &= IsConnected; UpdateActiveConnection(); ConnectionStateChanged?.Invoke(this, EventArgs.Empty); }
/// <summary> /// 引发连接状态改变事件 /// </summary> internal void RaiseConnectionStateChangedEvent(ConnectionState connectionState) { _connectionState = connectionState; switch (_connectionState) { case ConnectionState.Disconnected: Log.Info("未连接"); break; case ConnectionState.Disconnecting: Log.Info("正在断开"); break; case ConnectionState.Connecting: Log.Info("正在连接"); break; case ConnectionState.Connected: Log.Info("已连接, 且密码正确"); break; case ConnectionState.AutoReconnecting: Log.Info("正在自动重连"); break; case ConnectionState.PasswordVerifying: Log.Info("正在验证密码"); break; case ConnectionState.PasswordIncorrect: Log.Info("密码错误"); break; } ConnectionStateChanged?.Invoke(_connectionState); }
public void Disconnect() { closeConnection = true; tcpClient.Close(); ConnectionStateChanged?.Invoke(new EventArgs()); }
private async Task HandleDisconnection(MqttClientDisconnectedEventArgs arg) { if (ConnectionStateChanged != null) { await ConnectionStateChanged.Invoke(); } }
/// <summary> /// Called when the connection state of the LineaPro changes. /// </summary> /// <param name="state">The connection state.</param> public override void ConnectionState(ConnStates state) { if (ConnectionStateChanged != null) { ConnectionStateChanged.Invoke(this, new ConnectionStateChangedEventArgs(state)); } }
//--------------------------------------------------------Set-, Get- Methods:---------------------------------------------------------\\ #region --Set-, Get- Methods-- protected void setState(ConnectionState state) { this.state = state; ConnectionStateChanged?.Invoke(this, this.state); switch (this.state) { case ConnectionState.DISCONNECTED: ConnectionDisconnected?.Invoke(this, new EventArgs()); break; case ConnectionState.CONNECTING: ConnectionConnecting?.Invoke(this, new EventArgs()); break; case ConnectionState.CONNECTED: ConnectionConnected?.Invoke(this, new EventArgs()); break; case ConnectionState.DISCONNECTING: ConnectionDisconnecting?.Invoke(this, new EventArgs()); break; case ConnectionState.ERROR: ConnectionError?.Invoke(this, new EventArgs()); break; default: throw new InvalidOperationException("Invalid given state: " + state); } }
internal void RemoveConnection(Guid connectionId) { if (_connections.TryRemove(connectionId, out WsConnection connection) && !string.IsNullOrEmpty(connection.Username)) { ConnectionStateChanged?.Invoke(this, new ConnectionStateChangedEventArgs(connection.Username, false, DateTime.Now)); ConnectionReceived?.Invoke(this, new ConnectionReceivedEventArgs(connection.Username, false, DateTime.Now)); } }
private void SessionDisconnected(object sender, EventArgs args) { lock (_syncObj) { IsConnected = _sessionProvider.IsConnected; IsRunning = false; } ConnectionStateChanged?.Invoke(this, EventArgs.Empty); }
private void _websocket_OnFatality(string reason) { if (_websocket?.State != null) { ConnectionStateChanged?.Invoke(this, _websocket.State); } Error?.Invoke(this, new Exception(reason)); }
public void Disconnect() { if (_isConnected) { _isConnected = false; ConnectionStateChanged?.Invoke(this, new ConnectionStateChangedArgs(_isConnected)); } }
private void OnConnectionStateChanged(eConnectionState state) { ServerConnectionState = state; if (ConnectionStateChanged != null) { ConnectionStateChanged.Invoke(state); } }
private void InvokeConnectionStateChange(DroneNetworkConnectionState state) { if (ConnectionStateChanged != null) { String currentInterfaceName = currentWifiInterface != null ? currentWifiInterface.InterfaceName : ""; ConnectionStateChanged.Invoke(this, new DroneNetworkConnectionStateChangedEventArgs(currentInterfaceName, state, currentPingRetries, maxPingRetries)); } }
internal void HandleMessage(Guid clientId, Container container) { if (!_connections.TryGetValue(clientId, out WsConnection connection)) { return; } _connections.RefreshLifeClient(clientId); switch (container.Identifier) { case DispatchType.Login: if (((JObject)container.Payload).ToObject(typeof(LoginRequestContainer)) is LoginRequestContainer loginRequest) { LoginResponseContainer loginResponse; bool isEnter = true; DispatchType stage; if (UserOnlineList.Contains(loginRequest.Content)) { loginResponse = new LoginResponseContainer( new Response(ResponseType.Failure, $"Client with name '{loginRequest.Content}' yet connect."), null, null, null, null); connection.Send(loginResponse.GetContainer()); connection.Login = $"pseudo-{loginRequest.Content}"; stage = DispatchType.Connection; } else { isEnter = UserOfflineList.Contains(loginRequest.Content); loginResponse = new LoginResponseContainer(new Response(ResponseType.Ok, "Connected"), null, null, null, null); connection.Login = loginRequest.Content; stage = DispatchType.Login; } var eventLogMessage = new EventLogMessage { IsSuccessfully = loginResponse.Content.Result == ResponseType.Ok == isEnter, SenderName = _name, Text = loginResponse.Content.Reason, Time = DateTime.Now, Type = stage }; ConnectionStateChanged?.Invoke(this, new ConnectionStateChangedEventArgs(connection.Login, true, eventLogMessage)); } break; case DispatchType.Message: MessageReceivedEventArgs message = MessageSorter.GetSortedMessage((JObject)container.Payload); MessageReceived?.Invoke(this, message); Send(MessageSorter.GetSortedMessage(message.Author, message.Message, InterfaceType.WebSocket, message.Agenda), message.Agenda); break; } }
private void _device_ParameterChanged(object sender, Parameter parameter) { if (parameter == Parameter.State) { UpdateBatterySubscription(); SetInfoText(); ConnectionStateChanged?.Invoke(this, ConnectionState); } }
/// <summary> /// Private ctor since we're cheezy and use a singleton. /// </summary> private NetworkStatus() { m_nListUtil = PlatformTypes.New <INetworkInfo>(); m_nListUtil.ConnectionStateChanged += () => { ConnectionStateChanged?.Invoke(); }; }
protected virtual void OnConnectionStateChanged(ConnectionStateEventArgs e) #endif { if (ConnectionStateChanged != null) { ConnectionStateChanged.Invoke(this, e); } }
private void BrokerStateChanged(object sender, BrokerStateChangedEventArgs eventArgs) { lock (_syncObj) { IsConnected = _sessionProvider.IsConnected; IsRunning &= IsConnected; } UpdateActiveConnection(); ConnectionStateChanged?.Invoke(this, EventArgs.Empty); }
/// <summary> /// Private ctor since we're cheezy and use a singleton. /// </summary> private NetworkStatus() { m_nListUtil = new NetworkListUtil(); m_nListUtil.ConnectionStateChanged += () => { ConnectionStateChanged?.Invoke(); }; }
public async Task Disconnect() { await Task.Run(() => { _closing = true; _socket.Disconnect(false); ConnectionStateChanged?.Invoke("Verbindung getrennt.", false); }); }
internal void OnMessage(Guid clientId, MessageContainer container) { if (!_connections.TryGetValue(clientId, out WsConnection connection)) { return; } switch (container.Identifier) { case nameof(ConnectionRequest): var connectionRequest = ((JObject)container.Payload).ToObject(typeof(ConnectionRequest)) as ConnectionRequest; var connectionResponse = new ConnectionResponse { Result = ResultCode.Ok, IsSuccess = true, }; if (_connections.Values.Any(c => c.Username == connectionRequest.Username)) { string reason = $"User '{connectionRequest.Username}' is already logged in."; connectionResponse.Result = ResultCode.Failure; connectionResponse.IsSuccess = false; connectionResponse.Reason = reason; connection.Send(connectionResponse.GetContainer()); ErrorReceived?.Invoke(this, new ErrorReceivedEventArgs(reason, DateTime.Now)); } else { connection.Username = connectionRequest.Username; connectionResponse.ActiveUsers = _connections.Where(c => c.Value.Username != null).Select(u => u.Value.Username).ToList(); connection.Send(connectionResponse.GetContainer()); ConnectionStateChanged?.Invoke(this, new ConnectionStateChangedEventArgs(connection.Username, true, DateTime.Now)); ConnectionReceived?.Invoke(this, new ConnectionReceivedEventArgs(connection.Username, true, DateTime.Now)); } break; case nameof(MessageRequest): var messageRequest = ((JObject)container.Payload).ToObject(typeof(MessageRequest)) as MessageRequest; MessageReceived?.Invoke(this, new MessageReceivedEventArgs(connection.Username, messageRequest.Target, messageRequest.Message, messageRequest.Groupname, DateTime.Now)); break; case nameof(FiltrationRequest): var filtrationRequest = ((JObject)container.Payload).ToObject(typeof(FiltrationRequest)) as FiltrationRequest; FiltrationReceived?.Invoke(this, new FiltrationReceivedEventArgs(connection.Username, filtrationRequest.FirstDate, filtrationRequest.SecondDate, filtrationRequest.EventType)); break; case nameof(CreateGroupRequest): var createGroupRequest = ((JObject)container.Payload).ToObject(typeof(CreateGroupRequest)) as CreateGroupRequest; createGroupRequest.UserList.Add(connection.Username); GroupCreated?.Invoke(this, new GroupCreatedEventArgs(createGroupRequest.Groupname, createGroupRequest.UserList)); break; case nameof(LeaveGroupRequest): var leaveGroupRequest = ((JObject)container.Payload).ToObject(typeof(LeaveGroupRequest)) as LeaveGroupRequest; GroupLeaved?.Invoke(this, new GroupLeavedEventArgs(connection.Username, leaveGroupRequest.Groupname)); break; } }
protected internal virtual async Task OnConnectionStateChangedAsync(ConnectionState state, CancellationToken cancellationToken) { var oldConnectionState = Interlocked.Exchange(ref currentConnectionState, (int)state); if (oldConnectionState != (int)state) { await RunInEventTaskSchedulerAsync(() => ConnectionStateChanged?.Invoke(this, new ConnectionStateChangedArgs(state)), cancellationToken); } }
protected internal virtual void OnConnectionStateChanged(ConnectionState state) { var oldConnectionState = Interlocked.Exchange(ref currentConnectionState, (int)state); if (oldConnectionState != (int)state) { RunInEventTaskScheduler(() => ConnectionStateChanged?.Invoke(this, new ConnectionStateChangedArgs(state))); } }
private void ClientRegistration(MessageContainer container) { if (((JObject)container.Payload).ToObject(typeof(ConnectionResponse)) is ConnectionResponse connectionResponse && connectionResponse.Result == ResultCodes.Failure) { return; } ConnectionStateChanged?.Invoke(this, new ConnectionStateChangedEventArgs(true)); }
void SetConnectionState(ConnectionState newState) { if (ConnectionState == newState) { return; } ConnectionState = newState; GameThread.Post(() => ConnectionStateChanged?.Invoke(newState)); }
private void Connection_ConnectionStateChanged(object sender, ConnectionStateChangedEventArgs e) { switch (e.NewState) { case ConnectionState.Closed: RemoveConnection(e.Connection); break; } ConnectionStateChanged?.Invoke(this, e); }