/// <summary> /// ProcessDetailCmd /// </summary> /// <param name="param"></param> protected virtual void ProcessDetailCmd(DetailCmdParam param) { Type t = typeof(IDetailCmd); List <Type> lsType = new List <Type>(); foreach (var item in DetailCmdAssemblies) { Type[] arr = item.GetTypes(); lsType.AddRange(arr); } Type[] types = lsType.ToArray(); List <Type> ls = new List <Type>(); foreach (var item in types) { Type[] ts = item.GetInterfaces(); if (ts != null && ts.Any(x => x == t)) { ls.Add(item); } } if (!ls.Any()) { ConsoleHelper.WriteLine(ELogCategory.Warn, string.Format("Undefined Cmd: {0}", param.Cmd)); } else { bool bExist = false; foreach (var item in ls) { object o = Activator.CreateInstance(item); IDetailCmd obj = o as IDetailCmd; if (obj != null) { if (obj.Cmd.Equals(param.Cmd)) { bExist = true; try { obj.OnDetailCmd(param.Params); } catch (Exception e) { ConsoleHelper.WriteLine(ELogCategory.Fatal, "OnDetailCmd error"); CommonLogger.WriteLog(ELogCategory.Fatal, "OnDetailCmd Exception", e); } } } } if (!bExist) { ConsoleHelper.WriteLine(ELogCategory.Warn, string.Format("Undefined Cmd: {0}", param.Cmd)); } } }
/// <summary> /// On Detail Cmd /// </summary> /// <param name="param"></param> protected virtual void OnDetailCmd(DetailCmdParam param) { if (DetailCmd != null) { DetailCmd.Invoke(this, param); } ProcessDetailCmd(param); }