123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- using Edge.Core.Processor;
- using Edge.Core.Processor.Dispatcher.Attributes;
- using Edge.Core.UniversalApi;
- using Microsoft.Extensions.DependencyInjection;
- using Microsoft.Extensions.Logging;
- using Microsoft.Extensions.Logging.Abstractions;
- using System;
- using System.Collections.Generic;
- using System.Threading;
- namespace PetroChinaOnlineWatchPlugin
- {
- [UniversalApi(Name = OnUploadOnlineMonitorDataStateChangeEventName, EventDataType = typeof(UploadState),
- Description = "Notify the data uploading state change.")]
- [MetaPartsDescriptor(
- "lang-zh-cn:中国石油在线监测系统 Applang-en-us:Petro china online watch system",
- "lang-en-us:中国石油在线监测系统APP, 用于链接多个气液比收集板,以及多个压力表和多个气体浓度表。",
- new[] { "lang-zh-cn:在线监测lang-zh-tw:在線監測lang-en-us:OnlineWatch" })]
- //<webview src = "http://localhost:8384/WebConsoleHome" ></ webview >
- public class App : IAppProcessor
- {
- public const string OnUploadOnlineMonitorDataStateChangeEventName = "OnUploadOnlineMonitorDataStateChange";
- public string MetaConfigName { get; set; }
- private ILogger logger = NullLogger.Instance;
- private UniversalApiHub universalApiHub;
- //The specified number of seconds.
- private int heartBeatUdpPushingInterval = 0;
- private Timer heartBeatUdpPushingTimer;
- private AppConfigV1 appConfig;
- [ParamsJsonSchemas("PetroChinaOnlineWatchParamsJsonSchemas")]
- public App(AppConfigV1 appConfig, IServiceProvider services)
- {
- if (services != null)
- {
- this.appConfig = appConfig;
- var loggerFactory = services.GetRequiredService<ILoggerFactory>();
- logger = loggerFactory.CreateLogger("DynamicPrivate_PetroChinaOnlineWatch");
- universalApiHub = services.GetRequiredService<UniversalApiHub>();
- }
- }
- public void Init(IEnumerable<IProcessor> processors)
- {
- try
- {
- logger.LogInformation($"配置LNA地址为, RemoteSubnet {appConfig.RemoteSubnet}, RemoteNode {appConfig.RemoteNode}," +
- $" LocalSubnet {appConfig.LocalSubnet}, LocalNode {appConfig.LocalNode}");
- ConnectionController.Default.Start(appConfig, logger, this, universalApiHub);
- HeartBeatUdpProxy.Default.Start(appConfig, logger);
- heartBeatUdpPushingTimer = new Timer(FireTimerEvent, null, 600, 1000);
- }
- catch (Exception ex)
- {
- logger.LogError($"Init error, exception detail: {ex}");
- }
- }
- private void FireTimerEvent(object state)
- {
- try
- {
- if (heartBeatUdpPushingInterval < 0)
- {
- heartBeatUdpPushingInterval = 10;
- HeartBeatUdpProxy.Default.Udp_SendData();
- }
- else
- {
- heartBeatUdpPushingInterval -= 1;
- }
- ConnectionController.Default.SendUnsolicitedMessage();
- }
- catch (Exception ex)
- {
- logger.LogError($"Exception in FireTimerEvent(...):{Environment.NewLine}{ex}");
- }
- }
- }
- public enum DbAddressType
- {
- Configure,
- EnvironmentData,
- PumpData,
- FaultData
- }
- public class AppConfigV1
- {
- public int HeartBeatPortNumber { get; set; }
- public byte RemoteSubnet { get; set; }
- public byte RemoteNode { get; set; }
- public byte LocalSubnet { get; set; }
- public byte LocalNode { get; set; }
- public string NetworkConnections { get; set; }
- public string DatabaseConnStr { get; set; }
- public byte DispenserNumber { get; set; }
- public string MainAppDirectory { get; set; }
- }
- }
|