// 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.Threading; using System.Threading.Tasks; using System.Threading.Channels; namespace Microsoft.AspNetCore.SignalR.Client { public static partial class HubConnectionExtensions { private static IDisposable On(this HubConnection hubConnetion, string methodName, Type[] parameterTypes, Action handler) { return hubConnetion.On(methodName, parameterTypes, (parameters, state) => { var currentHandler = (Action)state; currentHandler(parameters); return Task.CompletedTask; }, handler); } public static IDisposable On(this HubConnection hubConnection, string methodName, Action handler) { if (hubConnection == null) { throw new ArgumentNullException(nameof(hubConnection)); } return hubConnection.On(methodName, Type.EmptyTypes, args => handler()); } public static IDisposable On(this HubConnection hubConnection, string methodName, Action handler) { if (hubConnection == null) { throw new ArgumentNullException(nameof(hubConnection)); } return hubConnection.On(methodName, new[] { typeof(T1) }, args => handler((T1)args[0])); } public static IDisposable On(this HubConnection hubConnection, string methodName, Action handler) { if (hubConnection == null) { throw new ArgumentNullException(nameof(hubConnection)); } return hubConnection.On(methodName, new[] { typeof(T1), typeof(T2) }, args => handler((T1)args[0], (T2)args[1])); } public static IDisposable On(this HubConnection hubConnection, string methodName, Action handler) { if (hubConnection == null) { throw new ArgumentNullException(nameof(hubConnection)); } return hubConnection.On(methodName, new[] { typeof(T1), typeof(T2), typeof(T3) }, args => handler((T1)args[0], (T2)args[1], (T3)args[2])); } public static IDisposable On(this HubConnection hubConnection, string methodName, Action handler) { if (hubConnection == null) { throw new ArgumentNullException(nameof(hubConnection)); } return hubConnection.On(methodName, new[] { typeof(T1), typeof(T2), typeof(T3), typeof(T4) }, args => handler((T1)args[0], (T2)args[1], (T3)args[2], (T4)args[3])); } public static void On(this HubConnection hubConnection, string methodName, Action handler) { if (hubConnection == null) { throw new ArgumentNullException(nameof(hubConnection)); } hubConnection.On(methodName, new[] { typeof(T1), typeof(T2), typeof(T3), typeof(T4), typeof(T5) }, args => handler((T1)args[0], (T2)args[1], (T3)args[2], (T4)args[3], (T5)args[4])); } public static IDisposable On(this HubConnection hubConnection, string methodName, Action handler) { if (hubConnection == null) { throw new ArgumentNullException(nameof(hubConnection)); } return hubConnection.On(methodName, new[] { typeof(T1), typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6) }, args => handler((T1)args[0], (T2)args[1], (T3)args[2], (T4)args[3], (T5)args[4], (T6)args[5])); } public static IDisposable On(this HubConnection hubConnection, string methodName, Action handler) { if (hubConnection == null) { throw new ArgumentNullException(nameof(hubConnection)); } return hubConnection.On(methodName, new[] { typeof(T1), typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7) }, args => handler((T1)args[0], (T2)args[1], (T3)args[2], (T4)args[3], (T5)args[4], (T6)args[5], (T7)args[6])); } public static IDisposable On(this HubConnection hubConnection, string methodName, Action handler) { if (hubConnection == null) { throw new ArgumentNullException(nameof(hubConnection)); } return hubConnection.On(methodName, new[] { typeof(T1), typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8) }, args => handler((T1)args[0], (T2)args[1], (T3)args[2], (T4)args[3], (T5)args[4], (T6)args[5], (T7)args[6], (T8)args[7])); } public static IDisposable On(this HubConnection hubConnection, string methodName, Type[] parameterTypes, Func handler) { return hubConnection.On(methodName, parameterTypes, (parameters, state) => { var currentHandler = (Func)state; return currentHandler(parameters); }, handler); } } }