public async Task ConnectAsync(TimeSpan timeout, CancellationToken cancellationToken) { ThrowIfDisposed(); try { if (timeout == TimeSpan.Zero) { await _channel.ConnectAsync(cancellationToken).ConfigureAwait(false); } else { await MqttTaskTimeout.WaitAsync(t => _channel.ConnectAsync(t), timeout, cancellationToken).ConfigureAwait(false); } } catch (Exception exception) { if (IsWrappedException(exception)) { throw; } WrapException(exception); } }
public void Setup() { var factory = new MqttFactory(); var tcpServer = new MqttTcpServerAdapter(new MqttNetEventLogger()); tcpServer.ClientHandler += args => { _serverChannel = (IMqttChannel)args.GetType().GetField("_channel", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance) .GetValue(args); return(Task.CompletedTask); }; _mqttServer = factory.CreateMqttServer(new[] { tcpServer }, new MqttNetEventLogger()); var serverOptions = new MqttServerOptionsBuilder().Build(); _mqttServer.StartAsync(serverOptions).GetAwaiter().GetResult(); var clientOptions = new MqttClientOptionsBuilder() .WithTcpServer("localhost").Build(); var tcpOptions = (MqttClientTcpOptions)clientOptions.ChannelOptions; _clientChannel = new MqttTcpChannel(new MqttClientOptions { ChannelOptions = tcpOptions }); _clientChannel.ConnectAsync(CancellationToken.None).GetAwaiter().GetResult(); }
public Task ConnectAsync(TimeSpan timeout) { ThrowIfDisposed(); _logger.Verbose <MqttChannelAdapter>("Connecting [Timeout={0}]", timeout); return(ExecuteAndWrapExceptionAsync(() => _channel.ConnectAsync().TimeoutAfter(timeout))); }
public async Task ConnectAsync(CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); try { await _channel.ConnectAsync(cancellationToken).ConfigureAwait(false); } catch (Exception exception) { if (!WrapAndThrowException(exception)) { throw; } } }
public async Task ConnectAsync(TimeSpan timeout, CancellationToken cancellationToken) { ThrowIfDisposed(); try { _logger.Verbose("Connecting [Timeout={0}]", timeout); await Common.TaskExtensions .TimeoutAfterAsync(ct => _channel.ConnectAsync(), timeout, cancellationToken) .ConfigureAwait(false); } catch (Exception exception) { if (IsWrappedException(exception)) { throw; } WrapException(exception); } }
public Task ConnectAsync(TimeSpan timeout) { _logger.Trace <MqttChannelAdapter>("Connecting [Timeout={0}]", timeout); return(ExecuteAndWrapExceptionAsync(() => _channel.ConnectAsync().TimeoutAfter(timeout))); }
public async Task ConnectAsync(TimeSpan timeout) { _logger.Info <MqttChannelAdapter>("Connecting [Timeout={0}]", timeout); await ExecuteAndWrapExceptionAsync(() => _channel.ConnectAsync().TimeoutAfter(timeout)); }