123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Threading.Tasks;
- using Applications.FDC;
- using Edge.Core.Processor;
- using Edge.Core.Processor.Dispatcher.Attributes;
- namespace Dfs.WayneChina.CheryFuelController
- {
- [MetaPartsDescriptor(
- "lang-zh-cn:奇瑞汽油加注控制系统lang-en-us:Chery fueling controller",
- "lang-zh-cn:通过车辆VIN控制加油" +
- "lang-en-us:Used for control filling by VIN (vehicle identification number)",
- new[] { "lang-zh-cn:奇瑞lang-en-us:Chery" })]
- public class CheryControllerApp: IAppProcessor
- {
- #region Fields
- private readonly IServiceProvider services;
- public string MetaConfigName { get; set; }
- private readonly CheryControllerAppConfigV1 config;
- private CheryClient _cheryClient;
- private FdcServerHostApp fdcServer;
- #endregion
- #region Logger
- NLog.Logger logger = NLog.LogManager.LoadConfiguration("NLog.config").GetLogger("Application");
- #endregion
- #region Constructor
- [ParamsJsonSchemas("appCtorParamsJsonSchema")]
- public CheryControllerApp(IServiceProvider services, CheryControllerAppConfigV1 config)
- {
- this.services = services;
- this.config = config;
- _cheryClient = new CheryClient(config.Host, config.Port, config.ClientId, config.Username,
- config.Password, config.ReconnectInterval, config.JobDownUrl, config.JobResultUpUrl);
- }
- #endregion
- #region IAppProcessor methods
- public async Task<bool> Start()
- {
- logger.Warn("Starting Chery client");
- await _cheryClient.StartAsync();
- return true;
- }
- public Task<bool> Stop()
- {
- logger.Warn("Stopping Chery client");
- _cheryClient.StopAsync();
- return Task.FromResult(true);
- }
- public Task Test(params object[] parameters)
- {
- return Task.CompletedTask;
- }
- public void Init(IEnumerable<IProcessor> processors)
- {
-
- foreach (dynamic processor in processors)
- {
- if (processor is IAppProcessor)
- {
- FdcServerHostApp fdcServer = processor as FdcServerHostApp;
- if (fdcServer != null)
- {
- logger.Info("FdcServerHostApp retrieved as an IApplication instance!");
- this.fdcServer = processor;
- }
- continue;
- }
- }
- if (fdcServer != null)
- logger.Info("Fdc Server instance alive");
- }
- #endregion
- }
- public class CheryControllerAppConfigV1
- {
-
-
-
- public string Host { get; set; }
-
-
-
- public int Port { get; set; }
-
-
-
- public string Username { get; set; }
-
-
-
- public string Password { get; set; }
-
-
-
- public string ClientId { get; set; }
-
-
-
- public int ReconnectInterval { get; set; }
-
-
-
- public string JobDownUrl { get; set; }
-
-
-
- public string JobResultUpUrl { get; set; }
- }
- }
|