using LJLib.Net.SPI.Com; using LJProxy.Excutor; using LJProxy.LJLib.Net.SPI.Server; using LJProxy.Models; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Newtonsoft.Json.Linq; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using LJProxy.Settings; namespace LJProxy { public static class GlobalVar { private static ExcutorManager excutorManager = null; static GlobalVar() { InitExcutorMap(); } private static void InitExcutorMap() { excutorManager = new ExcutorManager(); excutorManager.AddMap(new CheckUpdateRequest().GetApiName(), typeof(CheckUpdateRequest), new CheckUpdateExcutor()); excutorManager.AddMap(new GetUpdatePkgRequest().GetApiName(), typeof(GetUpdatePkgRequest), new GetUpdatePkgExcutor()); excutorManager.AddMap(new GetProxyDomainListRequest().GetApiName(), typeof(GetProxyDomainListRequest), new GetProxyDomainListExcutor()); excutorManager.AddMap(new GetUpdateJsonRequest().GetApiName(), typeof(GetUpdateJsonRequest), new GetUpdateJsonExcutor()); excutorManager.AddMap(new GetAppUpdateRequest().GetApiName(), typeof(GetAppUpdateRequest), new GetAppUpdateExcutor()); } public static Tuple Excute(string apiName,string requestBody,object requestState) { var requestType = excutorManager.GetRequestType(apiName); if (requestType == null) return new Tuple(false, null); ILJRequest request = null; if(!string.IsNullOrEmpty(requestBody)) request = JObject.Parse(requestBody).ToObject(requestType) as ILJRequest; else request = new JObject().ToObject(requestType) as ILJRequest; var result = excutorManager.DoExcute( request, requestState); return new Tuple(true, result); } public static AppSettings Setting { get; private set; } public static void InitSetting(IConfiguration configuration) { Setting = new AppSettings(); Setting.L1SvrUrl = configuration.GetSection("L1SvrUrl")?.Value; string threadSizeStr = configuration.GetSection("ThreadSize")?.Value; Setting.ThreadSize = string.IsNullOrEmpty(threadSizeStr)?20:Convert.ToInt32(threadSizeStr); Setting.ProxyDomainList = configuration.GetSection("ProxyDomainList").GetChildren().Select(c => c.Value).ToList(); } } }