1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- using LJLib.Net.SPI.Com;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- namespace LJProxy.LJLib.Net.SPI.Server
- {
- public abstract class LJServerBase : ILJServer
- {
- public delegate LJResponse 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 LJResponse 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;
- }
- }
- }
|