MsrThreadStatus.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Xml;
  8. using static OTSDataType.otsdataconst;
  9. namespace OTSModelSharp
  10. {
  11. public class CMsrThreadStatus
  12. {
  13. public CMsrThreadStatus()
  14. {
  15. Init();
  16. }
  17. // copy constructor
  18. public CMsrThreadStatus(ref CMsrThreadStatus a_oSource) //CMsrThreadStatus(const CMsrThreadStatus&); (const CMsrThreadStatus& 转换成 ref CMsrThreadStatus
  19. {
  20. // can't copy itself
  21. if (a_oSource == this)
  22. {
  23. return;
  24. }
  25. // copy data over
  26. Duplicate(a_oSource);
  27. }
  28. // copy constructor
  29. public CMsrThreadStatus(CMsrThreadStatus a_poSource)
  30. {
  31. // input check
  32. try
  33. {
  34. // can't copy itself
  35. if (a_poSource == this)
  36. {
  37. return;
  38. }
  39. // copy data over
  40. Duplicate(a_poSource);
  41. }
  42. catch
  43. {
  44. return;
  45. }
  46. }
  47. public OTS_MSR_THREAD_STATUS GetStatus()
  48. {
  49. return m_nStatus;
  50. }
  51. public void SetStatus(OTS_MSR_THREAD_STATUS a_nStatus)
  52. {
  53. m_nStatus = a_nStatus;
  54. }
  55. // start time
  56. public DateTime GetStartTime()
  57. {
  58. return m_timeStart;
  59. }
  60. public void SetStartTime(DateTime a_timeStart)
  61. {
  62. m_timeStart = a_timeStart;
  63. }
  64. // used time
  65. public TimeSpan GetUsedTime()
  66. {
  67. return m_timeUsed;
  68. }
  69. public void SetUsedTime(TimeSpan a_timeUsed)
  70. {
  71. m_timeUsed = a_timeUsed;
  72. }
  73. // end time
  74. public DateTime GetEndTime()
  75. {
  76. return m_timeEnd;
  77. }
  78. public void SetEndTime(DateTime a_timeEnd)
  79. {
  80. m_timeEnd = a_timeEnd;
  81. }
  82. // completed samples
  83. public List<string> GetCompletedSamples() //COTSSamplesList转List<string>
  84. {
  85. return m_listCpldSamples;
  86. }
  87. public void SetCompletedSamples(ref List<string> a_listCpldSamples) //COTSSamplesList转List<string>
  88. {
  89. m_listCpldSamples.Clear();
  90. for (int i=0; i< a_listCpldSamples.Count;i++)
  91. {
  92. m_listCpldSamples.Add(a_listCpldSamples[i]);
  93. }
  94. }
  95. // current start time
  96. public DateTime GetCurrentStartTime()
  97. {
  98. return m_timeStartCur;
  99. }
  100. public void SetCurrentStartTime(DateTime a_timeStartCur)
  101. {
  102. m_timeStartCur = a_timeStartCur;
  103. }
  104. // compute time
  105. public bool ComputeTime(OTS_THREAD_TIME_TYPE a_nType)
  106. {
  107. if (a_nType == OTS_THREAD_TIME_TYPE.START)
  108. {
  109. if (m_timeStart == new DateTime())
  110. {
  111. m_timeStart = DateTime.Now; //OleDateTime.GetCurrentTime();
  112. m_timeStartCur = m_timeStart;
  113. m_timeUsedLast = m_timeUsed;
  114. }
  115. else
  116. {
  117. m_timeStartCur = DateTime.Now;
  118. m_timeUsedLast = m_timeUsed;
  119. }
  120. }
  121. else if (a_nType == OTS_THREAD_TIME_TYPE.STOPPED)
  122. {
  123. // set current time as end time
  124. m_timeEnd = DateTime.Now;
  125. // compute used time
  126. if (m_timeStartCur == m_timeStart)
  127. {
  128. // first compute time
  129. m_timeUsed = m_timeEnd - m_timeStart;
  130. }
  131. else
  132. {
  133. // not the first compute time
  134. m_timeUsed = m_timeEnd - m_timeStartCur + m_timeUsedLast;
  135. }
  136. }
  137. else if (a_nType == OTS_THREAD_TIME_TYPE.COMPLT)
  138. {
  139. m_timeEnd = DateTime.Now;
  140. if (m_timeStartCur == m_timeStart)
  141. {
  142. // first compute time
  143. m_timeUsed = m_timeEnd - m_timeStart;
  144. }
  145. else
  146. {
  147. // not the first compute time
  148. m_timeUsed = m_timeEnd - m_timeStartCur + m_timeUsedLast;
  149. }
  150. }
  151. return true;
  152. }
  153. // cleanup
  154. protected void Cleanup()
  155. {
  156. m_listCpldSamples.Clear();
  157. }
  158. // initialization
  159. protected void Init()
  160. {
  161. m_nStatus = OTS_MSR_THREAD_STATUS.READY;
  162. m_timeStart = DateTime.Now;
  163. m_timeUsed = new TimeSpan(0);
  164. m_timeEnd = DateTime.Now;
  165. m_timeStartCur = DateTime.Now;
  166. m_listCpldSamples.Clear();
  167. }
  168. // duplication
  169. protected void Duplicate(CMsrThreadStatus a_oSource)
  170. {
  171. // initialization
  172. Init();
  173. // copy data over
  174. m_nStatus = a_oSource.m_nStatus;
  175. m_timeStart = a_oSource.m_timeStart;
  176. m_timeUsed = a_oSource.m_timeUsed;
  177. m_timeEnd = a_oSource.m_timeEnd;
  178. foreach (var pSample in a_oSource.m_listCpldSamples)
  179. {
  180. string pSampleNew = pSample; //COTSSamplePtr pSampleNew = COTSSamplePtr(new COTSSample(pSample.get()));??? vector<COTSSamplePtr>转成List<string> COTSSamplePtr 转换成string
  181. m_listCpldSamples.Add(pSampleNew);
  182. }
  183. }
  184. // status
  185. protected OTS_MSR_THREAD_STATUS m_nStatus = new OTS_MSR_THREAD_STATUS();
  186. // start time
  187. protected DateTime m_timeStart = new DateTime();
  188. // used time
  189. protected TimeSpan m_timeUsed = new TimeSpan();
  190. // end time
  191. protected DateTime m_timeEnd = new DateTime();
  192. // completed samples
  193. protected List<string> m_listCpldSamples = new List<string>();// vector<COTSSamplePtr>转成List<string>
  194. // current start time
  195. protected DateTime m_timeStartCur = new DateTime();
  196. private TimeSpan m_timeUsedLast;
  197. }
  198. }