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.

426 lines
10 KiB

  1. // ActionResultsView.cpp: implementation of the CActionResultsView class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "snapin.h"
  6. #include "ActionResultsView.h"
  7. #include "HealthmonResultsPane.h"
  8. #include "HMListViewColumn.h"
  9. #include "Action.h"
  10. #ifdef _DEBUG
  11. #undef THIS_FILE
  12. static char THIS_FILE[]=__FILE__;
  13. #define new DEBUG_NEW
  14. #endif
  15. IMPLEMENT_DYNCREATE(CActionResultsView,CSplitPaneResultsView)
  16. //////////////////////////////////////////////////////////////////////
  17. // Construction/Destruction
  18. //////////////////////////////////////////////////////////////////////
  19. CActionResultsView::CActionResultsView()
  20. {
  21. }
  22. CActionResultsView::~CActionResultsView()
  23. {
  24. Destroy();
  25. }
  26. //////////////////////////////////////////////////////////////////////
  27. // Create/Destroy
  28. //////////////////////////////////////////////////////////////////////
  29. bool CActionResultsView::Create(CScopePaneItem* pOwnerItem)
  30. {
  31. TRACEX(_T("CActionResultsView::Create\n"));
  32. TRACEARGn(pOwnerItem);
  33. if( ! CSplitPaneResultsView::Create(pOwnerItem) )
  34. {
  35. TRACE(_T("FAILED : CSplitPaneResultsView::Create failed.\n"));
  36. return false;
  37. }
  38. // add the upper columns
  39. CHMListViewColumn* pColumn = NULL;
  40. CString sTitle;
  41. DWORD dwFormat = LVCFMT_LEFT;
  42. // name
  43. pColumn = new CHMListViewColumn;
  44. sTitle.LoadString(IDS_STRING_NAME);
  45. pColumn->Create(this,sTitle,75,dwFormat);
  46. pColumn->SetToUpperPane();
  47. AddColumn(pColumn);
  48. // GUID
  49. pColumn = new CHMListViewColumn;
  50. sTitle.LoadString(IDS_STRING_GUID);
  51. pColumn->Create(this,sTitle,0,dwFormat);
  52. pColumn->SetToUpperPane();
  53. AddColumn(pColumn);
  54. // Type
  55. pColumn = new CHMListViewColumn;
  56. sTitle.LoadString(IDS_STRING_TYPE);
  57. pColumn->Create(this,sTitle,75,dwFormat);
  58. pColumn->SetToUpperPane();
  59. AddColumn(pColumn);
  60. // Condition
  61. pColumn = new CHMListViewColumn;
  62. sTitle.LoadString(IDS_STRING_CONDITION);
  63. pColumn->Create(this,sTitle,75,dwFormat);
  64. pColumn->SetToUpperPane();
  65. AddColumn(pColumn);
  66. // comment
  67. pColumn = new CHMListViewColumn;
  68. sTitle.LoadString(IDS_STRING_COMMENT);
  69. pColumn->Create(this,sTitle,125,dwFormat);
  70. pColumn->SetToUpperPane();
  71. AddColumn(pColumn);
  72. // add the lower columns
  73. // Severity
  74. pColumn = new CHMListViewColumn;
  75. sTitle.LoadString(IDS_STRING_SEVERITY);
  76. pColumn->Create(this,sTitle,75,dwFormat);
  77. pColumn->SetToLowerPane();
  78. AddColumn(pColumn);
  79. // ID
  80. pColumn = new CHMListViewColumn;
  81. sTitle.LoadString(IDS_STRING_ID);
  82. pColumn->Create(this,sTitle,75,dwFormat);
  83. pColumn->SetToLowerPane();
  84. AddColumn(pColumn);
  85. // Date/Time
  86. pColumn = new CHMListViewColumn;
  87. sTitle.LoadString(IDS_STRING_DATETIME);
  88. pColumn->Create(this,sTitle,175,dwFormat);
  89. pColumn->SetToLowerPane();
  90. AddColumn(pColumn);
  91. // Component
  92. pColumn = new CHMListViewColumn;
  93. sTitle.LoadString(IDS_STRING_DATA_POINT);
  94. pColumn->Create(this,sTitle,125,dwFormat);
  95. pColumn->SetToLowerPane();
  96. AddColumn(pColumn);
  97. // System
  98. pColumn = new CHMListViewColumn;
  99. sTitle.LoadString(IDS_STRING_SYSTEM);
  100. pColumn->Create(this,sTitle,75,dwFormat);
  101. pColumn->SetToLowerPane();
  102. AddColumn(pColumn);
  103. // Message
  104. pColumn = new CHMListViewColumn;
  105. sTitle.LoadString(IDS_STRING_MESSAGE);
  106. pColumn->Create(this,sTitle,75,dwFormat);
  107. pColumn->SetToLowerPane();
  108. AddColumn(pColumn);
  109. // add the stats columns
  110. // time
  111. pColumn = new CHMListViewColumn;
  112. sTitle.LoadString(IDS_STRING_DATETIME);
  113. pColumn->Create(this,sTitle,75,dwFormat);
  114. pColumn->SetToStatsPane();
  115. AddColumn(pColumn);
  116. // normal
  117. pColumn = new CHMListViewColumn;
  118. sTitle.LoadString(IDS_STRING_NORMAL);
  119. pColumn->Create(this,sTitle,75,dwFormat);
  120. pColumn->SetToStatsPane();
  121. AddColumn(pColumn);
  122. // warning
  123. pColumn = new CHMListViewColumn;
  124. sTitle.LoadString(IDS_STRING_WARNING);
  125. pColumn->Create(this,sTitle,75,dwFormat);
  126. pColumn->SetToStatsPane();
  127. AddColumn(pColumn);
  128. // critical
  129. pColumn = new CHMListViewColumn;
  130. sTitle.LoadString(IDS_STRING_CRITICAL);
  131. pColumn->Create(this,sTitle,75,dwFormat);
  132. pColumn->SetToStatsPane();
  133. AddColumn(pColumn);
  134. // unknown
  135. pColumn = new CHMListViewColumn;
  136. sTitle.LoadString(IDS_STRING_UNKNOWN);
  137. pColumn->Create(this,sTitle,75,dwFormat);
  138. pColumn->SetToStatsPane();
  139. AddColumn(pColumn);
  140. return true;
  141. }
  142. //////////////////////////////////////////////////////////////////////
  143. // MMC Notify Handlers
  144. //////////////////////////////////////////////////////////////////////
  145. HRESULT CActionResultsView::OnShow(CResultsPane* pPane, BOOL bSelecting, HSCOPEITEM hScopeItem)
  146. {
  147. TRACEX(_T("CActionResultsView::OnShow\n"));
  148. TRACEARGn(pPane);
  149. TRACEARGn(bSelecting);
  150. TRACEARGn(hScopeItem);
  151. if( ! GfxCheckObjPtr(pPane,CHealthmonResultsPane) )
  152. {
  153. TRACE(_T("FAILED : pPane is not a valid pointer.\n"));
  154. return E_FAIL;
  155. }
  156. CHealthmonResultsPane* pHMRP = (CHealthmonResultsPane*)pPane;
  157. HRESULT hr = S_OK;
  158. if( ! CHECKHRESULT(hr) )
  159. {
  160. TRACE(_T("FAILED : CResultsPaneView::OnShow failed.\n"));
  161. return hr;
  162. }
  163. _DHMListView* pUpperList = NULL;
  164. // get upper list control
  165. pUpperList = pHMRP->GetUpperListCtrl();
  166. if( ! pUpperList )
  167. {
  168. TRACE(_T("FAILED : CHealthmonResultsPane::GetUpperListCtrl returned a NULL pointer.\n"));
  169. return E_FAIL;
  170. }
  171. _DHMListView* pLowerList = NULL;
  172. // get lower list control
  173. pLowerList = pHMRP->GetLowerListCtrl();
  174. if( ! pLowerList )
  175. {
  176. TRACE(_T("FAILED : CHealthmonResultsPane::GetLowerListCtrl returned a NULL pointer.\n"));
  177. return E_FAIL;
  178. }
  179. _DHMListView* pStatsList = NULL;
  180. // get stats list control
  181. pStatsList = pHMRP->GetStatsListCtrl();
  182. if( ! pLowerList )
  183. {
  184. TRACE(_T("FAILED : CHealthmonResultsPane::GetLowerListCtrl returned a NULL pointer.\n"));
  185. return E_FAIL;
  186. }
  187. for( int i = 0; i < m_ResultItems.GetSize(); i++ )
  188. {
  189. delete m_ResultItems[i];
  190. }
  191. m_ResultItems.RemoveAll();
  192. pUpperList->DeleteAllItems();
  193. pLowerList->DeleteAllItems();
  194. pStatsList->DeleteAllItems();
  195. CScopePaneItem* pOwnerScopeItem = GetOwnerScopeItem();
  196. if( ! pOwnerScopeItem || ! GfxCheckObjPtr(pOwnerScopeItem,CHMScopeItem) )
  197. {
  198. TRACE(_T("FAILED : CResultsPaneView::GetOwnerScopeItem returns NULL pointer.\n"));
  199. return S_OK;
  200. }
  201. CAction* pObject = (CAction*)((CHMScopeItem*)(pOwnerScopeItem))->GetObjectPtr();
  202. if( ! pObject || ! GfxCheckObjPtr(pObject,CAction) )
  203. {
  204. return S_OK;
  205. }
  206. if( bSelecting )
  207. {
  208. CString sText;
  209. sText.Format(IDS_STRING_ASSOCIATIONS_OF_FORMAT,pOwnerScopeItem->GetDisplayName());
  210. pUpperList->SetTitle(sText);
  211. // add the configs associated to this action object
  212. CWbemClassObject* pClassObject = pObject->GetAssociatedConfigObjects();
  213. ULONG ulReturned = 0L;
  214. int iConfigCount = 0;
  215. while( pClassObject && pClassObject->GetNextObject(ulReturned) == S_OK && ulReturned > 0 )
  216. {
  217. CHMResultsPaneItem* pItem = new CHMResultsPaneItem;
  218. CStringArray saNames;
  219. CString sValue;
  220. pClassObject->GetLocaleStringProperty(IDS_STRING_MOF_NAME,sValue);
  221. saNames.Add(sValue);
  222. pClassObject->GetProperty(IDS_STRING_MOF_GUID,sValue);
  223. saNames.Add(sValue);
  224. CUIntArray iaIconIds;
  225. GetObjectTypeInfo(pClassObject,iaIconIds,sValue);
  226. saNames.Add(sValue);
  227. sValue = pObject->GetConditionString(saNames[1]);
  228. saNames.Add(sValue);
  229. pClassObject->GetLocaleStringProperty(IDS_STRING_MOF_DESCRIPTION,sValue);
  230. saNames.Add(sValue);
  231. if( ! pItem->Create(this,saNames,iaIconIds,0) )
  232. {
  233. TRACE(_T("FAILED : CHMResultsPaneItem::Create failed.\n"));
  234. if (pClassObject) // v-marfin
  235. {
  236. delete pClassObject;
  237. }
  238. return S_OK;
  239. }
  240. pItem->SetToUpperPane();
  241. m_ResultItems.Add(pItem);
  242. iConfigCount++;
  243. }
  244. if( pClassObject )
  245. {
  246. delete pClassObject;
  247. }
  248. sText.Format(IDS_STRING_COUNT_OF_FORMAT,iConfigCount);
  249. pUpperList->SetDescription(sText);
  250. hr = CResultsPaneView::OnShow(pPane,bSelecting,hScopeItem);
  251. // hr = AddEvents(pHMRP);
  252. // hr = AddStatistics(pHMRP);
  253. USES_CONVERSION;
  254. CString sOrder = AfxGetApp()->GetProfileString(A2T(pObject->GetRuntimeClass()->m_lpszClassName),_T("UpperColumnOrder"));
  255. if( ! sOrder.IsEmpty() && sOrder != pUpperList->GetColumnOrder() )
  256. {
  257. pUpperList->SetColumnOrder(sOrder);
  258. }
  259. sOrder = AfxGetApp()->GetProfileString(A2T(pObject->GetRuntimeClass()->m_lpszClassName),_T("LowerColumnOrder"));
  260. if( ! sOrder.IsEmpty() && sOrder != pLowerList->GetColumnOrder() )
  261. {
  262. pLowerList->SetColumnOrder(sOrder);
  263. }
  264. }
  265. else
  266. {
  267. hr = CResultsPaneView::OnShow(pPane,bSelecting,hScopeItem);
  268. int iUpperColCount = 0;
  269. int iLowerColCount = 0;
  270. for( int i=0; i < GetColumnCount(); i++ )
  271. {
  272. CHMListViewColumn* pColumn = (CHMListViewColumn*)GetColumn(i);
  273. if( pColumn )
  274. {
  275. if( pColumn->IsUpperPane() )
  276. {
  277. pColumn->SaveWidth(pPane,iUpperColCount++);
  278. }
  279. if( pColumn->IsLowerPane() )
  280. {
  281. pColumn->SaveWidth(pPane,iLowerColCount++);
  282. }
  283. }
  284. }
  285. USES_CONVERSION;
  286. CString sOrder = pUpperList->GetColumnOrder();
  287. AfxGetApp()->WriteProfileString(A2T(pObject->GetRuntimeClass()->m_lpszClassName),_T("UpperColumnOrder"),sOrder);
  288. sOrder.Empty();
  289. sOrder = pLowerList->GetColumnOrder();
  290. AfxGetApp()->WriteProfileString(A2T(pObject->GetRuntimeClass()->m_lpszClassName),_T("LowerColumnOrder"),sOrder);
  291. sOrder.Empty();
  292. for( i = 0; i < GetColumnCount(); i++ )
  293. {
  294. CHMListViewColumn* pColumn = (CHMListViewColumn*)GetColumn(i);
  295. if( pColumn->IsUpperPane() )
  296. {
  297. pUpperList->DeleteColumn(0);
  298. }
  299. if( pColumn->IsLowerPane() )
  300. {
  301. pLowerList->DeleteColumn(0);
  302. }
  303. if( pColumn->IsStatsPane() )
  304. {
  305. pStatsList->DeleteColumn(0);
  306. }
  307. }
  308. // clean up lower list control
  309. pLowerList->DeleteAllItems();
  310. // clean up stats list control
  311. pStatsList->DeleteAllItems();
  312. // RemoveStatistics(pHMRP);
  313. }
  314. return S_OK;
  315. }
  316. inline void CActionResultsView::GetObjectTypeInfo(CWbemClassObject* pObject,CUIntArray& uia,CString& sType)
  317. {
  318. CString sValue;
  319. pObject->GetProperty(_T("__CLASS"),sValue);
  320. sValue.MakeUpper();
  321. if( sValue.Find(_T("SYSTEM")) != -1 )
  322. {
  323. sType.LoadString(IDS_STRING_SYSTEM);
  324. uia.Add(IDI_ICON_SYSTEM);
  325. }
  326. else if( sValue.Find(_T("DATAGROUP")) != -1 )
  327. {
  328. sType.LoadString(IDS_STRING_DATA_GROUP);
  329. uia.Add(IDI_ICON_COMPONENT);
  330. }
  331. else if( sValue.Find(_T("DATACOLLECTOR")) != -1 )
  332. {
  333. sType.LoadString(IDS_STRING_DATA_POINT);
  334. uia.Add(IDI_ICON_DATAPOINT);
  335. }
  336. else if( sValue.Find(_T("THRESHOLD")) != -1 )
  337. {
  338. sType.LoadString(IDS_STRING_RULE);
  339. uia.Add(IDI_ICON_THRESHOLD);
  340. }
  341. else
  342. {
  343. ASSERT(FALSE);
  344. }
  345. }