Beispiel #1
0
 private void SubscribeToEvents(CentaurusConnection connection)
 {
     connection.OnClosed    += Connection_OnClosed;
     connection.OnException += Connection_OnException;
     connection.OnMessage   += Connection_OnMessage;
     connection.OnSend      += Connection_OnSend;
 }
Beispiel #2
0
 private void UnsubscribeFromEvents(CentaurusConnection connection)
 {
     if (connection == null)
     {
         return;
     }
     connection.OnClosed    -= Connection_OnClosed;
     connection.OnException -= Connection_OnException;
     connection.OnMessage   -= Connection_OnMessage;
     connection.OnSend      -= Connection_OnSend;
 }
Beispiel #3
0
        public async Task Connect()
        {
            try
            {
                await connectionSemaphore.WaitAsync();

                if (IsConnected)
                {
                    return;
                }

                handshakeResult = new TaskCompletionSource <int>();

                connection = new CentaurusConnection(alphaWebSocketAddress, keyPair, constellation);
                SubscribeToEvents(connection);
                await connection.EstablishConnection();

                await handshakeResult.Task;

                await UpdateAccountData();

                IsConnected = true;
            }
            catch (Exception exc)
            {
                UnsubscribeFromEvents(connection);
                if (connection != null)
                {
                    await connection.CloseAndDispose();
                }
                connection = null;
                throw new Exception("Login failed.", exc);
            }
            finally
            {
                connectionSemaphore.Release();
            }
        }