public ConnectAsync ( |
||
address | ||
Результат | Task |
/// <summary> /// Creates a WebSocket transport for the given address. /// </summary> /// <param name="address">The address to connect.</param> /// <returns>An IAsyncTransport object representing the transport.</returns> public override async Task <IAsyncTransport> CreateAsync(Address address) { var wsTransport = new WebSocketTransport(); await wsTransport.ConnectAsync(address, this.subprotocol, this.Options); return(wsTransport); }
/// <summary> /// Creates a new connection with a custom open frame and a callback to handle remote open frame. /// </summary> /// <param name="address">The address of remote endpoint to connect to.</param> /// <param name="open">If specified, it is sent to open the connection, otherwise an open frame created from the AMQP settings property is sent.</param> /// <param name="onOpened">If specified, it is invoked when an open frame is received from the remote peer.</param> /// <returns>A task for the connection creation operation. On success, the result is an AMQP <see cref="Connection"/></returns> public async Task <Connection> CreateAsync(Address address, Open open = null, OnOpened onOpened = null) { IAsyncTransport transport; TransportProvider provider; if (this.transportFactories != null && this.transportFactories.TryGetValue(address.Scheme, out provider)) { transport = await provider.CreateAsync(address).ConfigureAwait(false); } else if (TcpTransport.MatchScheme(address.Scheme)) { TcpTransport tcpTransport = new TcpTransport(this.BufferManager); await tcpTransport.ConnectAsync(address, this); transport = tcpTransport; } #if NETFX else if (WebSocketTransport.MatchScheme(address.Scheme)) { WebSocketTransport wsTransport = new WebSocketTransport(); await wsTransport.ConnectAsync(address, null); transport = wsTransport; } #endif else { throw new NotSupportedException(address.Scheme); } try { if (address.User != null) { SaslPlainProfile profile = new SaslPlainProfile(address.User, address.Password); transport = await profile.OpenAsync(address.Host, this.BufferManager, transport, null); } else if (this.saslSettings != null && this.saslSettings.Profile != null) { transport = await this.saslSettings.Profile.OpenAsync(address.Host, this.BufferManager, transport, null); } } catch { transport.Close(); throw; } AsyncPump pump = new AsyncPump(this.BufferManager, transport); Connection connection = new Connection(this.BufferManager, this.AMQP, address, transport, open, onOpened); pump.Start(connection); return(connection); }
void Connect(SaslProfile saslProfile, Open open) { ITransport transport; #if NETFX if (WebSocketTransport.MatchScheme(address.Scheme)) { WebSocketTransport wsTransport = new WebSocketTransport(); wsTransport.ConnectAsync(address, null).ConfigureAwait(false).GetAwaiter().GetResult(); transport = wsTransport; } else #endif { TcpTransport tcpTransport = new TcpTransport(); tcpTransport.Connect(this, this.address, DisableServerCertValidation); transport = tcpTransport; } try { if (saslProfile != null) { transport = saslProfile.Open(this.address.Host, transport); } else if (this.address.User != null) { transport = new SaslPlainProfile(this.address.User, this.address.Password).Open(this.address.Host, transport); } } catch { transport.Close(); throw; } this.writer = new Writer(transport); // after getting the transport, move state to open pipe before starting the pump this.SendHeader(); this.SendOpen(open); this.state = State.OpenPipe; this.reader = new Pump(this, transport); this.reader.Start(); }
async Task <IAsyncTransport> CreateTransportAsync(Address address, SaslProfile saslProfile, IHandler handler) { IAsyncTransport transport; TransportProvider provider; if (this.transportFactories != null && this.transportFactories.TryGetValue(address.Scheme, out provider)) { transport = await provider.CreateAsync(address).ConfigureAwait(false); } else if (TcpTransport.MatchScheme(address.Scheme)) { TcpTransport tcpTransport = new TcpTransport(this.BufferManager); await tcpTransport.ConnectAsync(address, this, handler).ConfigureAwait(false); transport = tcpTransport; } #if NETFX else if (WebSocketTransport.MatchScheme(address.Scheme)) { WebSocketTransport wsTransport = new WebSocketTransport(); await wsTransport.ConnectAsync(address, null).ConfigureAwait(false); transport = wsTransport; } #endif else { throw new NotSupportedException(address.Scheme); } if (saslProfile != null) { try { transport = await saslProfile.OpenAsync(address.Host, this.BufferManager, transport, null).ConfigureAwait(false); } catch { transport.Close(); throw; } } return(transport); }
/// <summary> /// Creates a new connection with a custom open frame and a callback to handle remote open frame. /// </summary> /// <param name="address">The address of remote endpoint to connect to.</param> /// <param name="open">If specified, it is sent to open the connection, otherwise an open frame created from the AMQP settings property is sent.</param> /// <param name="onOpened">If specified, it is invoked when an open frame is received from the remote peer.</param> /// <returns></returns> public async Task <Connection> CreateAsync(Address address, Open open, OnOpened onOpened) { IAsyncTransport transport; #if !WINDOWS_PHONE if (WebSocketTransport.MatchScheme(address.Scheme)) { WebSocketTransport wsTransport = new WebSocketTransport(); await wsTransport.ConnectAsync(address); transport = wsTransport; } else #endif if (string.Equals(address.Scheme, Address.Amqp, StringComparison.OrdinalIgnoreCase) || string.Equals(address.Scheme, Address.Amqps, StringComparison.OrdinalIgnoreCase)) { TcpTransport tcpTransport = new TcpTransport(); await tcpTransport.ConnectAsync(address, this); transport = tcpTransport; } else { throw new NotSupportedException(address.Scheme); } if (address.User != null) { SaslPlainProfile profile = new SaslPlainProfile(address.User, address.Password); transport = await profile.OpenAsync(address.Host, null, transport); } else if (this.saslSettings != null && this.saslSettings.Profile != null) { transport = await this.saslSettings.Profile.OpenAsync(address.Host, null, transport); } AsyncPump pump = new AsyncPump(null, transport); Connection connection = new Connection(null, this.AMQP, address, transport, open, onOpened); pump.Start(connection); return(connection); }
async Task <IAsyncTransport> CreateTransportAsync(Address address, SaslProfile saslProfile, IHandler handler) { IAsyncTransport transport; #if !WINDOWS_PHONE if (WebSocketTransport.MatchScheme(address.Scheme)) { WebSocketTransport wsTransport = new WebSocketTransport(); await wsTransport.ConnectAsync(address).ConfigureAwait(false); transport = wsTransport; } else #endif if (string.Equals(address.Scheme, Address.Amqp, StringComparison.OrdinalIgnoreCase) || string.Equals(address.Scheme, Address.Amqps, StringComparison.OrdinalIgnoreCase)) { TcpTransport tcpTransport = new TcpTransport(); await tcpTransport.ConnectAsync(address, this).ConfigureAwait(false); transport = tcpTransport; } else { throw new NotSupportedException(address.Scheme); } if (saslProfile != null) { try { transport = await saslProfile.OpenAsync(address.Host, null, transport, null).ConfigureAwait(false); } catch { transport.Close(); throw; } } return(transport); }
/// <summary> /// Creates a new connection with a custom open frame and a callback to handle remote open frame. /// </summary> /// <param name="address">The address of remote endpoint to connect to.</param> /// <param name="open">If specified, it is sent to open the connection, otherwise an open frame created from the AMQP settings property is sent.</param> /// <param name="onOpened">If specified, it is invoked when an open frame is received from the remote peer.</param> /// <returns></returns> public async Task <Connection> CreateAsync(Address address, Open open, OnOpened onOpened) { IAsyncTransport transport; if (WebSocketTransport.MatchScheme(address.Scheme)) { WebSocketTransport wsTransport = new WebSocketTransport(); await wsTransport.ConnectAsync(address); transport = wsTransport; } else { TcpTransport tcpTransport = new TcpTransport(); await tcpTransport.ConnectAsync(address, this); transport = tcpTransport; } if (address.User != null) { SaslPlainProfile profile = new SaslPlainProfile(address.User, address.Password); transport = await profile.OpenAsync(address.Host, null, transport); } else if (this.saslSettings != null && this.saslSettings.Profile != null) { transport = await this.saslSettings.Profile.OpenAsync(address.Host, null, transport); } AsyncPump pump = new AsyncPump(null, transport); Connection connection = new Connection(null, this.AMQP, address, transport, open, onOpened); pump.Start(connection); return(connection); }
void Connect(SaslProfile saslProfile, Open open) { if (open != null) { this.maxFrameSize = open.MaxFrameSize; this.channelMax = open.ChannelMax; } else { open = new Open() { ContainerId = Guid.NewGuid().ToString(), HostName = this.address.Host, MaxFrameSize = this.maxFrameSize, ChannelMax = this.channelMax }; } if (open.IdleTimeOut > 0) { this.heartBeat = new HeartBeat(this, open.IdleTimeOut); } ITransport transport; #if NETFX if (WebSocketTransport.MatchScheme(address.Scheme)) { WebSocketTransport wsTransport = new WebSocketTransport(); wsTransport.ConnectAsync(address, null).ConfigureAwait(false).GetAwaiter().GetResult(); transport = wsTransport; } else #endif { TcpTransport tcpTransport = new TcpTransport(); tcpTransport.Connect(this, this.address, DisableServerCertValidation); transport = tcpTransport; } try { if (saslProfile != null) { transport = saslProfile.Open(this.address.Host, transport); } else if (this.address.User != null) { transport = new SaslPlainProfile(this.address.User, this.address.Password).Open(this.address.Host, transport); } } catch { transport.Close(); throw; } this.writer = new Writer(transport); // after getting the transport, move state to open pipe before starting the pump this.SendHeader(); this.SendOpen(open); this.state = ConnectionState.OpenPipe; this.reader = new Pump(this, transport); this.reader.Start(); }
/// <summary> /// Creates a new connection with a custom open frame and a callback to handle remote open frame. /// </summary> /// <param name="address">The address of remote endpoint to connect to.</param> /// <param name="open">If specified, it is sent to open the connection, otherwise an open frame created from the AMQP settings property is sent.</param> /// <param name="onOpened">If specified, it is invoked when an open frame is received from the remote peer.</param> /// <returns>A task for the connection creation operation. On success, the result is an AMQP <see cref="Connection"/></returns> public async Task<Connection> CreateAsync(Address address, Open open, OnOpened onOpened) { IAsyncTransport transport; TransportProvider provider; if (this.transportFactories != null && this.transportFactories.TryGetValue(address.Scheme, out provider)) { transport = await provider.CreateAsync(address); } else if (TcpTransport.MatchScheme(address.Scheme)) { TcpTransport tcpTransport = new TcpTransport(this.BufferManager); await tcpTransport.ConnectAsync(address, this); transport = tcpTransport; } #if NETFX else if (WebSocketTransport.MatchScheme(address.Scheme)) { WebSocketTransport wsTransport = new WebSocketTransport(); await wsTransport.ConnectAsync(address, null); transport = wsTransport; } #endif else { throw new NotSupportedException(address.Scheme); } if (address.User != null) { SaslPlainProfile profile = new SaslPlainProfile(address.User, address.Password); transport = await profile.OpenAsync(address.Host, this.BufferManager, transport); } else if (this.saslSettings != null && this.saslSettings.Profile != null) { transport = await this.saslSettings.Profile.OpenAsync(address.Host, this.BufferManager, transport); } AsyncPump pump = new AsyncPump(this.BufferManager, transport); Connection connection = new Connection(this.BufferManager, this.AMQP, address, transport, open, onOpened); pump.Start(connection); return connection; }
void Connect(SaslProfile saslProfile, Open open) { ITransport transport; #if NETFX if (WebSocketTransport.MatchScheme(address.Scheme)) { WebSocketTransport wsTransport = new WebSocketTransport(); wsTransport.ConnectAsync(address).GetAwaiter().GetResult(); transport = wsTransport; } else #endif { TcpTransport tcpTransport = new TcpTransport(); tcpTransport.Connect(this, this.address, DisableServerCertValidation); transport = tcpTransport; } if (saslProfile != null) { transport = saslProfile.Open(this.address.Host, transport); } else if (this.address.User != null) { transport = new SaslPlainProfile(this.address.User, this.address.Password).Open(this.address.Host, transport); } this.transport = transport; // after getting the transport, move state to open pipe before starting the pump this.SendHeader(); this.SendOpen(open); this.state = State.OpenPipe; this.reader = new Pump(this); this.reader.Start(); }
/// <summary> /// Creates a new connection with a custom open frame and a callback to handle remote open frame. /// </summary> /// <param name="address">The address of remote endpoint to connect to.</param> /// <param name="open">If specified, it is sent to open the connection, otherwise an open frame created from the AMQP settings property is sent.</param> /// <param name="onOpened">If specified, it is invoked when an open frame is received from the remote peer.</param> /// <returns></returns> public async Task<Connection> CreateAsync(Address address, Open open, OnOpened onOpened) { IAsyncTransport transport; if (WebSocketTransport.MatchScheme(address.Scheme)) { WebSocketTransport wsTransport = new WebSocketTransport(); await wsTransport.ConnectAsync(address); transport = wsTransport; } else { TcpTransport tcpTransport = new TcpTransport(); await tcpTransport.ConnectAsync(address, this); transport = tcpTransport; } if (address.User != null) { SaslPlainProfile profile = new SaslPlainProfile(address.User, address.Password); transport = await profile.OpenAsync(address.Host, transport); } else if (this.saslSettings != null && this.saslSettings.Profile != null) { transport = await this.saslSettings.Profile.OpenAsync(address.Host, transport); } AsyncPump pump = new AsyncPump(transport); Connection connection = new Connection(this.AMQP, address, transport, open, onOpened); pump.Start(connection); return connection; }
/// <summary> /// Creates a new connection with a custom open frame and a callback to handle remote open frame. /// </summary> /// <param name="address">The address of remote endpoint to connect to.</param> /// <param name="open">If specified, it is sent to open the connection, otherwise an open frame created from the AMQP settings property is sent.</param> /// <param name="onOpened">If specified, it is invoked when an open frame is received from the remote peer.</param> /// <returns></returns> public async Task<Connection> CreateAsync(Address address, Open open, OnOpened onOpened) { IAsyncTransport transport; if (string.Equals(address.Scheme, Address.Amqp, StringComparison.OrdinalIgnoreCase) || string.Equals(address.Scheme, Address.Amqps, StringComparison.OrdinalIgnoreCase)) { TcpTransport tcpTransport = new TcpTransport(this.BufferManager); await tcpTransport.ConnectAsync(address, this); transport = tcpTransport; } #if NETFX else if (WebSocketTransport.MatchScheme(address.Scheme)) { WebSocketTransport wsTransport = new WebSocketTransport(); await wsTransport.ConnectAsync(address); transport = wsTransport; } #endif else { throw new NotSupportedException(address.Scheme); } if (address.User != null) { SaslPlainProfile profile = new SaslPlainProfile(address.User, address.Password); transport = await profile.OpenAsync(address.Host, this.BufferManager, transport); } else if (this.saslSettings != null && this.saslSettings.Profile != null) { transport = await this.saslSettings.Profile.OpenAsync(address.Host, this.BufferManager, transport); } AsyncPump pump = new AsyncPump(this.BufferManager, transport); Connection connection = new Connection(this.BufferManager, this.AMQP, address, transport, open, onOpened); pump.Start(connection); return connection; }
/// <summary> /// Creates a WebSocket transport for the given address. /// </summary> /// <param name="address">The address to connect.</param> /// <returns>An IAsyncTransport object representing the transport.</returns> public override async Task<IAsyncTransport> CreateAsync(Address address) { var wsTransport = new WebSocketTransport(); await wsTransport.ConnectAsync(address, this.Options); return wsTransport; }