|
@@ -1,6 +1,7 @@
|
|
|
using EVCB_OCPP.WSServer.Service.WsService;
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
+using Microsoft.AspNetCore.Mvc;
|
|
|
using NLog;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
@@ -30,17 +31,20 @@ public static class MapApiServceExtention
|
|
|
webApplication.MapGet("/", helpFunc);
|
|
|
webApplication.MapGet("/help", helpFunc);
|
|
|
|
|
|
- webApplication.MapPost("/stop", (ProtalServer server) => {
|
|
|
+ webApplication.MapPost("/stop", (ProtalServer server) =>
|
|
|
+ {
|
|
|
server.Stop();
|
|
|
return "Command stop";
|
|
|
}).AddAuthFilter(pass);
|
|
|
|
|
|
- webApplication.MapPost("/gc", () => {
|
|
|
+ webApplication.MapPost("/gc", () =>
|
|
|
+ {
|
|
|
GC.Collect();
|
|
|
return "Command GC";
|
|
|
}).AddAuthFilter(pass);
|
|
|
|
|
|
- webApplication.MapPost("/lc", (ProtalServer server) => {
|
|
|
+ webApplication.MapPost("/lc", (ProtalServer server) =>
|
|
|
+ {
|
|
|
List<string> toReturn = new List<string>() { "Command List Clients" };
|
|
|
Dictionary<string, WsClientData> clientDic = server.GetClientDic();
|
|
|
var list = clientDic.Select(c => c.Value).ToList();
|
|
@@ -53,7 +57,8 @@ public static class MapApiServceExtention
|
|
|
return string.Join("\r\n", toReturn);
|
|
|
}).AddAuthFilter(pass);
|
|
|
|
|
|
- webApplication.MapPost("/lcn", (ProtalServer server) => {
|
|
|
+ webApplication.MapPost("/lcn", (ProtalServer server) =>
|
|
|
+ {
|
|
|
List<string> toReturn = new List<string> { "Command List Customer Name" };
|
|
|
Dictionary<string, WsClientData> clientDic = server.GetClientDic();
|
|
|
var lcn = clientDic.Select(c => c.Value.CustomerName).Distinct().ToList();
|
|
@@ -66,7 +71,8 @@ public static class MapApiServceExtention
|
|
|
return string.Join("\r\n", toReturn);
|
|
|
}).AddAuthFilter(pass);
|
|
|
|
|
|
- webApplication.MapPost("/silent", () => {
|
|
|
+ webApplication.MapPost("/silent", () =>
|
|
|
+ {
|
|
|
foreach (var rule in LogManager.Configuration.LoggingRules)
|
|
|
{
|
|
|
if (rule.RuleName != "ConsoleLog")
|
|
@@ -84,7 +90,8 @@ public static class MapApiServceExtention
|
|
|
return "Command silent";
|
|
|
}).AddAuthFilter(pass);
|
|
|
|
|
|
- webApplication.MapPost("/show", () => {
|
|
|
+ webApplication.MapPost("/show", () =>
|
|
|
+ {
|
|
|
foreach (var rule in LogManager.Configuration.LoggingRules)
|
|
|
{
|
|
|
if (rule.RuleName != "ConsoleLog")
|
|
@@ -102,13 +109,15 @@ public static class MapApiServceExtention
|
|
|
return "Command show";
|
|
|
}).AddAuthFilter(pass);
|
|
|
|
|
|
- webApplication.MapGet("/threads", () => {
|
|
|
+ webApplication.MapGet("/threads", () =>
|
|
|
+ {
|
|
|
ThreadPool.GetMaxThreads(out var maxWorkerThread, out var maxCompletionPortThreads);
|
|
|
ThreadPool.GetAvailableThreads(out var avaliableWorkerThread, out var avaliableCompletionPortThreads);
|
|
|
return $"WorkerThread:{avaliableWorkerThread}/{maxWorkerThread} CompletionPortThreads{avaliableCompletionPortThreads}/{maxCompletionPortThreads}";
|
|
|
}).AddAuthFilter(pass);
|
|
|
|
|
|
- webApplication.MapPost("/threads", (int min, int max) => {
|
|
|
+ webApplication.MapPost("/threads", (int min, int max) =>
|
|
|
+ {
|
|
|
ThreadPool.GetMaxThreads(out var maxWorkerThread, out var maxCompletionPortThreads);
|
|
|
ThreadPool.GetAvailableThreads(out var avaliableWorkerThread, out var avaliableCompletionPortThreads);
|
|
|
ThreadPool.SetMinThreads(min, 0);
|
|
@@ -119,9 +128,11 @@ public static class MapApiServceExtention
|
|
|
|
|
|
public static void AddAuthFilter(this RouteHandlerBuilder routeHandlerBuilder, string pass)
|
|
|
{
|
|
|
- routeHandlerBuilder.AddEndpointFilter(async (context, next) => {
|
|
|
- var key = context.HttpContext.Request.Headers["key"];
|
|
|
- if (key != pass)
|
|
|
+ routeHandlerBuilder.AddEndpointFilter(async (context, next) =>
|
|
|
+ {
|
|
|
+ string key = context.HttpContext.Request.Headers["key"];
|
|
|
+ if (!string.IsNullOrEmpty(key) &&
|
|
|
+ key != pass)
|
|
|
{
|
|
|
return Results.BadRequest();
|
|
|
}
|