From 3f67529e0f492f30851f091fea7f97a01cb502e5 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期二, 03 二月 2026 11:05:23 +0800
Subject: [PATCH] 添加机器人/套接字任务支持;更新枚举与 .gitignore 文件
---
Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/QuartzNet/QuartzNetExtension.cs | 133 +++++++++++++++++++++++---------------------
1 files changed, 70 insertions(+), 63 deletions(-)
diff --git a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/QuartzNet/QuartzNetExtension.cs b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/QuartzNet/QuartzNetExtension.cs
index 95605e7..9991cd6 100644
--- a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/QuartzNet/QuartzNetExtension.cs
+++ b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/QuartzNet/QuartzNetExtension.cs
@@ -1,14 +1,7 @@
-锘縰sing System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Reflection;
-using System.Text;
-using System.Threading.Tasks;
-using WIDESEAWCS_Core.Helper;
+锘縰sing System.Reflection;
using WIDESEAWCS_Core;
+using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_QuartzJob.DTO;
-using Microsoft.Extensions.Logging;
-using WIDESEAWCS_QuartzJob.QuartzExtensions;
using WIDESEAWCS_QuartzJob.Service;
namespace WIDESEAWCS_QuartzJob.QuartzNet
@@ -54,62 +47,67 @@
{
try
{
- #region 杩炴帴PLC
- // 鍔犺浇绋嬪簭闆�
- Assembly assembly = Assembly.Load($"WIDESEAWCS_Communicator");
- // 鑾峰彇绫诲瀷
- Type? type = assembly.GetType($"WIDESEAWCS_Communicator.{x.DevicePlcType}");
- // 鍒涘缓瀹炰緥
- object? obj = Activator.CreateInstance(type, new object[] { x.DeviceIp, x.DevicePort, x.DeviceName });
- // 璋冪敤杩炴帴鏂规硶
- bool? connectResult = (bool)type.InvokeMember("Connect", BindingFlags.Default | BindingFlags.InvokeMethod, null, obj, new object[] { });
- // 鍒ゆ柇杩炴帴缁撴灉
- if (connectResult ?? false) ConsoleHelper.WriteSuccessLine(type.Name + x.DeviceCode + "杩炴帴鎴愬姛"); else ConsoleHelper.WriteErrorLine(type.Name + x.DeviceCode + "杩炴帴澶辫触");
- #endregion
-
-
-
- #region 瀹炰緥鍖栬澶囧璞�
- List<DeviceProDTO> devicePros = x.ProtocolList.Select(d => new DeviceProDTO
+ if (!x.DeviceName.Contains("鏈烘鎵�"))
{
- // 璁惧瀛愮紪鐮�
- DeviceChildCode = d.DeviceChildCode,
- // 璁惧鏁版嵁绫诲瀷
- DeviceDataType = d.DeviceProDataType,
- // 璁惧ID
- DeviceId = d.DeviceId,
- // 璁惧鍗忚ID
- DeviceProId = d.Id,
- // 璁惧鍗忚鏁版嵁鍧�
- DeviceProDataBlock = d.DeviceProDataBlock,
- // 璁惧鍗忚鏁版嵁闀垮害
- DeviceProDataLength = d.DeviceProDataLength,
- // 璁惧鍗忚鍋忕Щ閲�
- DeviceProOffset = d.DeviceProOffset,
- // 璁惧鍗忚鍙傛暟鎻忚堪
- DeviceProParamDes = d.DeviceProParamDes,
- // 璁惧鍗忚鍙傛暟鍚嶇О
- DeviceProParamName = d.DeviceProParamName,
- // 璁惧鍗忚鍙傛暟绫诲瀷
- DeviceProParamType = d.DeviceProParamType,
- // 璁惧PLC绫诲瀷
- DevicePlcType = x.DevicePlcType
- }).ToList();
+ #region 杩炴帴PLC
- // 鏍规嵁璁惧绫诲瀷鑾峰彇璁惧鍗忚璇︽儏
- List<DeviceProtocolDetailDTO> deviceProtocolDetails = _deviceProtocolDetailService.GetDeviceProtocolDetailsByDeviceType(x.DeviceType);
+ // 鍔犺浇绋嬪簭闆�
+ Assembly assembly = Assembly.Load($"WIDESEAWCS_Communicator");
+ // 鑾峰彇绫诲瀷
+ Type? type = assembly.GetType($"WIDESEAWCS_Communicator.{x.DevicePlcType}");
+ // 鍒涘缓瀹炰緥
+ object? obj = Activator.CreateInstance(type, new object[] { x.DeviceIp, x.DevicePort, x.DeviceName });
+ // 璋冪敤杩炴帴鏂规硶
+ bool? connectResult = (bool)type.InvokeMember("Connect", BindingFlags.Default | BindingFlags.InvokeMethod, null, obj, new object[] { });
+ // 鍒ゆ柇杩炴帴缁撴灉
+ if (connectResult ?? false) ConsoleHelper.WriteSuccessLine(type.Name + x.DeviceCode + "杩炴帴鎴愬姛"); else ConsoleHelper.WriteErrorLine(type.Name + x.DeviceCode + "杩炴帴澶辫触");
- // 鍔犺浇璁惧绋嬪簭闆�
- Assembly assemblyDevice = Assembly.Load($"WIDESEAWCS_QuartzJob");
- // 鑾峰彇璁惧绫诲瀷瀵瑰簲鐨勭被鍨�
- Type typeDevice = assemblyDevice.GetType($"WIDESEAWCS_QuartzJob.{x.DeviceType}");
- // 鍒涘缓璁惧瀹炰緥
- object deviceInstance = Activator.CreateInstance(typeDevice, new object[] { obj, devicePros, deviceProtocolDetails, x.DeviceCode, x.DeviceName });
- #endregion
+ #endregion 杩炴帴PLC
- x.Device = (IDevice)deviceInstance;
+ #region 瀹炰緥鍖栬澶囧璞�
- Storage.Devices.Add((IDevice)deviceInstance);
+ List<DeviceProDTO> devicePros = x.ProtocolList.Select(d => new DeviceProDTO
+ {
+ // 璁惧瀛愮紪鐮�
+ DeviceChildCode = d.DeviceChildCode,
+ // 璁惧鏁版嵁绫诲瀷
+ DeviceDataType = d.DeviceProDataType,
+ // 璁惧ID
+ DeviceId = d.DeviceId,
+ // 璁惧鍗忚ID
+ DeviceProId = d.Id,
+ // 璁惧鍗忚鏁版嵁鍧�
+ DeviceProDataBlock = d.DeviceProDataBlock,
+ // 璁惧鍗忚鏁版嵁闀垮害
+ DeviceProDataLength = d.DeviceProDataLength,
+ // 璁惧鍗忚鍋忕Щ閲�
+ DeviceProOffset = d.DeviceProOffset,
+ // 璁惧鍗忚鍙傛暟鎻忚堪
+ DeviceProParamDes = d.DeviceProParamDes,
+ // 璁惧鍗忚鍙傛暟鍚嶇О
+ DeviceProParamName = d.DeviceProParamName,
+ // 璁惧鍗忚鍙傛暟绫诲瀷
+ DeviceProParamType = d.DeviceProParamType,
+ // 璁惧PLC绫诲瀷
+ DevicePlcType = x.DevicePlcType
+ }).ToList();
+
+ // 鏍规嵁璁惧绫诲瀷鑾峰彇璁惧鍗忚璇︽儏
+ List<DeviceProtocolDetailDTO> deviceProtocolDetails = _deviceProtocolDetailService.GetDeviceProtocolDetailsByDeviceType(x.DeviceType);
+
+ // 鍔犺浇璁惧绋嬪簭闆�
+ Assembly assemblyDevice = Assembly.Load($"WIDESEAWCS_QuartzJob");
+ // 鑾峰彇璁惧绫诲瀷瀵瑰簲鐨勭被鍨�
+ Type typeDevice = assemblyDevice.GetType($"WIDESEAWCS_QuartzJob.{x.DeviceType}");
+ // 鍒涘缓璁惧瀹炰緥
+ object deviceInstance = Activator.CreateInstance(typeDevice, new object[] { obj, devicePros, deviceProtocolDetails, x.DeviceCode, x.DeviceName });
+
+ #endregion 瀹炰緥鍖栬澶囧璞�
+
+ x.Device = (IDevice)deviceInstance;
+
+ Storage.Devices.Add((IDevice)deviceInstance);
+ }
}
catch (Exception ex)
{
@@ -123,8 +121,17 @@
});
for (int i = 0; i < dispatches.Count; i++)
{
- DeviceInfoDTO? deviceProInfo = deviceInfos.FirstOrDefault(x => x.Id == dispatches[i].Id);
- dispatches[i].JobParams = deviceProInfo?.Device;
+ var targetDevice = deviceInfos.FirstOrDefault(x => x.Id == dispatches[i].Id);
+
+ if (targetDevice is null) continue;
+
+ // 浣跨敤妯″紡鍖归厤
+ dispatches[i].JobParams = targetDevice switch
+ {
+ { DeviceName: var name } when name.Contains("鏈烘鎵�")
+ => new RobotCraneDevice { DeviceCode = targetDevice.DeviceCode, DeviceName = targetDevice.DeviceName, IPAddress = targetDevice.DeviceIp + ":" + targetDevice.DevicePort },
+ _ => targetDevice.Device
+ };
WebResponseContent responseContent = await _schedulerCenter.AddScheduleJobAsync(dispatches[i]);
if (responseContent.Status) ConsoleHelper.WriteSuccessLine(dispatches[i].Name + "璋冨害鏈嶅姟娣诲姞鎴愬姛"); else ConsoleHelper.WriteErrorLine(dispatches[i].Name + "璋冨害鏈嶅姟娣诲姞澶辫触");
}
@@ -137,4 +144,4 @@
}
}
}
-}
+}
\ No newline at end of file
--
Gitblit v1.9.3