CheckFactory.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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.Extend;
  16. namespace ServiceRevitLib
  17. {
  18. /// <summary>
  19. /// CheckFactory
  20. /// </summary>
  21. public class CheckFactory:ResultBase
  22. {
  23. public CheckFactory()
  24. {
  25. Content=new List<CheckBase>();
  26. }
  27. #region 序列化的属性
  28. public List<CheckBase> Content { get; set; }
  29. public string FloorName { get; set; }
  30. #endregion
  31. #region Method
  32. /// <summary>
  33. /// 由传入字符串获取检查项
  34. /// 传入的检查列表使用“,”进行分割
  35. /// </summary>
  36. /// <param name="checkItemStrs"></param>
  37. public void SetCheckItems(string str)
  38. {
  39. var checkItemStrs= str.Split(',');
  40. var nameSpace = typeof(CheckBase).Namespace;
  41. foreach (string itemStr in checkItemStrs)
  42. {
  43. //子类与父类应该使用同一命名空间;如果为Program+BaseClass格式,会出错; 如果出现此情况,请更改方法
  44. string fullPath = nameSpace + "." + itemStr;
  45. Assembly tempAsembly = Assembly.GetExecutingAssembly();
  46. var check = (tempAsembly.CreateInstance(fullPath)) as CheckBase;
  47. Content.Add(check);
  48. }
  49. }
  50. public void Check(Document doc)
  51. {
  52. FloorName = doc.PathName;
  53. //Document doc = DocumentUtils.GetDocument(path);
  54. try
  55. {
  56. Content.ForEach(t => t.SetDoc(doc));
  57. Content.ForEach(t => t.Check());
  58. }
  59. catch (Exception e)
  60. {
  61. ResultMsg = e.Message;
  62. Result = ResultState.Failure;
  63. }
  64. finally
  65. {
  66. //doc.CloseExt();
  67. }
  68. }
  69. #endregion
  70. }
  71. }