Merge branch 'rel/1.0.0-alpha2' into dev
This commit is contained in:
commit
2adf24d1c6
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace ChatSample.Hubs
|
||||
{
|
||||
|
|
@ -23,12 +24,12 @@ namespace ChatSample.Hubs
|
|||
|
||||
public override Task OnUsersJoined(UserDetails[] users)
|
||||
{
|
||||
return Clients.Client(Context.ConnectionId).InvokeAsync("UsersJoined", new[] { users });
|
||||
return Clients.Client(Context.ConnectionId).InvokeAsync("UsersJoined", users);
|
||||
}
|
||||
|
||||
public override Task OnUsersLeft(UserDetails[] users)
|
||||
{
|
||||
return Clients.Client(Context.ConnectionId).InvokeAsync("UsersLeft", new[] { users });
|
||||
return Clients.Client(Context.ConnectionId).InvokeAsync("UsersLeft", users);
|
||||
}
|
||||
|
||||
public async Task Send(string message)
|
||||
|
|
|
|||
|
|
@ -131,32 +131,32 @@ namespace Microsoft.AspNetCore.SignalR.Client
|
|||
_handlers.AddOrUpdate(methodName, invocationHandler, (_, __) => invocationHandler);
|
||||
}
|
||||
|
||||
public async Task<ReadableChannel<object>> StreamAsync(string methodName, Type returnType, CancellationToken cancellationToken, params object[] args)
|
||||
public async Task<ReadableChannel<object>> StreamAsync(string methodName, Type returnType, object[] args, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return await StreamAsyncCore(methodName, returnType, cancellationToken).ForceAsync();
|
||||
return await StreamAsyncCore(methodName, returnType, args, cancellationToken).ForceAsync();
|
||||
}
|
||||
|
||||
private async Task<ReadableChannel<object>> StreamAsyncCore(string methodName, Type returnType, CancellationToken cancellationToken, params object[] args)
|
||||
private async Task<ReadableChannel<object>> StreamAsyncCore(string methodName, Type returnType, object[] args, CancellationToken cancellationToken)
|
||||
{
|
||||
var irq = InvocationRequest.Stream(cancellationToken, returnType, GetNextId(), _loggerFactory, out var channel);
|
||||
await InvokeCore(methodName, irq, args, nonBlocking: false);
|
||||
return channel;
|
||||
}
|
||||
|
||||
public async Task<object> InvokeAsync(string methodName, Type returnType, CancellationToken cancellationToken, params object[] args) =>
|
||||
await InvokeAsyncCore(methodName, returnType, cancellationToken, args).ForceAsync();
|
||||
public async Task<object> InvokeAsync(string methodName, Type returnType, object[] args, CancellationToken cancellationToken = default(CancellationToken)) =>
|
||||
await InvokeAsyncCore(methodName, returnType, args, cancellationToken).ForceAsync();
|
||||
|
||||
private async Task<object> InvokeAsyncCore(string methodName, Type returnType, CancellationToken cancellationToken, params object[] args)
|
||||
private async Task<object> InvokeAsyncCore(string methodName, Type returnType, object[] args, CancellationToken cancellationToken)
|
||||
{
|
||||
var irq = InvocationRequest.Invoke(cancellationToken, returnType, GetNextId(), _loggerFactory, out var task);
|
||||
await InvokeCore(methodName, irq, args, nonBlocking: false);
|
||||
return await task;
|
||||
}
|
||||
|
||||
public async Task SendAsync(string methodName, CancellationToken cancellationToken, params object[] args) =>
|
||||
await SendAsyncCore(methodName, cancellationToken, args).ForceAsync();
|
||||
public async Task SendAsync(string methodName, object[] args, CancellationToken cancellationToken = default(CancellationToken)) =>
|
||||
await SendAsyncCore(methodName, args, cancellationToken).ForceAsync();
|
||||
|
||||
private Task SendAsyncCore(string methodName, CancellationToken cancellationToken, params object[] args)
|
||||
private Task SendAsyncCore(string methodName, object[] args, CancellationToken cancellationToken)
|
||||
{
|
||||
var irq = InvocationRequest.Invoke(cancellationToken, typeof(void), GetNextId(), _loggerFactory, out _);
|
||||
return InvokeCore(methodName, irq, args, nonBlocking: true);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,79 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading;
|
||||
|
||||
namespace Microsoft.AspNetCore.SignalR.Client
|
||||
{
|
||||
public partial class HubConnectionExtensions
|
||||
{
|
||||
public static Task InvokeAsync(this HubConnection hubConnection, string methodName, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.InvokeAsync(methodName, Array.Empty<object>(), cancellationToken);
|
||||
}
|
||||
|
||||
public static Task InvokeAsync(this HubConnection hubConnection, string methodName, object arg1, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.InvokeAsync(methodName, new object[] { arg1 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task InvokeAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.InvokeAsync(methodName, new object[] { arg1, arg2 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task InvokeAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.InvokeAsync(methodName, new object[] { arg1, arg2, arg3 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task InvokeAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.InvokeAsync(methodName, new object[] { arg1, arg2, arg3, arg4 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task InvokeAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.InvokeAsync(methodName, new object[] { arg1, arg2, arg3, arg4, arg5 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task InvokeAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.InvokeAsync(methodName, new object[] { arg1, arg2, arg3, arg4, arg5, arg6 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task InvokeAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.InvokeAsync(methodName, new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task InvokeAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, object arg8, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.InvokeAsync(methodName, new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task InvokeAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, object arg8, object arg9, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.InvokeAsync(methodName, new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task InvokeAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, object arg8, object arg9, object arg10, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.InvokeAsync(methodName, new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task InvokeAsync(this HubConnection hubConnection, string methodName, object[] args, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
if (hubConnection == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(hubConnection));
|
||||
}
|
||||
|
||||
return hubConnection.InvokeAsync(methodName, typeof(object), args, cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading;
|
||||
|
||||
namespace Microsoft.AspNetCore.SignalR.Client
|
||||
{
|
||||
public static partial class HubConnectionExtensions
|
||||
{
|
||||
public static Task<TResult> InvokeAsync<TResult>(this HubConnection hubConnection, string methodName, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.InvokeAsync<TResult>(methodName, Array.Empty<object>(), cancellationToken);
|
||||
}
|
||||
|
||||
public static Task<TResult> InvokeAsync<TResult>(this HubConnection hubConnection, string methodName, object arg1, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.InvokeAsync<TResult>(methodName, new object[] { arg1 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task<TResult> InvokeAsync<TResult>(this HubConnection hubConnection, string methodName, object arg1, object arg2, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.InvokeAsync<TResult>(methodName, new object[] { arg1, arg2 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task<TResult> InvokeAsync<TResult>(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.InvokeAsync<TResult>(methodName, new object[] { arg1, arg2, arg3 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task<TResult> InvokeAsync<TResult>(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.InvokeAsync<TResult>(methodName, new object[] { arg1, arg2, arg3, arg4 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task<TResult> InvokeAsync<TResult>(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.InvokeAsync<TResult>(methodName, new object[] { arg1, arg2, arg3, arg4, arg5 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task<TResult> InvokeAsync<TResult>(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.InvokeAsync<TResult>(methodName, new object[] { arg1, arg2, arg3, arg4, arg5, arg6 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task<TResult> InvokeAsync<TResult>(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.InvokeAsync<TResult>(methodName, new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task<TResult> InvokeAsync<TResult>(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, object arg8, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.InvokeAsync<TResult>(methodName, new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task<TResult> InvokeAsync<TResult>(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, object arg8, object arg9, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.InvokeAsync<TResult>(methodName, new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task<TResult> InvokeAsync<TResult>(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, object arg8, object arg9, object arg10, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.InvokeAsync<TResult>(methodName, new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static async Task<TResult> InvokeAsync<TResult>(this HubConnection hubConnection, string methodName, object[] args, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
if (hubConnection == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(hubConnection));
|
||||
}
|
||||
|
||||
return (TResult)await hubConnection.InvokeAsync(methodName, typeof(TResult), args, cancellationToken);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.AspNetCore.SignalR.Client
|
||||
{
|
||||
public static partial class HubConnectionExtensions
|
||||
{
|
||||
public static Task SendAsync(this HubConnection hubConnection, string methodName, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.SendAsync(methodName, Array.Empty<object>(), cancellationToken);
|
||||
}
|
||||
|
||||
public static Task SendAsync(this HubConnection hubConnection, string methodName, object arg1, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.SendAsync(methodName, new object[] { arg1 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task SendAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.SendAsync(methodName, new object[] { arg1, arg2 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task SendAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.SendAsync(methodName, new object[] { arg1, arg2, arg3 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task SendAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.SendAsync(methodName, new object[] { arg1, arg2, arg3, arg4 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task SendAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.SendAsync(methodName, new object[] { arg1, arg2, arg3, arg4, arg5 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task SendAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.SendAsync(methodName, new object[] { arg1, arg2, arg3, arg4, arg5, arg6 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task SendAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.SendAsync(methodName, new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task SendAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, object arg8, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.SendAsync(methodName, new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task SendAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, object arg8, object arg9, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.SendAsync(methodName, new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task SendAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, object arg8, object arg9, object arg10, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.SendAsync(methodName, new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10 }, cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,121 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks.Channels;
|
||||
|
||||
namespace Microsoft.AspNetCore.SignalR.Client
|
||||
{
|
||||
public static partial class HubConnectionExtensions
|
||||
{
|
||||
public static Task<ReadableChannel<TResult>> StreamAsync<TResult>(this HubConnection hubConnection, string methodName, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.StreamAsync<TResult>(methodName, Array.Empty<object>(), cancellationToken);
|
||||
}
|
||||
|
||||
public static Task<ReadableChannel<TResult>> StreamAsync<TResult>(this HubConnection hubConnection, string methodName, object arg1, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.StreamAsync<TResult>(methodName, new object[] { arg1 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task<ReadableChannel<TResult>> StreamAsync<TResult>(this HubConnection hubConnection, string methodName, object arg1, object arg2, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.StreamAsync<TResult>(methodName, new object[] { arg1, arg2 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task<ReadableChannel<TResult>> StreamAsync<TResult>(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.StreamAsync<TResult>(methodName, new object[] { arg1, arg2, arg3 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task<ReadableChannel<TResult>> StreamAsync<TResult>(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.StreamAsync<TResult>(methodName, new object[] { arg1, arg2, arg3, arg4 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task<ReadableChannel<TResult>> StreamAsync<TResult>(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.StreamAsync<TResult>(methodName, new object[] { arg1, arg2, arg3, arg4, arg5 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task<ReadableChannel<TResult>> StreamAsync<TResult>(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.StreamAsync<TResult>(methodName, new object[] { arg1, arg2, arg3, arg4, arg5, arg6 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task<ReadableChannel<TResult>> StreamAsync<TResult>(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.StreamAsync<TResult>(methodName, new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task<ReadableChannel<TResult>> StreamAsync<TResult>(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, object arg8, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.StreamAsync<TResult>(methodName, new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task<ReadableChannel<TResult>> StreamAsync<TResult>(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, object arg8, object arg9, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.StreamAsync<TResult>(methodName, new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task<ReadableChannel<TResult>> StreamAsync<TResult>(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, object arg8, object arg9, object arg10, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.StreamAsync<TResult>(methodName, new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static async Task<ReadableChannel<TResult>> StreamAsync<TResult>(this HubConnection hubConnection, string methodName, object[] args, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
if (hubConnection == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(hubConnection));
|
||||
}
|
||||
|
||||
var inputChannel = await hubConnection.StreamAsync(methodName, typeof(TResult), args, cancellationToken);
|
||||
var outputChannel = Channel.CreateUnbounded<TResult>();
|
||||
|
||||
// Local function to provide a way to run async code as fire-and-forget
|
||||
// The output channel is how we signal completion to the caller.
|
||||
async Task RunChannel()
|
||||
{
|
||||
try
|
||||
{
|
||||
while (await inputChannel.WaitToReadAsync())
|
||||
{
|
||||
while (inputChannel.TryRead(out var item))
|
||||
{
|
||||
while (!outputChannel.Out.TryWrite((TResult)item))
|
||||
{
|
||||
if (!await outputChannel.Out.WaitToWriteAsync())
|
||||
{
|
||||
// Failed to write to the output channel because it was closed. Nothing really we can do but abort here.
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Manifest any errors in the completion task
|
||||
await inputChannel.Completion;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
outputChannel.Out.TryComplete(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
// This will safely no-op if the catch block above ran.
|
||||
outputChannel.Out.TryComplete();
|
||||
}
|
||||
}
|
||||
|
||||
_ = RunChannel();
|
||||
|
||||
return outputChannel.In;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -8,95 +8,11 @@ using System.Threading.Tasks.Channels;
|
|||
|
||||
namespace Microsoft.AspNetCore.SignalR.Client
|
||||
{
|
||||
public static class HubConnectionExtensions
|
||||
public static partial class HubConnectionExtensions
|
||||
{
|
||||
public static Task InvokeAsync(this HubConnection hubConnection, string methodName, params object[] args) =>
|
||||
InvokeAsync(hubConnection, methodName, CancellationToken.None, args);
|
||||
|
||||
public static Task InvokeAsync(this HubConnection hubConnection, string methodName, CancellationToken cancellationToken, params object[] args)
|
||||
{
|
||||
if (hubConnection == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(hubConnection));
|
||||
}
|
||||
|
||||
return hubConnection.InvokeAsync(methodName, typeof(object), cancellationToken, args);
|
||||
}
|
||||
|
||||
public static Task<TResult> InvokeAsync<TResult>(this HubConnection hubConnection, string methodName, params object[] args) =>
|
||||
InvokeAsync<TResult>(hubConnection, methodName, CancellationToken.None, args);
|
||||
|
||||
public async static Task<TResult> InvokeAsync<TResult>(this HubConnection hubConnection, string methodName, CancellationToken cancellationToken, params object[] args)
|
||||
{
|
||||
if (hubConnection == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(hubConnection));
|
||||
}
|
||||
|
||||
return (TResult)await hubConnection.InvokeAsync(methodName, typeof(TResult), cancellationToken, args);
|
||||
}
|
||||
|
||||
public static Task SendAsync(this HubConnection hubConnection, string methodName, params object[] args)
|
||||
{
|
||||
return hubConnection.SendAsync(methodName, CancellationToken.None, args);
|
||||
}
|
||||
|
||||
public static Task<ReadableChannel<TResult>> StreamAsync<TResult>(this HubConnection hubConnection, string methodName, params object[] args) =>
|
||||
StreamAsync<TResult>(hubConnection, methodName, CancellationToken.None, args);
|
||||
|
||||
public static async Task<ReadableChannel<TResult>> StreamAsync<TResult>(this HubConnection hubConnection, string methodName, CancellationToken cancellationToken, params object[] args)
|
||||
{
|
||||
if (hubConnection == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(hubConnection));
|
||||
}
|
||||
|
||||
var inputChannel = await hubConnection.StreamAsync(methodName, typeof(TResult), cancellationToken, args);
|
||||
var outputChannel = Channel.CreateUnbounded<TResult>();
|
||||
|
||||
// Local function to provide a way to run async code as fire-and-forget
|
||||
// The output channel is how we signal completion to the caller.
|
||||
async Task RunChannel()
|
||||
{
|
||||
try
|
||||
{
|
||||
while (await inputChannel.WaitToReadAsync())
|
||||
{
|
||||
while (inputChannel.TryRead(out var item))
|
||||
{
|
||||
while (!outputChannel.Out.TryWrite((TResult)item))
|
||||
{
|
||||
if (!await outputChannel.Out.WaitToWriteAsync())
|
||||
{
|
||||
// Failed to write to the output channel because it was closed. Nothing really we can do but abort here.
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Manifest any errors in the completion task
|
||||
await inputChannel.Completion;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
outputChannel.Out.TryComplete(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
// This will safely no-op if the catch block above ran.
|
||||
outputChannel.Out.TryComplete();
|
||||
}
|
||||
}
|
||||
|
||||
_ = RunChannel();
|
||||
|
||||
return outputChannel.In;
|
||||
}
|
||||
|
||||
private static void On(this HubConnection hubConnetion, string methodName, Type[] parameterTypes, Action<object[]> handler)
|
||||
{
|
||||
hubConnetion.On(methodName, parameterTypes, (parameters) =>
|
||||
hubConnetion.On(methodName, parameterTypes, (parameters) =>
|
||||
{
|
||||
handler(parameters);
|
||||
return Task.CompletedTask;
|
||||
|
|
|
|||
|
|
@ -13,6 +13,6 @@ namespace Microsoft.AspNetCore.SignalR
|
|||
/// <param name="method">name of the method to invoke</param>
|
||||
/// <param name="args">argumetns to pass to the client</param>
|
||||
/// <returns>A task that represents when the data has been sent to the client.</returns>
|
||||
Task InvokeAsync(string method, params object[] args);
|
||||
Task InvokeAsync(string method, object[] args);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,186 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.AspNetCore.SignalR
|
||||
{
|
||||
public static class IClientProxyExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Invokes a method on the connection(s) represented by the <see cref="IClientProxy"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="clientProxy">The <see cref="IClientProxy"/></param>
|
||||
/// <param name="method">name of the method to invoke</param>
|
||||
/// <returns>A task that represents when the data has been sent to the client.</returns>
|
||||
public static Task InvokeAsync(this IClientProxy clientProxy, string method)
|
||||
{
|
||||
return clientProxy.InvokeAsync(method, Array.Empty<object>());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invokes a method on the connection(s) represented by the <see cref="IClientProxy"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="clientProxy">The <see cref="IClientProxy"/></param>
|
||||
/// <param name="method">name of the method to invoke</param>
|
||||
/// <param name="arg1">The first argument</param>
|
||||
/// <returns>A task that represents when the data has been sent to the client.</returns>
|
||||
public static Task InvokeAsync(this IClientProxy clientProxy, string method, object arg1)
|
||||
{
|
||||
return clientProxy.InvokeAsync(method, new object[] { arg1 });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invokes a method on the connection(s) represented by the <see cref="IClientProxy"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="clientProxy">The <see cref="IClientProxy"/></param>
|
||||
/// <param name="method">name of the method to invoke</param>
|
||||
/// <param name="arg1">The first argument</param>
|
||||
/// <param name="arg2">The second argument</param>
|
||||
/// <returns>A task that represents when the data has been sent to the client.</returns>
|
||||
public static Task InvokeAsync(this IClientProxy clientProxy, string method, object arg1, object arg2)
|
||||
{
|
||||
return clientProxy.InvokeAsync(method, new object[] { arg1, arg2 });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invokes a method on the connection(s) represented by the <see cref="IClientProxy"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="clientProxy">The <see cref="IClientProxy"/></param>
|
||||
/// <param name="method">name of the method to invoke</param>
|
||||
/// <param name="arg1">The first argument</param>
|
||||
/// <param name="arg2">The second argument</param>
|
||||
/// <param name="arg3">The third argument</param>
|
||||
/// <returns>A task that represents when the data has been sent to the client.</returns>
|
||||
public static Task InvokeAsync(this IClientProxy clientProxy, string method, object arg1, object arg2, object arg3)
|
||||
{
|
||||
return clientProxy.InvokeAsync(method, new object[] { arg1, arg2, arg3 });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invokes a method on the connection(s) represented by the <see cref="IClientProxy"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="clientProxy">The <see cref="IClientProxy"/></param>
|
||||
/// <param name="method">name of the method to invoke</param>
|
||||
/// <param name="arg1">The first argument</param>
|
||||
/// <param name="arg2">The second argument</param>
|
||||
/// <param name="arg3">The third argument</param>
|
||||
/// <param name="arg4">The fourth argument</param>
|
||||
/// <returns>A task that represents when the data has been sent to the client.</returns>
|
||||
public static Task InvokeAsync(this IClientProxy clientProxy, string method, object arg1, object arg2, object arg3, object arg4)
|
||||
{
|
||||
return clientProxy.InvokeAsync(method, new object[] { arg1, arg2, arg3, arg4 });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invokes a method on the connection(s) represented by the <see cref="IClientProxy"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="clientProxy">The <see cref="IClientProxy"/></param>
|
||||
/// <param name="method">name of the method to invoke</param>
|
||||
/// <param name="arg1">The first argument</param>
|
||||
/// <param name="arg2">The second argument</param>
|
||||
/// <param name="arg3">The third argument</param>
|
||||
/// <param name="arg4">The fourth argument</param>
|
||||
/// <param name="arg5">The fifth argument</param>
|
||||
/// <returns>A task that represents when the data has been sent to the client.</returns>
|
||||
public static Task InvokeAsync(this IClientProxy clientProxy, string method, object arg1, object arg2, object arg3, object arg4, object arg5)
|
||||
{
|
||||
return clientProxy.InvokeAsync(method, new object[] { arg1, arg2, arg3, arg4, arg5 });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invokes a method on the connection(s) represented by the <see cref="IClientProxy"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="clientProxy">The <see cref="IClientProxy"/></param>
|
||||
/// <param name="method">name of the method to invoke</param>
|
||||
/// <param name="arg1">The first argument</param>
|
||||
/// <param name="arg2">The second argument</param>
|
||||
/// <param name="arg3">The third argument</param>
|
||||
/// <param name="arg4">The fourth argument</param>
|
||||
/// <param name="arg5">The fifth argument</param>
|
||||
/// <param name="arg6">The sixth argument</param>
|
||||
/// <returns>A task that represents when the data has been sent to the client.</returns>
|
||||
public static Task InvokeAsync(this IClientProxy clientProxy, string method, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6)
|
||||
{
|
||||
return clientProxy.InvokeAsync(method, new object[] { arg1, arg2, arg3, arg4, arg5, arg6 });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invokes a method on the connection(s) represented by the <see cref="IClientProxy"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="clientProxy">The <see cref="IClientProxy"/></param>
|
||||
/// <param name="method">name of the method to invoke</param>
|
||||
/// <param name="arg1">The first argument</param>
|
||||
/// <param name="arg2">The second argument</param>
|
||||
/// <param name="arg3">The third argument</param>
|
||||
/// <param name="arg4">The fourth argument</param>
|
||||
/// <param name="arg5">The fifth argument</param>
|
||||
/// <param name="arg6">The sixth argument</param>
|
||||
/// <param name="arg7">The seventh argument</param>
|
||||
/// <returns>A task that represents when the data has been sent to the client.</returns>
|
||||
public static Task InvokeAsync(this IClientProxy clientProxy, string method, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7)
|
||||
{
|
||||
return clientProxy.InvokeAsync(method, new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7 });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invokes a method on the connection(s) represented by the <see cref="IClientProxy"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="clientProxy">The <see cref="IClientProxy"/></param>
|
||||
/// <param name="method">name of the method to invoke</param>
|
||||
/// <param name="arg1">The first argument</param>
|
||||
/// <param name="arg2">The second argument</param>
|
||||
/// <param name="arg3">The third argument</param>
|
||||
/// <param name="arg4">The fourth argument</param>
|
||||
/// <param name="arg5">The fifth argument</param>
|
||||
/// <param name="arg6">The sixth argument</param>
|
||||
/// <param name="arg7">The seventh argument</param>
|
||||
/// <param name="arg8">The eigth argument</param>
|
||||
/// <returns>A task that represents when the data has been sent to the client.</returns>
|
||||
public static Task InvokeAsync(this IClientProxy clientProxy, string method, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, object arg8)
|
||||
{
|
||||
return clientProxy.InvokeAsync(method, new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8 });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invokes a method on the connection(s) represented by the <see cref="IClientProxy"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="clientProxy">The <see cref="IClientProxy"/></param>
|
||||
/// <param name="method">name of the method to invoke</param>
|
||||
/// <param name="arg1">The first argument</param>
|
||||
/// <param name="arg2">The second argument</param>
|
||||
/// <param name="arg3">The third argument</param>
|
||||
/// <param name="arg4">The fourth argument</param>
|
||||
/// <param name="arg5">The fifth argument</param>
|
||||
/// <param name="arg6">The sixth argument</param>
|
||||
/// <param name="arg7">The seventh argument</param>
|
||||
/// <param name="arg8">The eigth argument</param>
|
||||
/// <param name="arg9">The ninth argument</param>
|
||||
/// <returns>A task that represents when the data has been sent to the client.</returns>
|
||||
public static Task InvokeAsync(this IClientProxy clientProxy, string method, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, object arg8, object arg9)
|
||||
{
|
||||
return clientProxy.InvokeAsync(method, new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invokes a method on the connection(s) represented by the <see cref="IClientProxy"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="clientProxy">The <see cref="IClientProxy"/></param>
|
||||
/// <param name="method">name of the method to invoke</param>
|
||||
/// <param name="arg1">The first argument</param>
|
||||
/// <param name="arg2">The second argument</param>
|
||||
/// <param name="arg3">The third argument</param>
|
||||
/// <param name="arg4">The fourth argument</param>
|
||||
/// <param name="arg5">The fifth argument</param>
|
||||
/// <param name="arg6">The sixth argument</param>
|
||||
/// <param name="arg7">The seventh argument</param>
|
||||
/// <param name="arg8">The eigth argument</param>
|
||||
/// <param name="arg9">The ninth argument</param>
|
||||
/// <param name="arg10">The tenth argument</param>
|
||||
/// <returns>A task that represents when the data has been sent to the client.</returns>
|
||||
public static Task InvokeAsync(this IClientProxy clientProxy, string method, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, object arg8, object arg9, object arg10)
|
||||
{
|
||||
return clientProxy.InvokeAsync(method, new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10 });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -21,6 +21,7 @@ using Moq;
|
|||
using MsgPack;
|
||||
using MsgPack.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using Xunit;
|
||||
|
||||
|
|
@ -697,6 +698,42 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
|||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task SendArraySendsArrayToAllClients()
|
||||
{
|
||||
var serviceProvider = CreateServiceProvider();
|
||||
|
||||
var endPoint = serviceProvider.GetService<HubEndPoint<MethodHub>>();
|
||||
|
||||
using (var firstClient = new TestClient())
|
||||
using (var secondClient = new TestClient())
|
||||
{
|
||||
Task firstEndPointTask = endPoint.OnConnectedAsync(firstClient.Connection);
|
||||
Task secondEndPointTask = endPoint.OnConnectedAsync(secondClient.Connection);
|
||||
|
||||
await Task.WhenAll(firstClient.Connected, secondClient.Connected).OrTimeout();
|
||||
|
||||
await firstClient.SendInvocationAsync(nameof(MethodHub.SendArray)).OrTimeout();
|
||||
|
||||
foreach (var result in await Task.WhenAll(
|
||||
firstClient.ReadAsync(),
|
||||
secondClient.ReadAsync()).OrTimeout())
|
||||
{
|
||||
var invocation = Assert.IsType<InvocationMessage>(result);
|
||||
Assert.Equal("Array", invocation.Target);
|
||||
Assert.Single(invocation.Arguments);
|
||||
var values = ((JArray)invocation.Arguments[0]).Select(t => t.Value<int>()).ToArray();
|
||||
Assert.Equal(new int[] { 1, 2, 3 }, values);
|
||||
}
|
||||
|
||||
// kill the connections
|
||||
firstClient.Dispose();
|
||||
secondClient.Dispose();
|
||||
|
||||
await Task.WhenAll(firstEndPointTask, secondEndPointTask).OrTimeout();
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(HubTypes))]
|
||||
public async Task SendToAllExcept(Type hubType)
|
||||
|
|
@ -1570,6 +1607,11 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
|||
return Clients.All.InvokeAsync("Broadcast", new Result { Message = "test", paramName = "param" });
|
||||
}
|
||||
|
||||
public Task SendArray()
|
||||
{
|
||||
return Clients.All.InvokeAsync("Array", new int[] { 1, 2, 3 });
|
||||
}
|
||||
|
||||
public Task<int> TaskValueMethod()
|
||||
{
|
||||
return Task.FromResult(42);
|
||||
|
|
|
|||
Loading…
Reference in New Issue