Beispiel #1
0
    // This method is used within a lock so it shouldn't wait for lock itself anywhere inside.
    public async ValueTask ConnectAsync(string characterId, CancellationToken cancellationToken)
    {
        if (IsConnected)
        {
            throw new InvalidOperationException("Already connected.");
        }

        var connectionWithDisconnect = await _connectionFactory.ConnectAsync(cancellationToken)
                                       .ConfigureAwait(false);

        // Need to set it before calling ListenAndDispatchAsync.
        IsConnected = true;

        _resource = new ConnectionResource(
            connectionWithDisconnect,
            characterId,
            cancellationToken);

        Task listening(CancellationToken cancellationToken)
        => ListenAndDispatchAsync();

        _resource.SetListening(listening);

        await _authenticationService.AuthenticateAsync(this, characterId, _resource.CombinedCts.Token)
        .ConfigureAwait(false);
    }
Beispiel #2
0
 protected override void StartCommunicationListeners()
 {
     if (m_clientfactory == null)
     {
         ScanClientConnectionFactory();
     }
     m_client = m_clientfactory.ConnectAsync(m_endpoint, this).Result;
     ClientMemoryCloud.Initialize(m_client, this);
     this.Started += StartPolling;
 }