CheckFactory.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. var checkItemStrs= str.Split(',');
  41. var nameSpace = typeof(CheckBase).Namespace;
  42. foreach (string itemStr in checkItemStrs)
  43. {
  44. //子类与父类应该使用同一命名空间;如果为Program+BaseClass格式,会出错; 如果出现此情况,请更改方法
  45. string fullPath = nameSpace + "." + itemStr;
  46. Assembly tempAsembly = Assembly.GetExecutingAssembly();
  47. var check = (tempAsembly.CreateInstance(fullPath)) as CheckBase;
  48. Content.Add(check);
  49. }
  50. }
  51. public void Check(Document doc)
  52. {
  53. FloorName = doc.PathName;
  54. //Document doc = DocumentUtils.GetDocument(path);
  55. try
  56. {
  57. Content.ForEach(t => t.SetDoc(doc));
  58. Content.ForEach(t => t.Check());
  59. }
  60. catch (Exception e)
  61. {
  62. ResultMsg = e.Message;
  63. Result = ResultState.Failure;
  64. }
  65. finally
  66. {
  67. //doc.CloseExt();
  68. }
  69. }
  70. #endregion
  71. }
  72. }