OTSLicenseInfo.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. #include "stdafx.h"
  2. #include "OTSLicenseInfo.h"
  3. namespace OTSDATA {
  4. // license info class
  5. // used to handle license information
  6. IMPLEMENT_SERIAL(COTSLicenseInfo, CObject, 1)
  7. // constructor
  8. COTSLicenseInfo::COTSLicenseInfo()
  9. {
  10. Init();
  11. }
  12. // copy constructor
  13. COTSLicenseInfo::COTSLicenseInfo(const COTSLicenseInfo& a_oSource)
  14. {
  15. // can't copy itself
  16. if (&a_oSource == this)
  17. {
  18. return;
  19. }
  20. // copy data over
  21. Duplicate(a_oSource);
  22. }
  23. // copy constructor
  24. COTSLicenseInfo::COTSLicenseInfo(COTSLicenseInfo* a_poSource)
  25. {
  26. // input check
  27. ASSERT(a_poSource);
  28. if (!a_poSource)
  29. {
  30. return;
  31. }
  32. // can't copy itself
  33. if (a_poSource == this)
  34. {
  35. return;
  36. }
  37. // copy data over
  38. Duplicate(*a_poSource);
  39. }
  40. // =operator
  41. COTSLicenseInfo& COTSLicenseInfo::operator=(const COTSLicenseInfo& a_oSource)
  42. {
  43. // cleanup
  44. Cleanup();
  45. // copy the class data over
  46. Duplicate(a_oSource);
  47. // return class
  48. return *this;
  49. }
  50. // ==operator
  51. BOOL COTSLicenseInfo::operator==(const COTSLicenseInfo& a_oSource)
  52. {
  53. return m_strMachineId.Compare(a_oSource.m_strMachineId) == 0 &&
  54. m_nPackId == a_oSource.m_nPackId &&
  55. m_nLicType == a_oSource.m_nLicType &&
  56. m_oExpireDate == a_oSource.m_oExpireDate &&
  57. m_strComputerNickName.Compare(a_oSource.m_strComputerNickName) == 0;
  58. }
  59. // detractor
  60. COTSLicenseInfo::~COTSLicenseInfo()
  61. {
  62. // cleanup
  63. Cleanup();
  64. }
  65. // COTSLicenseInfo member functions
  66. // serialization
  67. void COTSLicenseInfo::Serialize(CArchive& ar)
  68. {
  69. // store?
  70. if (ar.IsStoring())
  71. {
  72. // store
  73. ar << m_strMachineId;
  74. ar << (int)m_nPackId;
  75. ar << (int)m_nLicType;
  76. ar << m_oExpireDate;
  77. ar << m_strComputerNickName;
  78. }
  79. else
  80. {
  81. // load
  82. ar >> m_strMachineId;
  83. int nTemp;
  84. ar >> nTemp;
  85. m_nPackId = (OTS_SOFT_PACKAGE_ID)nTemp;
  86. ar >> nTemp;
  87. m_nLicType = (OTS_LICENSE_TYPE)nTemp;
  88. ar >> m_oExpireDate;
  89. ar >> m_strComputerNickName;
  90. }
  91. // base object serialization
  92. CObject::Serialize(ar);
  93. }
  94. void COTSLicenseInfo::Serialize(bool isStoring, tinyxml2::XMLDocument * classDoc, tinyxml2::XMLElement * rootNode)
  95. {
  96. xmls::xString xstrMachineId;
  97. xmls::xInt xnPackId;
  98. xmls::xInt xnLicType;
  99. xmls::xOleDateTime xoExpireDate;
  100. xmls::xString xstrComputerNickName;
  101. this->Register("MachineId", &xstrMachineId);
  102. this->Register("PackId", &xnPackId);
  103. this->Register("LicType", &xnLicType);
  104. this->Register("ExpireDate", &xoExpireDate);
  105. this->Register("ComputerNickName", &xstrComputerNickName);
  106. if (isStoring)
  107. {
  108. xstrMachineId = m_strMachineId;
  109. xnPackId = (int)m_nPackId;
  110. xnLicType = (int)m_nLicType;
  111. xoExpireDate = m_oExpireDate;
  112. xstrComputerNickName = m_strComputerNickName;
  113. Slo::Serialize(true, classDoc, rootNode);
  114. }
  115. else
  116. {
  117. xmls::Slo::Serialize(false, classDoc, rootNode);
  118. m_strMachineId = xstrMachineId.value().c_str();
  119. m_nPackId = (OTS_SOFT_PACKAGE_ID)xnPackId.value();
  120. m_nLicType = (OTS_LICENSE_TYPE)xnLicType.value();
  121. m_oExpireDate = xoExpireDate.value();
  122. m_strComputerNickName = xstrComputerNickName.value().c_str();
  123. }
  124. }
  125. // protected:
  126. // cleanup
  127. void COTSLicenseInfo::Cleanup()
  128. {
  129. // nothing needs to be done at the moment
  130. }
  131. // initialization
  132. void COTSLicenseInfo::Init()
  133. {
  134. m_strMachineId = _T("");
  135. m_nPackId = OTS_SOFT_PACKAGE_ID::OTSIncA;
  136. m_nLicType = OTS_LICENSE_TYPE::Offline;
  137. m_oExpireDate = COleDateTime::GetCurrentTime();
  138. m_strComputerNickName = _T("");
  139. }
  140. // duplication
  141. void COTSLicenseInfo::Duplicate(const COTSLicenseInfo& a_oSource)
  142. {
  143. // initialization
  144. Init();
  145. // copy data over
  146. m_strMachineId = a_oSource.m_strMachineId;
  147. m_nPackId = a_oSource.m_nPackId;
  148. m_nLicType = a_oSource.m_nLicType;
  149. m_oExpireDate = a_oSource.m_oExpireDate;
  150. m_strComputerNickName = a_oSource.m_strComputerNickName;
  151. }
  152. }