CheckFactory.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* ==============================================================================
  2. * 功能描述:CheckFactory
  3. * 创 建 者:Garrett
  4. * 创建日期:2019/6/11 16:26:56
  5. * ==============================================================================*/
  6. using System;
  7. using System.Collections.Generic;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Reflection;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using ServiceRevitLib.Mode;
  14. using Autodesk.Revit.DB;
  15. using ServiceRevitLib.DataCheck.Mode;
  16. using ServiceRevitLib.Extend;
  17. namespace ServiceRevitLib
  18. {
  19. /// <summary>
  20. /// CheckFactory
  21. /// </summary>
  22. public class CheckFactory:ResultBase
  23. {
  24. public CheckFactory()
  25. {
  26. Content=new List<CheckBase>();
  27. }
  28. #region 序列化的属性
  29. public List<CheckBase> Content { get; set; }
  30. public string FloorName { get; set; }
  31. #endregion
  32. #region Method
  33. /// <summary>
  34. /// 由传入字符串获取检查项
  35. /// 传入的检查列表使用“,”进行分割
  36. /// </summary>
  37. /// <param name="checkItemStrs"></param>
  38. public void SetCheckItems(string str)
  39. {
  40. //SagaCheck,UnitCheck,FamilyNameCheck,EquipPartLocationCheck,ColumnCheck,ElementRangeCheck,ConnectorCheck,SystemNameCheck,EquipInSpaceCheck,SystemReferEquipCheck,ParameterIntegrityCheck,PipeCheck,XYZOverlapCheck
  41. var checkItemStrs = str.Split(',');
  42. var nameSpace = typeof(CheckBase).Namespace;
  43. foreach (string itemStr in checkItemStrs)
  44. {
  45. //子类与父类应该使用同一命名空间;如果为Program+BaseClass格式,会出错; 如果出现此情况,请更改方法
  46. string fullPath = nameSpace + "." + itemStr;
  47. Assembly tempAsembly = Assembly.GetExecutingAssembly();
  48. var check = (tempAsembly.CreateInstance(fullPath)) as CheckBase;
  49. Content.Add(check);
  50. }
  51. }
  52. public void Check(Document doc)
  53. {
  54. FloorName = doc.PathName;
  55. //Document doc = DocumentUtils.GetDocument(path);
  56. try
  57. {
  58. Content.ForEach(t => t.SetDoc(doc));
  59. Content.ForEach(t => t.Check());
  60. }
  61. catch (Exception e)
  62. {
  63. ResultMsg = e.Message;
  64. Result = ResultState.Failure;
  65. }
  66. finally
  67. {
  68. //doc.CloseExt();
  69. }
  70. }
  71. #endregion
  72. }
  73. }