// ImageProcessingAlgorithmFactory.cs 识别算法工厂,用于注册算法实现 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MvvmScaffoldFrame48.DLL.ThreadManager { public static class ImageProcessingAlgorithmHikVisionFactory { #region 变量与实例 // 存储所有算法实现类型的字典 private static readonly Dictionary _algorithmTypes = new Dictionary(); #endregion #region 构造方法 /// /// 静态构造函数,在类加载时注册所有可用的算法实现 /// static ImageProcessingAlgorithmHikVisionFactory() { // 注册所有可用的算法实现 RegisterAlgorithm("ProcessingAlgorithm"); // 可以继续注册更多算法... } #endregion #region 私有方法 /// /// 注册算法实现 /// /// 算法实现类型 /// 算法名称 private static void RegisterAlgorithm(string algorithmName) where T : IImageProcessingAlgorithmHikVision, new() { _algorithmTypes[algorithmName] = typeof(T); } #endregion #region 公有方法 /// /// 根据算法名称创建算法实例 /// /// 算法名称 /// 算法实例 public static IImageProcessingAlgorithmHikVision CreateAlgorithm(string algorithmName) { if (_algorithmTypes.ContainsKey(algorithmName)) { return (IImageProcessingAlgorithmHikVision)Activator.CreateInstance(_algorithmTypes[algorithmName]); } else { Console.WriteLine($"未找到名为 '{algorithmName}' 的算法实现"); return null; } } /// /// 获取所有已注册的算法名称 /// /// 算法名称列表 public static List GetAvailableAlgorithms() { return _algorithmTypes.Keys.ToList(); } /// /// 检查算法是否存在 /// /// 算法名称 /// 是否存在 public static bool AlgorithmExists(string algorithmName) { return _algorithmTypes.ContainsKey(algorithmName); } #endregion } }