将Feature/XP.Common和Feature/XP.Hardware分支合并至Develop/XP.forHardwareAndCommon,完善XPapp注册和相关硬件类库通用类库功能。
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
using Prism.Events;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using XP.Common.Logging.Interfaces;
|
||||
using XP.Hardware.RaySource.Abstractions;
|
||||
using XP.Hardware.RaySource.Config;
|
||||
using XP.Hardware.RaySource.Implementations;
|
||||
|
||||
namespace XP.Hardware.RaySource.Factories
|
||||
{
|
||||
/// <summary>
|
||||
/// 射线源工厂实现类 | X-Ray Source Factory Implementation
|
||||
/// 负责创建不同类型的射线源实例 | Responsible for creating different types of X-ray source instances
|
||||
/// </summary>
|
||||
public class RaySourceFactory : IRaySourceFactory
|
||||
{
|
||||
private readonly RaySourceConfig _config;
|
||||
private readonly IEventAggregator _eventAggregator;
|
||||
private readonly ILoggerService _logger;
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数 | Constructor
|
||||
/// </summary>
|
||||
/// <param name="config">配置对象 | Configuration object</param>
|
||||
/// <param name="eventAggregator">事件聚合器 | Event aggregator</param>
|
||||
/// <param name="logger">日志服务 | Logger service</param>
|
||||
public RaySourceFactory(RaySourceConfig config, IEventAggregator eventAggregator, ILoggerService logger)
|
||||
{
|
||||
_config = config ?? throw new ArgumentNullException(nameof(config));
|
||||
_eventAggregator = eventAggregator ?? throw new ArgumentNullException(nameof(eventAggregator));
|
||||
_logger = (logger ?? throw new ArgumentNullException(nameof(logger))).ForModule("RaySource.Factory");
|
||||
|
||||
_logger.Info("射线源工厂已创建 | X-ray source factory created");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建指定类型的射线源实例 | Create X-ray source instance of specified type
|
||||
/// </summary>
|
||||
/// <param name="sourceType">射线源类型名称 | X-ray source type name</param>
|
||||
/// <returns>射线源实例 | X-ray source instance</returns>
|
||||
public IXRaySource CreateRaySource(string sourceType)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(sourceType))
|
||||
{
|
||||
_logger.Error(null, "射线源类型不能为空 | X-ray source type cannot be empty");
|
||||
throw new ArgumentException("射线源类型不能为空", nameof(sourceType));
|
||||
}
|
||||
|
||||
_logger.Info($"创建射线源实例,类型: {sourceType} | Creating X-ray source instance, type: {sourceType}");
|
||||
|
||||
try
|
||||
{
|
||||
var instance = sourceType.ToUpperInvariant() switch
|
||||
{
|
||||
"COMET225" => CreateComet225RaySource(),
|
||||
_ => throw new NotSupportedException($"不支持的射线源类型: {sourceType}")
|
||||
};
|
||||
|
||||
_logger.Info($"射线源实例创建成功: {sourceType} | X-ray source instance created successfully: {sourceType}");
|
||||
return instance;
|
||||
}
|
||||
catch (NotSupportedException ex)
|
||||
{
|
||||
_logger.Error(ex, $"不支持的射线源类型: {sourceType} | Unsupported X-ray source type: {sourceType}");
|
||||
throw;
|
||||
}
|
||||
catch (TypeLoadException ex)
|
||||
{
|
||||
_logger.Error(ex, "跨框架类型加载失败,请检查 BR.AN.PviServices.dll 是否正确部署:{Message}", ex.Message);
|
||||
throw;
|
||||
}
|
||||
catch (FileNotFoundException ex)
|
||||
{
|
||||
_logger.Error(ex, "跨框架程序集未找到,请检查 XP.Hardware.RaySource.Comet.dll 和 BR.AN.PviServices.dll 是否存在:{Message}", ex.Message);
|
||||
throw;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Error(ex, $"创建射线源实例失败: {sourceType} | Failed to create X-ray source instance: {sourceType}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取支持的射线源类型列表 | Get list of supported X-ray source types
|
||||
/// </summary>
|
||||
/// <returns>类型名称列表 | List of type names</returns>
|
||||
public IEnumerable<string> GetSupportedSourceTypes()
|
||||
{
|
||||
return new List<string>
|
||||
{
|
||||
"Comet225"
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建 Comet225 射线源实例
|
||||
/// 通过 CometHostManager 管理 Host 进程生命周期,CometIpcClient 负责 IPC 通信
|
||||
/// </summary>
|
||||
private IXRaySource CreateComet225RaySource()
|
||||
{
|
||||
try
|
||||
{
|
||||
var hostManager = new CometHostManager(_logger, _config);
|
||||
var ipcClient = new CometIpcClient(_config, _eventAggregator, _logger);
|
||||
return new Comet225RaySource(hostManager, ipcClient, _logger);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Error(ex, "创建 Comet225 射线源实例失败:{Message}", ex.Message);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user