You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
2.6 KiB
C#

using Admin.Core.Common;
using Admin.Core.IService.IService_New;
using Aucma.Core.DataCollector.Factory;
using log4net;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Org.BouncyCastle.Crypto.Tls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Aucma.Core.DataCollector
{
public static class DataCollectorSetup
{
public static readonly log4net.ILog _logger = LogManager.GetLogger(typeof(DataCollectorSetup));
public static IApplicationBuilder UseDataCollectorExtensions(this IApplicationBuilder app)
{
if (app == null) throw new ArgumentNullException(nameof(app));
var stationCode = Appsettings.app("StationInfo", "StationCode");
var _deviceParamServices = app.ApplicationServices.GetService<IBaseDeviceParamServices>();
var _deviceAlarmInfoServices = app.ApplicationServices.GetService<IRecordDeviceAlarmInfoServices>();
var _deviceElectricityServices = app.ApplicationServices.GetService< IRecordDeviceElectricityServices>();
if (!string.IsNullOrEmpty(stationCode))
{
try
{
if (stationCode == "1001") //箱壳
{
//前板
Task.Run(() =>
{
DataCollectorFactory collector = new SidePanelFactory(_deviceParamServices, _deviceAlarmInfoServices, _deviceElectricityServices);
Parallel.Invoke(() => collector.CollectDeviceAlarmInfo(out var alarmInfos), () => collector.CollectDeviceElectricity(out var electricity));
});
//后板
Task.Run(() =>
{
DataCollectorFactory collector = new BackPanelFactory(_deviceParamServices, _deviceAlarmInfoServices, _deviceElectricityServices);
Parallel.Invoke(() => collector.CollectDeviceAlarmInfo(out var alarmInfos), () => collector.CollectDeviceElectricity(out var electricity));
});
}
}catch(Exception ex)
{
_logger.Error($"UseDataCollectorExtensions逻辑执行异常:{ex.Message}");
}
}
else
{
new InvalidOperationException($"设备数据采集逻辑初始化失败:未获取到工位编号");
}
return app;
}
}
}