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.

964 lines
31 KiB

  1. /*++
  2. Copyright (C) 1998-1999 Microsoft Corporation
  3. Module Name:
  4. alrtactp.cpp
  5. Abstract:
  6. Implementation of the alerts action property page.
  7. --*/
  8. #include "stdafx.h"
  9. #include <assert.h>
  10. #include <common.h>
  11. #include "smcfgmsg.h"
  12. #include "globals.h"
  13. #include "smlogs.h"
  14. #include "smalrtq.h"
  15. #include "alrtcmdd.h"
  16. #include "AlrtActP.h"
  17. #ifdef _DEBUG
  18. #define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22. USE_HANDLE_MACROS("SMLOGCFG(alrtactp.cpp)");
  23. static ULONG
  24. s_aulHelpIds[] =
  25. {
  26. IDC_ACTION_APPLOG_CHK, IDH_ACTION_APPLOG_CHK,
  27. IDC_ACTION_NETMSG_CHK, IDH_ACTION_NETMSG_CHK,
  28. IDC_ACTION_NETMSG_NAME_EDIT, IDH_ACTION_NETMSG_NAME_EDIT,
  29. IDC_ACTION_EXECUTE_CHK, IDH_ACTION_EXECUTE_CHK,
  30. IDC_ACTION_EXECUTE_EDIT, IDH_ACTION_EXECUTE_EDIT,
  31. IDC_ACTION_EXECUTE_BROWSE_BTN, IDH_ACTION_EXECUTE_BROWSE_BTN,
  32. IDC_ACTION_CMD_ARGS_BTN, IDH_ACTION_CMD_ARGS_BTN,
  33. IDC_ACTION_START_LOG_CHK, IDH_ACTION_START_LOG_CHK,
  34. IDC_ACTION_START_LOG_COMBO, IDH_ACTION_START_LOG_COMBO,
  35. IDC_ACTION_CMD_ARGS_DISPLAY, IDH_ACTION_CMD_ARGS_DISPLAY,
  36. 0,0
  37. };
  38. /////////////////////////////////////////////////////////////////////////////
  39. // CAlertActionProp property page
  40. IMPLEMENT_DYNCREATE(CAlertActionProp, CSmPropertyPage)
  41. CAlertActionProp::CAlertActionProp(MMC_COOKIE mmcCookie, LONG_PTR hConsole)
  42. : CSmPropertyPage(CAlertActionProp::IDD, hConsole)
  43. {
  44. //::OutputDebugStringA("\nCAlertActionProp::CAlertActionProp");
  45. // init variables from arg list
  46. m_pAlertQuery = reinterpret_cast <CSmAlertQuery *>(mmcCookie);
  47. // init AFX data
  48. InitAfxDataItems();
  49. // init other member variables
  50. m_pAlertInfo = NULL;
  51. }
  52. CAlertActionProp::CAlertActionProp() : CSmPropertyPage(CAlertActionProp::IDD)
  53. {
  54. ASSERT (FALSE); // the constructor w/ args should be used instead
  55. // init variables from arg list
  56. m_pAlertQuery = NULL;
  57. // init AFX data
  58. InitAfxDataItems();
  59. // init other member variables
  60. m_pAlertInfo = NULL;
  61. }
  62. CAlertActionProp::~CAlertActionProp()
  63. {
  64. if (m_pAlertInfo != NULL) delete m_pAlertInfo;
  65. }
  66. void CAlertActionProp::InitAfxDataItems ()
  67. {
  68. //{{AFX_DATA_INIT(CAlertActionProp)
  69. m_Action_bLogEvent = TRUE;
  70. m_Action_bExecCmd = FALSE;
  71. m_Action_bSendNetMsg = FALSE;
  72. m_Action_bStartLog = FALSE;
  73. m_Action_strCmdPath = _T("");
  74. m_Action_strNetName = _T("");
  75. m_CmdArg_bAlertName = FALSE;
  76. m_CmdArg_bDateTime = FALSE;
  77. m_CmdArg_bLimitValue = FALSE;
  78. m_CmdArg_bCounterPath = FALSE;
  79. m_CmdArg_bSingleArg = FALSE;
  80. m_CmdArg_bMeasuredValue = FALSE;
  81. m_CmdArg_bUserText = FALSE;
  82. m_CmdArg_strUserText = _T("");
  83. m_nCurLogSel = LB_ERR;
  84. //}}AFX_DATA_INIT
  85. }
  86. void CAlertActionProp::DoDataExchange(CDataExchange* pDX)
  87. {
  88. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  89. CPropertyPage::DoDataExchange(pDX);
  90. //{{AFX_DATA_MAP(CAlertActionProp)
  91. DDX_Control(pDX, IDC_ACTION_START_LOG_COMBO, m_pLogCombo);
  92. DDX_Check(pDX, IDC_ACTION_APPLOG_CHK, m_Action_bLogEvent);
  93. DDX_Check(pDX, IDC_ACTION_EXECUTE_CHK, m_Action_bExecCmd);
  94. DDX_Check(pDX, IDC_ACTION_NETMSG_CHK, m_Action_bSendNetMsg);
  95. DDX_Check(pDX, IDC_ACTION_START_LOG_CHK, m_Action_bStartLog);
  96. DDX_CBIndex(pDX, IDC_ACTION_START_LOG_COMBO, m_nCurLogSel);
  97. DDX_Text(pDX, IDC_ACTION_EXECUTE_EDIT, m_Action_strCmdPath);
  98. DDV_MaxChars(pDX, m_Action_strCmdPath, MAX_PATH );
  99. DDX_Text(pDX, IDC_ACTION_NETMSG_NAME_EDIT, m_Action_strNetName);
  100. DDV_MaxChars(pDX, m_Action_strNetName, MAX_PATH );
  101. //}}AFX_DATA_MAP
  102. }
  103. BEGIN_MESSAGE_MAP(CAlertActionProp, CSmPropertyPage)
  104. //{{AFX_MSG_MAP(CAlertActionProp)
  105. ON_WM_DESTROY()
  106. ON_BN_CLICKED(IDC_ACTION_EXECUTE_BROWSE_BTN, OnActionExecuteBrowseBtn)
  107. ON_BN_CLICKED(IDC_ACTION_APPLOG_CHK, OnActionApplogChk)
  108. ON_BN_CLICKED(IDC_ACTION_NETMSG_CHK, OnActionNetmsgChk)
  109. ON_BN_CLICKED(IDC_ACTION_EXECUTE_CHK, OnActionExecuteChk)
  110. ON_BN_CLICKED(IDC_ACTION_CMD_ARGS_BTN, OnActionCmdArgsBtn)
  111. ON_BN_CLICKED(IDC_ACTION_START_LOG_CHK, OnActionStartLogChk)
  112. ON_EN_CHANGE(IDC_ACTION_NETMSG_NAME_EDIT, OnNetNameTextEditChange)
  113. ON_EN_CHANGE(IDC_ACTION_EXECUTE_EDIT, OnCmdPathTextEditChange)
  114. ON_CBN_SELENDOK(IDC_ACTION_START_LOG_COMBO, OnSelendokStartLogCombo)
  115. //}}AFX_MSG_MAP
  116. END_MESSAGE_MAP()
  117. BOOL
  118. CAlertActionProp::SetControlState()
  119. {
  120. // Net Message items
  121. (GetDlgItem(IDC_ACTION_NETMSG_NAME_EDIT))->EnableWindow(m_Action_bSendNetMsg);
  122. // command line items
  123. (GetDlgItem(IDC_ACTION_EXECUTE_EDIT))->EnableWindow(m_Action_bExecCmd);
  124. (GetDlgItem(IDC_ACTION_EXECUTE_BROWSE_BTN))->EnableWindow(m_Action_bExecCmd);
  125. (GetDlgItem(IDC_ACTION_CMD_ARGS_BTN))->EnableWindow(m_Action_bExecCmd);
  126. (GetDlgItem(IDC_ACTION_CMD_ARGS_CAPTION))->EnableWindow(m_Action_bExecCmd);
  127. (GetDlgItem(IDC_ACTION_CMD_ARGS_DISPLAY))->EnableWindow(m_Action_bExecCmd);
  128. // perf data Log entries
  129. (GetDlgItem(IDC_ACTION_START_LOG_COMBO))->EnableWindow(m_Action_bStartLog);
  130. return TRUE;
  131. }
  132. BOOL
  133. CAlertActionProp::LoadLogQueries ( DWORD dwLogType )
  134. {
  135. DWORD dwStatus = ERROR_SUCCESS;
  136. DWORD dwQueryIndex = 0;
  137. LONG lEnumStatus = ERROR_SUCCESS;
  138. WCHAR szQueryName[MAX_PATH];
  139. DWORD dwQueryNameSize = MAX_PATH;
  140. LPTSTR szCollectionName = NULL;
  141. UINT uiCollectionNameLen = 0;
  142. FILETIME ftLastWritten;
  143. HKEY hKeyQuery;
  144. HKEY hKeyLogService;
  145. dwStatus = RegOpenKeyExW (
  146. HKEY_LOCAL_MACHINE, // handle of open key
  147. L"System\\CurrentControlSet\\Services\\Sysmonlog\\Log Queries", // address of name of subkey to open
  148. 0L,
  149. KEY_READ, // reserved REGSAM samDesired, // security access mask
  150. &hKeyLogService);
  151. if (dwStatus != ERROR_SUCCESS) return FALSE;
  152. // Load all queries for the specified registry key.
  153. // Enumerate the log names and create a new log object
  154. // for each one found.
  155. while ((lEnumStatus = RegEnumKeyEx (hKeyLogService,
  156. dwQueryIndex, szQueryName, &dwQueryNameSize,
  157. NULL, NULL, NULL, &ftLastWritten)) == ERROR_SUCCESS) {
  158. // open the query specified
  159. dwStatus = RegOpenKeyExW (
  160. hKeyLogService,
  161. szQueryName,
  162. 0,
  163. KEY_READ,
  164. &hKeyQuery);
  165. if ( ERROR_SUCCESS == dwStatus ) {
  166. // create a new object and add it to the query list
  167. // Determine the log type.
  168. DWORD dwType = 0;
  169. DWORD dwBufferSize = sizeof(DWORD);
  170. DWORD dwRegValue;
  171. dwType = 0;
  172. dwStatus = RegQueryValueExW (
  173. hKeyQuery,
  174. L"Log Type",
  175. NULL,
  176. &dwType,
  177. (LPBYTE)&dwRegValue,
  178. &dwBufferSize );
  179. if ( ( ERROR_SUCCESS == dwStatus )
  180. && ( dwLogType == dwRegValue ) )
  181. {
  182. // Query key is Guid if written by post Win2000 snapin.
  183. // Query key is name if written by Win2000 snapin.
  184. dwStatus = SmReadRegistryIndirectStringValue (
  185. hKeyQuery,
  186. L"Collection Name",
  187. NULL,
  188. &szCollectionName,
  189. &uiCollectionNameLen );
  190. ASSERT ( MAX_PATH >= uiCollectionNameLen );
  191. if ( ERROR_SUCCESS == dwStatus
  192. && NULL != szCollectionName )
  193. {
  194. if ( 0 < lstrlen ( szCollectionName )
  195. && ( MAX_PATH > lstrlen ( szCollectionName ) ) )
  196. {
  197. lstrcpy ( szQueryName, szCollectionName );
  198. }
  199. G_FREE ( szCollectionName );
  200. szCollectionName = NULL;
  201. }
  202. // add this to the combo box
  203. m_pLogCombo.AddString (szQueryName);
  204. }
  205. RegCloseKey (hKeyQuery);
  206. }
  207. // set up for the next item in the list
  208. dwQueryNameSize = sizeof (szQueryName) / sizeof (szQueryName[0]);
  209. dwQueryIndex++;
  210. memset (szQueryName, 0, sizeof (szQueryName));
  211. }
  212. RegCloseKey (hKeyLogService);
  213. return TRUE;
  214. }
  215. BOOL
  216. CAlertActionProp::IsValidLocalData()
  217. {
  218. BOOL bActionSet = FALSE;
  219. INT iPrevLength = 0;
  220. BOOL bUpdateNetNameUI = FALSE;
  221. ResourceStateManager rsm;
  222. if (m_Action_bLogEvent) {
  223. bActionSet = TRUE;
  224. }
  225. // assumes UpdateData has been called
  226. // Trim text fields before validating.
  227. iPrevLength = m_Action_strCmdPath.GetLength();
  228. m_Action_strCmdPath.TrimLeft();
  229. m_Action_strCmdPath.TrimRight();
  230. if ( iPrevLength != m_Action_strCmdPath.GetLength() ) {
  231. SetDlgItemText ( IDC_ACTION_EXECUTE_EDIT, m_Action_strCmdPath );
  232. }
  233. iPrevLength = m_Action_strNetName.GetLength();
  234. m_Action_strNetName.TrimLeft();
  235. m_Action_strNetName.TrimRight();
  236. if ( iPrevLength != m_Action_strNetName.GetLength() ) {
  237. bUpdateNetNameUI = TRUE;
  238. }
  239. if (m_Action_bSendNetMsg) {
  240. // make sure a net name has been entered
  241. while ( _T('\\') == m_Action_strNetName[0] ) {
  242. // NetMessageBufferSend does not understand machine names preceded by "\\"
  243. m_Action_strNetName = m_Action_strNetName.Right( m_Action_strNetName.GetLength() - 1 );
  244. bUpdateNetNameUI = TRUE;
  245. }
  246. if (m_Action_strNetName.GetLength() == 0) {
  247. CString strMessage;
  248. strMessage.LoadString ( IDS_ACTION_ERR_NONETNAME );
  249. MessageBox ( strMessage, m_pAlertQuery->GetLogName(), MB_OK | MB_ICONERROR);
  250. (GetDlgItem(IDC_ACTION_NETMSG_NAME_EDIT))->SetFocus();
  251. return FALSE;
  252. }
  253. bActionSet = TRUE;
  254. }
  255. if ( bUpdateNetNameUI ) {
  256. SetDlgItemText ( IDC_ACTION_NETMSG_NAME_EDIT, m_Action_strNetName );
  257. }
  258. if (m_Action_bExecCmd) {
  259. // make sure a command file has been entered
  260. if (m_Action_strCmdPath.GetLength() == 0) {
  261. CString strMessage;
  262. strMessage.LoadString ( IDS_ACTION_ERR_NOCMDFILE );
  263. MessageBox ( strMessage, m_pAlertQuery->GetLogName(), MB_OK | MB_ICONERROR);
  264. (GetDlgItem(IDC_ACTION_EXECUTE_EDIT))->SetFocus();
  265. return FALSE;
  266. }
  267. // If on local machine, make sure the command file exists.
  268. if ( m_pAlertQuery->GetLogService()->IsLocalMachine() ) {
  269. DWORD dwStatus;
  270. dwStatus = IsCommandFilePathValid ( m_Action_strCmdPath );
  271. if ( ERROR_SUCCESS != dwStatus ) {
  272. CString strMessage;
  273. FormatSmLogCfgMessage (
  274. strMessage,
  275. m_hModule,
  276. dwStatus );
  277. MessageBox ( strMessage, m_pAlertQuery->GetLogName(), MB_OK | MB_ICONERROR);
  278. GetDlgItem ( IDC_ACTION_EXECUTE_EDIT )->SetFocus();
  279. return FALSE;
  280. }
  281. }
  282. bActionSet = TRUE;
  283. }
  284. if (m_Action_bStartLog ) {
  285. // make sure a log has been selected
  286. if (m_pLogCombo.GetCurSel() == CB_ERR) {
  287. CString strMessage;
  288. strMessage.LoadString ( IDS_ACTION_ERR_NOLOGNAME );
  289. MessageBox ( strMessage, m_pAlertQuery->GetLogName(), MB_OK | MB_ICONERROR);
  290. m_pLogCombo.SetFocus();
  291. return FALSE;
  292. }
  293. bActionSet = TRUE;
  294. }
  295. if (!bActionSet ) {
  296. // make sure some action has been selected
  297. CString strMessage;
  298. strMessage.LoadString ( IDS_ACTION_ERR_NOACTION );
  299. MessageBox ( strMessage, m_pAlertQuery->GetLogName(), MB_OK | MB_ICONERROR);
  300. return FALSE;
  301. }
  302. return bActionSet;
  303. }
  304. void
  305. CAlertActionProp::UpdateCmdActionBox ()
  306. {
  307. UpdateData(TRUE);
  308. SetControlState();
  309. SetModifiedPage(TRUE);
  310. }
  311. /////////////////////////////////////////////////////////////////////////////
  312. // CAlertActionProp message handlers
  313. BOOL
  314. CAlertActionProp::OnSetActive()
  315. {
  316. BOOL bReturn = TRUE;
  317. bReturn = CSmPropertyPage::OnSetActive();
  318. if ( bReturn ) {
  319. m_pAlertQuery->GetPropPageSharedData ( &m_SharedData );
  320. }
  321. return bReturn;
  322. }
  323. BOOL
  324. CAlertActionProp::OnKillActive()
  325. {
  326. BOOL bContinue = TRUE;
  327. ResourceStateManager rsm;
  328. // Parent class OnKillActive calls UpdateData(TRUE)
  329. bContinue = CPropertyPage::OnKillActive();
  330. if ( bContinue ) {
  331. bContinue = IsValidData(m_pAlertQuery, VALIDATE_FOCUS );
  332. if ( bContinue ) {
  333. // Save property page shared data.
  334. m_pAlertQuery->SetPropPageSharedData ( &m_SharedData );
  335. }
  336. }
  337. if ( bContinue ) {
  338. SetIsActive ( FALSE );
  339. }
  340. return bContinue;
  341. }
  342. BOOL
  343. CAlertActionProp::OnApply()
  344. {
  345. DWORD dwFlags = 0;
  346. DWORD dwBufferSize = sizeof(ALERT_ACTION_INFO);
  347. LPTSTR szNextString;
  348. INT nCurLogSel = CB_ERR;
  349. BOOL bContinue = TRUE;
  350. ResourceStateManager rsm;
  351. // get current settings
  352. bContinue = UpdateData(TRUE);
  353. if ( bContinue ) {
  354. bContinue = IsValidData( m_pAlertQuery, VALIDATE_APPLY );
  355. }
  356. if ( bContinue ) {
  357. bContinue = SampleTimeIsLessThanSessionTime ( m_pAlertQuery );
  358. }
  359. // Write the data to the query.
  360. if ( bContinue ) {
  361. dwFlags |= (m_Action_bLogEvent ? ALRT_ACTION_LOG_EVENT : 0);
  362. dwFlags |= (m_Action_bExecCmd ? ALRT_ACTION_EXEC_CMD : 0);
  363. dwFlags |= (m_Action_bSendNetMsg ? ALRT_ACTION_SEND_MSG : 0);
  364. dwFlags |= (m_Action_bStartLog ? ALRT_ACTION_START_LOG : 0);
  365. if (m_Action_bSendNetMsg) {
  366. dwBufferSize += (m_Action_strNetName.GetLength() + 1) * sizeof (WCHAR);
  367. }
  368. if (m_Action_bExecCmd) {
  369. dwBufferSize += (m_Action_strCmdPath.GetLength() + 1) * sizeof (WCHAR);
  370. dwBufferSize += (m_CmdArg_strUserText .GetLength() + 1) * sizeof (WCHAR);
  371. dwFlags |= (m_CmdArg_bAlertName ? ALRT_CMD_LINE_A_NAME : 0);
  372. dwFlags |= (m_CmdArg_bDateTime ? ALRT_CMD_LINE_D_TIME : 0);
  373. dwFlags |= (m_CmdArg_bLimitValue ? ALRT_CMD_LINE_L_VAL : 0);
  374. dwFlags |= (m_CmdArg_bCounterPath ? ALRT_CMD_LINE_C_NAME : 0);
  375. dwFlags |= (m_CmdArg_bSingleArg ? ALRT_CMD_LINE_SINGLE : 0);
  376. dwFlags |= (m_CmdArg_bMeasuredValue ? ALRT_CMD_LINE_M_VAL : 0);
  377. dwFlags |= (m_CmdArg_bUserText ? ALRT_CMD_LINE_U_TEXT : 0);
  378. }
  379. if (m_Action_bStartLog) {
  380. nCurLogSel = m_pLogCombo.GetCurSel();
  381. if (nCurLogSel != CB_ERR) {
  382. dwBufferSize += (m_pLogCombo.GetLBTextLen(nCurLogSel) + 1) * sizeof(WCHAR);
  383. }
  384. }
  385. if (m_pAlertInfo != NULL) delete (m_pAlertInfo);
  386. MFC_TRY
  387. m_pAlertInfo = (PALERT_ACTION_INFO) new CHAR[dwBufferSize];
  388. MFC_CATCH_MINIMUM
  389. if (m_pAlertInfo != NULL) {
  390. m_pAlertInfo->dwSize = dwBufferSize;
  391. m_pAlertInfo->dwActionFlags = dwFlags;
  392. szNextString = (LPTSTR)&m_pAlertInfo[1];
  393. if ((m_Action_bSendNetMsg) && (m_Action_strNetName.GetLength() > 0)) {
  394. m_pAlertInfo->szNetName = szNextString;
  395. lstrcpyW(m_pAlertInfo->szNetName, (LPCWSTR)m_Action_strNetName);
  396. szNextString += m_Action_strNetName.GetLength() + 1;
  397. } else {
  398. m_pAlertInfo->szNetName = NULL;
  399. }
  400. if (m_Action_bExecCmd) {
  401. if (m_Action_strCmdPath.GetLength() > 0) {
  402. m_pAlertInfo->szCmdFilePath = szNextString;
  403. lstrcpyW (m_pAlertInfo->szCmdFilePath, (LPCWSTR)m_Action_strCmdPath);
  404. szNextString += m_Action_strCmdPath.GetLength() + 1;
  405. } else {
  406. m_pAlertInfo->szCmdFilePath = NULL;
  407. }
  408. if (m_CmdArg_strUserText.GetLength() > 0) {
  409. m_pAlertInfo->szUserText = szNextString;
  410. lstrcpyW (m_pAlertInfo->szUserText, (LPCWSTR)m_CmdArg_strUserText);
  411. szNextString += m_CmdArg_strUserText.GetLength() + 1;
  412. } else {
  413. m_pAlertInfo->szUserText = NULL;
  414. }
  415. } else {
  416. m_pAlertInfo->szCmdFilePath = NULL;
  417. m_pAlertInfo->szUserText = NULL;
  418. }
  419. if ((m_Action_bStartLog) && (nCurLogSel != CB_ERR)) {
  420. // get log name
  421. m_pAlertInfo->szLogName = szNextString; // for now
  422. m_pLogCombo.GetLBText(nCurLogSel, szNextString);
  423. } else {
  424. m_pAlertInfo->szLogName = NULL;
  425. }
  426. }
  427. if ( bContinue ) {
  428. bContinue = Apply(m_pAlertQuery);
  429. }
  430. bContinue = CPropertyPage::OnApply();
  431. if ( bContinue ) {
  432. bContinue = ( ERROR_SUCCESS == m_pAlertQuery->SetActionInfo ( m_pAlertInfo ) );
  433. }
  434. if ( bContinue ) {
  435. // Save property page shared data.
  436. m_pAlertQuery->UpdatePropPageSharedData();
  437. bContinue = UpdateService( m_pAlertQuery, FALSE );
  438. }
  439. }
  440. return bContinue;
  441. }
  442. void
  443. CAlertActionProp::OnCancel()
  444. {
  445. CPropertyPage::OnCancel();
  446. }
  447. void
  448. CAlertActionProp::OnActionCmdArgsBtn()
  449. {
  450. DWORD dwStatus = ERROR_SUCCESS;
  451. CAlertCommandArgsDlg dlgCmdArgs;
  452. INT_PTR iResult;
  453. dlgCmdArgs.SetAlertActionPage( this );
  454. dwStatus = m_pAlertQuery->GetLogName ( dlgCmdArgs.m_strAlertName );
  455. if ( ERROR_SUCCESS == dwStatus ) {
  456. MFC_TRY
  457. dlgCmdArgs.m_CmdArg_bAlertName = m_CmdArg_bAlertName;
  458. dlgCmdArgs.m_CmdArg_bDateTime = m_CmdArg_bDateTime;
  459. dlgCmdArgs.m_CmdArg_bLimitValue = m_CmdArg_bLimitValue;
  460. dlgCmdArgs.m_CmdArg_bCounterPath = m_CmdArg_bCounterPath;
  461. dlgCmdArgs.m_CmdArg_bSingleArg = m_CmdArg_bSingleArg;
  462. dlgCmdArgs.m_CmdArg_bMeasuredValue = m_CmdArg_bMeasuredValue;
  463. dlgCmdArgs.m_CmdArg_bUserText = m_CmdArg_bUserText;
  464. dlgCmdArgs.m_CmdArg_strUserText = m_CmdArg_strUserText;
  465. iResult = dlgCmdArgs.DoModal();
  466. if ( IDOK == iResult ) {
  467. if (dlgCmdArgs.m_CmdArg_bAlertName != m_CmdArg_bAlertName ) {
  468. m_CmdArg_bAlertName = dlgCmdArgs.m_CmdArg_bAlertName;
  469. SetModifiedPage ( TRUE );
  470. }
  471. if (dlgCmdArgs.m_CmdArg_bDateTime != m_CmdArg_bDateTime ) {
  472. m_CmdArg_bDateTime = dlgCmdArgs.m_CmdArg_bDateTime;
  473. SetModifiedPage ( TRUE );
  474. }
  475. if (dlgCmdArgs.m_CmdArg_bLimitValue != m_CmdArg_bLimitValue ) {
  476. m_CmdArg_bLimitValue = dlgCmdArgs.m_CmdArg_bLimitValue;
  477. SetModifiedPage ( TRUE );
  478. }
  479. if (dlgCmdArgs.m_CmdArg_bCounterPath != m_CmdArg_bCounterPath ) {
  480. m_CmdArg_bCounterPath = dlgCmdArgs.m_CmdArg_bCounterPath;
  481. SetModifiedPage ( TRUE );
  482. }
  483. if (dlgCmdArgs.m_CmdArg_bSingleArg != m_CmdArg_bSingleArg ) {
  484. m_CmdArg_bSingleArg = dlgCmdArgs.m_CmdArg_bSingleArg;
  485. SetModifiedPage ( TRUE );
  486. }
  487. if (dlgCmdArgs.m_CmdArg_bMeasuredValue != m_CmdArg_bMeasuredValue ) {
  488. m_CmdArg_bMeasuredValue = dlgCmdArgs.m_CmdArg_bMeasuredValue;
  489. SetModifiedPage ( TRUE );
  490. }
  491. if (dlgCmdArgs.m_CmdArg_bUserText != m_CmdArg_bUserText ) {
  492. m_CmdArg_bUserText = dlgCmdArgs.m_CmdArg_bUserText;
  493. SetModifiedPage ( TRUE );
  494. }
  495. if ( 0 != dlgCmdArgs.m_CmdArg_strUserText.CompareNoCase( m_CmdArg_strUserText ) ) {
  496. m_CmdArg_strUserText = dlgCmdArgs.m_CmdArg_strUserText;
  497. SetModifiedPage ( TRUE );
  498. }
  499. m_strCmdArgsExample = dlgCmdArgs.m_strSampleArgList;
  500. SetDlgItemText (IDC_ACTION_CMD_ARGS_DISPLAY, m_strCmdArgsExample);
  501. // Clear the selection
  502. ((CEdit*)GetDlgItem( IDC_ACTION_CMD_ARGS_DISPLAY ))->SetSel ( -1, FALSE );
  503. }
  504. MFC_CATCH_DWSTATUS
  505. }
  506. if ( ERROR_SUCCESS != dwStatus ) {
  507. CString strSysMessage;
  508. CString strMessage;
  509. MFC_TRY
  510. // TODO: Use static string for message in order to display in low memory situations.
  511. strMessage.LoadString ( IDS_ERRMSG_GENERAL );
  512. FormatSystemMessage ( dwStatus, strSysMessage );
  513. strMessage += strSysMessage;
  514. MessageBox ( strMessage, m_pAlertQuery->GetLogName(), MB_OK | MB_ICONERROR);
  515. MFC_CATCH_MINIMUM
  516. (GetDlgItem(IDC_ACTION_CMD_ARGS_BTN))->SetFocus();
  517. }
  518. return;
  519. }
  520. void
  521. CAlertActionProp::OnSelendokStartLogCombo()
  522. {
  523. INT nSel;
  524. nSel = m_pLogCombo.GetCurSel();
  525. if ( nSel != m_nCurLogSel && LB_ERR != nSel ) {
  526. UpdateData ( TRUE );
  527. SetModifiedPage ( TRUE );
  528. }
  529. }
  530. void CAlertActionProp::OnActionExecuteBrowseBtn()
  531. {
  532. CString strCmdPath;
  533. UpdateData (TRUE); // to get the current filename
  534. strCmdPath = m_Action_strCmdPath;
  535. if ( IDOK == BrowseCommandFilename ( this, strCmdPath )) {
  536. // Update the fields with the new information
  537. if ( strCmdPath != m_Action_strCmdPath ) {
  538. m_Action_strCmdPath = strCmdPath;
  539. SetModifiedPage();
  540. UpdateData(FALSE);
  541. }
  542. } // else ignore if they canceled out
  543. }
  544. BOOL CAlertActionProp::OnInitDialog()
  545. {
  546. INT nSelLog;
  547. DWORD dwInfoBufSize = 0;
  548. ResourceStateManager rsm;
  549. // Parent OnInitDialog calls UpdateData to initialize combo members.
  550. CSmPropertyPage::OnInitDialog();
  551. SetHelpIds ( (DWORD*)&s_aulHelpIds );
  552. // load service name combo box
  553. LoadLogQueries (SLQ_COUNTER_LOG);
  554. LoadLogQueries (SLQ_TRACE_LOG);
  555. if (m_pAlertInfo == NULL) {
  556. // get alert query info from alert class
  557. // get initial size by passing asking to fill a 0 len buffer
  558. m_pAlertQuery->GetActionInfo (m_pAlertInfo, &dwInfoBufSize);
  559. ASSERT (dwInfoBufSize > 0); // or something is wierd
  560. MFC_TRY;
  561. m_pAlertInfo = (PALERT_ACTION_INFO) new UCHAR [dwInfoBufSize];
  562. MFC_CATCH_MINIMUM;
  563. ASSERT (m_pAlertInfo != NULL);
  564. if ( NULL != m_pAlertInfo ) {
  565. memset (m_pAlertInfo, 0, dwInfoBufSize); // init new buffer
  566. if (!m_pAlertQuery->GetActionInfo (m_pAlertInfo, &dwInfoBufSize)) {
  567. // then free the info block and use the defaults
  568. delete m_pAlertInfo;
  569. m_pAlertInfo = NULL;
  570. }
  571. }
  572. }
  573. if (m_pAlertInfo != NULL) {
  574. // then initialize using the settings passed in
  575. m_Action_bLogEvent = ((m_pAlertInfo->dwActionFlags & ALRT_ACTION_LOG_EVENT) != 0);
  576. m_Action_bSendNetMsg = ((m_pAlertInfo->dwActionFlags & ALRT_ACTION_SEND_MSG) != 0);
  577. if (m_pAlertInfo->szNetName != NULL) {
  578. m_Action_strNetName = m_pAlertInfo->szNetName;
  579. } else {
  580. m_Action_strNetName.Empty();
  581. }
  582. m_Action_bExecCmd = ((m_pAlertInfo->dwActionFlags & ALRT_ACTION_EXEC_CMD) != 0);
  583. if (m_pAlertInfo->szCmdFilePath != NULL) {
  584. m_Action_strCmdPath = m_pAlertInfo->szCmdFilePath;
  585. } else {
  586. m_Action_strCmdPath.Empty();
  587. }
  588. if ( m_Action_bExecCmd ) {
  589. m_CmdArg_bAlertName = ((m_pAlertInfo->dwActionFlags & ALRT_CMD_LINE_A_NAME) != 0);
  590. m_CmdArg_bDateTime = ((m_pAlertInfo->dwActionFlags & ALRT_CMD_LINE_D_TIME) != 0);
  591. m_CmdArg_bLimitValue = ((m_pAlertInfo->dwActionFlags & ALRT_CMD_LINE_L_VAL) != 0);
  592. m_CmdArg_bCounterPath = ((m_pAlertInfo->dwActionFlags & ALRT_CMD_LINE_C_NAME) != 0);
  593. m_CmdArg_bSingleArg = ((m_pAlertInfo->dwActionFlags & ALRT_CMD_LINE_SINGLE) != 0);
  594. m_CmdArg_bMeasuredValue = ((m_pAlertInfo->dwActionFlags & ALRT_CMD_LINE_M_VAL) != 0);
  595. m_CmdArg_bUserText = ((m_pAlertInfo->dwActionFlags & ALRT_CMD_LINE_U_TEXT) != 0);
  596. } else {
  597. m_CmdArg_bAlertName = TRUE;
  598. m_CmdArg_bDateTime = TRUE;
  599. m_CmdArg_bLimitValue = TRUE;
  600. m_CmdArg_bCounterPath = TRUE;
  601. m_CmdArg_bSingleArg = TRUE;
  602. m_CmdArg_bMeasuredValue = TRUE;
  603. m_CmdArg_bUserText = FALSE;
  604. }
  605. if (m_pAlertInfo->szUserText != NULL) {
  606. m_CmdArg_strUserText = m_pAlertInfo->szUserText;
  607. }
  608. m_Action_bStartLog = ((m_pAlertInfo->dwActionFlags & ALRT_ACTION_START_LOG) != 0);
  609. if (m_pAlertInfo->szLogName != NULL) {
  610. nSelLog = m_pLogCombo.FindString (-1, m_pAlertInfo->szLogName);
  611. if (nSelLog != CB_ERR) {
  612. m_pLogCombo.SetCurSel (nSelLog);
  613. m_nCurLogSel = nSelLog;
  614. }
  615. }
  616. } else {
  617. // initialize using the default values as defined
  618. // in the constructor
  619. }
  620. MakeSampleArgList (
  621. m_strCmdArgsExample,
  622. m_CmdArg_bSingleArg,
  623. m_CmdArg_bAlertName,
  624. m_CmdArg_bDateTime,
  625. m_CmdArg_bCounterPath,
  626. m_CmdArg_bMeasuredValue,
  627. m_CmdArg_bLimitValue,
  628. m_CmdArg_bUserText,
  629. m_CmdArg_strUserText );
  630. SetDlgItemText (IDC_ACTION_CMD_ARGS_DISPLAY, m_strCmdArgsExample);
  631. // Clear the selection
  632. ((CEdit*)GetDlgItem( IDC_ACTION_CMD_ARGS_DISPLAY ))->SetSel ( -1, FALSE );
  633. // Call UpdateData again, after loading data.
  634. UpdateData ( FALSE );
  635. SetControlState();
  636. return TRUE; // return TRUE unless you set the focus to a control
  637. // EXCEPTION: OCX Property Pages should return FALSE
  638. }
  639. void CAlertActionProp::OnActionApplogChk()
  640. {
  641. UpdateData(TRUE);
  642. SetControlState();
  643. SetModifiedPage(TRUE);
  644. }
  645. void CAlertActionProp::OnActionNetmsgChk()
  646. {
  647. UpdateData(TRUE);
  648. SetControlState();
  649. SetModifiedPage(TRUE);
  650. }
  651. void CAlertActionProp::OnActionExecuteChk()
  652. {
  653. UpdateData(TRUE);
  654. SetControlState();
  655. SetModifiedPage(TRUE);
  656. }
  657. void CAlertActionProp::OnActionStartLogChk()
  658. {
  659. UpdateCmdActionBox ();
  660. }
  661. void CAlertActionProp::OnCmdPathTextEditChange()
  662. {
  663. CString strOldText;
  664. // When the user hits OK in the folder browse dialog,
  665. // the folder name might not have changed.
  666. strOldText = m_Action_strCmdPath;
  667. UpdateData( TRUE );
  668. if ( 0 != strOldText.Compare ( m_Action_strCmdPath ) ) {
  669. SetModifiedPage(TRUE);
  670. }
  671. }
  672. void CAlertActionProp::OnNetNameTextEditChange()
  673. {
  674. CString strOldText;
  675. // When the user hits OK in the folder browse dialog,
  676. // the folder name might not have changed.
  677. strOldText = m_Action_strNetName;
  678. UpdateData( TRUE );
  679. if ( 0 != strOldText.Compare ( m_Action_strNetName ) ) {
  680. SetModifiedPage(TRUE);
  681. }
  682. }
  683. DWORD
  684. CAlertActionProp::MakeSampleArgList (
  685. CString& rstrResult,
  686. const BOOL bSingleArg,
  687. const BOOL bAlertName,
  688. const BOOL bDateTime,
  689. const BOOL bCounterPath,
  690. const BOOL bMeasuredValue,
  691. const BOOL bLimitValue,
  692. const BOOL bUserText,
  693. const CString& rstrUserText )
  694. {
  695. DWORD dwStatus = ERROR_SUCCESS;
  696. CString strDelim1;
  697. CString strDelim2;
  698. BOOL bFirstArgDone = FALSE;
  699. CString strSampleString;
  700. CString strTimeString;
  701. CString strTemp;
  702. ResourceStateManager rsm;
  703. rstrResult.Empty(); // clear the old path
  704. MFC_TRY
  705. if ( bSingleArg ) {
  706. // then args are comma delimited
  707. strDelim1 = L",";
  708. strDelim2.Empty();
  709. } else {
  710. // for multiple args, they are enclosed in double quotes
  711. // and space delimited
  712. strDelim1 = L" \"";
  713. strDelim2 = L"\"";
  714. }
  715. if ( bAlertName ) {
  716. if (bFirstArgDone) {
  717. strSampleString += strDelim1; // add leading delimiter
  718. } else {
  719. strSampleString += L"\""; // add leading quote
  720. bFirstArgDone = TRUE;
  721. }
  722. strSampleString += m_pAlertQuery->GetLogName();
  723. strSampleString += strDelim2;
  724. }
  725. if ( bDateTime ) {
  726. if (bFirstArgDone) {
  727. strSampleString += strDelim1; // add leading delimiter
  728. } else {
  729. strSampleString += L"\""; // add leading quote
  730. bFirstArgDone = TRUE;
  731. }
  732. MakeTimeString(&strTimeString);
  733. strSampleString += strTimeString;
  734. strSampleString += strDelim2;
  735. }
  736. if ( bCounterPath ) {
  737. strTemp.LoadString ( IDS_SAMPLE_CMD_PATH );
  738. if (bFirstArgDone) {
  739. strSampleString += strDelim1; // add leading delimiter
  740. } else {
  741. strSampleString += L"\""; // add leading quote
  742. bFirstArgDone = TRUE;
  743. }
  744. strSampleString += strTemp;
  745. strSampleString += strDelim2;
  746. }
  747. if ( bMeasuredValue ) {
  748. strTemp.LoadString ( IDS_SAMPLE_CMD_MEAS_VAL );
  749. if (bFirstArgDone) {
  750. strSampleString += strDelim1; // add leading delimiter
  751. } else {
  752. strSampleString += L"\""; // add leading quote
  753. bFirstArgDone = TRUE;
  754. }
  755. strSampleString += strTemp;
  756. strSampleString += strDelim2;
  757. }
  758. if ( bLimitValue ) {
  759. strTemp.LoadString ( IDS_SAMPLE_CMD_LIMIT_VAL );
  760. if (bFirstArgDone) {
  761. strSampleString += strDelim1; // add leading delimiter
  762. } else {
  763. strSampleString += L"\""; // add leading quote
  764. bFirstArgDone = TRUE;
  765. }
  766. strSampleString += strTemp;
  767. strSampleString += strDelim2;
  768. }
  769. if ( bUserText ) {
  770. if (bFirstArgDone) {
  771. strSampleString += strDelim1; // add leading delimiter
  772. } else {
  773. strSampleString += L"\""; // add leading quote
  774. bFirstArgDone = TRUE;
  775. }
  776. strSampleString += rstrUserText;
  777. strSampleString += strDelim2;
  778. }
  779. if ( bFirstArgDone && bSingleArg ) {
  780. // add closing quote if there's at least 1 arg in the command line
  781. strSampleString += L"\"";
  782. }
  783. rstrResult = strSampleString;
  784. MFC_CATCH_DWSTATUS
  785. return dwStatus;
  786. }
  787. void CAlertActionProp::MakeTimeString(CString *pTimeString)
  788. {
  789. SYSTEMTIME st;
  790. pTimeString->Empty();
  791. GetLocalTime(&st);
  792. // Build string
  793. pTimeString->Format (L"%2.2d/%2.2d/%2.2d-%2.2d:%2.2d:%2.2d.%3.3d",
  794. st.wYear, st.wMonth, st.wDay, st.wHour,
  795. st.wMinute, st.wSecond, st.wMilliseconds);
  796. }