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.

831 lines
24 KiB

  1. // ActionAssociationPage.cpp : implementation file
  2. //
  3. // Copyright (c) 2000 Microsoft Corporation
  4. //
  5. // 03/23/00 v-marfin 61667 : Display MsgBox explaining that user needs to first
  6. // create an action before attempting to create a new
  7. // association (if there are no actions defined).
  8. // 03/23/00 v-marfin 62207 : In GetC2AAssociation(), check for passed GUID and if a singleton do not
  9. // enclose in braces when formatting the query.
  10. // 03/24/00 v-marfin 62192 : help link fix.
  11. // 04/05/00 v-marfin 59643b : unmarshal connection OnInitDialog.
  12. #include "stdafx.h"
  13. #include "snapin.h"
  14. #include "HMPropertyPage.h"
  15. #include "ActionAssociationPage.h"
  16. #include "NewActionAssociationDlg.h"
  17. #include "Action.h"
  18. #ifdef _DEBUG
  19. #define new DEBUG_NEW
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CActionAssociationPage property page
  25. IMPLEMENT_DYNCREATE(CActionAssociationPage, CHMPropertyPage)
  26. CActionAssociationPage::CActionAssociationPage() : CHMPropertyPage(CActionAssociationPage::IDD)
  27. {
  28. //{{AFX_DATA_INIT(CActionAssociationPage)
  29. // NOTE: the ClassWizard will add member initialization here
  30. //}}AFX_DATA_INIT
  31. m_sHelpTopic = _T("HMon21.chm::/dTHact.htm"); // v-marfin 62192 : help link fix
  32. }
  33. CActionAssociationPage::~CActionAssociationPage()
  34. {
  35. }
  36. inline CWbemClassObject* CActionAssociationPage::GetAssociatedActions()
  37. {
  38. // execute the query for actions
  39. CWbemClassObject* pActionConfigObject = new CWbemClassObject;
  40. CString sQuery;
  41. CString sGuid = GetObjectPtr()->GetGuid();
  42. if( sGuid == _T("@") ) // it is a System object... singleton class
  43. {
  44. sQuery = _T("ASSOCIATORS OF {Microsoft_HMSystemConfiguration=@} WHERE ResultClass=Microsoft_HMActionConfiguration");
  45. }
  46. else // it is an object beneath the system
  47. {
  48. sQuery.Format(IDS_STRING_C2A_ASSOC_QUERY,sGuid);
  49. }
  50. if( ! CHECKHRESULT(pActionConfigObject->Create(GetObjectPtr()->GetSystemName())) )
  51. {
  52. return NULL;
  53. }
  54. BSTR bsQuery = sQuery.AllocSysString();
  55. if( ! CHECKHRESULT(pActionConfigObject->ExecQuery(bsQuery)) )
  56. {
  57. ::SysFreeString(bsQuery);
  58. return NULL;
  59. }
  60. ::SysFreeString(bsQuery);
  61. return pActionConfigObject;
  62. }
  63. inline CString CActionAssociationPage::GetConditionString(const CString& sActionConfigGuid)
  64. {
  65. CWbemClassObject* pA2CAssociation = GetA2CAssociation(sActionConfigGuid);
  66. if( ! pA2CAssociation )
  67. {
  68. return _T("");
  69. }
  70. CString sQuery;
  71. CString sCondition;
  72. CString sResString;
  73. pA2CAssociation->GetProperty(_T("Query"),sQuery);
  74. sQuery.MakeUpper();
  75. if( sQuery.Find(_T("TARGETINSTANCE.STATE=0")) != -1 )
  76. {
  77. sResString.LoadString(IDS_STRING_NORMAL);
  78. sCondition += sResString + _T(",");
  79. }
  80. if( sQuery.Find(_T("TARGETINSTANCE.STATE=8")) != -1 )
  81. {
  82. sResString.LoadString(IDS_STRING_WARNING);
  83. sCondition += sResString + _T(",");
  84. }
  85. if( sQuery.Find(_T("TARGETINSTANCE.STATE=9")) != -1 )
  86. {
  87. sResString.LoadString(IDS_STRING_CRITICAL);
  88. sCondition += sResString + _T(",");
  89. }
  90. if( sQuery.Find(_T("TARGETINSTANCE.STATE=7")) != -1 )
  91. {
  92. sResString.LoadString(IDS_STRING_NODATA);
  93. sCondition += sResString + _T(",");
  94. }
  95. if( sQuery.Find(_T("TARGETINSTANCE.STATE=4")) != -1 )
  96. {
  97. sResString.LoadString(IDS_STRING_DISABLED);
  98. sCondition += sResString + _T(",");
  99. }
  100. sCondition.TrimRight(_T(","));
  101. delete pA2CAssociation;
  102. return sCondition;
  103. }
  104. inline CWbemClassObject* CActionAssociationPage::GetA2CAssociation(const CString& sActionConfigGuid)
  105. {
  106. CString sActionPath;
  107. sActionPath.Format(_T("Microsoft_HMActionConfiguration.GUID=\"%s\""),sActionConfigGuid);
  108. CString sQuery;
  109. sQuery.Format(_T("REFERENCES OF {%s} WHERE ResultClass=Microsoft_HMConfigurationActionAssociation Role=ChildPath"),sActionPath);
  110. CWbemClassObject* pAssociation = new CWbemClassObject;
  111. pAssociation->Create(GetObjectPtr()->GetSystemName());
  112. BSTR bsQuery = sQuery.AllocSysString();
  113. if( ! CHECKHRESULT(pAssociation->ExecQuery(bsQuery)) )
  114. {
  115. ::SysFreeString(bsQuery);
  116. delete pAssociation;
  117. return NULL;
  118. }
  119. ::SysFreeString(bsQuery);
  120. CString sParentPath;
  121. CString sEventFilterPath;
  122. ULONG ulReturned = 0L;
  123. while( pAssociation->GetNextObject(ulReturned) == S_OK && ulReturned > 0 )
  124. {
  125. pAssociation->GetProperty(_T("ParentPath"),sParentPath);
  126. if( sParentPath.Find(GetObjectPtr()->GetGuid()) != -1 )
  127. {
  128. break;
  129. }
  130. }
  131. return pAssociation;
  132. }
  133. inline CWbemClassObject* CActionAssociationPage::GetC2AAssociation(const CString& sConfigGuid)
  134. {
  135. CString sConfigPath;
  136. // v-marfin : 62207
  137. // If incoming GUID is a singleton, do not format it as a normal GUID since that causes the
  138. // qeury to fail with invalid object path msg.
  139. // For this the query should be:
  140. //
  141. // References of {Microsoft_HMConfiguration.GUID="@"}
  142. // where ResultClass=Microsoft_HMConfigurationActionAssociation Role=ParentPath
  143. //
  144. // Which is basically the same query being used except without the braces around the GUID.
  145. //
  146. //
  147. CString sGUID;
  148. // Is passed parm a singleton?
  149. if (sConfigGuid == _T("@"))
  150. {
  151. sGUID = sConfigGuid; // yes, do not enclose in braces.
  152. }
  153. else
  154. {
  155. sGUID.Format(_T("{%s}"),sConfigGuid); // no, enclose in braces
  156. }
  157. sConfigPath.Format(_T("Microsoft_HMConfiguration.GUID=\"%s\""),sGUID);
  158. CString sQuery;
  159. sQuery.Format(_T("REFERENCES OF {%s} WHERE ResultClass=Microsoft_HMConfigurationActionAssociation Role=ParentPath"),sConfigPath);
  160. CWbemClassObject* pAssociation = new CWbemClassObject;
  161. pAssociation->Create(GetObjectPtr()->GetSystemName());
  162. BSTR bsQuery = sQuery.AllocSysString();
  163. if( ! CHECKHRESULT(pAssociation->ExecQuery(bsQuery)) )
  164. {
  165. ::SysFreeString(bsQuery);
  166. delete pAssociation;
  167. return NULL;
  168. }
  169. ::SysFreeString(bsQuery);
  170. return pAssociation;
  171. }
  172. void CActionAssociationPage::DoDataExchange(CDataExchange* pDX)
  173. {
  174. CHMPropertyPage::DoDataExchange(pDX);
  175. //{{AFX_DATA_MAP(CActionAssociationPage)
  176. DDX_Control(pDX, IDC_LIST_ACTIONS, m_ActionsList);
  177. DDX_Control(pDX, IDC_BUTTON_PROPERTIES, m_PropertiesButton);
  178. DDX_Control(pDX, IDC_BUTTON_NEW, m_NewButton);
  179. DDX_Control(pDX, IDC_BUTTON_DELETE, m_DeleteButton);
  180. //}}AFX_DATA_MAP
  181. }
  182. BEGIN_MESSAGE_MAP(CActionAssociationPage, CHMPropertyPage)
  183. //{{AFX_MSG_MAP(CActionAssociationPage)
  184. ON_WM_DESTROY()
  185. ON_NOTIFY(NM_CLICK, IDC_LIST_ACTIONS, OnClickListActions)
  186. ON_BN_CLICKED(IDC_BUTTON_PROPERTIES, OnButtonProperties)
  187. ON_BN_CLICKED(IDC_BUTTON_NEW, OnButtonNew)
  188. ON_BN_CLICKED(IDC_BUTTON_DELETE, OnButtonDelete)
  189. ON_NOTIFY(NM_DBLCLK, IDC_LIST_ACTIONS, OnDblclkListActions)
  190. //}}AFX_MSG_MAP
  191. END_MESSAGE_MAP()
  192. /////////////////////////////////////////////////////////////////////////////
  193. // CActionAssociationPage message handlers
  194. BOOL CActionAssociationPage::OnInitDialog()
  195. {
  196. // unmarshal connmgr //59643b
  197. CnxPropertyPageCreate();
  198. CHMPropertyPage::OnInitDialog();
  199. // create the tooltip
  200. EnableToolTips();
  201. m_ToolTip.Create(this,TTS_ALWAYSTIP);
  202. m_ToolTip.AddTool(&m_NewButton,IDS_STRING_TOOLTIP_NEW);
  203. m_ToolTip.AddTool(&m_PropertiesButton,IDS_STRING_TOOLTIP_PROPERTY);
  204. m_ToolTip.AddTool(&m_DeleteButton,IDS_STRING_TOOLTIP_DELETE);
  205. m_ToolTip.Activate(TRUE);
  206. // create bitmaps and init each bitmap button
  207. CBitmap bitmap;
  208. bitmap.LoadBitmap(IDB_BITMAP_NEW);
  209. m_hNewBitmap = (HBITMAP)bitmap.Detach();
  210. bitmap.LoadBitmap(IDB_BITMAP_PROPERTIES);
  211. m_hPropertiesBitmap = (HBITMAP)bitmap.Detach();
  212. bitmap.LoadBitmap(IDB_BITMAP_DELETE);
  213. m_hDeleteBitmap = (HBITMAP)bitmap.Detach();
  214. SendDlgItemMessage(IDC_BUTTON_NEW,BM_SETIMAGE,IMAGE_BITMAP,(LPARAM)m_hNewBitmap);
  215. SendDlgItemMessage(IDC_BUTTON_PROPERTIES,BM_SETIMAGE,IMAGE_BITMAP,(LPARAM)m_hPropertiesBitmap);
  216. SendDlgItemMessage(IDC_BUTTON_DELETE,BM_SETIMAGE,IMAGE_BITMAP,(LPARAM)m_hDeleteBitmap);
  217. // add columns to the listctrl
  218. CString sTitle;
  219. sTitle.LoadString(IDS_STRING_NAME);
  220. m_ActionsList.InsertColumn(0,sTitle,LVCFMT_LEFT,LVSCW_AUTOSIZE_USEHEADER);
  221. sTitle.LoadString(IDS_STRING_GUID);
  222. m_ActionsList.InsertColumn(1,sTitle,LVCFMT_LEFT,0);
  223. sTitle.LoadString(IDS_STRING_CONDITION);
  224. m_ActionsList.InsertColumn(2,sTitle,LVCFMT_LEFT,LVSCW_AUTOSIZE);
  225. sTitle.LoadString(IDS_STRING_THROTTLE_TIME);
  226. m_ActionsList.InsertColumn(3,sTitle,LVCFMT_RIGHT,LVSCW_AUTOSIZE_USEHEADER);
  227. sTitle.LoadString(IDS_STRING_REMINDER_TIME);
  228. m_ActionsList.InsertColumn(4,sTitle,LVCFMT_RIGHT,LVSCW_AUTOSIZE_USEHEADER);
  229. sTitle.LoadString(IDS_STRING_COMMENT);
  230. m_ActionsList.InsertColumn(5,sTitle,LVCFMT_LEFT,LVSCW_AUTOSIZE_USEHEADER);
  231. m_ActionsList.SetColumnWidth(0,LVSCW_AUTOSIZE_USEHEADER);
  232. m_ActionsList.SetColumnWidth(1,0);
  233. m_ActionsList.SetColumnWidth(2,LVSCW_AUTOSIZE_USEHEADER);
  234. m_ActionsList.SetColumnWidth(3,LVSCW_AUTOSIZE_USEHEADER);
  235. m_ActionsList.SetColumnWidth(4,LVSCW_AUTOSIZE_USEHEADER);
  236. m_ActionsList.SetColumnWidth(5,LVSCW_AUTOSIZE_USEHEADER);
  237. CWbemClassObject* pAssociation = GetC2AAssociation(GetObjectPtr()->GetGuid());
  238. if( ! pAssociation )
  239. {
  240. return TRUE;
  241. }
  242. bool bFound = false;
  243. ULONG ulReturned = 0L;
  244. while( pAssociation->GetNextObject(ulReturned) == S_OK && ulReturned > 0 )
  245. {
  246. // get the action config object
  247. CString sActionPath;
  248. pAssociation->GetProperty(_T("ChildPath"),sActionPath);
  249. CWbemClassObject* pActionConfigObject = new CWbemClassObject;
  250. pActionConfigObject->Create(GetObjectPtr()->GetSystemName());
  251. if( CHECKHRESULT(pActionConfigObject->GetObject(sActionPath)) )
  252. {
  253. int iValue = -1;
  254. CString sValue;
  255. pActionConfigObject->GetLocaleStringProperty(IDS_STRING_MOF_NAME,sValue);
  256. int iIndex = m_ActionsList.InsertItem(0,sValue);
  257. // set the GUID of the ActionConfig
  258. pActionConfigObject->GetProperty(IDS_STRING_MOF_GUID,sValue);
  259. m_ActionsList.SetItem(iIndex,1,LVIF_TEXT,sValue,NULL,NULL,NULL,NULL);
  260. // set the Condition
  261. sValue = GetConditionString(sValue);
  262. m_ActionsList.SetItem(iIndex,2,LVIF_TEXT,sValue,NULL,NULL,NULL,NULL);
  263. // set throttle time
  264. pAssociation->GetProperty(_T("ThrottleTime"),iValue);
  265. sValue.Format(_T("%d"),iValue);
  266. m_ActionsList.SetItem(iIndex,3,LVIF_TEXT,sValue,NULL,NULL,NULL,NULL);
  267. // set reminder time
  268. pAssociation->GetProperty(_T("ReminderTime"),iValue);
  269. sValue.Format(_T("%d"),iValue);
  270. m_ActionsList.SetItem(iIndex,4,LVIF_TEXT,sValue,NULL,NULL,NULL,NULL);
  271. // set the Description
  272. pActionConfigObject->GetLocaleStringProperty(IDS_STRING_MOF_DESCRIPTION,sValue);
  273. m_ActionsList.SetItem(iIndex,5,LVIF_TEXT,sValue,NULL,NULL,NULL,NULL);
  274. bFound = true;
  275. }
  276. delete pActionConfigObject;
  277. }
  278. if( bFound )
  279. {
  280. m_ActionsList.SetColumnWidth(0,LVSCW_AUTOSIZE);
  281. m_ActionsList.SetColumnWidth(2,LVSCW_AUTOSIZE_USEHEADER);
  282. }
  283. delete pAssociation;
  284. return TRUE; // return TRUE unless you set the focus to a control
  285. // EXCEPTION: OCX Property Pages should return FALSE
  286. }
  287. LRESULT CActionAssociationPage::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
  288. {
  289. MSG msg;
  290. PeekMessage(&msg,GetSafeHwnd(),0,0,PM_NOREMOVE);
  291. if( m_ToolTip.GetSafeHwnd() )
  292. {
  293. m_ToolTip.RelayEvent(&msg);
  294. m_ToolTip.Activate(TRUE);
  295. }
  296. return CHMPropertyPage::WindowProc(message, wParam, lParam);
  297. }
  298. void CActionAssociationPage::OnDestroy()
  299. {
  300. CHMPropertyPage::OnDestroy();
  301. DeleteObject(m_hNewBitmap);
  302. DeleteObject(m_hPropertiesBitmap);
  303. DeleteObject(m_hDeleteBitmap);
  304. //59643
  305. CnxPropertyPageDestroy();
  306. }
  307. void CActionAssociationPage::OnClickListActions(NMHDR* pNMHDR, LRESULT* pResult)
  308. {
  309. POSITION pos = m_ActionsList.GetFirstSelectedItemPosition();
  310. int iIndex = 0;
  311. if( pos )
  312. {
  313. GetDlgItem(IDC_BUTTON_PROPERTIES)->EnableWindow(TRUE);
  314. GetDlgItem(IDC_BUTTON_DELETE)->EnableWindow(TRUE);
  315. iIndex = m_ActionsList.GetNextSelectedItem(pos);
  316. }
  317. else
  318. {
  319. GetDlgItem(IDC_BUTTON_PROPERTIES)->EnableWindow(FALSE);
  320. GetDlgItem(IDC_BUTTON_DELETE)->EnableWindow(FALSE);
  321. }
  322. *pResult = 0;
  323. }
  324. void CActionAssociationPage::OnButtonProperties()
  325. {
  326. POSITION pos = m_ActionsList.GetFirstSelectedItemPosition();
  327. int iIndex = 0;
  328. if( pos )
  329. {
  330. iIndex = m_ActionsList.GetNextSelectedItem(pos);
  331. CString sActionName = m_ActionsList.GetItemText(iIndex,0);
  332. CString sGuid = m_ActionsList.GetItemText(iIndex,1);
  333. CString sActionPath;
  334. sActionPath.Format(_T("Microsoft_HMActionConfiguration.GUID=\"%s\""),sGuid);
  335. CString sQuery;
  336. sQuery.Format(_T("REFERENCES OF {%s} WHERE ResultClass=Microsoft_HMConfigurationActionAssociation Role=ChildPath"),sActionPath);
  337. CWbemClassObject Association;
  338. Association.Create(GetObjectPtr()->GetSystemName());
  339. BSTR bsQuery = sQuery.AllocSysString();
  340. if( ! CHECKHRESULT(Association.ExecQuery(bsQuery)) )
  341. {
  342. ::SysFreeString(bsQuery);
  343. return;
  344. }
  345. ::SysFreeString(bsQuery);
  346. CString sParentPath;
  347. ULONG ulReturned = 0L;
  348. while( Association.GetNextObject(ulReturned) == S_OK && ulReturned > 0 )
  349. {
  350. Association.GetProperty(_T("ParentPath"),sParentPath);
  351. if( sParentPath.Find(GetObjectPtr()->GetGuid()) != -1 )
  352. {
  353. break;
  354. }
  355. }
  356. Association.GetProperty(_T("Query"),sQuery);
  357. sQuery.MakeUpper();
  358. CNewActionAssociationDlg dlg;
  359. if( sQuery.Find(_T("TARGETINSTANCE.STATE=9")) != -1 )
  360. {
  361. dlg.m_bCritical = TRUE;
  362. }
  363. if( sQuery.Find(_T("TARGETINSTANCE.STATE=8")) != -1 )
  364. {
  365. dlg.m_bWarning = TRUE;
  366. }
  367. if( sQuery.Find(_T("TARGETINSTANCE.STATE=7")) != -1 )
  368. {
  369. dlg.m_bNoData = TRUE;
  370. }
  371. if( sQuery.Find(_T("TARGETINSTANCE.STATE=4")) != -1 )
  372. {
  373. dlg.m_bDisabled = TRUE;
  374. }
  375. if( sQuery.Find(_T("TARGETINSTANCE.STATE=0")) != -1 )
  376. {
  377. dlg.m_bNormal = TRUE;
  378. }
  379. // set the selection to the proper action in the combobox
  380. dlg.m_saActions.Add(sActionName);
  381. dlg.m_iSelectedAction = 0;
  382. dlg.m_bEnableActionsComboBox = FALSE;
  383. Association.GetProperty(_T("ThrottleTime"),dlg.m_iThrottleTime);
  384. Association.GetProperty(_T("ReminderTime"),dlg.m_iReminderTime);
  385. if( dlg.DoModal() == IDOK )
  386. {
  387. // construct the EventFilter query
  388. CString sQuery;
  389. if( GetObjectPtr()->GetTypeName() == _T("Threshold") )
  390. {
  391. sQuery.Format(_T("select * from __InstanceModificationEvent where TargetInstance isa \"Microsoft_HMThresholdStatusInstance\" AND TargetInstance.GUID=\"{%s}\""),
  392. GetObjectPtr()->GetGuid());
  393. }
  394. else
  395. {
  396. sQuery.Format(IDS_STRING_HMSTATUS_QUERY_FMT,GetObjectPtr()->GetTypeName(),GetObjectPtr()->GetGuid());
  397. }
  398. CString sClause;
  399. CString sCondition;
  400. CString sResString;
  401. if( dlg.m_bNormal )
  402. {
  403. sClause += _T("TargetInstance.State=0 OR ");
  404. sResString.LoadString(IDS_STRING_NORMAL);
  405. sCondition += sResString + _T(",");
  406. }
  407. if( dlg.m_bWarning )
  408. {
  409. sClause += _T("TargetInstance.State=8 OR ");
  410. sResString.LoadString(IDS_STRING_WARNING);
  411. sCondition += sResString + _T(",");
  412. }
  413. if( dlg.m_bCritical )
  414. {
  415. sClause += _T("TargetInstance.State=9 OR ");
  416. sResString.LoadString(IDS_STRING_CRITICAL);
  417. sCondition += sResString + _T(",");
  418. }
  419. if( dlg.m_bDisabled )
  420. {
  421. sClause += _T("TargetInstance.State=4 OR ");
  422. sResString.LoadString(IDS_STRING_DISABLED);
  423. sCondition += sResString + _T(",");
  424. }
  425. if( dlg.m_bNoData )
  426. {
  427. sClause += _T("TargetInstance.State=7 OR ");
  428. sResString.LoadString(IDS_STRING_NODATA);
  429. sCondition += sResString + _T(",");
  430. }
  431. if( ! sClause.IsEmpty() )
  432. {
  433. sClause = _T(" AND (") + sClause;
  434. sClause = sClause.Left(sClause.GetLength() - 4);
  435. sClause += _T(")");
  436. sQuery += sClause;
  437. }
  438. sCondition.TrimRight(_T(","));
  439. Association.SetProperty(_T("Query"),sQuery);
  440. Association.SetProperty(_T("ReminderTime"),dlg.m_iReminderTime);
  441. Association.SetProperty(_T("ThrottleTime"),dlg.m_iThrottleTime);
  442. Association.SaveAllProperties();
  443. CString sValue;
  444. m_ActionsList.SetItem(iIndex,2,LVIF_TEXT,sCondition,NULL,NULL,NULL,NULL);
  445. sValue.Format(_T("%d"),dlg.m_iThrottleTime);
  446. m_ActionsList.SetItem(iIndex,3,LVIF_TEXT,sValue,NULL,NULL,NULL,NULL);
  447. sValue.Format(_T("%d"),dlg.m_iReminderTime);
  448. m_ActionsList.SetItem(iIndex,4,LVIF_TEXT,sValue,NULL,NULL,NULL,NULL);
  449. }
  450. } // end if pos
  451. }
  452. void CActionAssociationPage::OnButtonNew()
  453. {
  454. CNewActionAssociationDlg dlg;
  455. // query for the actions on this system
  456. CStringArray saGuids;
  457. CStringArray saDescriptions;
  458. CStringArray saConsumerPaths;
  459. CString sQuery = IDS_STRING_ACTIONCONFIG_QUERY;
  460. BSTR bsQuery = sQuery.AllocSysString();
  461. CWbemClassObject ActionConfigObject;
  462. ActionConfigObject.Create(GetObjectPtr()->GetSystemName());
  463. HRESULT hr = ActionConfigObject.ExecQuery(bsQuery);
  464. if( CHECKHRESULT(hr) )
  465. {
  466. ULONG ulReturned = 0L;
  467. while( ActionConfigObject.GetNextObject(ulReturned) == S_OK && ulReturned > 0 )
  468. {
  469. CString sValue;
  470. ActionConfigObject.GetLocaleStringProperty(IDS_STRING_MOF_NAME,sValue);
  471. dlg.m_saActions.Add(sValue);
  472. ActionConfigObject.GetProperty(IDS_STRING_MOF_GUID,sValue);
  473. saGuids.Add(sValue);
  474. ActionConfigObject.GetLocaleStringProperty(IDS_STRING_MOF_DESCRIPTION,sValue);
  475. saDescriptions.Add(sValue);
  476. ActionConfigObject.GetProperty(IDS_STRING_MOF_EVENTCONSUMER,sValue);
  477. saConsumerPaths.Add(sValue);
  478. }
  479. }
  480. BOOL bAtLeastOneActionAlreadyExists=FALSE;
  481. for( int i = (int)dlg.m_saActions.GetSize()-1; i >= 0; i-- )
  482. {
  483. LVFINDINFO lvfi;
  484. ZeroMemory(&lvfi,sizeof(LVFINDINFO));
  485. lvfi.flags = LVFI_WRAP|LVFI_STRING;
  486. lvfi.psz = dlg.m_saActions[i];
  487. int iListIndex = m_ActionsList.FindItem(&lvfi);
  488. if( iListIndex >= 0 )
  489. {
  490. bAtLeastOneActionAlreadyExists=TRUE;
  491. saGuids.RemoveAt(i);
  492. dlg.m_saActions.RemoveAt(i);
  493. }
  494. }
  495. if( dlg.m_saActions.GetSize() == 0 )
  496. {
  497. // v-marfin 61667 : Show why we are returning. User must first create
  498. // an action before attempting an association. Only if there were no
  499. // actions in the list to begin with. If there was an action in the
  500. // dialog list but that action is already being used, it will have been removed
  501. // from the m_saActions array so see if this is the case. If so, don't
  502. // show an error prompt, just return.
  503. if (!bAtLeastOneActionAlreadyExists)
  504. {
  505. AfxMessageBox(IDS_STRING_MUST_CREATE_ACTION);
  506. }
  507. return;
  508. }
  509. // display the dialog
  510. if( dlg.DoModal() == IDOK )
  511. {
  512. CString sParentPath = GetObjectPtr()->GetObjectPath();
  513. CString sChildPath;
  514. sChildPath.Format(_T("\\\\.\\root\\cimv2\\MicrosoftHealthmonitor:Microsoft_HMActionConfiguration.GUID=\"%s\""),saGuids[dlg.m_iSelectedAction]);
  515. // create the association instance and fill out the paths to child, parent and filter
  516. CWbemClassObject ActionAssociation;
  517. ActionAssociation.Create(GetObjectPtr()->GetSystemName());
  518. BSTR bsActionAssociation = ::SysAllocString(L"Microsoft_HMConfigurationActionAssociation");
  519. if( ! CHECKHRESULT(ActionAssociation.CreateInstance(bsActionAssociation)) )
  520. {
  521. ::SysFreeString(bsActionAssociation);
  522. return;
  523. }
  524. ::SysFreeString(bsActionAssociation);
  525. ActionAssociation.SetProperty(_T("ParentPath"),sParentPath);
  526. ActionAssociation.SetProperty(_T("ChildPath"),sChildPath);
  527. ActionAssociation.SetProperty(_T("ReminderTime"),dlg.m_iReminderTime);
  528. ActionAssociation.SetProperty(_T("ThrottleTime"),dlg.m_iThrottleTime);
  529. // construct the query for modification events on HMStatus
  530. CString sQuery;
  531. if( GetObjectPtr()->GetTypeName() == _T("Threshold") )
  532. {
  533. sQuery.Format(_T("select * from __InstanceModificationEvent where TargetInstance isa \"Microsoft_HMThresholdStatusInstance\" AND TargetInstance.GUID=\"{%s}\""),
  534. GetObjectPtr()->GetGuid());
  535. }
  536. else
  537. {
  538. sQuery.Format(IDS_STRING_HMSTATUS_QUERY_FMT,GetObjectPtr()->GetTypeName(),GetObjectPtr()->GetGuid());
  539. }
  540. CString sClause;
  541. CString sCondition;
  542. CString sResString;
  543. if( dlg.m_bNormal )
  544. {
  545. sClause += _T("TargetInstance.State=0 OR ");
  546. sResString.LoadString(IDS_STRING_NORMAL);
  547. sCondition += sResString + _T(",");
  548. }
  549. if( dlg.m_bWarning )
  550. {
  551. sClause += _T("TargetInstance.State=8 OR ");
  552. sResString.LoadString(IDS_STRING_WARNING);
  553. sCondition += sResString + _T(",");
  554. }
  555. if( dlg.m_bCritical )
  556. {
  557. sClause += _T("TargetInstance.State=9 OR ");
  558. sResString.LoadString(IDS_STRING_CRITICAL);
  559. sCondition += sResString + _T(",");
  560. }
  561. if( dlg.m_bDisabled )
  562. {
  563. sClause += _T("TargetInstance.State=4 OR ");
  564. sResString.LoadString(IDS_STRING_DISABLED);
  565. sCondition += sResString + _T(",");
  566. }
  567. if( dlg.m_bNoData )
  568. {
  569. sClause += _T("TargetInstance.State=7 OR ");
  570. sResString.LoadString(IDS_STRING_NODATA);
  571. sCondition += sResString + _T(",");
  572. }
  573. if( ! sClause.IsEmpty() )
  574. {
  575. sClause = _T(" AND (") + sClause;
  576. sClause = sClause.Left(sClause.GetLength() - 4);
  577. sClause += _T(")");
  578. sQuery += sClause;
  579. }
  580. sCondition.TrimRight(_T(","));
  581. ActionAssociation.SetProperty(IDS_STRING_MOF_QUERY,sQuery);
  582. #ifdef SAVE
  583. // create the __EventFilter instance and fill out the query
  584. CWbemClassObject EventFilter;
  585. EventFilter.Create(GetObjectPtr()->GetSystemName());
  586. BSTR bsEventFilter = ::SysAllocString(L"__EventFilter");
  587. if( ! CHECKHRESULT(EventFilter.CreateInstance(bsEventFilter)) )
  588. {
  589. ::SysFreeString(bsEventFilter);
  590. return;
  591. }
  592. ::SysFreeString(bsEventFilter);
  593. // create the GUID
  594. GUID ChildGuid;
  595. CoCreateGuid(&ChildGuid);
  596. OLECHAR szGuid[GUID_CCH];
  597. ::StringFromGUID2(ChildGuid, szGuid, GUID_CCH);
  598. CString sGuid = OLE2CT(szGuid);
  599. EventFilter.SetProperty(_T("Name"),sGuid);
  600. EventFilter.SetProperty(_T("QueryLanguage"),CString(_T("WQL")));
  601. // set event filter query to ActionStatus creation event
  602. sQuery.Format(IDS_STRING_HMACTIONSTATUS_QUERY_FMT,saGuids[dlg.m_iSelectedAction]);
  603. EventFilter.SetProperty(_T("Query"),sQuery);
  604. EventFilter.SaveAllProperties();
  605. #endif
  606. CString sEventFilterPath;
  607. // sEventFilterPath.Format(_T("\\\\.\\root\\cimv2\\MicrosoftHealthmonitor:__EventFilter.Name=\"%s\""),sGuid);
  608. sEventFilterPath.Format(_T("\\\\.\\root\\cimv2\\MicrosoftHealthmonitor:__EventFilter.Name=\"%s\""),saGuids[dlg.m_iSelectedAction]);
  609. ActionAssociation.SetProperty(_T("EventFilter"),sEventFilterPath);
  610. ActionAssociation.SaveAllProperties();
  611. #ifdef SAVE
  612. // create the __FilterToConsumerBinding instance and fill out the paths
  613. CWbemClassObject FilterToConsumerBinding;
  614. FilterToConsumerBinding.Create(GetObjectPtr()->GetSystemName());
  615. BSTR bsFTCB = ::SysAllocString(L"__FilterToConsumerBinding");
  616. if( ! CHECKHRESULT(FilterToConsumerBinding.CreateInstance(bsFTCB)) )
  617. {
  618. ::SysFreeString(bsFTCB);
  619. return;
  620. }
  621. ::SysFreeString(bsFTCB);
  622. FilterToConsumerBinding.SetProperty(_T("Consumer"),saConsumerPaths[dlg.m_iSelectedAction]);
  623. FilterToConsumerBinding.SetProperty(_T("Filter"),sEventFilterPath);
  624. FilterToConsumerBinding.SaveAllProperties();
  625. #endif
  626. // now add an item to the list control
  627. CString sValue;
  628. int iIndex = m_ActionsList.InsertItem(0,dlg.m_saActions[dlg.m_iSelectedAction]);
  629. m_ActionsList.SetItem(iIndex,1,LVIF_TEXT,saGuids[dlg.m_iSelectedAction],NULL,NULL,NULL,NULL);
  630. m_ActionsList.SetItem(iIndex,2,LVIF_TEXT,sCondition,NULL,NULL,NULL,NULL);
  631. sValue.Format(_T("%d"),dlg.m_iThrottleTime);
  632. m_ActionsList.SetItem(iIndex,3,LVIF_TEXT,sValue,NULL,NULL,NULL,NULL);
  633. sValue.Format(_T("%d"),dlg.m_iReminderTime);
  634. m_ActionsList.SetItem(iIndex,4,LVIF_TEXT,sValue,NULL,NULL,NULL,NULL);
  635. m_ActionsList.SetItem(iIndex,5,LVIF_TEXT,saDescriptions[dlg.m_iSelectedAction],NULL,NULL,NULL,NULL);
  636. m_ActionsList.SetColumnWidth(0,LVSCW_AUTOSIZE);
  637. }
  638. }
  639. void CActionAssociationPage::OnButtonDelete()
  640. {
  641. POSITION pos = m_ActionsList.GetFirstSelectedItemPosition();
  642. int iIndex = 0;
  643. if( pos )
  644. {
  645. iIndex = m_ActionsList.GetNextSelectedItem(pos);
  646. CString sActionGuid = m_ActionsList.GetItemText(iIndex,1);
  647. GetObjectPtr()->DeleteActionAssoc(sActionGuid);
  648. m_ActionsList.DeleteItem(iIndex);
  649. }
  650. }
  651. void CActionAssociationPage::OnDblclkListActions(NMHDR* pNMHDR, LRESULT* pResult)
  652. {
  653. OnButtonProperties();
  654. *pResult = 0;
  655. }