forked from dsuryd/dotNetify
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored pipelines to separate class, updated middleware definition…
…s and invocation model, added DisconnectionMiddleware and ExceptionMiddleware.
- Loading branch information
dicky
authored and
dicky
committed
Jul 30, 2017
1 parent
6d5453e
commit 25a4c81
Showing
14 changed files
with
424 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
Copyright 2017 Dicky Suryadi | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
using DotNetify; | ||
using Microsoft.AspNetCore.SignalR.Hubs; | ||
using Newtonsoft.Json; | ||
|
||
namespace WebApplication.Core.React | ||
{ | ||
public delegate void LogTraceDelegate(string log); | ||
|
||
public class DeveloperLoggingMiddleware : IMiddleware, IDisconnectionMiddleware, IExceptionMiddleware | ||
{ | ||
private readonly LogTraceDelegate _trace; | ||
|
||
public DeveloperLoggingMiddleware(LogTraceDelegate trace) | ||
{ | ||
_trace = trace; | ||
} | ||
|
||
public Task Invoke(DotNetifyHubContext hubContext, NextDelegate next) | ||
{ | ||
_trace($@"[dotNetify] connId={hubContext.CallerContext.ConnectionId} type={hubContext.CallType} | ||
vmId={hubContext.VMId} | ||
data={JsonConvert.SerializeObject(hubContext.Data ?? string.Empty)} | ||
headers={JsonConvert.SerializeObject(hubContext.Headers ?? string.Empty)}"); | ||
|
||
return next(hubContext); | ||
} | ||
|
||
public Task OnDisconnected(HubCallerContext context) | ||
{ | ||
_trace($"[dotNetify] connId={context.ConnectionId} type=OnDisconnected"); | ||
return Task.CompletedTask; | ||
} | ||
|
||
public Task<Exception> OnException(HubCallerContext context, Exception exception) | ||
{ | ||
_trace($"[dotNetify] connId={context.ConnectionId} {exception.GetType().Name}={exception.Message}"); | ||
return Task.FromResult(exception); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Method extension to specify parameter type for the middleware. | ||
/// </summary> | ||
public static class DeveloperLoggingMiddlewareExtensions | ||
{ | ||
public static void UseDeveloperLogging(this IDotNetifyConfiguration config, LogTraceDelegate logTraceDelegate) | ||
{ | ||
config.UseMiddleware<DeveloperLoggingMiddleware>(logTraceDelegate); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.