Esempio n. 1
0
        void OnAcceptTransport(TransportAsyncCallbackArgs args)
        {
            Fx.Assert(args.Exception == null, "Should not be failed.");
            Fx.Assert(args.Transport != null, "Should have a transport");

            AmqpConnectionSettings settings = this.connectionSettings.Clone();

            settings.OnOpenCallback = this.OnReceiveConnectionOpen;
            AmqpConnection connection = null;

            try
            {
                connection = this.CreateConnection(
                    args.Transport,
                    (ProtocolHeader)args.UserToken,
                    false,
                    this.amqpSettings.Clone(),
                    settings);
                connection.BeginOpen(connection.DefaultOpenTimeout, this.onConnectionOpenComplete, connection);
            }
            catch (Exception ex)
            {
                if (Fx.IsFatal(ex))
                {
                    throw;
                }

                if (connection != null)
                {
                    connection.TryClose(ExceptionHelper.ToAmqpException(ex));
                }
            }
        }
Esempio n. 2
0
        void OnConnectionOpenComplete(IAsyncResult result)
        {
            AmqpConnection connection = (AmqpConnection)result.AsyncState;

            try
            {
                connection.EndOpen(result);

                this.HandleConnection(connection);
            }
            catch (Exception exception)
            {
                if (Fx.IsFatal(exception))
                {
                    throw;
                }

                connection.TryClose(ExceptionHelper.ToAmqpException(exception));
            }
        }
Esempio n. 3
0
            protected override void HandleConnection(AmqpConnection connection)
            {
                try
                {
                    Fx.Assert(connection.Settings.RemoteHostName != null, "RemoteHostName cannot be null. It has been validated in OnConnectionOpen.");
                    IConnectionHandler handler = null;
                    if (!this.connectionHandlers.TryGetValue(connection.Settings.RemoteHostName, out handler))
                    {
                        throw new AmqpException(AmqpError.NotFound, SR.AmqpConnectionHandlerNotFound(connection.Settings.RemoteHostName));
                    }

                    handler.HandleConnection(connection);
                }
                catch (Exception exception)
                {
                    if (Fx.IsFatal(exception))
                    {
                        throw;
                    }

                    throw ExceptionHelper.ToAmqpException(exception);
                }
            }