ParameterIntegrityCheck.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 System.Text.RegularExpressions;
  10. using Autodesk.Revit.DB;
  11. using SAGA.DotNetUtils.Extend;
  12. using ServiceRevitLib.Common;
  13. using SAGA.RevitUtils.Extends;
  14. using ServiceRevitLib.Extend;
  15. namespace ServiceRevitLib.Mode
  16. {
  17. /// <summary>
  18. /// SagaCheck
  19. /// </summary>
  20. class ParameterIntegrityCheck : CheckBase
  21. {
  22. public override void Check()
  23. {
  24. base.Check();
  25. #region
  26. var doc = m_Doc;
  27. var instances = doc.GetEqEcElements();
  28. var familyGroups = instances.GroupBy(t => t.GetFamilyName());
  29. foreach (IGrouping<string, Element> familyGroup in familyGroups)
  30. {
  31. Element fi = familyGroup.FirstOrDefault();
  32. if (fi == null) continue;
  33. var result = GetCheckResult(fi);
  34. if (result == null) continue;
  35. result.FamilyName = familyGroup.Key;
  36. Content.Add(result);
  37. }
  38. #endregion
  39. }
  40. /// <summary>
  41. /// 获取检测结果
  42. /// </summary>
  43. /// <param name="fi"></param>
  44. /// <returns></returns>
  45. private ParameterIntegrityCheckResult GetCheckResult(Element fi)
  46. {
  47. //检查项
  48. var checkParamNames = new List<string>() { MBIConst.EquipLocalName, MBIConst.EquipLocalID };
  49. var result = new ParameterIntegrityCheckResult();
  50. List<string> list = new List<string>();
  51. foreach (var paramName in checkParamNames)
  52. {
  53. var parameter = fi.GetParameter(paramName);
  54. if (parameter == null)
  55. list.Add(paramName);
  56. }
  57. if (list.Any())
  58. {
  59. result.Result = ResultState.Failure;
  60. result.ResultMsg = $"缺失的参数为:{string.Join("、", list)}";
  61. }
  62. else
  63. {
  64. result.Result = ResultState.Success;
  65. }
  66. return result;
  67. }
  68. }
  69. }