using LJLib.Net.SPI.Com; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace LJProxy.LJLib.Net.SPI.Server { public abstract class LJServerBase { public delegate IActionResult DHandle(ILJRequest request, object state); protected Dictionary handlers = new Dictionary(StringComparer.OrdinalIgnoreCase); protected Dictionary requestTypes = new Dictionary(StringComparer.OrdinalIgnoreCase); public IActionResult DoExcute(ILJRequest request, object state) { if (!handlers.ContainsKey(request.GetApiName())) { throw new Exception("接口未定义:" + request.GetApiName().ToString()); } var handler = handlers[request.GetApiName()]; if (handler == null) { throw new Exception("接口未定义:" + request.GetApiName().ToString()); } return handler(request, state); } public Type GetRequestType(string apiName) { if (requestTypes.ContainsKey(apiName)) { return requestTypes[apiName]; } else { return null; } } public void AddMap(string apiName,Type requestType,DHandle handler) { requestTypes[apiName] = requestType; handlers[apiName] = handler; } } }