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
17 KiB

  1. // DPNtEventPage.cpp : implementation file
  2. //
  3. // 03/05/00 v-marfin bug 59643 : Make this the default starting page.
  4. // 03/29/00 v-marfin bug 62585 : Set new Data collector's ENABLED to TRUE if user presses OK.
  5. // 03/30/00 v-marfin bug 59237 : If user does not change the default name of the data
  6. // collector when they first create it, change it for
  7. // them to a more meaningful name based on the data
  8. // they select in the property pages.
  9. #include "stdafx.h"
  10. #include "snapin.h"
  11. #include "DPNtEventPage.h"
  12. #include "HMObject.h"
  13. #include "DataElement.h"
  14. #include "DataGroupScopeItem.h"
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #endif
  20. /////////////////////////////////////////////////////////////////////////////
  21. // CDPNtEventPage property page
  22. IMPLEMENT_DYNCREATE(CDPNtEventPage, CHMPropertyPage)
  23. CDPNtEventPage::CDPNtEventPage() : CHMPropertyPage(CDPNtEventPage::IDD)
  24. {
  25. //{{AFX_DATA_INIT(CDPNtEventPage)
  26. m_bCategory = FALSE;
  27. m_bError = FALSE;
  28. m_bEventID = FALSE;
  29. m_bFailure = FALSE;
  30. m_bInformation = FALSE;
  31. m_bRequireReset = TRUE;
  32. m_bSource = FALSE;
  33. m_bSuccess = FALSE;
  34. m_bUser = FALSE;
  35. m_bWarning = FALSE;
  36. m_sCategory = _T("");
  37. m_sEventID = _T("");
  38. m_sSource = _T("");
  39. m_sUser = _T("");
  40. m_sLogFile = _T("");
  41. //}}AFX_DATA_INIT
  42. m_sHelpTopic = _T("HMon21.chm::/dDEntev.htm");
  43. }
  44. CDPNtEventPage::~CDPNtEventPage()
  45. {
  46. }
  47. void CDPNtEventPage::DoDataExchange(CDataExchange* pDX)
  48. {
  49. CHMPropertyPage::DoDataExchange(pDX);
  50. //{{AFX_DATA_MAP(CDPNtEventPage)
  51. DDX_Control(pDX, IDC_COMBO_LOG_FILE, m_LogFile);
  52. DDX_Check(pDX, IDC_CHECK_CATEGORY, m_bCategory);
  53. DDX_Check(pDX, IDC_CHECK_ERROR, m_bError);
  54. DDX_Check(pDX, IDC_CHECK_EVENTID, m_bEventID);
  55. DDX_Check(pDX, IDC_CHECK_FAILURE, m_bFailure);
  56. DDX_Check(pDX, IDC_CHECK_INFORMATION, m_bInformation);
  57. DDX_Check(pDX, IDC_CHECK_REQUIRE_RESET, m_bRequireReset);
  58. DDX_Check(pDX, IDC_CHECK_SOURCE, m_bSource);
  59. DDX_Check(pDX, IDC_CHECK_SUCCESS, m_bSuccess);
  60. DDX_Check(pDX, IDC_CHECK_USER, m_bUser);
  61. DDX_Check(pDX, IDC_CHECK_WARNING, m_bWarning);
  62. DDX_Text(pDX, IDC_EDIT_CATEGORY, m_sCategory);
  63. DDX_Text(pDX, IDC_EDIT_EVENTID, m_sEventID);
  64. DDX_Text(pDX, IDC_EDIT_SOURCE, m_sSource);
  65. DDX_Text(pDX, IDC_EDIT_USER, m_sUser);
  66. DDX_CBString(pDX, IDC_COMBO_LOG_FILE, m_sLogFile);
  67. //}}AFX_DATA_MAP
  68. GetDlgItem(IDC_EDIT_CATEGORY)->EnableWindow(m_bCategory);
  69. GetDlgItem(IDC_EDIT_EVENTID)->EnableWindow(m_bEventID);
  70. GetDlgItem(IDC_EDIT_SOURCE)->EnableWindow(m_bSource);
  71. GetDlgItem(IDC_EDIT_USER)->EnableWindow(m_bUser);
  72. }
  73. BEGIN_MESSAGE_MAP(CDPNtEventPage, CHMPropertyPage)
  74. //{{AFX_MSG_MAP(CDPNtEventPage)
  75. ON_WM_DESTROY()
  76. ON_BN_CLICKED(IDC_BUTTON_TEST, OnButtonTest)
  77. ON_BN_CLICKED(IDC_CHECK_CATEGORY, OnCheckCategory)
  78. ON_BN_CLICKED(IDC_CHECK_EVENTID, OnCheckEventid)
  79. ON_BN_CLICKED(IDC_CHECK_SOURCE, OnCheckSource)
  80. ON_BN_CLICKED(IDC_CHECK_USER, OnCheckUser)
  81. ON_BN_CLICKED(IDC_CHECK_ERROR, OnCheckError)
  82. ON_BN_CLICKED(IDC_CHECK_FAILURE, OnCheckFailure)
  83. ON_BN_CLICKED(IDC_CHECK_INFORMATION, OnCheckInformation)
  84. ON_BN_CLICKED(IDC_CHECK_REQUIRE_RESET, OnCheckRequireReset)
  85. ON_BN_CLICKED(IDC_CHECK_SUCCESS, OnCheckSuccess)
  86. ON_BN_CLICKED(IDC_CHECK_WARNING, OnCheckWarning)
  87. ON_CBN_EDITCHANGE(IDC_COMBO_LOG_FILE, OnEditchangeComboLogFile)
  88. ON_EN_CHANGE(IDC_EDIT_CATEGORY, OnChangeEditCategory)
  89. ON_EN_CHANGE(IDC_EDIT_EVENTID, OnChangeEditEventid)
  90. ON_EN_CHANGE(IDC_EDIT_SOURCE, OnChangeEditSource)
  91. ON_EN_CHANGE(IDC_EDIT_USER, OnChangeEditUser)
  92. //}}AFX_MSG_MAP
  93. END_MESSAGE_MAP()
  94. /////////////////////////////////////////////////////////////////////////////
  95. // CDPNtEventPage message handlers
  96. BOOL CDPNtEventPage::OnInitDialog()
  97. {
  98. // v-marfin : bug 59643 : This will be the default starting page for the property
  99. // sheet so call CnxPropertyPageCreate() to unmarshal the
  100. // connection for this thread. This function must be called
  101. // by the first page of the property sheet. It used to
  102. // be called by the "General" page and its call still remains
  103. // there as well in case the general page is loaded by a
  104. // different code path that does not also load this page.
  105. // The CnxPropertyPageCreate function has been safeguarded
  106. // to simply return if the required call has already been made.
  107. // CnxPropertyPageDestory() must be called from this page's
  108. // OnDestroy function.
  109. // unmarshal connmgr
  110. CnxPropertyPageCreate();
  111. CHMPropertyPage::OnInitDialog();
  112. CWbemClassObject* pClassObject = GetObjectPtr()->GetClassObject();
  113. if( ! GfxCheckObjPtr(pClassObject,CWbemClassObject) )
  114. {
  115. return TRUE;
  116. }
  117. //-------------------------------------------------------------------------
  118. // v-marfin 59237 : Store original name in case this data collector is
  119. // just being created. When they save, we will modify the
  120. // name if they haven't.
  121. pClassObject->GetProperty(IDS_STRING_MOF_NAME,m_sOriginalName);
  122. //-------------------------------------------------------------------------
  123. CString sQuery;
  124. pClassObject->GetProperty(IDS_STRING_MOF_QUERY,sQuery);
  125. if( ! sQuery.IsEmpty() )
  126. {
  127. // parse out the Type phrases
  128. CString sTemp = IDS_STRING_MOF_TYPE;
  129. if( sQuery.Find(sTemp + _T("=\"error\"")) != -1 )
  130. {
  131. m_bError = TRUE;
  132. }
  133. if( sQuery.Find(sTemp + _T("=\"warning\"")) != -1 )
  134. {
  135. m_bWarning = TRUE;
  136. }
  137. if( sQuery.Find(sTemp + _T("=\"information\"")) != -1 )
  138. {
  139. m_bInformation = TRUE;
  140. }
  141. if( sQuery.Find(sTemp + _T("=\"audit success\"")) != -1 )
  142. {
  143. m_bSuccess = TRUE;
  144. }
  145. if( sQuery.Find(sTemp + _T("=\"audit failure\"")) != -1 )
  146. {
  147. m_bFailure = TRUE;
  148. }
  149. // parse out the LogFile
  150. CWbemClassObject::GetPropertyValueFromString(sQuery,_T("Logfile"),m_sLogFile);
  151. // parse out the EventIdentifier phrase
  152. if( CWbemClassObject::GetPropertyValueFromString(sQuery,IDS_STRING_MOF_EVENTID,m_sEventID) )
  153. {
  154. m_bEventID = TRUE;
  155. }
  156. // parse out the SourceName
  157. if( CWbemClassObject::GetPropertyValueFromString(sQuery,IDS_STRING_MOF_SOURCENAME,m_sSource) )
  158. {
  159. m_bSource = TRUE;
  160. }
  161. // parse out the CategoryString
  162. if( CWbemClassObject::GetPropertyValueFromString(sQuery,IDS_STRING_MOF_CATEGORYSTRING,m_sCategory) )
  163. {
  164. m_bCategory = TRUE;
  165. }
  166. // parse out the User
  167. if( CWbemClassObject::GetPropertyValueFromString(sQuery,IDS_STRING_MOF_USER,m_sUser) )
  168. {
  169. m_bUser = TRUE;
  170. }
  171. }
  172. // Get require reset
  173. bool bReset;
  174. pClassObject->GetProperty(IDS_STRING_MOF_REQUIRERESET,bReset);
  175. m_bRequireReset = bReset;
  176. UpdateData(FALSE);
  177. delete pClassObject;
  178. return TRUE; // return TRUE unless you set the focus to a control
  179. // EXCEPTION: OCX Property Pages should return FALSE
  180. }
  181. void CDPNtEventPage::OnOK()
  182. {
  183. CHMPropertyPage::OnOK();
  184. }
  185. void CDPNtEventPage::OnDestroy()
  186. {
  187. // v-marfin 62585 : For this new data collector, set its Enabled property to TRUE, but
  188. // only if the user is not cancelling these property pages.
  189. if (m_bOnApplyUsed)
  190. {
  191. ClearStatistics(); // 62548
  192. CDataElement* pElement = (CDataElement*)GetObjectPtr();
  193. if (pElement && pElement->IsStateSetToEnabledOnOK())
  194. {
  195. TRACE(_T("CDPNtEventPage::OnDestroy - New Perfmon Collector: Setting to Enabled\n"));
  196. pElement->SetStateToEnabledOnOK(FALSE); // don't do this again
  197. CWbemClassObject* pClassObject = GetObjectPtr()->GetClassObject();
  198. if( ! GfxCheckObjPtr(pClassObject,CWbemClassObject) )
  199. {
  200. TRACE(_T("ERROR: CDPNtEventPage::OnDestroy - Failed to GetClassObject()\n"));
  201. return;
  202. }
  203. // Set the new collector to enabled.
  204. BOOL bEnabled=TRUE;
  205. HRESULT hr = pClassObject->GetProperty(IDS_STRING_MOF_ENABLE,bEnabled);
  206. hr = pClassObject->SetProperty(IDS_STRING_MOF_ENABLE,TRUE);
  207. if (!CHECKHRESULT(hr))
  208. {
  209. TRACE(_T("ERROR: CDPNtEventPage::OnDestroy - Failed to set ENABLED property on new collector\n"));
  210. }
  211. //-------------------------------------------------------------------
  212. // v-marfin 59237 : If the user has not changed the original default
  213. // name, do so for them. Compare against original
  214. // name we fetched during OnInitDialog.
  215. CString sName;
  216. pClassObject->GetProperty(IDS_STRING_MOF_NAME,sName);
  217. // Did the user change the default name?
  218. if (m_sOriginalName.CompareNoCase(sName)==0)
  219. {
  220. /*
  221. m_bCategory = FALSE;
  222. m_bError = FALSE;
  223. m_bEventID = FALSE;
  224. m_bFailure = FALSE;
  225. m_bInformation = FALSE;
  226. m_bRequireReset = TRUE;
  227. m_bSource = FALSE;
  228. m_bSuccess = FALSE;
  229. m_bUser = FALSE;
  230. m_bWarning = FALSE;
  231. m_sCategory = _T("");
  232. m_sEventID = _T("");
  233. m_sSource = _T("");
  234. m_sUser = _T("");
  235. m_sLogFile = _T("");
  236. */
  237. CString sType;
  238. CString sNewName;
  239. // Format the name
  240. //------------------------
  241. if ((m_bError) &&
  242. ((!m_bWarning) && (!m_bInformation) && (!m_bSuccess) && (!m_bFailure)))
  243. {
  244. sType.LoadString(IDS_NTEVENT_TYPE_ERRORS);
  245. }
  246. else if (((m_bError) && (m_bWarning)) &&
  247. ((!m_bInformation) && (!m_bSuccess) && (!m_bFailure)))
  248. {
  249. sType.LoadString(IDS_NTEVENT_TYPE_ERRORS_AND_WARNINGS);
  250. }
  251. else
  252. {
  253. sType.LoadString(IDS_NTEVENT_TYPE_EVENTS);
  254. }
  255. if ((!m_bError) && (!m_bWarning) && (!m_bInformation) && (!m_bSuccess) && (!m_bFailure))
  256. {
  257. sNewName.Format(IDS_NTEVENT_NEWNAME_EVENTLOG,m_sLogFile);
  258. }
  259. else if ((!m_sSource.IsEmpty()) && (m_sEventID.IsEmpty()))
  260. {
  261. sNewName.Format(IDS_NTEVENT_NEWNAME,m_sSource,sType,m_sLogFile);
  262. }
  263. else if (!m_sEventID.IsEmpty())
  264. {
  265. sNewName.Format(IDS_NTEVENT_NEWNAME_EVENTID,m_sEventID,m_sLogFile);
  266. }
  267. else
  268. {
  269. sNewName.Format(IDS_NTEVENT_NEWNAME_LOGNAME,m_sLogFile,sType);
  270. }
  271. if (!sNewName.IsEmpty())
  272. {
  273. // Use parent to ensure name is unique
  274. //CDataGroup* pParent = (CDataGroup*) pElement->GetCollectorsParentClassObject();
  275. if(pElement->GetScopeItemCount())
  276. {
  277. CDataElementScopeItem* pItem = (CDataElementScopeItem*)pElement->GetScopeItem(0);
  278. if( pItem )
  279. {
  280. CDataGroupScopeItem* pDGItem = (CDataGroupScopeItem*)pItem->GetParent();
  281. sName = pDGItem->GetUniqueDisplayName(sNewName);
  282. }
  283. }
  284. // Set the local element's object data
  285. pElement->SetName(sName);
  286. // Set its WMI property
  287. pClassObject->SetProperty(IDS_STRING_MOF_NAME,sName);
  288. // Refresh to show the new name in the IU
  289. //pElement->Refresh(); // 63005
  290. pElement->UpdateStatus(); // 63005
  291. }
  292. }
  293. //-------------------------------------------------------------------
  294. pClassObject->SaveAllProperties();
  295. delete pClassObject;
  296. } // if (pElement && pElement->IsStateSetToEnabledOnOK())
  297. } // if (m_bOnApplyUsed)
  298. CHMPropertyPage::OnDestroy();
  299. // v-marfin : bug 59643 : CnxPropertyPageDestory() must be called from this page's
  300. // OnDestroy function.
  301. CnxPropertyPageDestroy();
  302. }
  303. void CDPNtEventPage::OnButtonTest()
  304. {
  305. // TODO: Add your control notification handler code here
  306. }
  307. void CDPNtEventPage::OnCheckCategory()
  308. {
  309. UpdateData();
  310. SetModified();
  311. }
  312. void CDPNtEventPage::OnCheckEventid()
  313. {
  314. UpdateData();
  315. SetModified();
  316. }
  317. void CDPNtEventPage::OnCheckSource()
  318. {
  319. UpdateData();
  320. SetModified();
  321. }
  322. void CDPNtEventPage::OnCheckUser()
  323. {
  324. UpdateData();
  325. SetModified();
  326. }
  327. BOOL CDPNtEventPage::OnApply()
  328. {
  329. if( ! CHMPropertyPage::OnApply() )
  330. {
  331. return FALSE;
  332. }
  333. // v-marfin 62585 : So we can set the collector's state to enabled when OK pressed.
  334. m_bOnApplyUsed=TRUE;
  335. UpdateData();
  336. CString sQuery = IDS_STRING_MOF_EVENT_LOG_QUERY;
  337. CString sTemp;
  338. // parse out the LogFile
  339. sTemp.Format(_T(" AND TargetInstance.Logfile=\"%s\""), m_sLogFile);
  340. sQuery += sTemp;
  341. // parse out the Type phrases
  342. bool bAppendOr = false;
  343. if( m_bError )
  344. {
  345. sTemp = _T(" AND (TargetInstance.Type=\"error\"");
  346. bAppendOr = true;
  347. sQuery += sTemp;
  348. }
  349. if( m_bWarning )
  350. {
  351. sTemp = bAppendOr ? _T(" OR TargetInstance.Type=\"warning\"") : _T(" AND (TargetInstance.Type=\"warning\"");
  352. bAppendOr = true;
  353. sQuery += sTemp;
  354. }
  355. if( m_bInformation )
  356. {
  357. sTemp = bAppendOr ? _T(" OR TargetInstance.Type=\"information\"") : _T(" AND (TargetInstance.Type=\"information\"");
  358. bAppendOr = true;
  359. sQuery += sTemp;
  360. }
  361. if( m_bSuccess )
  362. {
  363. sTemp = bAppendOr ? _T(" OR TargetInstance.Type=\"audit success\"") : _T(" AND (TargetInstance.Type=\"audit success\"");
  364. bAppendOr = true;
  365. sQuery += sTemp;
  366. }
  367. if( m_bFailure )
  368. {
  369. sTemp = bAppendOr ? _T(" OR TargetInstance.Type=\"audit failure\"") : _T(" AND (TargetInstance.Type=\"audit failure\"");
  370. bAppendOr = true;
  371. sQuery += sTemp;
  372. }
  373. if (bAppendOr)
  374. sQuery += _T(")");
  375. // parse out the EventIdentifier phrase
  376. if( m_bEventID )
  377. {
  378. sTemp.Format(_T(" AND TargetInstance.EventIdentifier=%s"), m_sEventID);
  379. sQuery += sTemp;
  380. }
  381. // parse out the SourceName
  382. if( m_bSource )
  383. {
  384. sTemp.Format(_T(" AND TargetInstance.SourceName=\"%s\""), m_sSource);
  385. sQuery += sTemp;
  386. }
  387. // parse out the CategoryString
  388. if( m_bCategory )
  389. {
  390. sTemp.Format(_T(" AND TargetInstance.CategoryString=\"%s\""), m_sCategory);
  391. sQuery += sTemp;
  392. }
  393. // parse out the User
  394. if( m_bUser )
  395. {
  396. sTemp.Format(_T(" AND TargetInstance.User=\"%s\""), m_sUser);
  397. sQuery += sTemp;
  398. }
  399. CWbemClassObject* pClassObject = GetObjectPtr()->GetClassObject();
  400. if( ! GfxCheckObjPtr(pClassObject,CWbemClassObject) )
  401. {
  402. return FALSE;
  403. }
  404. pClassObject->SetProperty(IDS_STRING_MOF_QUERY,sQuery);
  405. /* 63128
  406. CStringArray saPropertyNames;
  407. saPropertyNames.Add(_T("EventIdentifier"));
  408. saPropertyNames.Add(_T("SourceName"));
  409. saPropertyNames.Add(_T("Type"));
  410. saPropertyNames.Add(_T("CategoryString"));
  411. saPropertyNames.Add(_T("User"));
  412. saPropertyNames.Add(_T("LogFile"));
  413. pClassObject->SetProperty(IDS_STRING_MOF_STATISTICSPROPERTYNAMES,saPropertyNames);*/
  414. CString sNamespace = _T("root\\cimv2");
  415. pClassObject->SetProperty(IDS_STRING_MOF_TARGETNAMESPACE,sNamespace);
  416. bool bReset = m_bRequireReset ? true : false;
  417. pClassObject->SetProperty(IDS_STRING_MOF_REQUIRERESET,bReset);
  418. pClassObject->SaveAllProperties();
  419. delete pClassObject;
  420. SetModified(FALSE);
  421. return TRUE;
  422. }
  423. void CDPNtEventPage::OnCheckError()
  424. {
  425. UpdateData();
  426. SetModified();
  427. }
  428. void CDPNtEventPage::OnCheckFailure()
  429. {
  430. UpdateData();
  431. SetModified();
  432. }
  433. void CDPNtEventPage::OnCheckInformation()
  434. {
  435. UpdateData();
  436. SetModified();
  437. }
  438. void CDPNtEventPage::OnCheckRequireReset()
  439. {
  440. UpdateData();
  441. SetModified();
  442. }
  443. void CDPNtEventPage::OnCheckSuccess()
  444. {
  445. UpdateData();
  446. SetModified();
  447. }
  448. void CDPNtEventPage::OnCheckWarning()
  449. {
  450. UpdateData();
  451. SetModified();
  452. }
  453. void CDPNtEventPage::OnEditchangeComboLogFile()
  454. {
  455. UpdateData();
  456. SetModified();
  457. }
  458. void CDPNtEventPage::OnChangeEditCategory()
  459. {
  460. // TODO: If this is a RICHEDIT control, the control will not
  461. // send this notification unless you override the CHMPropertyPage::OnInitDialog()
  462. // function and call CRichEditCtrl().SetEventMask()
  463. // with the ENM_CHANGE flag ORed into the mask.
  464. UpdateData();
  465. SetModified();
  466. }
  467. void CDPNtEventPage::OnChangeEditEventid()
  468. {
  469. // TODO: If this is a RICHEDIT control, the control will not
  470. // send this notification unless you override the CHMPropertyPage::OnInitDialog()
  471. // function and call CRichEditCtrl().SetEventMask()
  472. // with the ENM_CHANGE flag ORed into the mask.
  473. UpdateData();
  474. SetModified();
  475. }
  476. void CDPNtEventPage::OnChangeEditSource()
  477. {
  478. // TODO: If this is a RICHEDIT control, the control will not
  479. // send this notification unless you override the CHMPropertyPage::OnInitDialog()
  480. // function and call CRichEditCtrl().SetEventMask()
  481. // with the ENM_CHANGE flag ORed into the mask.
  482. UpdateData();
  483. SetModified();
  484. }
  485. void CDPNtEventPage::OnChangeEditUser()
  486. {
  487. // TODO: If this is a RICHEDIT control, the control will not
  488. // send this notification unless you override the CHMPropertyPage::OnInitDialog()
  489. // function and call CRichEditCtrl().SetEventMask()
  490. // with the ENM_CHANGE flag ORed into the mask.
  491. UpdateData();
  492. SetModified();
  493. }