123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- 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<AppSettings> appSettingModel)
- {
- if (_appSettingModel == null)
- {
- _appSettingModel = appSettingModel.Value;
- }
- }
- private static ILJClient _PROPool { get; set; }
- private static ILJClient PROPool
- {
- get
- {
- if (_PROPool == null)
- {
- lock (_syncRoot)
- {
- var url = _appSettingModel.L1SvrPROUrl;
- var urlArr = url.Split(':');
- var ip = urlArr[0];
- var port = urlArr[1];
- var creator = new DirectP1ClientCreator(ip, Convert.ToInt32(port));
- _PROPool = new LJClientPool(creator, 1000);
- }
- }
- return _PROPool;
- }
- }
- private static ILJClient _pool { get; set; }
- private static ILJClient Pool
- {
- get
- {
- if (_pool == null)
- {
- lock (_syncRoot)
- {
- var url = _appSettingModel.L1SvrCRPUrl;
- var urlArr = url.Split(':');
- var ip = urlArr[0];
- var port = urlArr[1];
- var creator = new DirectP1ClientCreator(ip, Convert.ToInt32(port));
- _pool = new LJClientPool(creator, 20);
- }
- }
- return _pool;
- }
- }
- //[Route("PRO/{apiName}")]
- //[HttpPost]
- //public string PRO(string apiName, [FromBody] object requestBody)
- //{
- // var rslt = PROPool.DoExcute(apiName, requestBody.ToString());
- // return rslt;
- //}
- //[Route("CRP/{apiName}/{**restPath}")]
- //[HttpPost]
- //[HttpGet]
- //public async Task<IActionResult> CRP(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;
- // else
- // {
- // var rslt = CRPPool.DoExcute(apiName, requestBody);
- // return Content(rslt,"application/json");
- // }
- //}
- [Route("svr/{apiName}")]
- [HttpPost]
- [HttpGet]
- public async Task<IActionResult> 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");
- }
-
- }
- }
|