ParameterIntegrityCheck.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* ==============================================================================
  2. * 功能描述:SagaCheck
  3. * 创 建 者:Garrett
  4. * 创建日期:2019/6/11 16:09:09
  5. * ==============================================================================*/
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using Autodesk.Revit.DB;
  10. using SAGA.RevitUtils.Extends;
  11. using ServiceRevitLib.Common;
  12. using ServiceRevitLib.Extend;
  13. using ServiceRevitLib.Mode;
  14. namespace ServiceRevitLib.DataCheck.Mode
  15. {
  16. /// <summary>
  17. /// SagaCheck
  18. /// </summary>
  19. class ParameterIntegrityCheck : CheckBase
  20. {
  21. public override void Check()
  22. {
  23. try
  24. {
  25. base.Check();
  26. #region
  27. var doc = m_Doc;
  28. var instances = doc.GetEqEcElements();
  29. var familyGroups = instances.GroupBy(t => t.GetFamilyName());
  30. foreach (IGrouping<string, Element> familyGroup in familyGroups)
  31. {
  32. Element fi = familyGroup.FirstOrDefault();
  33. if (fi == null) continue;
  34. var result = GetCheckResult(fi);
  35. if (result == null) continue;
  36. result.FamilyName = familyGroup.Key;
  37. Content.Add(result);
  38. }
  39. #endregion
  40. }
  41. catch (Exception e)
  42. {
  43. Result = ResultState.Failure;
  44. ResultMsg = $"{e.Message}\r\n{e.StackTrace}";
  45. }
  46. }
  47. /// <summary>
  48. /// 获取检测结果
  49. /// </summary>
  50. /// <param name="fi"></param>
  51. /// <returns></returns>
  52. private ParameterIntegrityCheckResult GetCheckResult(Element fi)
  53. {
  54. //检查项
  55. var checkParamNames = new List<string>() { MBIConst.EquipLocalName, MBIConst.EquipLocalID };
  56. var result = new ParameterIntegrityCheckResult();
  57. List<string> list = new List<string>();
  58. foreach (var paramName in checkParamNames)
  59. {
  60. var parameter = fi.GetParameter(paramName);
  61. if (parameter == null)
  62. list.Add(paramName);
  63. }
  64. if (list.Any())
  65. {
  66. result.Result = ResultState.Failure;
  67. result.ResultMsg = $"缺失的参数为:{string.Join("、", list)}";
  68. }
  69. else
  70. {
  71. result.Result = ResultState.Success;
  72. }
  73. return result;
  74. }
  75. }
  76. }