Пример #1
0
        public virtual Task Start(IConnection connection, string connectionData, CancellationToken disconnectToken)
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }

            _initializeHandler = new TransportInitializationHandler(connection.TransportConnectTimeout, disconnectToken);

            // Tie into the OnFailure event so that we can stop the transport silently.
            _initializeHandler.OnFailure += () =>
            {
                Dispose();
            };

            _disconnectToken = disconnectToken;
            _connectionInfo  = new WebSocketConnectionInfo(connection, connectionData);

            // We don't need to await this task
            PerformConnect().ContinueWith(task =>
            {
                if (task.IsFaulted)
                {
                    _initializeHandler.Fail(task.Exception);
                }
                else if (task.IsCanceled)
                {
                    _initializeHandler.Fail();
                }
            },
                                          TaskContinuationOptions.NotOnRanToCompletion);

            return(_initializeHandler.Task);
        }
Пример #2
0
 // internal for testing
 protected internal void TransportFailed(Exception ex)
 {
     // will be no-op if handler already finished (either succeeded or failed)
     if (ex == null)
     {
         _initializationHandler.Fail();
     }
     else
     {
         _initializationHandler.Fail(ex);
     }
 }