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.

83 lines
3.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 == "1002") //箱壳、内胆,包含预装线、集存库
{
Task.Run(() =>
{
DataCollectorFactory collector = new ShellStoreFactory(_deviceParamServices, _deviceAlarmInfoServices, _deviceElectricityServices);
Parallel.Invoke(() => collector.CollectDeviceAlarmInfo(out var alarmInfos), () => collector.CollectDeviceElectricity(out var electricity));
});
Task.Run(() =>
{
DataCollectorFactory collector = new LinerStoreFactory(_deviceParamServices, _deviceAlarmInfoServices, _deviceElectricityServices);
Parallel.Invoke(() => collector.CollectDeviceAlarmInfo(out var alarmInfos), () => collector.CollectDeviceElectricity(out var electricity));
});
}
else if (stationCode == "1005")//泡前库、发泡线、发泡机、泡后库
{
Task.Run(() =>
{
DataCollectorFactory collector = new BoxFoamFactory(_deviceParamServices, _deviceAlarmInfoServices, _deviceElectricityServices);
Parallel.Invoke(() => collector.CollectDeviceAlarmInfo(out var alarmInfos), () => collector.CollectDeviceElectricity(out var electricity));
});
}
else if (stationCode == "1010")//成品分垛
{
Task.Run(() =>
{
DataCollectorFactory collector = new PalletizFactory(_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;
}
}
}