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.

154 lines
3.7 KiB

  1. // Rule.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "snapin.h"
  5. #include "Rule.h"
  6. #include "EventManager.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CRule
  14. IMPLEMENT_DYNCREATE(CRule, CHMObject)
  15. CRule::CRule()
  16. {
  17. EnableAutomation();
  18. // To keep the application running as long as an OLE automation
  19. // object is active, the constructor calls AfxOleLockApp.
  20. AfxOleLockApp();
  21. m_sTypeName = IDS_STRING_MOF_RULE;
  22. m_nState = HMS_NODATA;
  23. }
  24. CRule::~CRule()
  25. {
  26. // To terminate the application when all objects created with
  27. // with OLE automation, the destructor calls AfxOleUnlockApp.
  28. // TODO: Destroy all stats
  29. // TODO: Destroy all events
  30. AfxOleUnlockApp();
  31. }
  32. void CRule::UpdateStatus()
  33. {
  34. TRACEX(_T("CRule::UpdateStatus\n"));
  35. CEventContainer* pContainer = NULL;
  36. EvtGetEventManager()->GetEventContainer(GetSystemName(),GetGuid(),pContainer);
  37. if( ! pContainer )
  38. {
  39. ASSERT(FALSE);
  40. return;
  41. }
  42. SetState(CEvent::GetStatus(pContainer->m_iState));
  43. for( int i = 0; i < GetScopeItemCount(); i++ )
  44. {
  45. CScopePaneItem* pItem = GetScopeItem(i);
  46. if( pItem )
  47. {
  48. CStringArray saNames;
  49. CString sValue;
  50. // Name of Rule
  51. saNames.Add(GetName());
  52. // Status
  53. CString sStatus;
  54. CEvent::GetStatus(pContainer->m_iState,sStatus);
  55. saNames.Add(sStatus);
  56. // Guid
  57. saNames.Add(GetGuid());
  58. // Threshold
  59. sValue = GetThresholdString();
  60. saNames.Add(sValue);
  61. // Last Message
  62. CString sLastMessage = pContainer->GetLastEventDTime();
  63. if( sLastMessage.IsEmpty() )
  64. {
  65. sLastMessage.LoadString(IDS_STRING_NONE);
  66. }
  67. saNames.Add(sLastMessage);
  68. // Comment
  69. saNames.Add(GetComment());
  70. pItem->SetDisplayNames(saNames);
  71. pItem->SetIconIndex(CEvent::GetStatus(pContainer->m_iState));
  72. pItem->SetOpenIconIndex(CEvent::GetStatus(pContainer->m_iState));
  73. pItem->SetItem();
  74. }
  75. }
  76. m_lNormalCount = pContainer->m_iNumberNormals;
  77. m_lWarningCount = pContainer->m_iNumberWarnings;
  78. m_lCriticalCount = pContainer->m_iNumberCriticals;
  79. m_lUnknownCount = pContainer->m_iNumberUnknowns;
  80. }
  81. void CRule::OnFinalRelease()
  82. {
  83. // When the last reference for an automation object is released
  84. // OnFinalRelease is called. The base class will automatically
  85. // deletes the object. Add additional cleanup required for your
  86. // object before calling the base class.
  87. CHMObject::OnFinalRelease();
  88. }
  89. BEGIN_MESSAGE_MAP(CRule, CHMObject)
  90. //{{AFX_MSG_MAP(CRule)
  91. // NOTE - the ClassWizard will add and remove mapping macros here.
  92. //}}AFX_MSG_MAP
  93. END_MESSAGE_MAP()
  94. BEGIN_DISPATCH_MAP(CRule, CHMObject)
  95. //{{AFX_DISPATCH_MAP(CRule)
  96. // NOTE - the ClassWizard will add and remove mapping macros here.
  97. //}}AFX_DISPATCH_MAP
  98. END_DISPATCH_MAP()
  99. // Note: we add support for IID_IRule to support typesafe binding
  100. // from VBA. This IID must match the GUID that is attached to the
  101. // dispinterface in the .ODL file.
  102. // {D9BF4FA8-F673-11D2-BDC4-0000F87A3912}
  103. static const IID IID_IRule =
  104. { 0xd9bf4fa8, 0xf673, 0x11d2, { 0xbd, 0xc4, 0x0, 0x0, 0xf8, 0x7a, 0x39, 0x12 } };
  105. BEGIN_INTERFACE_MAP(CRule, CHMObject)
  106. INTERFACE_PART(CRule, IID_IRule, Dispatch)
  107. END_INTERFACE_MAP()
  108. // {D9BF4FA9-F673-11D2-BDC4-0000F87A3912}
  109. IMPLEMENT_OLECREATE_EX(CRule, "SnapIn.Rule", 0xd9bf4fa9, 0xf673, 0x11d2, 0xbd, 0xc4, 0x0, 0x0, 0xf8, 0x7a, 0x39, 0x12)
  110. BOOL CRule::CRuleFactory::UpdateRegistry(BOOL bRegister)
  111. {
  112. if (bRegister)
  113. return AfxOleRegisterServerClass(m_clsid, m_lpszProgID, m_lpszProgID, m_lpszProgID, OAT_DISPATCH_OBJECT);
  114. else
  115. return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
  116. }
  117. /////////////////////////////////////////////////////////////////////////////
  118. // CRule message handlers