Refactoring

This commit is contained in:
Christian Kratky
2018-06-06 21:29:34 +02:00
parent ae72bc3f99
commit 3480d9ac35
17 changed files with 88 additions and 19 deletions
@@ -0,0 +1,47 @@
using System;
using System.Threading.Tasks;
using MQTTnet.Client;
namespace MQTTnet.TestApp.NetCore
{
public static class ClientFlowTest
{
public static async Task RunAsync()
{
MqttNetConsoleLogger.ForwardToConsole();
try
{
var factory = new MqttFactory();
var client = factory.CreateMqttClient();
var options = new MqttClientOptionsBuilder()
.WithTcpServer("localhost")
.Build();
Console.WriteLine("BEFORE CONNECT");
await client.ConnectAsync(options);
Console.WriteLine("AFTER CONNECT");
Console.WriteLine("BEFORE SUBSCRIBE");
await client.SubscribeAsync("test/topic");
Console.WriteLine("AFTER SUBSCRIBE");
Console.WriteLine("BEFORE PUBLISH");
await client.PublishAsync("test/topic", "payload");
Console.WriteLine("AFTER PUBLISH");
await Task.Delay(1000);
Console.WriteLine("BEFORE DISCONNECT");
await client.DisconnectAsync();
Console.WriteLine("AFTER DISCONNECT");
Console.WriteLine("FINISHED");
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
}
}
@@ -15,6 +15,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Extensions\MQTTnet.Extensions.ManagedClient\MQTTnet.Extensions.ManagedClient.csproj" />
<ProjectReference Include="..\..\Frameworks\MQTTnet.NetStandard\MQTTnet.NetStandard.csproj" />
</ItemGroup>
@@ -4,7 +4,7 @@ using System.IO;
using Newtonsoft.Json;
using System.Collections.Generic;
using MQTTnet.Client;
using MQTTnet.ManagedClient;
using MQTTnet.Extensions.ManagedClient;
using MQTTnet.Protocol;
namespace MQTTnet.TestApp.NetCore
+5
View File
@@ -21,6 +21,7 @@ namespace MQTTnet.TestApp.NetCore
Console.WriteLine("4 = Start managed client");
Console.WriteLine("5 = Start public broker test");
Console.WriteLine("6 = Start server & client");
Console.WriteLine("7 = Client flow test");
var pressedKey = Console.ReadKey(true);
if (pressedKey.KeyChar == '1')
@@ -47,6 +48,10 @@ namespace MQTTnet.TestApp.NetCore
{
Task.Run(ServerAndClientTest.RunAsync);
}
else if (pressedKey.KeyChar == '7')
{
Task.Run(ClientFlowTest.RunAsync);
}
Thread.Sleep(Timeout.Infinite);
}