namespace SHJX.Service.Control.LiquidHandler { public class LiquidContent { private const string LIQUIDCONTENT_NAMESPACE = "SHJX.Service.Control.LiquidHandler.Content"; private static readonly ILogger logger = LogFactory.BuildLogger(typeof(LiquidContent)); private static readonly object obj_locker = new(); private readonly ConcurrentDictionary DicContent = new(); public static LiquidContent StartNew { get { lock (obj_locker) { return new(); } } } private LiquidContent() { } /// /// 执行 /// /// 液体名称 /// 处理方式 /// /// public bool Execute(string liquidName, string handleType, Action callBack = null, params object[] args) { try { ILiquidContent content = ContentFactory(liquidName); bool response = handleType switch { TaskTypeName.WASH => content.WashFactory().Execute(), _ => content.NormalFactory().Execute(callBack, args), }; logger.LogDebug($"液体{liquidName}以{handleType}方式下发{(response ? "成功" : "失败")}"); return response; } catch (Exception ex) { logger.LogError(ex.ToString()); return false; } } private ILiquidContent ContentFactory(string liquidName) { if (DicContent.TryGetValue(liquidName, out ILiquidContent value)) { return value; } string fullName = CreatContentClassFullName(liquidName); ILiquidContent content = Activator.CreateInstance(Type.GetType(fullName), true) as ILiquidContent; DicContent.TryAdd(liquidName, content); return content; } private static string CreatContentClassFullName(string name) { return $"{LIQUIDCONTENT_NAMESPACE}.{name}Content"; } } }