Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
0
 private void Disconnect()
 {
     if (Client != null)
     {
         Client.Close();
     }
     if (Stream != null)
     {
         Stream.Close();
     }
     ConnectionDisconnected?.Invoke(this);
 }
Exemplo n.º 3
0
        public void Disconnect(bool sendToServer, string reason = "Client disconnected")
        {
            if ((int)CurrentState % 5 != 0)
            {
                CurrentState = ClientConnectionState.DISCONNECTED;
            }
            else
            {
                return;
            }

            try
            {
                if (sendToServer)
                {
                    Write(GetDisconnectPacket(reason));
                }
            }
            catch (Exception)
            { }

            try
            {
                if (Client.Client.Connected)
                {
                    Client.Close();
                }
            }
            catch (Exception)
            { }

            ConnectionDisconnected?.Invoke(this, new ConnectionDisconnectedEventArgs()
            {
                Reason = reason,
                Client = this,
            });
        }
Exemplo n.º 4
0
 protected virtual void OnConnectionDisconnected(ServerConnectionEventArgs e)
 {
     ConnectionDisconnected?.SafeInvoke(this, e);
 }
Exemplo n.º 5
0
 private void OnSystemDisconnected(object sender, EventArgs args)
 {
     ConnectionDisconnected?.Invoke("System disconnected");
 }
Exemplo n.º 6
0
 private void Bglib_BLEEventConnectionDisconnected(object sender, DisconnectedEventArgs e) => ConnectionDisconnected?.Invoke(this, e);