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.

521 lines
13 KiB

  1. // DataElementResultsView.cpp: implementation of the CDataElementResultsView class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "snapin.h"
  6. #include "DataElementResultsView.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(CDataElementResultsView, CSplitPaneResultsView)
  16. //////////////////////////////////////////////////////////////////////
  17. // Construction/Destruction
  18. //////////////////////////////////////////////////////////////////////
  19. CDataElementResultsView::CDataElementResultsView()
  20. {
  21. }
  22. CDataElementResultsView::~CDataElementResultsView()
  23. {
  24. Destroy();
  25. }
  26. //////////////////////////////////////////////////////////////////////
  27. // Create/Destroy
  28. //////////////////////////////////////////////////////////////////////
  29. bool CDataElementResultsView::Create(CScopePaneItem* pOwnerItem)
  30. {
  31. TRACEX(_T("CDataElementResultsView::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. // GUID
  55. pColumn = new CHMListViewColumn;
  56. sTitle.LoadString(IDS_STRING_GUID);
  57. pColumn->Create(this,sTitle,0,dwFormat);
  58. pColumn->SetToUpperPane();
  59. AddColumn(pColumn);
  60. // Threshold
  61. pColumn = new CHMListViewColumn;
  62. sTitle.LoadString(IDS_STRING_RULE);
  63. pColumn->Create(this,sTitle,175,dwFormat);
  64. pColumn->SetToUpperPane();
  65. AddColumn(pColumn);
  66. // last message
  67. pColumn = new CHMListViewColumn;
  68. sTitle.LoadString(IDS_STRING_LAST_MESSAGE);
  69. pColumn->Create(this,sTitle,125,dwFormat);
  70. pColumn->SetToUpperPane();
  71. AddColumn(pColumn);
  72. // comment
  73. pColumn = new CHMListViewColumn;
  74. sTitle.LoadString(IDS_STRING_COMMENT);
  75. pColumn->Create(this,sTitle,125,dwFormat);
  76. pColumn->SetToUpperPane();
  77. AddColumn(pColumn);
  78. // add the lower columns
  79. // Severity
  80. pColumn = new CHMListViewColumn;
  81. sTitle.LoadString(IDS_STRING_SEVERITY);
  82. pColumn->Create(this,sTitle,75,dwFormat);
  83. pColumn->SetToLowerPane();
  84. AddColumn(pColumn);
  85. // ID
  86. pColumn = new CHMListViewColumn;
  87. sTitle.LoadString(IDS_STRING_ID);
  88. pColumn->Create(this,sTitle,75,dwFormat);
  89. pColumn->SetToLowerPane();
  90. AddColumn(pColumn);
  91. // Date/Time
  92. pColumn = new CHMListViewColumn;
  93. sTitle.LoadString(IDS_STRING_DATETIME);
  94. pColumn->Create(this,sTitle,175,dwFormat);
  95. pColumn->SetToLowerPane();
  96. AddColumn(pColumn);
  97. // Component
  98. pColumn = new CHMListViewColumn;
  99. sTitle.LoadString(IDS_STRING_DATA_POINT);
  100. pColumn->Create(this,sTitle,125,dwFormat);
  101. pColumn->SetToLowerPane();
  102. AddColumn(pColumn);
  103. // System
  104. pColumn = new CHMListViewColumn;
  105. sTitle.LoadString(IDS_STRING_SYSTEM);
  106. pColumn->Create(this,sTitle,75,dwFormat);
  107. pColumn->SetToLowerPane();
  108. AddColumn(pColumn);
  109. // Message
  110. pColumn = new CHMListViewColumn;
  111. sTitle.LoadString(IDS_STRING_MESSAGE);
  112. pColumn->Create(this,sTitle,75,dwFormat);
  113. pColumn->SetToLowerPane();
  114. AddColumn(pColumn);
  115. // add the stats columns
  116. // property
  117. pColumn = new CHMListViewColumn;
  118. sTitle.LoadString(IDS_STRING_PROPERTY);
  119. pColumn->Create(this,sTitle,75,dwFormat);
  120. pColumn->SetToStatsPane();
  121. AddColumn(pColumn);
  122. // instance
  123. pColumn = new CHMListViewColumn;
  124. sTitle.LoadString(IDS_STRING_INSTANCE);
  125. pColumn->Create(this,sTitle,75,dwFormat);
  126. pColumn->SetToStatsPane();
  127. AddColumn(pColumn);
  128. // current
  129. pColumn = new CHMListViewColumn;
  130. sTitle.LoadString(IDS_STRING_CURRENT);
  131. pColumn->Create(this,sTitle,75,dwFormat);
  132. pColumn->SetToStatsPane();
  133. AddColumn(pColumn);
  134. // min
  135. pColumn = new CHMListViewColumn;
  136. sTitle.LoadString(IDS_STRING_MINIMUM);
  137. pColumn->Create(this,sTitle,75,dwFormat);
  138. pColumn->SetToStatsPane();
  139. AddColumn(pColumn);
  140. // max
  141. pColumn = new CHMListViewColumn;
  142. sTitle.LoadString(IDS_STRING_MAXIMUM);
  143. pColumn->Create(this,sTitle,75,dwFormat);
  144. pColumn->SetToStatsPane();
  145. AddColumn(pColumn);
  146. // avg
  147. pColumn = new CHMListViewColumn;
  148. sTitle.LoadString(IDS_STRING_AVERAGE);
  149. pColumn->Create(this,sTitle,75,dwFormat);
  150. pColumn->SetToStatsPane();
  151. AddColumn(pColumn);
  152. // Last Update
  153. pColumn = new CHMListViewColumn;
  154. sTitle.LoadString(IDS_STRING_LASTUPDATE);
  155. pColumn->Create(this,sTitle,75,dwFormat);
  156. pColumn->SetToStatsPane();
  157. AddColumn(pColumn);
  158. return true;
  159. }
  160. //////////////////////////////////////////////////////////////////////
  161. // Eventing and Statistics Members
  162. //////////////////////////////////////////////////////////////////////
  163. void CDataElementResultsView::AddStatistic(CEventContainer* pContainer, CStatistics* pStatistic, bool bUpdateGraph /*=true*/)
  164. {
  165. TRACEX(_T("CDataElementResultsView::AddStatistic\n"));
  166. TRACEARGn(pContainer);
  167. TRACEARGn(pStatistic);
  168. CDataPointStatistics* pDPStat = (CDataPointStatistics*)pStatistic;
  169. if( bUpdateGraph )
  170. {
  171. CHMScopeItem* pHMItem = (CHMScopeItem*)GetOwnerScopeItem();
  172. if( ! GfxCheckObjPtr(pHMItem,CHMScopeItem) )
  173. {
  174. TRACE(_T("FAILED : pHMItem is not a valid pointer.\n"));
  175. return;
  176. }
  177. CHMObject* pObject = pHMItem->GetObjectPtr();
  178. if( !pObject || ! GfxCheckObjPtr(pObject,CHMObject) )
  179. {
  180. return;
  181. }
  182. for( int j = 0; j < GetResultsPanesCount(); j++ )
  183. {
  184. CHealthmonResultsPane* pPane = (CHealthmonResultsPane*)GetResultsPane(j);
  185. if( pPane )
  186. {
  187. _DHMGraphView* pGraphView = pPane->GetGraphViewCtrl();
  188. if( pGraphView )
  189. {
  190. pPane->GetGraphViewSink()->SetResultsViewPtr(this);
  191. long lCurrentStyle = pGraphView->GetStyle();
  192. pGraphView->Clear();
  193. if( lCurrentStyle & HMGVS_CURRENT )
  194. {
  195. pGraphView->SetStyle(HMGVS_CURRENT|HMGVS_ELEMENT);
  196. }
  197. if( lCurrentStyle & HMGVS_HISTORIC )
  198. {
  199. pGraphView->SetStyle(HMGVS_HISTORIC|HMGVS_ELEMENT);
  200. }
  201. pGraphView->SetName(pObject->GetName());
  202. }
  203. CEventContainer* pContainer = NULL;
  204. EvtGetEventManager()->GetEventContainer(pObject->GetSystemName(),pObject->GetGuid(),pContainer);
  205. if( pContainer )
  206. {
  207. CTypedPtrMap<CMapStringToPtr,CString,StatsArray*> StatMap;
  208. for(int i = pContainer->GetStatisticsCount()-1; i >= 0; i-- )
  209. {
  210. CDataPointStatistics* pDPStat = (CDataPointStatistics*)pContainer->GetStatistic(i);
  211. CString sKey = pDPStat->m_sPropertyName+pDPStat->m_sInstanceName;
  212. StatsArray* pStats;
  213. if( ! StatMap.Lookup(sKey,pStats) )
  214. {
  215. pStats = new StatsArray;
  216. StatMap.SetAt(sKey,pStats);
  217. pStats->Add(pDPStat);
  218. }
  219. else
  220. {
  221. if( pStats->GetSize() < 6 )
  222. {
  223. pStats->Add(pDPStat);
  224. }
  225. }
  226. }
  227. POSITION pos = StatMap.GetStartPosition();
  228. while( pos != NULL )
  229. {
  230. CString sKey;
  231. StatsArray* pStats = NULL;
  232. StatMap.GetNextAssoc(pos,sKey,pStats);
  233. for( i = (int)pStats->GetSize()-1; i >= 0; i-- )
  234. {
  235. pStats->GetAt(i)->UpdateGraph(pGraphView);
  236. }
  237. delete pStats;
  238. }
  239. }
  240. }
  241. }
  242. }
  243. // if this statistic exists in the results pane already, just update the displaynames, then update the graph
  244. for( int i = 0; i < m_ResultItems.GetSize(); i++ )
  245. {
  246. CHMEventResultsPaneItem* pItem = (CHMEventResultsPaneItem*)m_ResultItems[i];
  247. if( pItem && pItem->IsStatsPane() )
  248. {
  249. if( pItem->GetDisplayName(0) == pDPStat->m_sPropertyName &&
  250. pItem->GetDisplayName(1) == pDPStat->m_sInstanceName )
  251. {
  252. pDPStat->SetResultsPaneItem(pItem);
  253. UpdateItem(pItem);
  254. return;
  255. }
  256. }
  257. }
  258. AddItem(pStatistic->CreateResultsPaneItem(this));
  259. }
  260. inline HRESULT CDataElementResultsView::AddStatistics(CHealthmonResultsPane* pPane)
  261. {
  262. TRACEX(_T("CDataElementResultsView::AddStatistics\n"));
  263. CScopePaneItem* pSPI = GetOwnerScopeItem();
  264. if( ! pSPI->IsKindOf(RUNTIME_CLASS(CHMScopeItem)) )
  265. {
  266. return S_FALSE;
  267. }
  268. CHMScopeItem* pHMItem = (CHMScopeItem*)pSPI;
  269. if( ! GfxCheckObjPtr(pPane,CHealthmonResultsPane) )
  270. {
  271. TRACE(_T("FAILED : pPane is not a valid pointer.\n"));
  272. return E_FAIL;
  273. }
  274. CString sText;
  275. sText.Format(IDS_STRING_STATISTICS_FOR,pSPI->GetDisplayName());
  276. pPane->GetStatsListCtrl()->SetTitle(sText);
  277. CHMObject* pObject = pHMItem->GetObjectPtr();
  278. if( !pObject || ! GfxCheckObjPtr(pObject,CHMObject) )
  279. {
  280. return E_FAIL;
  281. }
  282. _DHMGraphView* pGraphView = pPane->GetGraphViewCtrl();
  283. if( pGraphView )
  284. {
  285. pPane->GetGraphViewSink()->SetResultsViewPtr(this);
  286. long lCurrentStyle = pGraphView->GetStyle();
  287. pGraphView->Clear();
  288. if( lCurrentStyle & HMGVS_CURRENT )
  289. {
  290. pGraphView->SetStyle(HMGVS_CURRENT|HMGVS_ELEMENT);
  291. }
  292. if( lCurrentStyle & HMGVS_HISTORIC )
  293. {
  294. pGraphView->SetStyle(HMGVS_HISTORIC|HMGVS_ELEMENT);
  295. }
  296. pGraphView->SetName(pObject->GetName());
  297. }
  298. CEventContainer* pContainer = NULL;
  299. EvtGetEventManager()->GetEventContainer(pObject->GetSystemName(),pObject->GetGuid(),pContainer);
  300. if( pContainer )
  301. {
  302. CTypedPtrMap<CMapStringToPtr,CString,StatsArray*> StatMap;
  303. for(int i = pContainer->GetStatisticsCount()-1; i >= 0; i-- )
  304. {
  305. CDataPointStatistics* pDPStat = (CDataPointStatistics*)pContainer->GetStatistic(i);
  306. CString sKey = pDPStat->m_sPropertyName+pDPStat->m_sInstanceName;
  307. StatsArray* pStats;
  308. if( ! StatMap.Lookup(sKey,pStats) )
  309. {
  310. pStats = new StatsArray;
  311. StatMap.SetAt(sKey,pStats);
  312. pStats->Add(pDPStat);
  313. }
  314. else
  315. {
  316. if( pStats->GetSize() < 6 )
  317. {
  318. pStats->Add(pDPStat);
  319. }
  320. }
  321. }
  322. POSITION pos = StatMap.GetStartPosition();
  323. while( pos != NULL )
  324. {
  325. CString sKey;
  326. StatsArray* pStats = NULL;
  327. StatMap.GetNextAssoc(pos,sKey,pStats);
  328. for( i = (int)pStats->GetSize()-1; i >= 0; i-- )
  329. {
  330. AddStatistic(pContainer,pStats->GetAt(i),i==pStats->GetSize()-1);
  331. }
  332. delete pStats;
  333. }
  334. }
  335. sText.Format(IDS_STRING_COUNT_OF_FORMAT,pContainer->GetStatisticsCount());
  336. pPane->GetStatsListCtrl()->SetDescription(sText);
  337. EvtGetEventManager()->ActivateStatisticsEvents(pObject->GetSystemName(),pObject->GetGuid());
  338. return S_OK;
  339. }
  340. inline HRESULT CDataElementResultsView::RemoveStatistics(CHealthmonResultsPane* pPane)
  341. {
  342. TRACEX(_T("CDataElementResultsView::RemoveStatistics\n"));
  343. CScopePaneItem* pSPI = GetOwnerScopeItem();
  344. if( ! pSPI->IsKindOf(RUNTIME_CLASS(CHMScopeItem)) )
  345. {
  346. return S_FALSE;
  347. }
  348. CHMScopeItem* pHMItem = (CHMScopeItem*)pSPI;
  349. if( ! GfxCheckObjPtr(pPane,CHealthmonResultsPane) )
  350. {
  351. TRACE(_T("FAILED : pPane is not a valid pointer.\n"));
  352. return E_FAIL;
  353. }
  354. CHMObject* pObject = pHMItem->GetObjectPtr();
  355. if( !pObject || ! GfxCheckObjPtr(pObject,CHMObject) )
  356. {
  357. return E_FAIL;
  358. }
  359. EvtGetEventManager()->DeactivateStatisticsEvents(pObject->GetSystemName(), pObject->GetGuid());
  360. pPane->GetGraphViewSink()->SetResultsViewPtr(NULL);
  361. if(pPane->GetGraphViewCtrl())
  362. {
  363. pPane->GetGraphViewCtrl()->Clear();
  364. }
  365. CString sWaiting;
  366. sWaiting.LoadString(IDS_STRING_WAITING);
  367. pPane->GetStatsListCtrl()->SetTitle(sWaiting);
  368. return S_OK;
  369. }
  370. //////////////////////////////////////////////////////////////////////
  371. // GraphView Events Members
  372. //////////////////////////////////////////////////////////////////////
  373. void CDataElementResultsView::OnGraphViewStyleChange(_DHMGraphView* pGraphView)
  374. {
  375. if( ! pGraphView )
  376. {
  377. ASSERT(FALSE);
  378. return;
  379. }
  380. CScopePaneItem* pSPI = GetOwnerScopeItem();
  381. if( ! pSPI->IsKindOf(RUNTIME_CLASS(CHMScopeItem)) )
  382. {
  383. return;
  384. }
  385. CHMScopeItem* pHMItem = (CHMScopeItem*)pSPI;
  386. CHMObject* pObject = pHMItem->GetObjectPtr();
  387. if( !pObject || ! GfxCheckObjPtr(pObject,CHMObject) )
  388. {
  389. return;
  390. }
  391. pGraphView->SetName(pObject->GetName());
  392. CEventContainer* pContainer = NULL;
  393. EvtGetEventManager()->GetEventContainer(pObject->GetSystemName(),pObject->GetGuid(),pContainer);
  394. if( pContainer )
  395. {
  396. CTypedPtrMap<CMapStringToPtr,CString,StatsArray*> StatMap;
  397. for(int i = pContainer->GetStatisticsCount()-1; i >= 0; i-- )
  398. {
  399. CDataPointStatistics* pDPStat = (CDataPointStatistics*)pContainer->GetStatistic(i);
  400. CString sKey = pDPStat->m_sPropertyName+pDPStat->m_sInstanceName;
  401. StatsArray* pStats;
  402. if( ! StatMap.Lookup(sKey,pStats) )
  403. {
  404. pStats = new StatsArray;
  405. StatMap.SetAt(sKey,pStats);
  406. pStats->Add(pDPStat);
  407. }
  408. else
  409. {
  410. if( pStats->GetSize() < 6 )
  411. {
  412. pStats->Add(pDPStat);
  413. }
  414. }
  415. }
  416. POSITION pos = StatMap.GetStartPosition();
  417. while( pos != NULL )
  418. {
  419. CString sKey;
  420. StatsArray* pStats = NULL;
  421. StatMap.GetNextAssoc(pos,sKey,pStats);
  422. for( i = (int)pStats->GetSize()-1; i >= 0; i-- )
  423. {
  424. AddStatistic(pContainer,pStats->GetAt(i));
  425. }
  426. delete pStats;
  427. }
  428. }
  429. }