TestCommand.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.IO;
  5. using System.Linq;
  6. using Autodesk.Revit.Attributes;
  7. using Autodesk.Revit.DB;
  8. using Autodesk.Revit.UI;
  9. using Newtonsoft.Json;
  10. using Newtonsoft.Json.Converters;
  11. using SAGA.DotNetUtils.Data;
  12. using SAGA.DotNetUtils.Geometry;
  13. using SAGA.RevitUtils;
  14. using SAGA.RevitUtils.Extends;
  15. using ServiceRevitLib.Mode;
  16. namespace ServiceRevitLib
  17. {
  18. #region 测试命令
  19. public class ServiceDataCheckTest
  20. {
  21. public static string Check(Document doc)
  22. {
  23. string result = null;
  24. try
  25. {
  26. var factory = new CheckFactory();
  27. factory.SetCheckItems("SagaCheck,UnitCheck,FamilyNameCheck,EquipPartLocationCheck,ColumnCheck,ElementRangeCheck,ConnectorCheck,SystemNameCheck,EquipInSpaceCheck,SystemReferEquipCheck,ParameterIntegrityCheck,PipeCheck,XYZOverlapCheck");
  28. factory.Check(doc);
  29. result = Serialze(factory);
  30. #if DEBUG
  31. string fileName = DateTime.Now.ToString("yyyyMMddHHmmss");
  32. string path = Path.Combine(@"D:\", $"DataCheck{fileName}.json");
  33. File.WriteAllText(path, result);
  34. #endif
  35. }
  36. catch (Exception e)
  37. {
  38. result = Serialze(ResultBase.Exception(e.Message));
  39. }
  40. return result;
  41. }
  42. public static string Serialze(object obj)
  43. {
  44. JsonSerializerSettings jsetting = CreateDefaultSettings();
  45. var result = JsonConvert.SerializeObject(obj, jsetting);
  46. return result;
  47. }
  48. private static JsonSerializerSettings CreateDefaultSettings()
  49. {
  50. JsonSerializerSettings jsetting = new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore };
  51. jsetting.Converters.Add(new StringEnumConverter());
  52. return jsetting;
  53. }
  54. }
  55. #endregion
  56. }