TestCommand.cs 1.8 KB

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