L1SvrController.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using LJLib.Client;
  2. using LJLib.Net.SPI.Client;
  3. using LJLib.Net.SPI.Com;
  4. using LJProxy.Models;
  5. using LJProxy.Settings;
  6. using Microsoft.AspNetCore.Mvc;
  7. using Microsoft.Extensions.Options;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Threading.Tasks;
  12. using Newtonsoft.Json;
  13. using System.IO;
  14. using System.Text;
  15. using Newtonsoft.Json.Linq;
  16. namespace LJProxy.Controllers
  17. {
  18. [Route("api/[controller]")]
  19. [ApiController]
  20. public class L1SvrController : Controller
  21. {
  22. private static object _syncRoot = new object();
  23. public static AppSettings _appSettingModel;
  24. public L1SvrController(IOptions<AppSettings> appSettingModel)
  25. {
  26. if (_appSettingModel == null)
  27. {
  28. _appSettingModel = appSettingModel.Value;
  29. }
  30. }
  31. private static ILJClient _pool { get; set; }
  32. private static ILJClient Pool
  33. {
  34. get
  35. {
  36. if (_pool == null)
  37. {
  38. lock (_syncRoot)
  39. {
  40. var url = _appSettingModel.L1SvrUrl;
  41. var urlArr = url.Split(':');
  42. var ip = urlArr[0];
  43. var port = urlArr[1];
  44. var creator = new DirectP1ClientCreator(ip, Convert.ToInt32(port));
  45. _pool = new LJClientPool(creator, _appSettingModel.ThreadSize);
  46. }
  47. }
  48. return _pool;
  49. }
  50. }
  51. [Route("svr/{apiName}")]
  52. [HttpPost]
  53. [HttpGet]
  54. public async Task<IActionResult> Svr(string apiName)
  55. {
  56. string requestBody;
  57. using (StreamReader reader = new StreamReader(Request.Body, Encoding.UTF8))
  58. {
  59. requestBody = await reader.ReadToEndAsync();
  60. }
  61. //var excuteResult = GlobalVar.Excute(apiName, requestBody, Request);
  62. //if (excuteResult.Item1) return excuteResult.Item2;
  63. var rslt = Pool.DoExcute(apiName, requestBody);
  64. return Content(rslt, "application/json");
  65. }
  66. }
  67. }