diff --git a/samples/ClientSample/ClientSample.csproj b/samples/ClientSample/ClientSample.csproj
index 1bd801900c..53645b78b9 100644
--- a/samples/ClientSample/ClientSample.csproj
+++ b/samples/ClientSample/ClientSample.csproj
@@ -16,6 +16,7 @@
+
diff --git a/samples/ClientSample/HubSample.cs b/samples/ClientSample/HubSample.cs
index ff89b1d3a3..049e20551d 100644
--- a/samples/ClientSample/HubSample.cs
+++ b/samples/ClientSample/HubSample.cs
@@ -2,40 +2,48 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
+using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.SignalR;
using Microsoft.AspNetCore.SignalR.Client;
+using Microsoft.Extensions.CommandLineUtils;
using Microsoft.Extensions.Logging;
namespace ClientSample
{
internal class HubSample
{
- public static async Task MainAsync(string[] args)
+ internal static void Register(CommandLineApplication app)
{
- var baseUrl = "http://localhost:5000/hubs";
- if (args.Length > 0)
+ app.Command("hub", cmd =>
{
- baseUrl = args[0];
- }
+ cmd.Description = "Tests a connection to a hub";
+
+ var baseUrlArgument = cmd.Argument("", "The URL to the Chat Hub to test");
+
+ cmd.OnExecute(() => ExecuteAsync(baseUrlArgument.Value));
+ });
+ }
+
+ public static async Task ExecuteAsync(string baseUrl)
+ {
+ baseUrl = string.IsNullOrEmpty(baseUrl) ? "http://localhost:5000/hubs" : baseUrl;
var loggerFactory = new LoggerFactory();
- loggerFactory.AddConsole(LogLevel.Debug);
- var logger = loggerFactory.CreateLogger();
- logger.LogInformation("Connecting to {0}", baseUrl);
+ Console.WriteLine("Connecting to {0}", baseUrl);
var connection = new HubConnection(new Uri(baseUrl), new JsonNetInvocationAdapter(), loggerFactory);
try
{
await connection.StartAsync();
- logger.LogInformation("Connected to {0}", baseUrl);
+ Console.WriteLine("Connected to {0}", baseUrl);
var cts = new CancellationTokenSource();
Console.CancelKeyPress += (sender, a) =>
{
a.Cancel = true;
- logger.LogInformation("Stopping loops...");
+ Console.WriteLine("Stopping loops...");
cts.Cancel();
};
@@ -43,21 +51,32 @@ namespace ClientSample
connection.On("Send", new[] { typeof(string) }, a =>
{
var message = (string)a[0];
- Console.WriteLine("RECEIVED: " + message);
+ Console.WriteLine(message);
});
while (!cts.Token.IsCancellationRequested)
{
- var line = Console.ReadLine();
- logger.LogInformation("Sending: {0}", line);
+ var line = await Task.Run(() => Console.ReadLine(), cts.Token);
- await connection.Invoke