CheryControllerApp.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Threading.Tasks;
  5. using Applications.FDC;
  6. using Edge.Core.Processor;
  7. using Edge.Core.Processor.Dispatcher.Attributes;
  8. namespace Dfs.WayneChina.CheryFuelController
  9. {
  10. [MetaPartsDescriptor(
  11. "lang-zh-cn:奇瑞汽油加注控制系统lang-en-us:Chery fueling controller",
  12. "lang-zh-cn:通过车辆VIN控制加油" +
  13. "lang-en-us:Used for control filling by VIN (vehicle identification number)",
  14. new[] { "lang-zh-cn:奇瑞lang-en-us:Chery" })]
  15. public class CheryControllerApp: IAppProcessor
  16. {
  17. #region Fields
  18. private readonly IServiceProvider services;
  19. public string MetaConfigName { get; set; }
  20. private readonly CheryControllerAppConfigV1 config;
  21. private CheryClient _cheryClient;
  22. private FdcServerHostApp fdcServer;
  23. #endregion
  24. #region Logger
  25. NLog.Logger logger = NLog.LogManager.LoadConfiguration("NLog.config").GetLogger("Application");
  26. #endregion
  27. #region Constructor
  28. [ParamsJsonSchemas("appCtorParamsJsonSchema")]
  29. public CheryControllerApp(IServiceProvider services, CheryControllerAppConfigV1 config)
  30. {
  31. this.services = services;
  32. this.config = config;
  33. _cheryClient = new CheryClient(config.Host, config.Port, config.ClientId, config.Username,
  34. config.Password, config.ReconnectInterval, config.JobDownUrl, config.JobResultUpUrl);
  35. }
  36. #endregion
  37. #region IAppProcessor methods
  38. public async Task<bool> Start()
  39. {
  40. logger.Warn("Starting Chery client");
  41. await _cheryClient.StartAsync();
  42. return true;
  43. }
  44. public Task<bool> Stop()
  45. {
  46. logger.Warn("Stopping Chery client");
  47. _cheryClient.StopAsync();
  48. return Task.FromResult(true);
  49. }
  50. public Task Test(params object[] parameters)
  51. {
  52. return Task.CompletedTask;
  53. }
  54. public void Init(IEnumerable<IProcessor> processors)
  55. {
  56. //get the FdcServer instance during init
  57. foreach (dynamic processor in processors)
  58. {
  59. if (processor is IAppProcessor)
  60. {
  61. FdcServerHostApp fdcServer = processor as FdcServerHostApp;
  62. if (fdcServer != null)
  63. {
  64. logger.Info("FdcServerHostApp retrieved as an IApplication instance!");
  65. this.fdcServer = processor;
  66. }
  67. continue;
  68. }
  69. }
  70. if (fdcServer != null)
  71. logger.Info("Fdc Server instance alive");
  72. }
  73. #endregion
  74. }
  75. public class CheryControllerAppConfigV1
  76. {
  77. /// <summary>
  78. /// Chery IoT Platform host
  79. /// </summary>
  80. public string Host { get; set; }
  81. /// <summary>
  82. /// Chery IoT Platform port
  83. /// </summary>
  84. public int Port { get; set; }
  85. /// <summary>
  86. /// Chery IoT Platform user name
  87. /// </summary>
  88. public string Username { get; set; }
  89. /// <summary>
  90. /// Chery IoT Platform user password
  91. /// </summary>
  92. public string Password { get; set; }
  93. /// <summary>
  94. /// Client ID
  95. /// </summary>
  96. public string ClientId { get; set; }
  97. /// <summary>
  98. /// Interval for reconnection
  99. /// </summary>
  100. public int ReconnectInterval { get; set; }
  101. /// <summary>
  102. /// Url for the path of the topic
  103. /// </summary>
  104. public string JobDownUrl { get; set; }
  105. /// <summary>
  106. /// Url for the execution result of the filling job
  107. /// </summary>
  108. public string JobResultUpUrl { get; set; }
  109. }
  110. }