//little bugs
 private void OnConnectionStateChanged(object sender, ConnectionStateChangedEventArgs e)
 {
     if (!String.IsNullOrEmpty(e.Username))
     {
         ConnectionStateChanged?.Invoke(this, e);
     }
 }
示例#2
0
 private void InvokeConnectionStateChange()
 {
     if (ConnectionStateChanged != null)
     {
         ConnectionStateChanged.Invoke(this, new DroneConnectionStateChangedEventArgs(connected));
     }
 }
示例#3
0
 public void HandleConnectionStateChanged(object sender, ConnectionStateChangedEventArgs e)
 {
     if (!String.IsNullOrEmpty(e.Client))
     {
         ConnectionStateChanged?.Invoke(this, e);
     }
 }
示例#4
0
        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);
        }
示例#5
0
        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();
                });
            }
        }
示例#6
0
 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);
        }
示例#8
0
        public void Disconnect()
        {
            closeConnection = true;
            tcpClient.Close();

            ConnectionStateChanged?.Invoke(new EventArgs());
        }
示例#9
0
 private async Task HandleDisconnection(MqttClientDisconnectedEventArgs arg)
 {
     if (ConnectionStateChanged != null)
     {
         await ConnectionStateChanged.Invoke();
     }
 }
示例#10
0
 /// <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));
     }
 }
示例#11
0
        //--------------------------------------------------------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);
            }
        }
示例#12
0
 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));
     }
 }
示例#13
0
 private void SessionDisconnected(object sender, EventArgs args)
 {
     lock (_syncObj) {
         IsConnected = _sessionProvider.IsConnected;
         IsRunning   = false;
     }
     ConnectionStateChanged?.Invoke(this, EventArgs.Empty);
 }
示例#14
0
 private void _websocket_OnFatality(string reason)
 {
     if (_websocket?.State != null)
     {
         ConnectionStateChanged?.Invoke(this, _websocket.State);
     }
     Error?.Invoke(this, new Exception(reason));
 }
示例#15
0
 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));
     }
 }
示例#18
0
        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;
            }
        }
示例#19
0
 private void _device_ParameterChanged(object sender, Parameter parameter)
 {
     if (parameter == Parameter.State)
     {
         UpdateBatterySubscription();
         SetInfoText();
         ConnectionStateChanged?.Invoke(this, ConnectionState);
     }
 }
示例#20
0
        /// <summary>
        /// Private ctor since we're cheezy and use a singleton.
        /// </summary>
        private NetworkStatus()
        {
            m_nListUtil = PlatformTypes.New <INetworkInfo>();

            m_nListUtil.ConnectionStateChanged += () =>
            {
                ConnectionStateChanged?.Invoke();
            };
        }
示例#21
0
        protected virtual void OnConnectionStateChanged(ConnectionStateEventArgs e)
#endif

        {
            if (ConnectionStateChanged != null)
            {
                ConnectionStateChanged.Invoke(this, e);
            }
        }
示例#22
0
 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();
            };
        }
示例#24
0
 public async Task Disconnect()
 {
     await Task.Run(() =>
     {
         _closing = true;
         _socket.Disconnect(false);
         ConnectionStateChanged?.Invoke("Verbindung getrennt.", false);
     });
 }
示例#25
0
        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;
            }
        }
示例#26
0
        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)));
            }
        }
示例#28
0
文件: WsClient.cs 项目: ekinel/Rythm
        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));
        }
示例#29
0
        void SetConnectionState(ConnectionState newState)
        {
            if (ConnectionState == newState)
            {
                return;
            }

            ConnectionState = newState;
            GameThread.Post(() => ConnectionStateChanged?.Invoke(newState));
        }
示例#30
0
        private void Connection_ConnectionStateChanged(object sender, ConnectionStateChangedEventArgs e)
        {
            switch (e.NewState)
            {
            case ConnectionState.Closed:
                RemoveConnection(e.Connection);
                break;
            }

            ConnectionStateChanged?.Invoke(this, e);
        }