L1SvrController.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using LJLib.Client;
  2. using LJLib.Net.SPI.Client;
  3. using LJProxy.Settings;
  4. using Microsoft.AspNetCore.Mvc;
  5. using Microsoft.Extensions.Options;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Threading.Tasks;
  10. namespace LJProxy.Controllers
  11. {
  12. [Route("api/[controller]")]
  13. [ApiController]
  14. public class L1SvrController : Controller
  15. {
  16. private static object _syncRoot = new object();
  17. public static AppSettings _appSettingModel;
  18. public L1SvrController(IOptions<AppSettings> appSettingModel)
  19. {
  20. if (_appSettingModel == null)
  21. {
  22. _appSettingModel = appSettingModel.Value;
  23. }
  24. }
  25. private static ILJClient _PROPool { get; set; }
  26. private static ILJClient PROPool
  27. {
  28. get
  29. {
  30. if (_PROPool == null)
  31. {
  32. lock (_syncRoot)
  33. {
  34. var url = _appSettingModel.L1SvrPROUrl;
  35. var urlArr = url.Split(':');
  36. var ip = urlArr[0];
  37. var port = urlArr[1];
  38. var creator = new DirectP1ClientCreator(ip, Convert.ToInt32(port));
  39. _PROPool = new LJClientPool(creator, 1000);
  40. }
  41. }
  42. return _PROPool;
  43. }
  44. }
  45. private static ILJClient _CRPPool { get; set; }
  46. private static ILJClient CRPPool
  47. {
  48. get
  49. {
  50. if (_CRPPool == null)
  51. {
  52. lock (_syncRoot)
  53. {
  54. var url = _appSettingModel.L1SvrCRPUrl;
  55. var urlArr = url.Split(':');
  56. var ip = urlArr[0];
  57. var port = urlArr[1];
  58. var creator = new DirectP1ClientCreator(ip, Convert.ToInt32(port));
  59. _CRPPool = new LJClientPool(creator, 20);
  60. }
  61. }
  62. return _CRPPool;
  63. }
  64. }
  65. [Route("PRO/{apiName}")]
  66. [HttpPost]
  67. public string PRO(string apiName, [FromBody] object requestBody)
  68. {
  69. var rslt = PROPool.DoExcute(apiName, requestBody.ToString());
  70. return rslt;
  71. }
  72. [Route("CRP/{apiName}")]
  73. [HttpPost]
  74. public string CRP(string apiName,[FromBody] object requestBody)
  75. {
  76. var rslt = CRPPool.DoExcute(apiName, requestBody.ToString());
  77. return rslt;
  78. }
  79. }
  80. }