Refactor options

This commit is contained in:
Christian Kratky
2017-10-04 13:58:51 +02:00
parent d23ab88add
commit 67267c05fd
40 changed files with 291 additions and 197 deletions
@@ -37,15 +37,32 @@ namespace MQTTnet.TestApp.UniversalWindows
private async void Connect(object sender, RoutedEventArgs e)
{
var options = new MqttClientOptions
MqttClientOptions options = null;
if (UseTcp.IsChecked == true)
{
Server = Server.Text,
UserName = User.Text,
Password = Password.Text,
ClientId = ClientId.Text,
TlsOptions = { UseTls = UseTls.IsChecked == true },
ConnectionType = UseTcp.IsChecked == true ? MqttConnectionType.Tcp : MqttConnectionType.Ws
};
options = new MqttClientTcpOptions
{
Server = Server.Text
};
}
if (UseWs.IsChecked == true)
{
options = new MqttClientWebSocketOptions
{
Uri = Server.Text
};
}
if (options == null)
{
throw new InvalidOperationException();
}
options.UserName = User.Text;
options.Password = Password.Text;
options.ClientId = ClientId.Text;
options.TlsOptions.UseTls = UseTls.IsChecked == true;
try
{
@@ -56,7 +73,7 @@ namespace MQTTnet.TestApp.UniversalWindows
var factory = new MqttClientFactory();
_mqttClient = factory.CreateMqttClient(options);
await _mqttClient.ConnectAsync();
await _mqttClient.ConnectAsync(options);
}
catch (Exception exception)
{