using LJLib.Client; using LJLib.Net.SPI.Client; using LJLib.Net.SPI.Com; using LJProxy.Models; using LJProxy.Settings; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Newtonsoft.Json; using System.IO; using System.Text; using Newtonsoft.Json.Linq; namespace LJProxy.Controllers { [Route("api/[controller]")] [ApiController] public class L1SvrController : Controller { private static object _syncRoot = new object(); public static AppSettings _appSettingModel; public L1SvrController(IOptions appSettingModel) { if (_appSettingModel == null) { _appSettingModel = appSettingModel.Value; } } private static ILJClient _pool { get; set; } private static ILJClient Pool { get { if (_pool == null) { lock (_syncRoot) { var url = _appSettingModel.L1SvrUrl; var urlArr = url.Split(':'); var ip = urlArr[0]; var port = urlArr[1]; var creator = new DirectP1ClientCreator(ip, Convert.ToInt32(port)); _pool = new LJClientPool(creator, _appSettingModel.ThreadSize); } } return _pool; } } [Route("svr/{apiName}")] [HttpPost] [HttpGet] public async Task Svr(string apiName) { string requestBody; using (StreamReader reader = new StreamReader(Request.Body, Encoding.UTF8)) { requestBody = await reader.ReadToEndAsync(); } //var excuteResult = GlobalVar.Excute(apiName, requestBody, Request); //if (excuteResult.Item1) return excuteResult.Item2; var rslt = Pool.DoExcute(apiName, requestBody); return Content(rslt, "application/json"); } } }