123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- 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<string, DHandle> handlers = new Dictionary<string, DHandle>(StringComparer.OrdinalIgnoreCase);
- protected Dictionary<string, Type> requestTypes = new Dictionary<string, Type>(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;
- }
- }
- }
|