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 Start() { logger.Warn("Starting Chery client"); await _cheryClient.StartAsync(); return true; } public Task 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 processors) { //get the FdcServer instance during init 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 { /// /// Chery IoT Platform host /// public string Host { get; set; } /// /// Chery IoT Platform port /// public int Port { get; set; } /// /// Chery IoT Platform user name /// public string Username { get; set; } /// /// Chery IoT Platform user password /// public string Password { get; set; } /// /// Client ID /// public string ClientId { get; set; } /// /// Interval for reconnection /// public int ReconnectInterval { get; set; } /// /// Url for the path of the topic /// public string JobDownUrl { get; set; } /// /// Url for the execution result of the filling job /// public string JobResultUpUrl { get; set; } } }