checkpoint

This commit is contained in:
2021-11-21 10:07:35 -06:00
parent cf3fbbbc1d
commit 433ab2772a
23 changed files with 1556 additions and 1487 deletions

View File

@@ -1,43 +1,50 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using System.IO;
using System.Text;
using System.Threading.Tasks;
namespace Gameboard.ShogiUI.Sockets.Extensions
{
public class LogMiddleware
{
private readonly RequestDelegate next;
private readonly ILogger logger;
public class LogMiddleware
{
private readonly RequestDelegate next;
private readonly ILogger logger;
public LogMiddleware(RequestDelegate next, ILoggerFactory factory)
{
this.next = next;
logger = factory.CreateLogger<LogMiddleware>();
}
public async Task Invoke(HttpContext context)
{
try
{
await next(context);
}
finally
{
logger.LogInformation("Request {method} {url} => {statusCode}",
context.Request?.Method,
context.Request?.Path.Value,
context.Response?.StatusCode);
}
}
}
public LogMiddleware(RequestDelegate next, ILoggerFactory factory)
{
this.next = next;
logger = factory.CreateLogger<LogMiddleware>();
}
public static class IApplicationBuilderExtensions
{
public static IApplicationBuilder UseRequestResponseLogging(this IApplicationBuilder builder)
{
builder.UseMiddleware<LogMiddleware>();
return builder;
}
}
public async Task Invoke(HttpContext context)
{
try
{
await next(context);
}
finally
{
using var stream = new MemoryStream();
context.Request?.Body.CopyToAsync(stream);
logger.LogInformation("Request {method} {url} => {statusCode} \n Body: {body}",
context.Request?.Method,
context.Request?.Path.Value,
context.Response?.StatusCode,
Encoding.UTF8.GetString(stream.ToArray()));
}
}
}
public static class IApplicationBuilderExtensions
{
public static IApplicationBuilder UseRequestResponseLogging(this IApplicationBuilder builder)
{
builder.UseMiddleware<LogMiddleware>();
return builder;
}
}
}

View File

@@ -1,5 +1,4 @@
using Gameboard.ShogiUI.Sockets.ServiceModels.Types;
using System;
using System.Text;
using System.Text.RegularExpressions;
@@ -21,7 +20,7 @@ namespace Gameboard.ShogiUI.Sockets.Extensions
WhichPiece.Pawn => self.IsPromoted ? "^P " : " P ",
_ => " ? ",
};
if (self.Owner == WhichPlayer.Player2)
if (self.Owner == WhichPerspective.Player2)
name = Regex.Replace(name, @"([^\s]+)\s", "$1.");
return name;
}