VisionProject.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * ==============================================================================
  3. *
  4. * Filename: VisionProject
  5. * Description:
  6. *
  7. * Version: 1.0
  8. * Created: 2021/2/27 15:49:25
  9. *
  10. * Author: liu.wenjie
  11. *
  12. * ==============================================================================
  13. */
  14. using CommonMethods;
  15. using System;
  16. using System.Collections.Generic;
  17. using System.IO;
  18. using System.Linq;
  19. using System.Text;
  20. using System.Threading.Tasks;
  21. using System.Windows.Forms;
  22. namespace ToolLib.VisionJob
  23. {
  24. public class VisionProject
  25. {
  26. /// <summary>
  27. /// 工程路径
  28. /// </summary>
  29. public string prjFilePath { get; set; } = @"D:\vision.prj";
  30. /// <summary>
  31. /// 工程名称
  32. /// </summary>
  33. public string prjName { get; set; }
  34. /// <summary>
  35. /// 工程中所包含的VisionJob
  36. /// </summary>
  37. public Dictionary<string, VisionJob> Project { get; set; } = new Dictionary<string, VisionJob>() { };
  38. public bool LoadProject()
  39. {
  40. if(!File.Exists(prjFilePath))
  41. {
  42. return false;
  43. }
  44. else
  45. {
  46. try
  47. {
  48. Project = Serialize.BinaryDeserialize<Dictionary<string, VisionJob>>(prjFilePath);
  49. foreach (var item in Project)
  50. {
  51. OperateProject.Instance.CreateNewJob(item.Key, false);
  52. }
  53. return true;
  54. }
  55. catch (Exception ex)
  56. {
  57. Logger.LoggerClass.WriteLog("载入项目工程时出现异常!", ex);
  58. return false;
  59. }
  60. }
  61. }
  62. public void SaveObject()
  63. {
  64. Serialize.BinarySerialize(prjFilePath, Project);
  65. }
  66. public bool LoadJob(string jobName,string path)
  67. {
  68. if (!File.Exists(path))
  69. {
  70. Logger.LoggerClass.WriteLog("job路径不存在!", true);
  71. return false;
  72. }
  73. else if(Project.ContainsKey(jobName))
  74. {
  75. Logger.LoggerClass.WriteLog("项目中已存在该JOB名称,请更换!", true);
  76. return false;
  77. }
  78. else
  79. {
  80. try
  81. {
  82. VisionJob myNewJob = Serialize.BinaryDeserialize<VisionJob>(path);
  83. OperateProject.Instance.CreateNewJob(jobName, myNewJob, true); // 新添加job
  84. return true;
  85. }
  86. catch (Exception ex)
  87. {
  88. Logger.LoggerClass.WriteLog("载入项目工程时出现异常!", ex);
  89. return false;
  90. }
  91. }
  92. }
  93. public void SaveJob(string jobName,string filePath)
  94. {
  95. if(Project.ContainsKey(jobName))
  96. {
  97. Serialize.BinarySerialize(filePath, Project[jobName]);
  98. }
  99. else
  100. {
  101. Logger.LoggerClass.WriteLog("保存时出现异常,未找到Job", true);
  102. }
  103. }
  104. }
  105. }