Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

242 lines
4.6 KiB

  1. // HMRuleStatusInstance.cpp: implementation of the CHMRuleStatusInstance class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "snapin.h"
  6. #include "HMRuleStatus.h"
  7. #ifdef _DEBUG
  8. #undef THIS_FILE
  9. static char THIS_FILE[]=__FILE__;
  10. #define new DEBUG_NEW
  11. #endif
  12. IMPLEMENT_DYNCREATE(CHMRuleStatusInstance,CHMEvent)
  13. //////////////////////////////////////////////////////////////////////
  14. // Construction/Destruction
  15. //////////////////////////////////////////////////////////////////////
  16. CHMRuleStatusInstance::CHMRuleStatusInstance()
  17. {
  18. m_iState = 2;
  19. m_sState.LoadString(IDS_STRING_UNKNOWN);
  20. m_sMessage.LoadString(IDS_STRING_CONNECTED);
  21. m_sCurrentValue.LoadString(IDS_STRING_UNKNOWN);
  22. }
  23. CHMRuleStatusInstance::CHMRuleStatusInstance(const CHMRuleStatusInstance& rsi)
  24. {
  25. m_sSystemName = rsi.m_sSystemName;
  26. m_sGuid = rsi.m_sGuid;
  27. m_ID= rsi.m_ID;
  28. m_sMessage = rsi.m_sMessage;
  29. m_sInstanceName = rsi.m_sInstanceName;
  30. m_iState = rsi.m_iState;
  31. m_sState = rsi.m_sState;
  32. m_sStatusGuid = rsi.m_sStatusGuid;
  33. m_sCurrentValue = rsi.m_sCurrentValue;
  34. m_sDateTime= rsi.m_sDateTime;
  35. m_st = rsi.m_st;
  36. m_sDataElementName = rsi.m_sDataElementName;
  37. }
  38. CHMRuleStatusInstance::~CHMRuleStatusInstance()
  39. {
  40. Destroy();
  41. }
  42. //////////////////////////////////////////////////////////////////////
  43. // Create
  44. //////////////////////////////////////////////////////////////////////
  45. HRESULT CHMRuleStatusInstance::Create(const CString& sMachineName)
  46. {
  47. HRESULT hr = CHMEvent::Create(sMachineName);
  48. if( !CHECKHRESULT(hr) )
  49. {
  50. return hr;
  51. }
  52. // create the enumerator for Microsoft_HMRuleStatus object instances
  53. BSTR bsClass = SysAllocString(_T("Microsoft_HMThresholdStatusInstance"));
  54. hr = CreateEnumerator(bsClass);
  55. SysFreeString(bsClass);
  56. if( !CHECKHRESULT(hr) )
  57. {
  58. return hr;
  59. }
  60. return hr;
  61. }
  62. HRESULT CHMRuleStatusInstance::Create(IWbemClassObject* pObject)
  63. {
  64. HRESULT hr = CHMEvent::Create(pObject);
  65. if( !CHECKHRESULT(hr) )
  66. {
  67. return hr;
  68. }
  69. return hr;
  70. }
  71. //////////////////////////////////////////////////////////////////////
  72. // Property Retrieval Operations
  73. //////////////////////////////////////////////////////////////////////
  74. HRESULT CHMRuleStatusInstance::GetAllProperties()
  75. {
  76. ASSERT(m_pIWbemClassObject);
  77. if( m_pIWbemClassObject == NULL )
  78. {
  79. ASSERT(FALSE);
  80. return S_FALSE;
  81. }
  82. HRESULT hr = S_OK;
  83. // GUID
  84. hr = GetProperty(IDS_STRING_MOF_GUID,m_sGuid);
  85. m_sGuid.TrimLeft(_T("{"));
  86. m_sGuid.TrimRight(_T("}"));
  87. // StatusGUID
  88. hr = GetProperty(IDS_STRING_MOF_STATUSGUID,m_sStatusGuid);
  89. m_sStatusGuid.TrimLeft(_T("{"));
  90. m_sStatusGuid.TrimRight(_T("}"));
  91. // State
  92. hr = GetProperty(IDS_STRING_MOF_STATE,m_iState);
  93. switch( m_iState )
  94. {
  95. case 0:
  96. {
  97. m_sState.LoadString(IDS_STRING_CRITICAL);
  98. }
  99. break;
  100. case 1:
  101. {
  102. m_sState.LoadString(IDS_STRING_WARNING);
  103. }
  104. break;
  105. case 2:
  106. {
  107. m_sState.LoadString(IDS_STRING_NODATA);
  108. }
  109. break;
  110. case 3:
  111. {
  112. m_sState.LoadString(IDS_STRING_UNKNOWN);
  113. }
  114. break;
  115. case 4:
  116. {
  117. m_sState.LoadString(IDS_STRING_OUTAGE);
  118. }
  119. break;
  120. case 5:
  121. {
  122. m_sState.LoadString(IDS_STRING_DISABLED);
  123. }
  124. break;
  125. case 6:
  126. {
  127. m_sState.LoadString(IDS_STRING_INFORMATION);
  128. }
  129. break;
  130. case 7:
  131. {
  132. m_sState.LoadString(IDS_STRING_RESET);
  133. }
  134. break;
  135. case 8:
  136. {
  137. m_sState.LoadString(IDS_STRING_NORMAL);
  138. }
  139. break;
  140. }
  141. // Message
  142. hr = GetProperty(IDS_STRING_MOF_MESSAGE,m_sMessage);
  143. // CurrentValue
  144. hr = GetProperty(IDS_STRING_MOF_CURRENTVALUE,m_sCurrentValue);
  145. // InstanceName
  146. hr = GetProperty(IDS_STRING_MOF_INSTANCENAME,m_sInstanceName);
  147. // ID
  148. hr = GetProperty(IDS_STRING_MOF_ID,m_ID);
  149. // DTime
  150. CTime time;
  151. hr = GetProperty(IDS_STRING_MOF_LOCALTIME,time);
  152. time.GetAsSystemTime(m_st);
  153. CString sTime;
  154. CString sDate;
  155. int iLen = GetTimeFormat(LOCALE_USER_DEFAULT,0L,&m_st,NULL,NULL,0);
  156. iLen = GetTimeFormat(LOCALE_USER_DEFAULT,0L,&m_st,NULL,sTime.GetBuffer(iLen+(sizeof(TCHAR)*1)),iLen);
  157. sTime.ReleaseBuffer();
  158. iLen = GetDateFormat(LOCALE_USER_DEFAULT,0L,&m_st,NULL,NULL,0);
  159. iLen = GetDateFormat(LOCALE_USER_DEFAULT,0L,&m_st,NULL,sDate.GetBuffer(iLen+(sizeof(TCHAR)*1)),iLen);
  160. sDate.ReleaseBuffer();
  161. m_sDateTime = sDate + _T(" ") + sTime;
  162. // propogate the status back up to the HMSystemStatus instance
  163. // this gives us a roll up of status at each node in the tree
  164. CHMEvent* pParent = GetParent();
  165. CHMRuleStatusInstance* pStatus = NULL;
  166. while(pParent)
  167. {
  168. pStatus = new CHMRuleStatusInstance(*this);
  169. pStatus->SetParent(this);
  170. pParent->m_RolledUpRuleStatus.Add(pStatus);
  171. pParent = pParent->GetParent();
  172. }
  173. return hr;
  174. }