CSmplMsrResult.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. 
  2. using OTSDataType;
  3. using System.IO;
  4. using System.Xml;
  5. namespace OTSModelSharp
  6. {
  7. public class CSmplMsrResult
  8. {
  9. //----------------定义----------------------
  10. protected static NLog.Logger logger = null;
  11. string m_strSampleWorkingFolder;
  12. string m_strFieldFileSubFolder;
  13. // pathname
  14. string m_strRstFileName;
  15. string m_strdbPathName;
  16. CIncAFileMgr m_DBFileMgr ;
  17. public string SMPL_MSR_RESULT_FILE_EXT = ".rst";
  18. // fields file sub-directory string
  19. public string SMPL_MSR_RESULT_FIELDS_FILE_SUBFOLDER = "FIELD_FILES";
  20. public string DBFILE_NAME = "Inclusion.db";
  21. // BSE file name
  22. public string SMPL_MSR_RESULT_FIELDS_BSE = ("Field");
  23. public string SMPL_MSR_RESULT_FILE_FILTER = ("Sample Measure Result Files (*.rst)|*.rst||");
  24. //----------全局定义------------------
  25. // sample measure result file mark
  26. public int SMPL_MSR_RESULT_FILE_MARK = 'S' + 'M' + 'P' + 'L' + 'M' + 'S' + 'R' + 'R' + 'E' + 'S' + 'U' + 'L' + 'T';
  27. // sample measure result file version
  28. public string SMPL_MSR_RESULT_FILE_VERSION = ("2.0.0");
  29. // sample measure result file extension
  30. //----------定义----------------------
  31. // file version string
  32. string m_strFileVersion;
  33. // SEM sample stage
  34. CSEMStageData m_pSEMStageData;
  35. // sample stage
  36. CStage m_pStage;
  37. CSEMDataGnr m_pSEMData;
  38. // sample setting
  39. COTSSample m_pSample;
  40. // switch
  41. bool m_bSwitch;
  42. public CIncAFileMgr DBFileMgr { get => m_DBFileMgr; set => m_DBFileMgr = value; }
  43. public CSmplMsrResult(string measureWorkingFolder,COTSSample a_pSample)
  44. {
  45. Init();
  46. logger = NLog.LogManager.GetCurrentClassLogger();
  47. m_pSample = a_pSample;
  48. m_strSampleWorkingFolder = measureWorkingFolder + "\\" + a_pSample.GetName();
  49. m_strFieldFileSubFolder = m_strSampleWorkingFolder + "\\" + SMPL_MSR_RESULT_FIELDS_FILE_SUBFOLDER;
  50. m_strRstFileName = m_strSampleWorkingFolder + "\\" + a_pSample.GetName() + SMPL_MSR_RESULT_FILE_EXT;
  51. m_strdbPathName = m_strFieldFileSubFolder + "\\" + DBFILE_NAME;
  52. m_DBFileMgr = new CIncAFileMgr(m_strdbPathName);
  53. }
  54. protected void Init()
  55. {
  56. m_strFileVersion = ("");
  57. m_pSEMStageData = new CSEMStageData();
  58. m_pStage = new CStage();
  59. m_pSEMData = new CSEMDataGnr();
  60. m_bSwitch = false;
  61. }
  62. protected void Cleanup()
  63. {
  64. m_pSample.GetFieldsData().Clear();
  65. }
  66. public string GetFileVersion()
  67. {
  68. return m_strFileVersion;
  69. }
  70. public void SetFileVersion(string a_strFileVersion)
  71. {
  72. m_strFileVersion = a_strFileVersion;
  73. }
  74. public COTSSample GetSample()
  75. {
  76. return m_pSample;
  77. }
  78. public void SetSample(COTSSample a_pSample)
  79. {
  80. if (a_pSample != null)
  81. {
  82. return;
  83. }
  84. m_pSample = a_pSample;
  85. }
  86. public CSEMStageData GetSEMStageData()
  87. {
  88. return m_pSEMStageData;
  89. }
  90. public void SetSEMStageData(CSEMStageData a_pSEMStageData)
  91. {
  92. m_pSEMStageData = a_pSEMStageData;
  93. }
  94. // sample stage
  95. public CStage GetStage()
  96. {
  97. return m_pStage;
  98. }
  99. public void SetStage(CStage a_pStage)
  100. {
  101. if (a_pStage != null)
  102. {
  103. return;
  104. }
  105. m_pStage = a_pStage;
  106. }
  107. // SEM condition
  108. public CSEMDataGnr GetSEMStage()
  109. {
  110. return m_pSEMData;
  111. }
  112. public void SetSEMStage(CSEMDataGnr a_pSEMData)
  113. {
  114. if (a_pSEMData != null)
  115. {
  116. return;
  117. }
  118. m_pSEMData = a_pSEMData;
  119. }
  120. public void Serialize(bool isStoring, XmlDocument classDoc, XmlNode rootNode)
  121. {
  122. xInt xnFileMark = new xInt();
  123. xString xnVersion = new xString();
  124. xBool xbSwitch = new xBool();
  125. Collection<Slo> xfields = new Collection<Slo>();
  126. Slo slo = new Slo();
  127. slo.Register("FileMark", xnFileMark);
  128. slo.Register("Version", xnVersion);
  129. slo.Register("Switch", xbSwitch);
  130. slo.Register("SEMStageData", m_pSEMStageData);
  131. slo.Register("Stage", m_pStage);
  132. slo.Register("SEMData", m_pSEMData);
  133. slo.Register("Sample", m_pSample);
  134. slo.Register("Fields", xfields);
  135. if (isStoring)
  136. {
  137. xnFileMark.AssignValue(SMPL_MSR_RESULT_FILE_MARK);
  138. xnVersion.AssignValue(SMPL_MSR_RESULT_FILE_VERSION);
  139. xbSwitch.AssignValue(m_bSwitch);
  140. slo.Serialize(true, classDoc, rootNode);
  141. }
  142. else
  143. {
  144. slo.Serialize(false, classDoc, rootNode);
  145. m_bSwitch = xbSwitch.value();
  146. m_strFileVersion = xnVersion.value();
  147. }
  148. }
  149. private bool InitFolders()
  150. {
  151. if (!Exists(m_strSampleWorkingFolder))
  152. {
  153. // the working directory is not exit, create it
  154. if (!CreateFolder(m_strSampleWorkingFolder))
  155. {
  156. return false;
  157. }
  158. }
  159. // check if the field files directory exists
  160. if (!Exists(m_strFieldFileSubFolder))
  161. {
  162. // field files directory exists not exists, creates it
  163. if (!CreateFolder(m_strFieldFileSubFolder))
  164. {
  165. // failed to create the field files directory
  166. return false;
  167. }
  168. }
  169. return true;
  170. }
  171. // creates a folder.
  172. private bool CreateFolder(string a_strFolder)
  173. {
  174. // make sure the folder name string are not empty
  175. string strFolder = a_strFolder;
  176. strFolder.Trim();
  177. if (strFolder=="")
  178. {
  179. return false;
  180. }
  181. // if the folder exist?
  182. if (Exists(strFolder))
  183. {
  184. return true;
  185. }
  186. Directory.CreateDirectory(strFolder);
  187. bool bRet = true;
  188. // return folder create result
  189. return bRet;
  190. }
  191. // check if the file exists or not
  192. private bool Exists(string a_sPath)
  193. {
  194. return Directory.Exists(a_sPath);
  195. }
  196. // Save
  197. public bool CreateResultFiles()
  198. {
  199. InitFolders();
  200. XmlDocument xmlDoc = new XmlDocument();
  201. XmlDeclaration xmlDeclaration = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null);
  202. xmlDoc.AppendChild(xmlDeclaration);
  203. XmlElement rootNode = xmlDoc.CreateElement("XMLData");
  204. xmlDoc.AppendChild(rootNode);
  205. XmlNode root = xmlDoc.SelectSingleNode("XMLData");
  206. Serialize(true, xmlDoc, root);
  207. if (!File.Exists(m_strRstFileName))
  208. {
  209. xmlDoc.Save(m_strRstFileName);
  210. }
  211. m_DBFileMgr.InitFile();
  212. m_DBFileMgr.InitDataTable();
  213. return true;
  214. }
  215. public string GetFieldFileSubFolderStr()
  216. {
  217. // return field file sub folder string
  218. return m_strFieldFileSubFolder;
  219. }
  220. public void SetSEMGnr(CSEMDataGnr a_pSEMGnr)
  221. {
  222. if (a_pSEMGnr == null)
  223. {
  224. logger.Info("input a invalid SEM general data pointer.");
  225. return;
  226. }
  227. m_pSEMData= a_pSEMGnr;
  228. }
  229. public void SetSEMStage(CStage a_pStage)
  230. {
  231. //ASSERT(a_pStage);
  232. if (a_pStage == null)
  233. {
  234. logger.Info("input a invalid stage pointer.");
  235. return;
  236. }
  237. m_pStage= a_pStage;
  238. }
  239. }
  240. }