DocumentRule.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using Sugar.Enties;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using WebAPIBase.Utils;
  8. using System.IO;
  9. public class DocumentRule : DbContext<SafeQualityCheck>
  10. {
  11. public AttachmentSaveMode _SaveMode;
  12. public static AttachmentSavePathMode _SavePathMode;
  13. private string _Path;
  14. public void Init()
  15. {
  16. var manager = new ConfigItemValueManager();
  17. string itemLower = manager.GetConfigItemValue("基础模块-附件存储设置-存储模式");
  18. _Path = manager.GetConfigItemValue("基础模块-附件存储设置-文件存储目录");
  19. if (itemLower != null && itemLower.ToLower() == "file")
  20. {
  21. _SaveMode = AttachmentSaveMode.file;
  22. if (_Path == null || _Path == "")
  23. {
  24. throw new Exception("未定义文档存储目录,请检查附件存储路径参数配置");
  25. }
  26. try
  27. {
  28. if (!Directory.Exists(_Path))
  29. {
  30. Directory.CreateDirectory(_Path);
  31. }
  32. }
  33. catch
  34. {
  35. throw new Exception("文档存储目录有误,请检查附件存储路径参数配置");
  36. }
  37. }
  38. else
  39. {
  40. _SaveMode = AttachmentSaveMode.database;
  41. }
  42. string itemLower2 = manager.GetConfigItemValue("基础模块-附件存储设置-文件目录模式");
  43. try
  44. {
  45. _SavePathMode = (AttachmentSavePathMode)Enum.Parse(typeof(AttachmentSavePathMode), itemLower2.ToUpper());
  46. }
  47. catch
  48. {
  49. _SavePathMode = AttachmentSavePathMode.ROOT;
  50. }
  51. }
  52. }