MsrThreadStatus.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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;
  112. m_timeStartCur = m_timeStart;
  113. }
  114. else
  115. {
  116. m_timeStartCur = DateTime.Now;
  117. m_timeUsedLast = m_timeUsed;
  118. }
  119. //m_timeEnd = DateTime.Now;
  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
  138. {
  139. return false;
  140. }
  141. return true;
  142. }
  143. // cleanup
  144. protected void Cleanup()
  145. {
  146. m_listCpldSamples.Clear();
  147. }
  148. // initialization
  149. protected void Init()
  150. {
  151. m_nStatus = OTS_MSR_THREAD_STATUS.READY;
  152. m_timeStart = DateTime.Now;
  153. m_timeUsed = new TimeSpan(0);
  154. m_timeEnd = DateTime.Now;
  155. m_timeStartCur = DateTime.Now;
  156. m_listCpldSamples.Clear();
  157. }
  158. // duplication
  159. protected void Duplicate(CMsrThreadStatus a_oSource)
  160. {
  161. // initialization
  162. Init();
  163. // copy data over
  164. m_nStatus = a_oSource.m_nStatus;
  165. m_timeStart = a_oSource.m_timeStart;
  166. m_timeUsed = a_oSource.m_timeUsed;
  167. m_timeEnd = a_oSource.m_timeEnd;
  168. foreach (var pSample in a_oSource.m_listCpldSamples)
  169. {
  170. string pSampleNew = pSample; //COTSSamplePtr pSampleNew = COTSSamplePtr(new COTSSample(pSample.get()));??? vector<COTSSamplePtr>转成List<string> COTSSamplePtr 转换成string
  171. m_listCpldSamples.Add(pSampleNew);
  172. }
  173. }
  174. // status
  175. protected OTS_MSR_THREAD_STATUS m_nStatus = new OTS_MSR_THREAD_STATUS();
  176. // start time
  177. protected DateTime m_timeStart = new DateTime();
  178. // used time
  179. protected TimeSpan m_timeUsed = new TimeSpan();
  180. // end time
  181. protected DateTime m_timeEnd = new DateTime();
  182. // completed samples
  183. protected List<string> m_listCpldSamples = new List<string>();// vector<COTSSamplePtr>转成List<string>
  184. // current start time
  185. protected DateTime m_timeStartCur = new DateTime();
  186. private TimeSpan m_timeUsedLast;
  187. }
  188. }