Microsoft.AspNetCore.SignalR.Hubs.HubPipelineModule.BuildIncoming C# (CSharp) Method

BuildIncoming() public method

Wraps a function that invokes a server-side hub method. Even if a client has not been authorized to connect to a hub, it will still be authorized to invoke server-side methods on that hub unless it is prevented in IHubPipelineModule.BuildIncoming by not executing the invoke parameter.
public BuildIncoming ( Func invoke ) : Task>.Func
invoke Func A function that invokes a server-side hub method.
return Task>.Func
        public virtual Func<IHubIncomingInvokerContext, Task<object>> BuildIncoming(Func<IHubIncomingInvokerContext, Task<object>> invoke)
        {
            return async context =>
            {
                if (OnBeforeIncoming(context))
                {
                    try
                    {
                        var result = await invoke(context).OrEmpty().PreserveCulture();
                        return OnAfterIncoming(result, context);
                    }
                    catch (Exception ex)
                    {
                        var exContext = new ExceptionContext(ex);
                        OnIncomingError(exContext, context);

                        var error = exContext.Error;
                        if (error == ex)
                        {
                            throw;
                        }
                        else if (error != null)
                        {
                            throw error;
                        }
                        else
                        {
                            return exContext.Result;
                        }
                    }
                }

                return null;
            };
        }