/* ============================================================================== * 功能描述:CheckFactory * 创 建 者:Garrett * 创建日期:2019/6/11 16:26:56 * ==============================================================================*/ using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; using ServiceRevitLib.Mode; using Autodesk.Revit.DB; using ServiceRevitLib.DataCheck.Mode; using ServiceRevitLib.Extend; namespace ServiceRevitLib { /// /// CheckFactory /// public class CheckFactory:ResultBase { public CheckFactory() { Content=new List(); } #region 序列化的属性 public List Content { get; set; } public string FloorName { get; set; } #endregion #region Method /// /// 由传入字符串获取检查项 /// 传入的检查列表使用“,”进行分割 /// /// public void SetCheckItems(string str) { //SagaCheck,UnitCheck,FamilyNameCheck,EquipPartLocationCheck,ColumnCheck,ElementRangeCheck,ConnectorCheck,SystemNameCheck,EquipInSpaceCheck,SystemReferEquipCheck,ParameterIntegrityCheck,PipeCheck,XYZOverlapCheck var checkItemStrs = str.Split(','); var nameSpace = typeof(CheckBase).Namespace; foreach (string itemStr in checkItemStrs) { //子类与父类应该使用同一命名空间;如果为Program+BaseClass格式,会出错; 如果出现此情况,请更改方法 string fullPath = nameSpace + "." + itemStr; Assembly tempAsembly = Assembly.GetExecutingAssembly(); var check = (tempAsembly.CreateInstance(fullPath)) as CheckBase; Content.Add(check); } } public void Check(Document doc) { FloorName = doc.PathName; //Document doc = DocumentUtils.GetDocument(path); try { Content.ForEach(t => t.SetDoc(doc)); Content.ForEach(t => t.Check()); } catch (Exception e) { ResultMsg = e.Message; Result = ResultState.Failure; } finally { //doc.CloseExt(); } } #endregion } }