public async Task ConnectAsync(Stream stream, CancellationToken cancellationToken = default) { if (this.IsConnected == true) { throw Assert.Exception(new InvalidOperationException("Connection has already been made.")); } IMessageTransmitter messageTransmitter = this.SerializationProvider.CreateMessageTransmitter(stream); try { await this.DialogProvider.ConnectAsync(messageTransmitter, cancellationToken); this.IsConnected = true; }catch { messageTransmitter.Dispose(); throw; } }
public void Connect(Stream stream) { if (this.IsConnected == true) { throw Assert.Exception(new InvalidOperationException("Connection has already been made.")); } IMessageTransmitter messageTransmitter = this.SerializationProvider.CreateMessageTransmitter(stream); try { this.DialogProvider.Connect(messageTransmitter); this.IsConnected = true; }catch { messageTransmitter.Dispose(); throw; } }