EicpWebHooks.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using log4net;
  2. using Newtonsoft.Json;
  3. using SCADA.CommonLib.Helper;
  4. using SCADA.CommonLib.LoggerHelper;
  5. using SCADA_DAQ.Plugin.Machine.WebHookConfig;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Web.Http;
  12. namespace SCADA_DAQ.Customer.Controllers
  13. {
  14. // 如果需要对外提供webapi接口,可以通过自定义 Service 继承 BaseService后从服务管理中配置自定义服务实现,对外访问,也可以通过自定义有的ApiController提供对外访问接口
  15. // 本demo就是提供可以一个对外的Api服务,设备通信中的 WebHooks 触发后会回调此接口
  16. /// <summary>
  17. /// 寄存器回调接口
  18. /// </summary>
  19. public class RegWebHookController : ApiController
  20. {
  21. private static ILog Log = Logger.CreateLogger("RegWebHook");
  22. /// <summary>
  23. ///
  24. /// </summary>
  25. /// <param name="hookValue"></param>
  26. public void RegTriggered(RegWebHook hookValue)
  27. {
  28. Log.Info($"收到WebHook回调");
  29. Log.Info($"{JsonHelper.JsonSerialize(hookValue)}");
  30. }
  31. }
  32. /// <summary>
  33. ///
  34. /// </summary>
  35. public class RegWebHook
  36. {
  37. /// <summary>
  38. ///
  39. /// </summary>
  40. public string TaskName { get; set; }
  41. /// <summary>
  42. ///
  43. /// </summary>
  44. public string TriggerParameter { get; set; }
  45. /// <summary>
  46. /// 触发设备的Id
  47. /// </summary>
  48. public string TriggerMachine { get; set; }
  49. /// <summary>
  50. /// 触发的寄存器
  51. /// </summary>
  52. public string TriggerReg { get; set; }
  53. /// <summary>
  54. /// 触发时的值
  55. /// </summary>
  56. public object TriggerValue { get; set; }
  57. /// <summary>
  58. /// 子项明细
  59. /// </summary>
  60. public List<RegWebHookValueItem> Items { get; set; }
  61. }
  62. /// <summary>
  63. ///
  64. /// </summary>
  65. public class RegWebHookValueItem
  66. {
  67. /// <summary>
  68. ///
  69. /// </summary>
  70. public string Key { get; set; }
  71. /// <summary>
  72. ///
  73. /// </summary>
  74. public string Desc { get; set; }
  75. /// <summary>
  76. ///
  77. /// </summary>
  78. public object Value { get; set; }
  79. }
  80. }