TestCommand.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. string fileName = DateTime.Now.ToString("yyyyMMddHHmmss");
  31. string path = Path.Combine(@"D:\", $"DataCheck{fileName}.json");
  32. //File.WriteAllText(path, result);
  33. }
  34. catch (Exception e)
  35. {
  36. result = Serialze(ResultBase.Exception(e.Message));
  37. }
  38. return result;
  39. }
  40. public static string Serialze(object obj)
  41. {
  42. JsonSerializerSettings jsetting = CreateDefaultSettings();
  43. var result = JsonConvert.SerializeObject(obj, jsetting);
  44. return result;
  45. }
  46. private static JsonSerializerSettings CreateDefaultSettings()
  47. {
  48. JsonSerializerSettings jsetting = new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore };
  49. jsetting.Converters.Add(new StringEnumConverter());
  50. return jsetting;
  51. }
  52. }
  53. #endregion
  54. }