Leaked source code of windows server 2003
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.

1461 lines
48 KiB

  1. /*++
  2. Copyright (C) 1998-1999 Microsoft Corporation
  3. Module Name:
  4. alrtgenp.cpp
  5. Abstract:
  6. Implementation of the alerts general property page.
  7. --*/
  8. #include "stdafx.h"
  9. #include <assert.h>
  10. #include <math.h>
  11. #include <limits.h>
  12. #include <float.h>
  13. #include <strsafe.h>
  14. #include <pdh.h>
  15. #include <pdhmsg.h>
  16. #include <common.h>
  17. #include "smcfgmsg.h"
  18. #include "dialogs.h"
  19. #include "smlogs.h"
  20. #include "smalrtq.h"
  21. #include "AlrtGenP.h"
  22. #include <pdhp.h>
  23. #ifdef _DEBUG
  24. #define new DEBUG_NEW
  25. #undef THIS_FILE
  26. static char THIS_FILE[] = __FILE__;
  27. #endif
  28. USE_HANDLE_MACROS("SMLOGCFG(alrtgenp.cpp)");
  29. static const COMBO_BOX_DATA_MAP OverUnderCombo[] =
  30. {
  31. {OU_OVER, IDS_OVER},
  32. {OU_UNDER, IDS_UNDER}
  33. };
  34. static const DWORD dwOverUnderComboEntries = sizeof(OverUnderCombo)/sizeof(OverUnderCombo[0]);
  35. static ULONG
  36. s_aulHelpIds[] =
  37. {
  38. IDC_ALRTS_COUNTER_LIST, IDH_ALRTS_COUNTER_LIST,
  39. IDC_ALRTS_ADD_BTN, IDH_ALRTS_ADD_BTN,
  40. IDC_ALRTS_REMOVE_BTN, IDH_ALRTS_REMOVE_BTN,
  41. IDC_ALRTS_OVER_UNDER, IDH_ALRTS_OVER_UNDER,
  42. IDC_ALRTS_VALUE_EDIT, IDH_ALRTS_VALUE_EDIT,
  43. IDC_ALRTS_COMMENT_EDIT, IDH_ALRTS_COMMENT_EDIT,
  44. IDC_ALRTS_SAMPLE_EDIT, IDH_ALRTS_SAMPLE_EDIT,
  45. IDC_ALRTS_SAMPLE_SPIN, IDH_ALRTS_SAMPLE_EDIT,
  46. IDC_ALRTS_SAMPLE_UNITS_COMBO, IDH_ALRTS_SAMPLE_UNITS_COMBO,
  47. IDC_RUNAS_EDIT, IDH_RUNAS_EDIT,
  48. IDC_SETPWD_BTN, IDH_SETPWD_BTN,
  49. 0,0
  50. };
  51. ULONG
  52. CAlertGenProp::HashCounter(
  53. LPWSTR szCounterName,
  54. ULONG lHashSize)
  55. {
  56. ULONG h = 0;
  57. ULONG a = 31415; //a, b, k are primes
  58. const ULONG k = 16381;
  59. const ULONG b = 27183;
  60. LPWSTR szThisChar;
  61. WCHAR Char;
  62. if (szCounterName) {
  63. for (szThisChar = szCounterName; * szThisChar; szThisChar ++) {
  64. Char = * szThisChar;
  65. if (_istupper(Char) ) {
  66. Char = _tolower(Char);
  67. }
  68. h = (a * h + ((ULONG) Char)) % k;
  69. a = a * b % (k - 1);
  70. }
  71. }
  72. return (h % lHashSize);
  73. }
  74. PDH_STATUS
  75. CAlertGenProp::InsertAlertToHashTable(
  76. PALERT_INFO_BLOCK paibInfo)
  77. {
  78. ULONG lHashValue;
  79. PHASH_ENTRY pEntry;
  80. PHASH_ENTRY pNewEntry = NULL;
  81. BOOLEAN bInsert = TRUE;
  82. PPDH_COUNTER_PATH_ELEMENTS pCounter = NULL;
  83. PDH_STATUS pdhStatus = ERROR_SUCCESS;
  84. // Todo: validate pointers
  85. lHashValue = HashCounter(paibInfo->szCounterPath, eHashTableSize);
  86. pEntry = m_HashTable[lHashValue];
  87. pdhStatus = AllocInitCounterPath ( paibInfo->szCounterPath, &pCounter );
  88. if (pdhStatus == ERROR_SUCCESS && pCounter ) {
  89. while (pEntry) {
  90. pdhStatus = CheckDuplicateCounterPaths(pCounter, pEntry->pCounter );
  91. if ( ( AIBF_OVER & pEntry->dwFlags ) == ( AIBF_OVER & paibInfo->dwFlags )
  92. && pEntry->dLimit == paibInfo->dLimit
  93. && ERROR_SUCCESS != pdhStatus )
  94. {
  95. pdhStatus = SMCFG_DUPL_SINGLE_PATH;
  96. bInsert = FALSE;
  97. break;
  98. }
  99. pEntry = pEntry->pNext;
  100. }
  101. if (bInsert) {
  102. // Insert at head of bucket list
  103. pNewEntry = (PHASH_ENTRY) G_ALLOC(sizeof(HASH_ENTRY));
  104. if (pNewEntry) {
  105. pNewEntry->pCounter = pCounter;
  106. pCounter = NULL;
  107. pNewEntry->dwFlags = paibInfo->dwFlags;
  108. pNewEntry->dLimit = paibInfo->dLimit;
  109. pNewEntry->pNext = m_HashTable[lHashValue];
  110. m_HashTable[lHashValue] = pNewEntry;
  111. } else {
  112. pdhStatus = PDH_MEMORY_ALLOCATION_FAILURE;
  113. bInsert = FALSE;
  114. }
  115. }
  116. } else {
  117. bInsert = FALSE;
  118. }
  119. if ( NULL != pCounter ) {
  120. G_FREE(pCounter);
  121. }
  122. if ( bInsert ) {
  123. pdhStatus = ERROR_SUCCESS;
  124. }
  125. return (pdhStatus);
  126. }
  127. void
  128. CAlertGenProp::InitAlertHashTable( void )
  129. {
  130. memset(&m_HashTable, 0, sizeof(m_HashTable));
  131. }
  132. void
  133. CAlertGenProp::ClearAlertHashTable( void )
  134. {
  135. ULONG i;
  136. PHASH_ENTRY pEntry;
  137. PHASH_ENTRY pNext;
  138. for (i = 0; i < eHashTableSize; i ++) {
  139. pNext = m_HashTable[i];
  140. while (pNext != NULL) {
  141. pEntry = pNext;
  142. pNext = pEntry->pNext;
  143. G_FREE(pEntry->pCounter);
  144. G_FREE(pEntry);
  145. }
  146. }
  147. }
  148. //
  149. // browse counters callback function
  150. //
  151. static
  152. PDH_FUNCTION
  153. DialogCallBack(CAlertGenProp *pDlg)
  154. {
  155. // add strings in buffer to list box
  156. LPWSTR NewCounterName;
  157. INT iListIndex;
  158. LONG lFirstNewIndex = LB_ERR;
  159. DWORD dwItemExtent;
  160. CListBox *pCounterList;
  161. PALERT_INFO_BLOCK paibInfo = NULL;
  162. DWORD dwIbSize;
  163. DWORD dwReturnStatus = ERROR_SUCCESS;
  164. CDC* pCDC = NULL;
  165. ResourceStateManager rsm;
  166. #define CTRBUFLIMIT (0x7fffffff)
  167. if ( PDH_MORE_DATA == pDlg->m_dlgConfig.CallBackStatus ) {
  168. if ( pDlg->m_dlgConfig.cchReturnPathLength < CTRBUFLIMIT ) {
  169. pDlg->m_dwCounterListBufferSize *= 2;
  170. delete [] pDlg->m_szCounterListBuffer;
  171. pDlg->m_szCounterListBuffer = NULL;
  172. try {
  173. pDlg->m_szCounterListBuffer = new WCHAR[pDlg->m_dwCounterListBufferSize];
  174. } catch ( ... ) {
  175. pDlg->m_dwCounterListBufferSize = 0;
  176. pDlg->m_dlgConfig.CallBackStatus = PDH_MEMORY_ALLOCATION_FAILURE;
  177. dwReturnStatus = PDH_MEMORY_ALLOCATION_FAILURE;
  178. }
  179. if ( ERROR_SUCCESS == dwReturnStatus ) {
  180. // clear buffer
  181. memset (pDlg->m_szCounterListBuffer, 0, pDlg->m_dwCounterListBufferSize);
  182. pDlg->m_dlgConfig.szReturnPathBuffer = pDlg->m_szCounterListBuffer;
  183. pDlg->m_dlgConfig.cchReturnPathLength = pDlg->m_dwCounterListBufferSize;
  184. pDlg->m_dlgConfig.CallBackStatus = PDH_RETRY;
  185. dwReturnStatus = PDH_RETRY;
  186. }
  187. } else {
  188. pDlg->m_dlgConfig.CallBackStatus = PDH_MEMORY_ALLOCATION_FAILURE;
  189. dwReturnStatus = PDH_MEMORY_ALLOCATION_FAILURE;
  190. }
  191. } else if ( ERROR_SUCCESS == pDlg->m_dlgConfig.CallBackStatus ) {
  192. pCounterList = (CListBox *)pDlg->GetDlgItem(IDC_ALRTS_COUNTER_LIST);
  193. pCDC = pCounterList->GetDC();
  194. for (NewCounterName = pDlg->m_szCounterListBuffer;
  195. *NewCounterName != 0;
  196. NewCounterName += (lstrlen(NewCounterName) + 1)) {
  197. // Allocate a buffer to hold the alert info and
  198. // add to list box
  199. dwIbSize = sizeof(ALERT_INFO_BLOCK) +
  200. ((lstrlen(NewCounterName) + 1) * sizeof(WCHAR));
  201. MFC_TRY
  202. paibInfo = (PALERT_INFO_BLOCK) new UCHAR[dwIbSize];
  203. MFC_CATCH_MINIMUM;
  204. if (paibInfo != NULL) {
  205. // load the fields
  206. paibInfo->dwSize = dwIbSize;
  207. paibInfo->szCounterPath = (LPWSTR)&paibInfo[1];
  208. paibInfo->dwFlags = AIBF_OVER; // clear all the flags, setting default to "Over"
  209. paibInfo->dLimit = CAlertGenProp::eInvalidLimit;
  210. StringCchCopy (paibInfo->szCounterPath, lstrlen(NewCounterName) + 1, NewCounterName);
  211. // Insert the new string at the end of the list box.
  212. iListIndex = pCounterList->InsertString (-1, NewCounterName );
  213. if (iListIndex != LB_ERR) {
  214. pCounterList->SetItemDataPtr (iListIndex, (LPVOID)paibInfo);
  215. if ( LB_ERR == lFirstNewIndex )
  216. lFirstNewIndex = iListIndex;
  217. // update list box extent
  218. if ( NULL != pCDC ) {
  219. dwItemExtent = (DWORD)(pCDC->GetTextExtent(NewCounterName)).cx;
  220. if (dwItemExtent > pDlg->m_dwMaxHorizListExtent) {
  221. pDlg->m_dwMaxHorizListExtent = dwItemExtent;
  222. pCounterList->SetHorizontalExtent(dwItemExtent);
  223. }
  224. }
  225. } else {
  226. dwReturnStatus = PDH_MEMORY_ALLOCATION_FAILURE;
  227. delete [] (char*)paibInfo;
  228. }
  229. } else {
  230. dwReturnStatus = PDH_MEMORY_ALLOCATION_FAILURE;
  231. }
  232. }
  233. if ( NULL != pCDC ) {
  234. pDlg->m_CounterList.ReleaseDC(pCDC);
  235. pCDC = NULL;
  236. }
  237. // select the first new entry in the list box.
  238. if (lFirstNewIndex != LB_ERR) {
  239. pCounterList->SetCurSel (lFirstNewIndex);
  240. pDlg->PublicOnSelchangeCounterList();
  241. pDlg->SetModifiedPage(); // to indicate a change
  242. }
  243. // clear buffer
  244. memset (pDlg->m_szCounterListBuffer, 0, pDlg->m_dwCounterListBufferSize);
  245. dwReturnStatus = ERROR_SUCCESS;
  246. } else {
  247. // Not successful
  248. dwReturnStatus = pDlg->m_dlgConfig.CallBackStatus;
  249. }
  250. return dwReturnStatus;
  251. }
  252. /////////////////////////////////////////////////////////////////////////////
  253. // CAlertGenProp property page
  254. IMPLEMENT_DYNCREATE(CAlertGenProp, CSmPropertyPage)
  255. CAlertGenProp::CAlertGenProp(MMC_COOKIE mmcCookie, LONG_PTR hConsole)
  256. : CSmPropertyPage ( CAlertGenProp::IDD, hConsole )
  257. {
  258. // save variables from arg list
  259. m_pAlertQuery = reinterpret_cast <CSmAlertQuery *>(mmcCookie);
  260. ASSERT ( m_pAlertQuery->CastToAlertQuery() );
  261. m_pQuery = dynamic_cast <CSmLogQuery*>(m_pAlertQuery);
  262. // init AFX variables
  263. InitAfxDataItems();
  264. // init other member variables
  265. ZeroMemory ( &m_dlgConfig, sizeof(m_dlgConfig) );
  266. m_szCounterListBuffer = NULL;
  267. m_dwCounterListBufferSize = 0L;
  268. m_ndxCurrentItem = LB_ERR; // nothing selected
  269. m_szAlertCounterList = NULL;
  270. m_cchAlertCounterListSize = 0;
  271. m_dwMaxHorizListExtent = 0;
  272. }
  273. CAlertGenProp::CAlertGenProp() : CSmPropertyPage(CAlertGenProp::IDD)
  274. {
  275. ASSERT (FALSE); // the constructor w/ args should be used instead
  276. // init variables that should be from arg list
  277. m_pAlertQuery = NULL;
  278. // init AFX variables
  279. InitAfxDataItems();
  280. // init other member variables
  281. m_szCounterListBuffer = NULL;
  282. m_dwCounterListBufferSize = 0L;
  283. m_ndxCurrentItem = LB_ERR; // nothing selected
  284. m_szAlertCounterList = NULL;
  285. m_cchAlertCounterListSize = 0;
  286. m_dwMaxHorizListExtent = 0;
  287. }
  288. CAlertGenProp::~CAlertGenProp()
  289. {
  290. if (m_szAlertCounterList != NULL) delete [] (m_szAlertCounterList);
  291. if (m_szCounterListBuffer != NULL) delete [] (m_szCounterListBuffer);
  292. }
  293. void
  294. CAlertGenProp::InitAfxDataItems()
  295. {
  296. //{{AFX_DATA_INIT(CAlertGenProp)
  297. m_dLimitValue = eInvalidLimit;
  298. m_nSampleUnits = 0;
  299. //}}AFX_DATA_INIT
  300. }
  301. void
  302. CAlertGenProp::DoDataExchange(CDataExchange* pDX)
  303. {
  304. HWND hWndCtrl = NULL;
  305. CString strTemp;
  306. WCHAR szT[MAXSTR];
  307. LPWSTR szStop;
  308. DOUBLE dTemp;
  309. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  310. CPropertyPage::DoDataExchange(pDX);
  311. //{{AFX_DATA_MAP(CAlertGenProp)
  312. DDX_Control(pDX, IDC_ALRTS_SAMPLE_UNITS_COMBO, m_SampleUnitsCombo);
  313. DDX_Control(pDX, IDC_ALRTS_OVER_UNDER, m_OverUnderCombo);
  314. DDX_Control(pDX, IDC_ALRTS_COUNTER_LIST, m_CounterList);
  315. ValidateTextEdit(pDX, IDC_ALRTS_SAMPLE_EDIT, 6, &m_SharedData.stiSampleTime.dwValue, eMinSampleInterval, eMaxSampleInterval);
  316. DDX_CBIndex(pDX, IDC_ALRTS_SAMPLE_UNITS_COMBO, m_nSampleUnits);
  317. DDX_Text(pDX, IDC_ALRTS_COMMENT_EDIT, m_strComment);
  318. DDV_MaxChars(pDX, m_strComment, 255);
  319. DDX_Text(pDX, IDC_ALRTS_START_STRING, m_strStartDisplay);
  320. DDX_Text(pDX, IDC_RUNAS_EDIT, m_strUserDisplay );
  321. //}}AFX_DATA_MAP
  322. //
  323. // User defined DDX
  324. //
  325. if ( pDX->m_bSaveAndValidate ) {
  326. m_SharedData.stiSampleTime.dwUnitType =
  327. (DWORD)((CComboBox *)GetDlgItem(IDC_ALRTS_SAMPLE_UNITS_COMBO))->
  328. GetItemData(m_nSampleUnits);
  329. }
  330. // Alert limit value
  331. {
  332. hWndCtrl = pDX->PrepareEditCtrl(IDC_ALRTS_VALUE_EDIT);
  333. if (pDX->m_bSaveAndValidate) {
  334. ::GetWindowText(hWndCtrl, szT, MAXSTR);
  335. strTemp = szT;
  336. DDV_MaxChars(pDX, strTemp, 23);
  337. if (szT[0] == L'.' || (szT[0] >= L'0' && szT[0] <= L'9')) {
  338. dTemp = _tcstod(szT, & szStop);
  339. if ( HUGE_VAL != dTemp ) {
  340. m_dLimitValue = dTemp;
  341. } else {
  342. StringCchPrintf ( szT, MAXSTR, L"%.*g", DBL_DIG, m_dLimitValue );
  343. strTemp.Format (IDS_ALERT_CHECK_LIMIT_VALUE, DBL_MAX );
  344. MessageBox (strTemp, m_pAlertQuery->GetLogName(), MB_OK | MB_ICONERROR);
  345. GetDlgItem(IDC_ALRTS_VALUE_EDIT)->SetWindowText(szT);
  346. GetDlgItem(IDC_ALRTS_VALUE_EDIT)->SetFocus();
  347. }
  348. } else {
  349. m_dLimitValue = eInvalidLimit;
  350. }
  351. } else {
  352. if ( eInvalidLimit != m_dLimitValue ) {
  353. StringCchPrintf ( szT, MAXSTR, L"%.*g", DBL_DIG, m_dLimitValue );
  354. } else {
  355. // Display NULL string for invalid limit value.
  356. szT[0] = L'\0';
  357. }
  358. GetDlgItem(IDC_ALRTS_VALUE_EDIT)->SetWindowText(szT);
  359. }
  360. }
  361. }
  362. void
  363. CAlertGenProp::ImplementAdd()
  364. {
  365. LONG lBeforeCount;
  366. LONG lAfterCount;
  367. CString strText;
  368. CString strBrowseTitle;
  369. CString strDefaultPath;
  370. CString strObjCounter;
  371. ResourceStateManager rsm;
  372. static DWORD sdwDefaultBufferListSize = 0x4000;
  373. if (m_szCounterListBuffer == NULL) {
  374. MFC_TRY
  375. strObjCounter.LoadString ( IDS_DEFAULT_PATH_OBJ_CTR );
  376. m_dwCounterListBufferSize = sdwDefaultBufferListSize;
  377. m_szCounterListBuffer = new WCHAR[m_dwCounterListBufferSize];
  378. if ( ((CSmLogService*)m_pAlertQuery->GetLogService())->IsLocalMachine() ) {
  379. strDefaultPath = L"\\";
  380. } else {
  381. strDefaultPath = L"\\\\";
  382. strDefaultPath += ((CSmLogService*)m_pAlertQuery->GetLogService())->GetMachineName();
  383. }
  384. strDefaultPath += strObjCounter;
  385. MFC_CATCH_MINIMUM;
  386. if ( NULL != m_szCounterListBuffer && !strDefaultPath.IsEmpty() ) {
  387. StringCchCopy ( m_szCounterListBuffer, m_dwCounterListBufferSize, strDefaultPath );
  388. } else {
  389. m_dwCounterListBufferSize = 0;
  390. return;
  391. }
  392. }
  393. m_dlgConfig.bIncludeInstanceIndex = 1;
  394. m_dlgConfig.bLocalCountersOnly = 0;
  395. m_dlgConfig.bSingleCounterPerAdd = 0;
  396. m_dlgConfig.bSingleCounterPerDialog = 0;
  397. // disallow wild cards.
  398. m_dlgConfig.bWildCardInstances = 0;
  399. m_dlgConfig.bHideDetailBox = 1;
  400. m_dlgConfig.bInitializePath = 1;
  401. m_dlgConfig.bDisableMachineSelection = 0;
  402. m_dlgConfig.bIncludeCostlyObjects = 0;
  403. m_dlgConfig.bReserved = 0;
  404. m_dlgConfig.hWndOwner = this->m_hWnd;
  405. m_dlgConfig.szDataSource = NULL;
  406. m_dlgConfig.szReturnPathBuffer = m_szCounterListBuffer;
  407. m_dlgConfig.cchReturnPathLength = m_dwCounterListBufferSize;
  408. m_dlgConfig.pCallBack = (CounterPathCallBack)DialogCallBack;
  409. m_dlgConfig.dwDefaultDetailLevel = PERF_DETAIL_WIZARD;
  410. m_dlgConfig.dwCallBackArg = (UINT_PTR)this;
  411. strBrowseTitle.LoadString ( IDS_ADD_COUNTERS );
  412. m_dlgConfig.szDialogBoxCaption = strBrowseTitle.GetBuffer( strBrowseTitle.GetLength() );
  413. // get count of items in the list box before calling the browser
  414. lBeforeCount = m_CounterList.GetCount();
  415. PdhBrowseCountersW (&m_dlgConfig);
  416. strBrowseTitle.ReleaseBuffer();
  417. // get count of items in the list box After calling the browser
  418. // to see if the Apply button should enabled
  419. lAfterCount = m_CounterList.GetCount();
  420. if (lAfterCount > lBeforeCount)
  421. SetModifiedPage(TRUE);
  422. // see if the remove button should be enabled
  423. GetDlgItem (IDC_ALRTS_REMOVE_BTN)->EnableWindow(
  424. lAfterCount > 0 ? TRUE : FALSE);
  425. delete [] m_szCounterListBuffer;
  426. m_szCounterListBuffer = NULL;
  427. m_dwCounterListBufferSize = 0;
  428. GetDlgItem(IDC_ALRTS_VALUE_EDIT)->SetFocus();
  429. SetButtonState ();
  430. }
  431. BEGIN_MESSAGE_MAP(CAlertGenProp, CSmPropertyPage)
  432. //{{AFX_MSG_MAP(CAlertGenProp)
  433. ON_BN_CLICKED(IDC_ALRTS_ADD_BTN, OnAddBtn)
  434. ON_LBN_DBLCLK(IDC_ALRTS_COUNTER_LIST, OnDblclkAlrtsCounterList)
  435. ON_BN_CLICKED(IDC_ALRTS_REMOVE_BTN, OnRemoveBtn)
  436. ON_LBN_SELCHANGE(IDC_ALRTS_COUNTER_LIST, OnSelchangeCounterList)
  437. ON_EN_CHANGE(IDC_ALRTS_COMMENT_EDIT, OnCommentEditChange)
  438. ON_EN_KILLFOCUS(IDC_ALRTS_COMMENT_EDIT, OnCommentEditKillFocus)
  439. ON_NOTIFY(UDN_DELTAPOS, IDC_ALRTS_SAMPLE_SPIN, OnDeltaposSampleSpin)
  440. ON_CBN_SELENDOK(IDC_ALRTS_SAMPLE_UNITS_COMBO, OnSelendokSampleUnitsCombo)
  441. ON_EN_CHANGE( IDC_RUNAS_EDIT, OnChangeUser )
  442. ON_EN_CHANGE(IDC_ALRTS_SAMPLE_EDIT, OnSampleTimeChanged)
  443. ON_EN_KILLFOCUS(IDC_ALRTS_SAMPLE_EDIT, OnSampleTimeChanged)
  444. ON_CBN_SELENDOK(IDC_ALRTS_OVER_UNDER, OnKillFocusUpdateAlertData)
  445. ON_CBN_KILLFOCUS (IDC_ALRTS_OVER_UNDER, OnKillFocusUpdateAlertData)
  446. ON_EN_CHANGE(IDC_ALRTS_VALUE_EDIT, OnChangeAlertValueEdit)
  447. ON_EN_KILLFOCUS (IDC_ALRTS_VALUE_EDIT, OnKillFocusUpdateAlertData)
  448. ON_BN_CLICKED(IDC_SETPWD_BTN, OnPwdBtn)
  449. ON_WM_CLOSE()
  450. //}}AFX_MSG_MAP
  451. END_MESSAGE_MAP()
  452. /////////////////////////////////////////////////////////////////////////////
  453. // CAlertGenProp message handlers
  454. void
  455. CAlertGenProp::OnChangeUser()
  456. {
  457. //
  458. // If you can not access remote WBEM, you can not modify RunAs info,
  459. // changing the user name is not allowed.
  460. //
  461. if (m_bCanAccessRemoteWbem) {
  462. // When the user hits OK in the password dialog,
  463. // the user name might not have changed.
  464. UpdateData ( TRUE );
  465. m_strUserDisplay.TrimLeft();
  466. m_strUserDisplay.TrimRight();
  467. if ( 0 != m_strUserSaved.Compare ( m_strUserDisplay ) ) {
  468. m_pAlertQuery->m_fDirtyPassword = PASSWORD_DIRTY;
  469. SetModifiedPage(TRUE);
  470. }
  471. else {
  472. m_pAlertQuery->m_fDirtyPassword &= ~PASSWORD_DIRTY;
  473. }
  474. //
  475. // If default user is typed, never need to set password
  476. //
  477. if (m_strUserDisplay.IsEmpty() || m_strUserDisplay.GetAt(0) == L'<') {
  478. if (m_bPwdButtonEnabled) {
  479. GetDlgItem(IDC_SETPWD_BTN)->EnableWindow(FALSE);
  480. m_bPwdButtonEnabled = FALSE;
  481. }
  482. }
  483. else {
  484. if (!m_bPwdButtonEnabled) {
  485. GetDlgItem(IDC_SETPWD_BTN)->EnableWindow(TRUE);
  486. m_bPwdButtonEnabled = TRUE;
  487. }
  488. }
  489. }
  490. else {
  491. //
  492. // We can not modify the RunAs info, then display
  493. // an error message and retore the original user name in RunAs
  494. //
  495. UpdateData(TRUE);
  496. if (ConnectRemoteWbemFail(m_pAlertQuery, FALSE)) {
  497. GetDlgItem(IDC_RUNAS_EDIT)->SetWindowText(m_strUserSaved);
  498. }
  499. }
  500. }
  501. void
  502. CAlertGenProp::OnPwdBtn()
  503. {
  504. CString strTempUser;
  505. UpdateData();
  506. if (!m_bCanAccessRemoteWbem) {
  507. ConnectRemoteWbemFail(m_pAlertQuery, TRUE);
  508. return;
  509. }
  510. MFC_TRY
  511. strTempUser = m_strUserDisplay;
  512. m_strUserDisplay.TrimLeft();
  513. m_strUserDisplay.TrimRight();
  514. m_pAlertQuery->m_strUser = m_strUserDisplay;
  515. SetRunAs(m_pAlertQuery);
  516. m_strUserDisplay = m_pAlertQuery->m_strUser;
  517. if ( 0 != strTempUser.CompareNoCase ( m_strUserDisplay ) ) {
  518. SetDlgItemText ( IDC_RUNAS_EDIT, m_strUserDisplay );
  519. }
  520. MFC_CATCH_MINIMUM;
  521. }
  522. void
  523. CAlertGenProp::OnAddBtn()
  524. {
  525. ImplementAdd();
  526. return;
  527. }
  528. void
  529. CAlertGenProp::OnDblclkAlrtsCounterList()
  530. {
  531. ImplementAdd();
  532. return;
  533. }
  534. void
  535. CAlertGenProp::OnRemoveBtn()
  536. {
  537. PALERT_INFO_BLOCK paibInfo;
  538. INT nCurSel;
  539. INT nLbItemCount;
  540. BOOL bChanged = FALSE;
  541. DWORD dwItemExtent;
  542. INT iIndex;
  543. LPWSTR szPath= NULL;
  544. LONG lSize = 0;
  545. CDC* pCDC = NULL;
  546. nLbItemCount = m_CounterList.GetCount();
  547. nCurSel = m_CounterList.GetCurSel();
  548. if (nCurSel != LB_ERR) {
  549. paibInfo = (PALERT_INFO_BLOCK)m_CounterList.GetItemDataPtr(nCurSel);
  550. if ( paibInfo != NULL )
  551. delete [] (char*)paibInfo;
  552. if ( LB_ERR != m_CounterList.DeleteString(nCurSel) ) {
  553. // clear the max extent
  554. m_dwMaxHorizListExtent = 0;
  555. szPath = new WCHAR [PDH_MAX_COUNTER_PATH+1];
  556. if (szPath == NULL) {
  557. return;
  558. }
  559. lSize = PDH_MAX_COUNTER_PATH;
  560. pCDC = m_CounterList.GetDC();
  561. if ( NULL != pCDC ) {
  562. for ( iIndex = 0; iIndex < m_CounterList.GetCount(); iIndex++ ) {
  563. if (m_CounterList.GetTextLen(iIndex) > lSize) {
  564. lSize = max(m_CounterList.GetTextLen(iIndex) + 1, lSize * 2);
  565. delete [] szPath;
  566. szPath = new WCHAR [lSize];
  567. if (szPath == NULL) {
  568. m_CounterList.ReleaseDC(pCDC);
  569. return;
  570. }
  571. }
  572. if ( 0 < m_CounterList.GetText( iIndex, szPath ) ) {
  573. dwItemExtent = (DWORD)(pCDC->GetTextExtent (szPath)).cx;
  574. if (dwItemExtent > m_dwMaxHorizListExtent) {
  575. m_dwMaxHorizListExtent = dwItemExtent;
  576. m_CounterList.SetHorizontalExtent(dwItemExtent);
  577. }
  578. }
  579. }
  580. if (nCurSel == (nLbItemCount - 1)) {
  581. // then the last item was deleted so select the new "last"
  582. if ( 0 == nCurSel ) {
  583. nCurSel = LB_ERR;
  584. } else {
  585. nCurSel--;
  586. }
  587. } //else the current selection should still be in the list box
  588. m_CounterList.SetCurSel (nCurSel);
  589. m_ndxCurrentItem = nCurSel;
  590. LoadAlertItemData (nCurSel);
  591. bChanged = TRUE;
  592. }
  593. if ( NULL != pCDC ) {
  594. m_CounterList.ReleaseDC(pCDC);
  595. pCDC = NULL;
  596. }
  597. if ( szPath ) {
  598. delete [] szPath;
  599. }
  600. }
  601. }
  602. SetButtonState();
  603. SetModifiedPage(bChanged);
  604. }
  605. void
  606. CAlertGenProp::OnDeltaposSampleSpin(NMHDR* pNMHDR, LRESULT* pResult)
  607. {
  608. OnDeltaposSpin(pNMHDR, pResult, &m_SharedData.stiSampleTime.dwValue, eMinSampleInterval, eMaxSampleInterval);
  609. }
  610. void
  611. CAlertGenProp::OnSelendokSampleUnitsCombo()
  612. {
  613. int nSel;
  614. nSel = ((CComboBox *)GetDlgItem(IDC_ALRTS_SAMPLE_UNITS_COMBO))->GetCurSel();
  615. if ((nSel != LB_ERR) && (nSel != m_nSampleUnits)) {
  616. UpdateData ( TRUE );
  617. SetModifiedPage ( TRUE );
  618. }
  619. }
  620. void CAlertGenProp::OnSampleTimeChanged()
  621. {
  622. DWORD dwOldValue;
  623. dwOldValue = m_SharedData.stiSampleTime.dwValue;
  624. UpdateData ( TRUE );
  625. if (dwOldValue != m_SharedData.stiSampleTime.dwValue) {
  626. SetModifiedPage(TRUE);
  627. }
  628. }
  629. void CAlertGenProp::OnChangeAlertValueEdit()
  630. {
  631. SaveAlertItemData();
  632. }
  633. void CAlertGenProp::PublicOnSelchangeCounterList()
  634. {
  635. OnSelchangeCounterList();
  636. }
  637. void CAlertGenProp::OnKillFocusUpdateAlertData()
  638. {
  639. SaveAlertItemData();
  640. }
  641. void CAlertGenProp::OnSelchangeCounterList()
  642. {
  643. INT nCurSel;
  644. nCurSel = m_CounterList.GetCurSel();
  645. if (nCurSel != LB_ERR) {
  646. // Save the data from the previous item.
  647. SaveAlertItemData();
  648. // Load the data from the new item.
  649. LoadAlertItemData(nCurSel);
  650. } else {
  651. // clear the fields
  652. m_dLimitValue=eInvalidLimit;
  653. UpdateData(FALSE);
  654. }
  655. }
  656. void
  657. CAlertGenProp::UpdateAlertStartString ()
  658. {
  659. eStartType eCurrentStartType;
  660. int nResId = 0;
  661. ResourceStateManager rsm;
  662. eCurrentStartType = DetermineCurrentStartType();
  663. if ( eStartManually == eCurrentStartType ) {
  664. nResId = IDS_ALERT_START_MANUALLY;
  665. } else if ( eStartImmediately == eCurrentStartType ) {
  666. nResId = IDS_ALERT_START_IMMED;
  667. } else if ( eStartSched == eCurrentStartType ) {
  668. nResId = IDS_ALERT_START_SCHED;
  669. }
  670. if ( 0 != nResId ) {
  671. m_strStartDisplay.LoadString(nResId);
  672. } else {
  673. m_strStartDisplay.Empty();
  674. }
  675. return;
  676. }
  677. BOOL
  678. CAlertGenProp::IsValidLocalData()
  679. {
  680. BOOL bIsValid = FALSE;
  681. INT nInvalidIndex = -1;
  682. PDH_STATUS pdhStatus = ERROR_SUCCESS;
  683. PALERT_INFO_BLOCK paibInfo;
  684. int iListCount;
  685. int iIndex;
  686. BOOL bInsert;
  687. BOOL bAtLeastOneDuplicateCounter = FALSE;
  688. BOOL bSelectionDeleted = FALSE;
  689. CString strText;
  690. // test to see if there are any counters in the list box
  691. if (m_CounterList.GetCount() > 0) {
  692. if ( GetDlgItem(IDC_ALRTS_VALUE_EDIT) == GetFocus() ) {
  693. SaveAlertItemData(); // Set the Is Saved flag for this value.
  694. }
  695. bIsValid = LoadListFromDlg(&nInvalidIndex, TRUE);
  696. if ( ((!bIsValid) && (nInvalidIndex != -1))
  697. || ((m_dLimitValue < 0.0) || (m_dLimitValue > DBL_MAX)))
  698. {
  699. // then one of the list items has not been reviewed
  700. // by the user so remind them
  701. strText.Format (IDS_ALERT_CHECK_LIMITS, DBL_MAX );
  702. MessageBox (strText, m_pAlertQuery->GetLogName(), MB_OK | MB_ICONERROR);
  703. m_CounterList.SetCurSel(nInvalidIndex);
  704. OnSelchangeCounterList();
  705. SetFocusAnyPage ( IDC_ALRTS_VALUE_EDIT );
  706. bIsValid = FALSE;
  707. } else {
  708. // Eliminate duplicate alert paths, then reload the list
  709. iListCount = m_CounterList.GetCount();
  710. if ( LB_ERR != iListCount ) {
  711. InitAlertHashTable ( );
  712. // Walk the list backwards to delete duplicate items.
  713. for ( iIndex = iListCount - 1; iIndex >= 0; iIndex-- ) {
  714. paibInfo = (PALERT_INFO_BLOCK)m_CounterList.GetItemDataPtr(iIndex);
  715. if ( NULL != paibInfo ) {
  716. pdhStatus = InsertAlertToHashTable ( paibInfo );
  717. if (SMCFG_DUPL_SINGLE_PATH == pdhStatus) {
  718. bAtLeastOneDuplicateCounter = TRUE;
  719. }
  720. bInsert = (pdhStatus == ERROR_SUCCESS) ? TRUE : FALSE;
  721. } else {
  722. bInsert = FALSE;
  723. }
  724. //
  725. // If the item is duplicated, then remove it
  726. //
  727. if (! bInsert) {
  728. // Set item data pointer to NULL because
  729. // SaveAlertItemData can be called after this.
  730. // Clear the selection if >= current index.
  731. if ( m_ndxCurrentItem >= iIndex ) {
  732. m_ndxCurrentItem = LB_ERR;
  733. bSelectionDeleted = TRUE;
  734. }
  735. m_CounterList.SetItemDataPtr(iIndex, NULL);
  736. m_CounterList.DeleteString(iIndex);
  737. delete [] (char*)paibInfo;
  738. }
  739. //
  740. // Display error code other than duplicated counter in loop
  741. //
  742. if ( SMCFG_DUPL_SINGLE_PATH != pdhStatus && ERROR_SUCCESS != pdhStatus) {
  743. // Message box Pdh error message, go on to next
  744. CString strMsg;
  745. CString strPdhMessage;
  746. FormatSystemMessage ( pdhStatus, strPdhMessage );
  747. MFC_TRY
  748. strMsg.Format ( IDS_CTRS_PDH_ERROR, paibInfo->szCounterPath );
  749. strMsg += strPdhMessage;
  750. MFC_CATCH_MINIMUM
  751. MessageBox ( strMsg, m_pAlertQuery->GetLogName(), MB_OK | MB_ICONERROR);
  752. }
  753. }
  754. ClearAlertHashTable ( );
  755. //
  756. // If there is at least one duplicated case, display the error message
  757. // outside the loop above
  758. //
  759. if ( bAtLeastOneDuplicateCounter ) {
  760. CString strMsg;
  761. strMsg.LoadString ( IDS_ALERT_DUPL_PATH );
  762. MessageBox ( strMsg, m_pAlertQuery->GetLogName(), MB_OK | MB_ICONWARNING);
  763. // Only deleting duplicates, so no need to recalculate the max extent
  764. // Reset the selection if necessary
  765. if ( bSelectionDeleted && LB_ERR == m_ndxCurrentItem ) {
  766. if (m_CounterList.GetCount() > 0) {
  767. m_CounterList.SetCurSel (0);
  768. m_ndxCurrentItem = 0;
  769. SetFocusAnyPage ( IDC_ALRTS_COUNTER_LIST );
  770. LoadAlertItemData (0);
  771. }
  772. }
  773. }
  774. bIsValid = LoadListFromDlg ( &nInvalidIndex );
  775. assert ( bIsValid );
  776. }
  777. }
  778. } else {
  779. // the counter list is empty
  780. strText.LoadString (IDS_NO_COUNTERS);
  781. MessageBox (strText, m_pAlertQuery->GetLogName(), MB_OK | MB_ICONERROR);
  782. SetFocusAnyPage ( IDC_ALRTS_ADD_BTN );
  783. bIsValid = FALSE;
  784. }
  785. if (bIsValid)
  786. {
  787. bIsValid = ValidateDWordInterval(IDC_ALRTS_SAMPLE_EDIT,
  788. m_pAlertQuery->GetLogName(),
  789. (long) m_SharedData.stiSampleTime.dwValue,
  790. eMinSampleInterval,
  791. eMaxSampleInterval);
  792. }
  793. if (bIsValid) {
  794. // Validate sample interval value and unit type
  795. bIsValid = SampleIntervalIsInRange(
  796. m_SharedData.stiSampleTime,
  797. m_pAlertQuery->GetLogName() );
  798. if ( !bIsValid ) {
  799. SetFocusAnyPage ( IDC_ALRTS_SAMPLE_EDIT );
  800. }
  801. }
  802. return bIsValid;
  803. }
  804. BOOL
  805. CAlertGenProp::OnSetActive()
  806. {
  807. BOOL bReturn;
  808. bReturn = CSmPropertyPage::OnSetActive();
  809. if (!bReturn) return FALSE;
  810. ResourceStateManager rsm;
  811. m_pAlertQuery->GetPropPageSharedData ( &m_SharedData );
  812. UpdateAlertStartString();
  813. m_strUserDisplay = m_pAlertQuery->m_strUser;
  814. UpdateData(FALSE); //to load the static string.
  815. return TRUE;
  816. }
  817. BOOL
  818. CAlertGenProp::OnKillActive()
  819. {
  820. BOOL bContinue = TRUE;
  821. ResourceStateManager rsm;
  822. // Parent class OnKillActive calls UpdateData(TRUE)
  823. bContinue = CPropertyPage::OnKillActive();
  824. if ( bContinue ) {
  825. m_pAlertQuery->m_strUser = m_strUserDisplay;
  826. bContinue = IsValidData(m_pAlertQuery, VALIDATE_FOCUS);
  827. if ( bContinue ) {
  828. // Save property page shared data.
  829. m_pAlertQuery->SetPropPageSharedData ( &m_SharedData );
  830. }
  831. }
  832. if ( bContinue ) {
  833. SetIsActive ( FALSE );
  834. }
  835. return bContinue;
  836. }
  837. BOOL
  838. CAlertGenProp::OnApply()
  839. {
  840. BOOL bContinue = TRUE;
  841. CString strText;
  842. ResourceStateManager rsm;
  843. bContinue = UpdateData(TRUE);
  844. if ( bContinue ) {
  845. bContinue = IsValidData(m_pAlertQuery, VALIDATE_APPLY );
  846. }
  847. if ( bContinue ) {
  848. bContinue = SampleTimeIsLessThanSessionTime( m_pAlertQuery );
  849. if ( !bContinue ) {
  850. SetFocusAnyPage ( IDC_ALRTS_SAMPLE_EDIT );
  851. }
  852. }
  853. // Write the data to the query.
  854. if ( bContinue ) {
  855. // send the list to the parent query
  856. // update counter list
  857. m_pAlertQuery->SetCounterList( m_szAlertCounterList, m_cchAlertCounterListSize );
  858. m_pAlertQuery->SetLogComment ( m_strComment );
  859. // Sample interval
  860. ASSERT ( SLQ_TT_TTYPE_SAMPLE == m_SharedData.stiSampleTime.wTimeType );
  861. ASSERT ( SLQ_TT_DTYPE_UNITS == m_SharedData.stiSampleTime.wDataType );
  862. // update counter sample interval
  863. bContinue = m_pAlertQuery->SetLogTime (&m_SharedData.stiSampleTime, (DWORD)m_SharedData.stiSampleTime.wTimeType);
  864. }
  865. if ( bContinue ) {
  866. // ApplyRunAs must be called before UpdateService
  867. bContinue = ApplyRunAs(m_pAlertQuery);
  868. }
  869. if (bContinue) {
  870. bContinue = CSmPropertyPage::OnApply();
  871. }
  872. if (bContinue) {
  873. // Save property page shared data.
  874. m_pAlertQuery->UpdatePropPageSharedData();
  875. bContinue = UpdateService ( m_pAlertQuery, FALSE );
  876. }
  877. return bContinue;
  878. }
  879. void CAlertGenProp::OnCancel()
  880. {
  881. m_pAlertQuery->SyncPropPageSharedData(); // clear memory shared between property pages.
  882. }
  883. void CAlertGenProp::OnClose()
  884. {
  885. // free the item data pointers from the list box
  886. INT nNumItems;
  887. INT nCurSel;
  888. PALERT_INFO_BLOCK paibInfo;
  889. nNumItems = m_CounterList.GetCount();
  890. if (nNumItems != LB_ERR) {
  891. for (nCurSel = 0; nCurSel < nNumItems; nCurSel++) {
  892. paibInfo = (PALERT_INFO_BLOCK)m_CounterList.GetItemDataPtr(nCurSel);
  893. if (paibInfo != NULL) {
  894. delete [] (char*)paibInfo;
  895. m_CounterList.SetItemDataPtr(nCurSel, NULL);
  896. }
  897. }
  898. }
  899. CPropertyPage::OnClose();
  900. }
  901. void CAlertGenProp::PostNcDestroy()
  902. {
  903. // delete this;
  904. if ( NULL != m_pAlertQuery ) {
  905. m_pAlertQuery->SetActivePropertyPage( NULL );
  906. }
  907. CPropertyPage::PostNcDestroy();
  908. }
  909. BOOL CAlertGenProp::SaveAlertItemData ()
  910. {
  911. // update the info block to reflect the current values
  912. PALERT_INFO_BLOCK paibInfo;
  913. BOOL bReturn = FALSE;
  914. CComboBox* pOverUnder;
  915. INT nCurSel;
  916. DWORD dwFlags;
  917. pOverUnder = (CComboBox *)GetDlgItem(IDC_ALRTS_OVER_UNDER);
  918. if ((pOverUnder != NULL) && (m_ndxCurrentItem != LB_ERR)) {
  919. nCurSel = m_ndxCurrentItem;
  920. if (nCurSel != LB_ERR) {
  921. paibInfo = (PALERT_INFO_BLOCK)m_CounterList.GetItemDataPtr(nCurSel);
  922. if (paibInfo != NULL) {
  923. DWORD dwOldFlags;
  924. double dOldLimit;
  925. dwOldFlags = paibInfo->dwFlags;
  926. dOldLimit = paibInfo->dLimit;
  927. if (UpdateData(TRUE)) {
  928. paibInfo->dLimit = m_dLimitValue;
  929. dwFlags = (pOverUnder->GetCurSel() == OU_OVER) ? AIBF_OVER : 0;
  930. if ( eInvalidLimit < paibInfo->dLimit ) {
  931. dwFlags |= AIBF_SAVED;
  932. }
  933. paibInfo->dwFlags = dwFlags;
  934. if ( ( dOldLimit != m_dLimitValue )
  935. || ( dwOldFlags & AIBF_OVER ) != ( dwFlags & AIBF_OVER ) ) {
  936. SetModifiedPage(); // to indicate a change
  937. }
  938. bReturn = TRUE;
  939. }
  940. }
  941. }
  942. }
  943. return bReturn;
  944. }
  945. BOOL CAlertGenProp::LoadAlertItemData (INT nIndex)
  946. {
  947. // update the info block to reflect the current values
  948. PALERT_INFO_BLOCK paibInfo;
  949. BOOL bReturn = FALSE;
  950. CComboBox* pOverUnder;
  951. INT nCurSel;
  952. pOverUnder = (CComboBox *)GetDlgItem(IDC_ALRTS_OVER_UNDER);
  953. if ( pOverUnder != NULL ) {
  954. nCurSel = m_CounterList.GetCurSel();
  955. if (nCurSel != LB_ERR) {
  956. paibInfo = (PALERT_INFO_BLOCK)m_CounterList.GetItemDataPtr(nCurSel);
  957. if (paibInfo != NULL) {
  958. pOverUnder->SetCurSel(
  959. ((paibInfo->dwFlags & AIBF_OVER) == AIBF_OVER) ? OU_OVER : OU_UNDER);
  960. m_dLimitValue = paibInfo->dLimit;
  961. m_ndxCurrentItem = nIndex;
  962. // If the data is loaded from a property bag, the limit might not have been seen.
  963. if ( eInvalidLimit < m_dLimitValue ) {
  964. paibInfo->dwFlags |= AIBF_SEEN;
  965. }
  966. UpdateData(FALSE);
  967. bReturn = TRUE;
  968. }
  969. }
  970. }
  971. return bReturn;
  972. }
  973. BOOL CAlertGenProp::SetButtonState ()
  974. {
  975. BOOL bState;
  976. // enable the windows base on whether or not the list box
  977. // has any contents
  978. bState = (m_CounterList.GetCount() > 0);
  979. GetDlgItem(IDC_ALRTS_TRIGGER_CAPTION)->EnableWindow(bState);
  980. GetDlgItem(IDC_ALRTS_TRIGGER_VALUE_CAPTION)->EnableWindow(bState);
  981. GetDlgItem(IDC_ALRTS_OVER_UNDER)->EnableWindow(bState);
  982. GetDlgItem(IDC_ALRTS_VALUE_EDIT)->EnableWindow(bState);
  983. GetDlgItem(IDC_ALRTS_REMOVE_BTN)->EnableWindow(bState);
  984. GetDlgItem(IDC_ALRTS_SAMPLE_EDIT)->EnableWindow(bState);
  985. GetDlgItem(IDC_ALRTS_SAMPLE_CAPTION)->EnableWindow(bState);
  986. GetDlgItem(IDC_ALRTS_SAMPLE_INTERVAL_CAPTION)->EnableWindow(bState);
  987. GetDlgItem(IDC_ALRTS_SAMPLE_SPIN)->EnableWindow(bState);
  988. GetDlgItem(IDC_ALRTS_SAMPLE_UNITS_CAPTION)->EnableWindow(bState);
  989. GetDlgItem(IDC_ALRTS_SAMPLE_UNITS_COMBO)->EnableWindow(bState);
  990. if (m_pAlertQuery->GetLogService()->TargetOs() == OS_WIN2K) {
  991. GetDlgItem(IDC_RUNAS_STATIC)->EnableWindow(FALSE);
  992. GetDlgItem(IDC_RUNAS_EDIT)->EnableWindow(FALSE);
  993. }
  994. if (m_pAlertQuery->GetLogService()->TargetOs() == OS_WIN2K ||
  995. m_strUserDisplay.IsEmpty() ||
  996. m_strUserDisplay.GetAt(0) == L'<') {
  997. GetDlgItem(IDC_SETPWD_BTN)->EnableWindow(FALSE);
  998. m_bPwdButtonEnabled = FALSE;
  999. }
  1000. return bState;
  1001. }
  1002. BOOL CAlertGenProp::LoadDlgFromList ()
  1003. {
  1004. BOOL bReturn = TRUE;
  1005. LPWSTR szThisString = NULL;
  1006. DWORD dwBufSize;
  1007. DWORD dwThisStringLen;
  1008. UINT nIndex;
  1009. DWORD dwItemExtent;
  1010. CDC* pCDC = NULL;
  1011. PALERT_INFO_BLOCK paibInfo = NULL;
  1012. if (m_szAlertCounterList != NULL) {
  1013. pCDC = m_CounterList.GetDC();
  1014. if ( NULL != pCDC ) {
  1015. for (szThisString = m_szAlertCounterList;
  1016. *szThisString != 0 && TRUE == bReturn;
  1017. szThisString += dwThisStringLen +1) {
  1018. dwThisStringLen = lstrlen(szThisString);
  1019. dwBufSize = sizeof (ALERT_INFO_BLOCK) + ((dwThisStringLen + 1) * sizeof (WCHAR));
  1020. MFC_TRY
  1021. paibInfo = (PALERT_INFO_BLOCK) new CHAR[dwBufSize];
  1022. MFC_CATCH_MINIMUM;
  1023. if (paibInfo != NULL) {
  1024. if (MakeInfoFromString(szThisString, paibInfo, &dwBufSize)) {
  1025. if ( 0 <= paibInfo->dLimit ) {
  1026. paibInfo->dwFlags |= AIBF_SAVED;
  1027. }
  1028. nIndex = m_CounterList.AddString(paibInfo->szCounterPath);
  1029. if (nIndex != LB_ERR) {
  1030. m_CounterList.SetItemDataPtr (nIndex, (LPVOID)paibInfo);
  1031. // update list box extent
  1032. if ( NULL != pCDC ) {
  1033. dwItemExtent = (DWORD)(pCDC->GetTextExtent (paibInfo->szCounterPath)).cx;
  1034. if (dwItemExtent > m_dwMaxHorizListExtent) {
  1035. m_dwMaxHorizListExtent = dwItemExtent;
  1036. m_CounterList.SetHorizontalExtent(dwItemExtent);
  1037. }
  1038. }
  1039. paibInfo = NULL;
  1040. } else {
  1041. delete [] (char*)paibInfo;
  1042. bReturn = FALSE;
  1043. }
  1044. } else {
  1045. delete [] (char*)paibInfo;
  1046. bReturn = FALSE;
  1047. }
  1048. } else {
  1049. bReturn = FALSE;
  1050. }
  1051. }
  1052. }
  1053. }
  1054. if ( NULL != pCDC ) {
  1055. m_CounterList.ReleaseDC(pCDC);
  1056. pCDC = NULL;
  1057. }
  1058. // Todo: Error message on failure
  1059. return bReturn;
  1060. }
  1061. BOOL CAlertGenProp::LoadListFromDlg ( INT *piInvalidEntry, BOOL bInvalidateOnly )
  1062. {
  1063. INT nNumItems;
  1064. INT nCurSel;
  1065. PALERT_INFO_BLOCK paibInfo;
  1066. DWORD dwSizeReqd = 0;
  1067. DWORD dwSize;
  1068. DWORD dwSizeLeft = 0;
  1069. LPWSTR szNextString;
  1070. BOOL bReturn = TRUE;
  1071. nNumItems = m_CounterList.GetCount();
  1072. if ((nNumItems != LB_ERR) && (nNumItems > 0)) {
  1073. // find size required for buffer
  1074. for (nCurSel = 0; nCurSel < nNumItems; nCurSel++) {
  1075. paibInfo = (PALERT_INFO_BLOCK)m_CounterList.GetItemDataPtr(nCurSel);
  1076. if (paibInfo != NULL) {
  1077. if ((paibInfo->dwFlags & (AIBF_SEEN | AIBF_SAVED)) != 0) {
  1078. // First addition includes room for NULL
  1079. dwSizeReqd += (paibInfo->dwSize - sizeof(ALERT_INFO_BLOCK)) / sizeof (WCHAR);
  1080. dwSizeReqd += 1; // for '<' or '>'
  1081. dwSizeReqd += SLQ_MAX_VALUE_LEN;
  1082. dwSizeReqd += MAX_ALIGN_BYTES;
  1083. } else {
  1084. if (piInvalidEntry != NULL) {
  1085. *piInvalidEntry = nCurSel;
  1086. bReturn = FALSE;
  1087. break;
  1088. }
  1089. }
  1090. }
  1091. }
  1092. if ( bReturn && !bInvalidateOnly ) {
  1093. LPWSTR pszTemp = NULL;
  1094. dwSizeReqd += 1; // add room for the MSZ NULL
  1095. MFC_TRY;
  1096. pszTemp = new WCHAR[dwSizeReqd];
  1097. MFC_CATCH_MINIMUM;
  1098. if ( NULL != pszTemp ) {
  1099. // allocate a block of memory for the list
  1100. if (m_szAlertCounterList != NULL) {
  1101. delete [] (m_szAlertCounterList);
  1102. }
  1103. m_cchAlertCounterListSize = 0;
  1104. m_szAlertCounterList = pszTemp;
  1105. // now fill it with the Alert paths
  1106. dwSizeLeft = dwSizeReqd;
  1107. szNextString = m_szAlertCounterList;
  1108. for (nCurSel = 0; nCurSel < nNumItems; nCurSel++) {
  1109. paibInfo = (PALERT_INFO_BLOCK)m_CounterList.GetItemDataPtr(nCurSel);
  1110. if (paibInfo != NULL) {
  1111. dwSize = dwSizeLeft;
  1112. if (MakeStringFromInfo (paibInfo, szNextString, &dwSize)) {
  1113. dwSizeLeft -= dwSize;
  1114. m_cchAlertCounterListSize += dwSize;
  1115. szNextString += dwSize;
  1116. ASSERT (m_cchAlertCounterListSize < dwSizeReqd);
  1117. } else {
  1118. // ran out of buffer
  1119. bReturn = FALSE;
  1120. break;
  1121. }
  1122. }
  1123. }
  1124. if (bReturn) {
  1125. *szNextString++ = 0; // MSZ Null
  1126. m_cchAlertCounterListSize++;
  1127. if (piInvalidEntry != NULL) {
  1128. *piInvalidEntry = -1;
  1129. }
  1130. }
  1131. } // else error
  1132. }
  1133. } else {
  1134. // no items to return
  1135. bReturn = FALSE;
  1136. }
  1137. return bReturn;
  1138. }
  1139. BOOL CAlertGenProp::OnInitDialog()
  1140. {
  1141. CComboBox *pCombo;
  1142. CString csComboBoxString;
  1143. DWORD nIndex;
  1144. UINT nResult;
  1145. LPWSTR szTmpCtrLst;
  1146. DWORD dwSize;
  1147. ResourceStateManager rsm;
  1148. //
  1149. // Here m_pAlertQuery should not be NULL, if it is,
  1150. // There must be something wrong.
  1151. //
  1152. if ( NULL == m_pAlertQuery ) {
  1153. return TRUE;
  1154. }
  1155. m_pAlertQuery->TranslateCounterListToLocale();
  1156. m_bCanAccessRemoteWbem = m_pAlertQuery->GetLogService()->CanAccessWbemRemote();
  1157. m_pAlertQuery->SetActivePropertyPage( this );
  1158. // call property page init to init combo members.
  1159. CSmPropertyPage::OnInitDialog();
  1160. SetHelpIds ( (DWORD*)&s_aulHelpIds );
  1161. Initialize( m_pAlertQuery );
  1162. m_strUserDisplay = m_pAlertQuery->m_strUser;
  1163. m_strUserSaved = m_strUserDisplay;
  1164. // Load the shared data to get the sample data unit type.
  1165. m_pAlertQuery->GetPropPageSharedData ( &m_SharedData );
  1166. // load combo box
  1167. pCombo = &m_SampleUnitsCombo;
  1168. pCombo->ResetContent();
  1169. for (nIndex = 0; nIndex < dwTimeUnitComboEntries; nIndex++) {
  1170. csComboBoxString.Empty();
  1171. if (csComboBoxString.LoadString ( TimeUnitCombo[nIndex].nResId)) {
  1172. nResult = pCombo->InsertString (nIndex, (LPCWSTR)csComboBoxString);
  1173. ASSERT (nResult != CB_ERR);
  1174. nResult = pCombo->SetItemData (nIndex, (DWORD)TimeUnitCombo[nIndex].nData);
  1175. ASSERT (nResult != CB_ERR);
  1176. // set selected in combo box here
  1177. if (m_SharedData.stiSampleTime.dwUnitType == (DWORD)(TimeUnitCombo[nIndex].nData)) {
  1178. m_nSampleUnits = nIndex;
  1179. nResult = pCombo->SetCurSel(nIndex);
  1180. ASSERT (nResult != CB_ERR);
  1181. }
  1182. }
  1183. }
  1184. pCombo = &m_OverUnderCombo;
  1185. pCombo->ResetContent();
  1186. for (nIndex = 0; nIndex < dwOverUnderComboEntries; nIndex++) {
  1187. csComboBoxString.Empty();
  1188. if (csComboBoxString.LoadString ( OverUnderCombo[nIndex].nResId)) {
  1189. nResult = pCombo->InsertString (nIndex, (LPCWSTR)csComboBoxString);
  1190. ASSERT (nResult != CB_ERR);
  1191. nResult = pCombo->SetItemData (nIndex, (DWORD)TimeUnitCombo[nIndex].nData);
  1192. ASSERT (nResult != CB_ERR);
  1193. }
  1194. }
  1195. // get data from current alert query
  1196. m_pAlertQuery->GetLogComment( m_strComment );
  1197. szTmpCtrLst = (LPWSTR)m_pAlertQuery->GetCounterList (&dwSize);
  1198. if (szTmpCtrLst != NULL) {
  1199. MFC_TRY;
  1200. m_szAlertCounterList = new WCHAR [dwSize];
  1201. MFC_CATCH_MINIMUM;
  1202. if ( NULL != m_szAlertCounterList ) {
  1203. memcpy (m_szAlertCounterList, szTmpCtrLst, (dwSize * sizeof(WCHAR)));
  1204. m_cchAlertCounterListSize = dwSize;
  1205. }
  1206. }
  1207. // Call UpdateData again, after loading data into members.
  1208. UpdateData ( FALSE );
  1209. // load list box
  1210. LoadDlgFromList();
  1211. // m_CounterList is initialized in UpdateData
  1212. if (m_CounterList.GetCount() > 0) {
  1213. m_CounterList.SetCurSel (0);
  1214. m_CounterList.SetFocus();
  1215. LoadAlertItemData (0);
  1216. }
  1217. SetButtonState ();
  1218. return FALSE; // return TRUE unless you set the focus to a control
  1219. // EXCEPTION: OCX Property Pages should return FALSE
  1220. }
  1221. void CAlertGenProp::OnCommentEditChange()
  1222. {
  1223. UpdateData( TRUE );
  1224. SetModifiedPage(TRUE);
  1225. }
  1226. void CAlertGenProp::OnCommentEditKillFocus()
  1227. {
  1228. CString strOldText;
  1229. strOldText = m_strComment;
  1230. UpdateData ( TRUE );
  1231. if ( 0 != strOldText.Compare ( m_strComment ) ) {
  1232. SetModifiedPage(TRUE);
  1233. }
  1234. }