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.

612 lines
15 KiB

  1. // RuleResultsView.cpp: implementation of the CRuleResultsView class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "snapin.h"
  6. #include "RuleResultsView.h"
  7. #include "HMListViewColumn.h"
  8. #include "EventManager.h"
  9. #include "HealthmonResultsPane.h"
  10. #ifdef _DEBUG
  11. #undef THIS_FILE
  12. static char THIS_FILE[]=__FILE__;
  13. #define new DEBUG_NEW
  14. #endif
  15. IMPLEMENT_DYNCREATE(CRuleResultsView,CSplitPaneResultsView)
  16. //////////////////////////////////////////////////////////////////////
  17. // Construction/Destruction
  18. //////////////////////////////////////////////////////////////////////
  19. CRuleResultsView::CRuleResultsView()
  20. {
  21. }
  22. CRuleResultsView::~CRuleResultsView()
  23. {
  24. Destroy();
  25. }
  26. //////////////////////////////////////////////////////////////////////
  27. // Create/Destroy
  28. //////////////////////////////////////////////////////////////////////
  29. bool CRuleResultsView::Create(CScopePaneItem* pOwnerItem)
  30. {
  31. TRACEX(_T("CRuleResultsView::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. // Status
  49. pColumn = new CHMListViewColumn;
  50. sTitle.LoadString(IDS_STRING_STATUS);
  51. pColumn->Create(this,sTitle,75,dwFormat);
  52. pColumn->SetToUpperPane();
  53. AddColumn(pColumn);
  54. // Action Policy
  55. pColumn = new CHMListViewColumn;
  56. sTitle.LoadString(IDS_STRING_ACTION_POLICY);
  57. pColumn->Create(this,sTitle,75,dwFormat);
  58. pColumn->SetToUpperPane();
  59. AddColumn(pColumn);
  60. // last message
  61. pColumn = new CHMListViewColumn;
  62. sTitle.LoadString(IDS_STRING_LAST_MESSAGE);
  63. pColumn->Create(this,sTitle,125,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. // property
  111. pColumn = new CHMListViewColumn;
  112. sTitle.LoadString(IDS_STRING_PROPERTY);
  113. pColumn->Create(this,sTitle,75,dwFormat);
  114. pColumn->SetToStatsPane();
  115. AddColumn(pColumn);
  116. // instance
  117. pColumn = new CHMListViewColumn;
  118. sTitle.LoadString(IDS_STRING_INSTANCE);
  119. pColumn->Create(this,sTitle,75,dwFormat);
  120. pColumn->SetToStatsPane();
  121. AddColumn(pColumn);
  122. // current
  123. pColumn = new CHMListViewColumn;
  124. sTitle.LoadString(IDS_STRING_CURRENT);
  125. pColumn->Create(this,sTitle,75,dwFormat);
  126. pColumn->SetToStatsPane();
  127. AddColumn(pColumn);
  128. // min
  129. pColumn = new CHMListViewColumn;
  130. sTitle.LoadString(IDS_STRING_MINIMUM);
  131. pColumn->Create(this,sTitle,75,dwFormat);
  132. pColumn->SetToStatsPane();
  133. AddColumn(pColumn);
  134. // max
  135. pColumn = new CHMListViewColumn;
  136. sTitle.LoadString(IDS_STRING_MAXIMUM);
  137. pColumn->Create(this,sTitle,75,dwFormat);
  138. pColumn->SetToStatsPane();
  139. AddColumn(pColumn);
  140. // avg
  141. pColumn = new CHMListViewColumn;
  142. sTitle.LoadString(IDS_STRING_AVERAGE);
  143. pColumn->Create(this,sTitle,75,dwFormat);
  144. pColumn->SetToStatsPane();
  145. AddColumn(pColumn);
  146. // Last Update
  147. pColumn = new CHMListViewColumn;
  148. sTitle.LoadString(IDS_STRING_LASTUPDATE);
  149. pColumn->Create(this,sTitle,75,dwFormat);
  150. pColumn->SetToStatsPane();
  151. AddColumn(pColumn);
  152. return true;
  153. }
  154. //////////////////////////////////////////////////////////////////////
  155. // Eventing and Statistics Members
  156. //////////////////////////////////////////////////////////////////////
  157. void CRuleResultsView::AddStatistic(CEventContainer* pContainer, CStatistics* pStatistic, bool bUpdateGraph /*=true*/)
  158. {
  159. TRACEX(_T("CRuleResultsView::AddStatistic\n"));
  160. TRACEARGn(pContainer);
  161. TRACEARGn(pStatistic);
  162. // get the property name the rule is watching
  163. CString sPropName = GetRulePropertyName();
  164. if( sPropName.IsEmpty() )
  165. {
  166. return;
  167. }
  168. if( bUpdateGraph )
  169. {
  170. CHMScopeItem* pHMItem = (CHMScopeItem*)GetOwnerScopeItem();
  171. if( ! GfxCheckObjPtr(pHMItem,CHMScopeItem) )
  172. {
  173. TRACE(_T("FAILED : pHMItem is not a valid pointer.\n"));
  174. return;
  175. }
  176. CHMObject* pObject = pHMItem->GetObjectPtr();
  177. if( !pObject || ! GfxCheckObjPtr(pObject,CHMObject) )
  178. {
  179. return;
  180. }
  181. for( int j = 0; j < GetResultsPanesCount(); j++ )
  182. {
  183. CHealthmonResultsPane* pPane = (CHealthmonResultsPane*)GetResultsPane(j);
  184. if( pPane )
  185. {
  186. _DHMGraphView* pGraphView = pPane->GetGraphViewCtrl();
  187. if( pGraphView )
  188. {
  189. pPane->GetGraphViewSink()->SetResultsViewPtr(this);
  190. long lCurrentStyle = pGraphView->GetStyle();
  191. pGraphView->Clear();
  192. if( lCurrentStyle & HMGVS_CURRENT )
  193. {
  194. pGraphView->SetStyle(HMGVS_CURRENT|HMGVS_ELEMENT);
  195. }
  196. if( lCurrentStyle & HMGVS_HISTORIC )
  197. {
  198. pGraphView->SetStyle(HMGVS_HISTORIC|HMGVS_ELEMENT);
  199. }
  200. pGraphView->SetName(pObject->GetName());
  201. }
  202. CEventContainer* pContainer = NULL;
  203. EvtGetEventManager()->GetEventContainer(pObject->GetSystemName(),pObject->GetGuid(),pContainer);
  204. if( pContainer )
  205. {
  206. CTypedPtrMap<CMapStringToPtr,CString,StatsArray*> StatMap;
  207. for(int i = pContainer->GetStatisticsCount()-1; i >= 0; i-- )
  208. {
  209. CDataPointStatistics* pDPStat = (CDataPointStatistics*)pContainer->GetStatistic(i);
  210. if( pDPStat && pDPStat->m_sPropertyName.CompareNoCase(sPropName) != 0 )
  211. {
  212. continue;
  213. }
  214. CString sKey = pDPStat->m_sPropertyName+pDPStat->m_sInstanceName;
  215. StatsArray* pStats;
  216. if( ! StatMap.Lookup(sKey,pStats) )
  217. {
  218. pStats = new StatsArray;
  219. StatMap.SetAt(sKey,pStats);
  220. pStats->Add(pDPStat);
  221. }
  222. else
  223. {
  224. if( pStats->GetSize() < 6 )
  225. {
  226. pStats->Add(pDPStat);
  227. }
  228. }
  229. }
  230. POSITION pos = StatMap.GetStartPosition();
  231. while( pos != NULL )
  232. {
  233. CString sKey;
  234. StatsArray* pStats = NULL;
  235. StatMap.GetNextAssoc(pos,sKey,pStats);
  236. for( i = (int)pStats->GetSize()-1; i >= 0; i-- )
  237. {
  238. pStats->GetAt(i)->UpdateGraph(pGraphView);
  239. }
  240. delete pStats;
  241. }
  242. }
  243. }
  244. }
  245. }
  246. CDataPointStatistics* pDPStat = (CDataPointStatistics*)pStatistic;
  247. if( pDPStat && pDPStat->m_sPropertyName.CompareNoCase(sPropName) != 0 )
  248. {
  249. return;
  250. }
  251. // if this statistic exists in the results pane already, just update the displaynames
  252. for( int i = 0; i < m_ResultItems.GetSize(); i++ )
  253. {
  254. CHMEventResultsPaneItem* pItem = (CHMEventResultsPaneItem*)m_ResultItems[i];
  255. if( pItem && pItem->IsStatsPane() )
  256. {
  257. if( pItem->GetDisplayName(0) == pDPStat->m_sPropertyName &&
  258. pItem->GetDisplayName(1) == pDPStat->m_sInstanceName )
  259. {
  260. pDPStat->SetResultsPaneItem(pItem);
  261. UpdateItem(pItem);
  262. return;
  263. }
  264. }
  265. }
  266. AddItem(pStatistic->CreateResultsPaneItem(this));
  267. }
  268. inline HRESULT CRuleResultsView::AddStatistics(CHealthmonResultsPane* pPane)
  269. {
  270. TRACEX(_T("CRuleResultsView::AddStatistics\n"));
  271. CScopePaneItem* pSPI = GetOwnerScopeItem();
  272. if( ! pSPI->IsKindOf(RUNTIME_CLASS(CHMScopeItem)) )
  273. {
  274. return S_FALSE;
  275. }
  276. CHMScopeItem* pHMItem = (CHMScopeItem*)pSPI;
  277. if( ! GfxCheckObjPtr(pPane,CHealthmonResultsPane) )
  278. {
  279. TRACE(_T("FAILED : pPane is not a valid pointer.\n"));
  280. return E_FAIL;
  281. }
  282. CString sText;
  283. sText.Format(IDS_STRING_STATISTICS_FOR,pSPI->GetDisplayName());
  284. pPane->GetStatsListCtrl()->SetTitle(sText);
  285. CHMObject* pObject = pHMItem->GetObjectPtr();
  286. if( !pObject || ! GfxCheckObjPtr(pObject,CHMObject) )
  287. {
  288. return E_FAIL;
  289. }
  290. _DHMGraphView* pGraphView = pPane->GetGraphViewCtrl();
  291. if( pGraphView )
  292. {
  293. pPane->GetGraphViewSink()->SetResultsViewPtr(this);
  294. long lCurrentStyle = pGraphView->GetStyle();
  295. pGraphView->Clear();
  296. if( lCurrentStyle & HMGVS_CURRENT )
  297. {
  298. pGraphView->SetStyle(HMGVS_CURRENT|HMGVS_ELEMENT);
  299. }
  300. if( lCurrentStyle & HMGVS_HISTORIC )
  301. {
  302. pGraphView->SetStyle(HMGVS_HISTORIC|HMGVS_ELEMENT);
  303. }
  304. pGraphView->SetName(pObject->GetName());
  305. }
  306. CEventContainer* pContainer = NULL;
  307. EvtGetEventManager()->GetEventContainer(pObject->GetSystemName(),pObject->GetGuid(),pContainer);
  308. if( pContainer )
  309. {
  310. // get the property name the rule is watching
  311. CString sPropName = GetRulePropertyName();
  312. if( sPropName.IsEmpty() )
  313. {
  314. return E_FAIL;
  315. }
  316. CTypedPtrMap<CMapStringToPtr,CString,StatsArray*> StatMap;
  317. for(int i = pContainer->GetStatisticsCount()-1; i >= 0; i-- )
  318. {
  319. CDataPointStatistics* pDPStat = (CDataPointStatistics*)pContainer->GetStatistic(i);
  320. CString sKey = pDPStat->m_sPropertyName+pDPStat->m_sInstanceName;
  321. StatsArray* pStats;
  322. if( ! StatMap.Lookup(sKey,pStats) )
  323. {
  324. pStats = new StatsArray;
  325. StatMap.SetAt(sKey,pStats);
  326. pStats->Add(pDPStat);
  327. }
  328. else
  329. {
  330. if( pStats->GetSize() < 6 )
  331. {
  332. pStats->Add(pDPStat);
  333. }
  334. }
  335. }
  336. POSITION pos = StatMap.GetStartPosition();
  337. while( pos != NULL )
  338. {
  339. CString sKey;
  340. StatsArray* pStats = NULL;
  341. StatMap.GetNextAssoc(pos,sKey,pStats);
  342. for( i = (int)pStats->GetSize()-1; i >= 0; i-- )
  343. {
  344. AddStatistic(pContainer,pStats->GetAt(i),i==pStats->GetSize()-1);
  345. }
  346. delete pStats;
  347. }
  348. }
  349. sText.Format(IDS_STRING_COUNT_OF_FORMAT,pContainer->GetStatisticsCount());
  350. pPane->GetStatsListCtrl()->SetDescription(sText);
  351. CHMScopeItem* pParentItem = (CHMScopeItem*)pHMItem->GetParent();
  352. ASSERT(pParentItem);
  353. if( ! pParentItem )
  354. {
  355. return E_FAIL;
  356. }
  357. CHMObject* pParentObject = pParentItem->GetObjectPtr();
  358. ASSERT(pParentObject);
  359. if( ! pParentObject )
  360. {
  361. return E_FAIL;
  362. }
  363. EvtGetEventManager()->ActivateStatisticsEvents(pObject->GetSystemName(),pParentObject->GetGuid());
  364. return S_OK;
  365. }
  366. inline HRESULT CRuleResultsView::RemoveStatistics(CHealthmonResultsPane* pPane)
  367. {
  368. TRACEX(_T("CRuleResultsView::RemoveStatistics\n"));
  369. CScopePaneItem* pSPI = GetOwnerScopeItem();
  370. if( ! pSPI->IsKindOf(RUNTIME_CLASS(CHMScopeItem)) )
  371. {
  372. return S_FALSE;
  373. }
  374. CHMScopeItem* pHMItem = (CHMScopeItem*)pSPI;
  375. if( ! GfxCheckObjPtr(pPane,CHealthmonResultsPane) )
  376. {
  377. TRACE(_T("FAILED : pPane is not a valid pointer.\n"));
  378. return E_FAIL;
  379. }
  380. CHMObject* pObject = pHMItem->GetObjectPtr();
  381. if( !pObject || ! GfxCheckObjPtr(pObject,CHMObject) )
  382. {
  383. return E_FAIL;
  384. }
  385. CHMScopeItem* pParentItem = (CHMScopeItem*)pHMItem->GetParent();
  386. ASSERT(pParentItem);
  387. if( ! pParentItem )
  388. {
  389. return E_FAIL;
  390. }
  391. CHMObject* pParentObject = pParentItem->GetObjectPtr();
  392. ASSERT(pParentObject);
  393. if( ! pParentObject )
  394. {
  395. return E_FAIL;
  396. }
  397. EvtGetEventManager()->DeactivateStatisticsEvents(pObject->GetSystemName(), pParentObject->GetGuid());
  398. pPane->GetGraphViewSink()->SetResultsViewPtr(NULL);
  399. if(pPane->GetGraphViewCtrl())
  400. {
  401. pPane->GetGraphViewCtrl()->Clear();
  402. }
  403. CString sWaiting;
  404. sWaiting.LoadString(IDS_STRING_WAITING);
  405. pPane->GetStatsListCtrl()->SetTitle(sWaiting);
  406. return S_OK;
  407. }
  408. inline CString CRuleResultsView::GetRulePropertyName()
  409. {
  410. CScopePaneItem* pSPI = GetOwnerScopeItem();
  411. if( ! pSPI->IsKindOf(RUNTIME_CLASS(CHMScopeItem)) )
  412. {
  413. ASSERT(FALSE);
  414. return _T("");
  415. }
  416. CHMScopeItem* pHMItem = (CHMScopeItem*)pSPI;
  417. CHMObject* pObject = pHMItem->GetObjectPtr();
  418. if( !pObject || ! GfxCheckObjPtr(pObject,CHMObject) )
  419. {
  420. ASSERT(FALSE);
  421. return _T("");
  422. }
  423. CWbemClassObject* pClassObject = pObject->GetClassObject();
  424. if( ! pClassObject )
  425. {
  426. ASSERT(FALSE);
  427. return _T("");
  428. }
  429. CString sPropName;
  430. HRESULT hr = pClassObject->GetProperty(IDS_STRING_MOF_PROPERTYNAME,sPropName);
  431. delete pClassObject;
  432. if( ! CHECKHRESULT(hr) )
  433. {
  434. return _T("");
  435. }
  436. return sPropName;
  437. }
  438. //////////////////////////////////////////////////////////////////////
  439. // GraphView Events Members
  440. //////////////////////////////////////////////////////////////////////
  441. void CRuleResultsView::OnGraphViewStyleChange(_DHMGraphView* pGraphView)
  442. {
  443. if( ! pGraphView )
  444. {
  445. ASSERT(FALSE);
  446. return;
  447. }
  448. CScopePaneItem* pSPI = GetOwnerScopeItem();
  449. if( ! pSPI->IsKindOf(RUNTIME_CLASS(CHMScopeItem)) )
  450. {
  451. return;
  452. }
  453. CHMScopeItem* pHMItem = (CHMScopeItem*)pSPI;
  454. CHMObject* pObject = pHMItem->GetObjectPtr();
  455. if( !pObject || ! GfxCheckObjPtr(pObject,CHMObject) )
  456. {
  457. return;
  458. }
  459. pGraphView->SetName(pObject->GetName());
  460. CEventContainer* pContainer = NULL;
  461. EvtGetEventManager()->GetEventContainer(pObject->GetSystemName(),pObject->GetGuid(),pContainer);
  462. if( pContainer )
  463. {
  464. // get the property name the rule is watching
  465. CString sPropName = GetRulePropertyName();
  466. if( sPropName.IsEmpty() )
  467. {
  468. return;
  469. }
  470. CTypedPtrMap<CMapStringToPtr,CString,StatsArray*> StatMap;
  471. for(int i = pContainer->GetStatisticsCount()-1; i >= 0; i-- )
  472. {
  473. CDataPointStatistics* pDPStat = (CDataPointStatistics*)pContainer->GetStatistic(i);
  474. CString sKey = pDPStat->m_sPropertyName+pDPStat->m_sInstanceName;
  475. StatsArray* pStats;
  476. if( ! StatMap.Lookup(sKey,pStats) )
  477. {
  478. pStats = new StatsArray;
  479. StatMap.SetAt(sKey,pStats);
  480. pStats->Add(pDPStat);
  481. }
  482. else
  483. {
  484. if( pStats->GetSize() < 6 )
  485. {
  486. pStats->Add(pDPStat);
  487. }
  488. }
  489. }
  490. POSITION pos = StatMap.GetStartPosition();
  491. while( pos != NULL )
  492. {
  493. CString sKey;
  494. StatsArray* pStats = NULL;
  495. StatMap.GetNextAssoc(pos,sKey,pStats);
  496. for( i = (int)pStats->GetSize()-1; i >= 0; i-- )
  497. {
  498. AddStatistic(pContainer,pStats->GetAt(i));
  499. }
  500. delete pStats;
  501. }
  502. }
  503. }