CmdService.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using Grpc.Core;
  2. using System;
  3. using System.Threading.Tasks;
  4. using Grpc.Extension.BaseService.Model;
  5. namespace Grpc.Extension.BaseService
  6. {
  7. /// <summary>
  8. /// 执行命令的服务
  9. /// </summary>
  10. public class CmdService : IGrpcBaseService
  11. {
  12. /// <summary>
  13. /// 添加删除截流的method
  14. /// </summary>
  15. public Task<CmdRS> AddDelThrottle(AddDelThrottleRQ rq, ServerCallContext context)
  16. {
  17. return Task.Run(() =>
  18. {
  19. if (string.IsNullOrWhiteSpace(rq.MethodName))
  20. {
  21. return CmdRS.Fail("MethodName is null");
  22. }
  23. if(rq.IsDel)
  24. ThrottleManager.Instance.Del(rq.MethodName);
  25. else
  26. ThrottleManager.Instance.Add(rq.MethodName);
  27. return CmdRS.Success();
  28. });
  29. }
  30. /// <summary>
  31. /// 添加删除是否允许保存响应的method
  32. /// </summary>
  33. public Task<CmdRS> AddDelSaveResponseEnable(AddDelSaveResponseEnableRQ rq, ServerCallContext context)
  34. {
  35. return Task.Run(() =>
  36. {
  37. if (string.IsNullOrWhiteSpace(rq.MethodName))
  38. {
  39. return CmdRS.Fail("MethodName is null");
  40. }
  41. if (rq.IsDel)
  42. MonitorManager.Instance.DelSaveResponseMethod(rq.MethodName);
  43. else
  44. MonitorManager.Instance.AddSaveResponseMethod(rq.MethodName);
  45. return CmdRS.Success();
  46. });
  47. }
  48. }
  49. }