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.

1925 lines
63 KiB

  1. /*++
  2. Copyright (C) 1996-1999 Microsoft Corporation
  3. Module Name:
  4. srcprop.cpp
  5. Abstract:
  6. Implementation of the source property page.
  7. --*/
  8. #include <windows.h>
  9. #include <stdio.h>
  10. #include <assert.h>
  11. #include <sql.h>
  12. #include <pdhmsg.h>
  13. #include <pdhp.h>
  14. #include "polyline.h"
  15. #include "utils.h"
  16. #include "smonmsg.h"
  17. #include "strids.h"
  18. #include "unihelpr.h"
  19. #include "winhelpr.h"
  20. #include "odbcinst.h"
  21. #include "smonid.h"
  22. #include "srcprop.h"
  23. CSourcePropPage::CSourcePropPage()
  24. : m_pTimeRange ( NULL ),
  25. m_eDataSourceType ( sysmonCurrentActivity ),
  26. m_hDataSource(H_REALTIME_DATASOURCE),
  27. m_pInfoDeleted ( NULL ),
  28. m_bLogFileChg ( FALSE ),
  29. m_bSqlDsnChg ( FALSE ),
  30. m_bSqlLogSetChg ( FALSE ),
  31. m_bRangeChg ( FALSE ),
  32. m_bDataSourceChg ( FALSE )
  33. {
  34. m_uIDDialog = IDD_SRC_PROPP_DLG;
  35. m_uIDTitle = IDS_SRC_PROPP_TITLE;
  36. m_szSqlDsnName[0] = _T('\0');
  37. m_szSqlLogSetName[0] = _T('\0');
  38. }
  39. CSourcePropPage::~CSourcePropPage(
  40. void
  41. )
  42. {
  43. return;
  44. }
  45. /*
  46. * CSourcePropPage::Init
  47. *
  48. * Purpose:
  49. * Performs initialization operations that might fail.
  50. *
  51. * Parameters:
  52. * None
  53. *
  54. * Return Value:
  55. * BOOL TRUE if initialization successful, FALSE
  56. * otherwise.
  57. */
  58. BOOL
  59. CSourcePropPage::Init(void)
  60. {
  61. BOOL bResult;
  62. bResult = RegisterTimeRangeClass();
  63. return bResult;
  64. }
  65. BOOL
  66. CSourcePropPage::InitControls ( void )
  67. {
  68. BOOL bResult = FALSE;
  69. HWND hwndTimeRange;
  70. // create time range object attached to dialog control
  71. hwndTimeRange = GetDlgItem(m_hDlg, IDC_TIMERANGE);
  72. if ( NULL != hwndTimeRange ) {
  73. m_pTimeRange = new CTimeRange(hwndTimeRange);
  74. if (m_pTimeRange) {
  75. bResult = m_pTimeRange->Init();
  76. if ( FALSE == bResult ) {
  77. delete m_pTimeRange;
  78. m_pTimeRange = NULL;
  79. }
  80. }
  81. }
  82. return bResult;
  83. }
  84. void
  85. CSourcePropPage::DeinitControls ( void )
  86. {
  87. HWND hwndLogFileList = NULL;
  88. INT iIndex;
  89. INT iLogFileCnt = 0;;
  90. PLogItemInfo pInfo = NULL;
  91. ISystemMonitor *pObj;
  92. CImpISystemMonitor *pPrivObj;
  93. pObj = m_ppISysmon[0];
  94. pPrivObj = (CImpISystemMonitor*)pObj;
  95. // Hide the log view start and stop bars on the graph
  96. pPrivObj->SetLogViewTempRange( MIN_TIME_VALUE, MAX_TIME_VALUE );
  97. // delete time range object attached to dialog control
  98. if (m_pTimeRange != NULL) {
  99. delete m_pTimeRange;
  100. m_pTimeRange = NULL;
  101. }
  102. hwndLogFileList = DialogControl(m_hDlg, IDC_LIST_LOGFILENAME);
  103. if ( NULL != hwndLogFileList ) {
  104. iLogFileCnt = LBNumItems(hwndLogFileList);
  105. for (iIndex = 0; iIndex < iLogFileCnt; iIndex++ ) {
  106. pInfo = (PLogItemInfo)LBData(hwndLogFileList,iIndex);
  107. if ( NULL != pInfo ) {
  108. if ( NULL != pInfo->pItem ) {
  109. pInfo->pItem->Release();
  110. }
  111. if (NULL != pInfo->pszPath ) {
  112. delete pInfo->pszPath;
  113. }
  114. delete pInfo;
  115. }
  116. }
  117. }
  118. return;
  119. }
  120. /*
  121. * CSourcePropPage::GetProperties
  122. *
  123. */
  124. BOOL CSourcePropPage::GetProperties(void)
  125. {
  126. BOOL bReturn = TRUE;
  127. DWORD dwStatus = ERROR_SUCCESS;
  128. ISystemMonitor *pObj = NULL;
  129. CImpISystemMonitor *pPrivObj = NULL;
  130. BSTR bstrPath;
  131. DATE date;
  132. LPWSTR szLogFileList = NULL;
  133. ULONG ulLogListBufLen = 0;
  134. BOOL bIsValidLogFile = FALSE;
  135. BOOL bIsValidLogFileRange = TRUE;
  136. ILogFileItem *pItem = NULL;
  137. PLogItemInfo pInfo = NULL;
  138. BSTR bstrTemp = NULL;
  139. INT iLogFile = 0;
  140. INT iIndex = 0;
  141. INT nChar = 0;
  142. USES_CONVERSION
  143. if (m_cObjects == 0) {
  144. bReturn = FALSE;
  145. } else {
  146. pObj = m_ppISysmon[0];
  147. // Get pointer to actual object for internal methods
  148. pPrivObj = (CImpISystemMonitor*)pObj;
  149. }
  150. if ( NULL == pObj || NULL == pPrivObj ) {
  151. bReturn = FALSE;
  152. } else {
  153. // Set the data source type
  154. pObj->get_DataSourceType (&m_eDataSourceType);
  155. CheckRadioButton(
  156. m_hDlg, IDC_SRC_REALTIME, IDC_SRC_SQL,
  157. IDC_SRC_REALTIME + m_eDataSourceType - 1);
  158. SetSourceControlStates();
  159. while (SUCCEEDED(pPrivObj->LogFile(iLogFile, &pItem))) {
  160. // Create LogItemInfo to hold the log file item and path
  161. pInfo = new LogItemInfo;
  162. if ( NULL == pInfo ) {
  163. bReturn = FALSE;
  164. break;
  165. }
  166. ZeroMemory ( pInfo, sizeof(LogItemInfo) );
  167. pInfo->pItem = pItem;
  168. if ( FAILED ( pItem->get_Path( &bstrPath ) ) ) {
  169. bReturn = FALSE;
  170. delete pInfo;
  171. break;
  172. } else {
  173. #if UNICODE
  174. nChar = lstrlen(bstrPath) + 1;
  175. #else
  176. nChar = (wcslen(bstrPath) + 1) * 2; // * 2???
  177. #endif
  178. pInfo->pszPath = new TCHAR [nChar];
  179. if ( NULL == pInfo->pszPath ) {
  180. delete pInfo;
  181. SysFreeString(bstrPath);
  182. bReturn = FALSE;
  183. break;
  184. }
  185. #if UNICODE
  186. lstrcpy(pInfo->pszPath, bstrPath);
  187. #else
  188. WideCharToMultiByte(CP_ACP, 0, bstrPath, nChar,
  189. pInfo->pszPath, nChar, NULL, NULL);
  190. #endif
  191. SysFreeString(bstrPath);
  192. }
  193. // Add the log file name to the list box
  194. iIndex = AddItemToFileListBox(pInfo);
  195. if ( LB_ERR == iIndex ) {
  196. bReturn = FALSE;
  197. delete pInfo->pszPath;
  198. delete pInfo;
  199. break;
  200. }
  201. iLogFile++;
  202. }
  203. // Get SQL DSN name, populate list box.
  204. pObj->get_SqlDsnName(&bstrTemp);
  205. memset ( m_szSqlDsnName, 0, sizeof (m_szSqlDsnName) );
  206. if ( NULL != bstrTemp ) {
  207. if ( bstrTemp[0] != _T('\0') ) {
  208. lstrcpyn (
  209. m_szSqlDsnName,
  210. W2T( bstrTemp ), min(SQL_MAX_DSN_LENGTH, lstrlen (W2T(bstrTemp))+1) );
  211. }
  212. SysFreeString (bstrTemp);
  213. bstrTemp = NULL;
  214. }
  215. InitSqlDsnList();
  216. // Get SQL log set name, populate list box.
  217. pObj->get_SqlLogSetName(&bstrTemp);
  218. memset ( m_szSqlLogSetName, 0, sizeof (m_szSqlLogSetName) );
  219. if ( NULL != bstrTemp ) {
  220. if ( bstrTemp[0] != _T('\0') ) {
  221. lstrcpyn (
  222. m_szSqlLogSetName,
  223. W2T( bstrTemp ), min(MAX_PATH-1, lstrlen (W2T(bstrTemp))+1) );
  224. }
  225. SysFreeString (bstrTemp);
  226. }
  227. InitSqlLogSetList();
  228. if ( m_eDataSourceType == sysmonLogFiles
  229. || m_eDataSourceType == sysmonSqlLog) {
  230. pPrivObj->GetLogFileRange(&m_llBegin, &m_llEnd);
  231. m_pTimeRange->SetBeginEnd(m_llBegin, m_llEnd);
  232. pObj->get_LogViewStart(&date);
  233. VariantDateToLLTime(date, &m_llStart);
  234. pObj->get_LogViewStop(&date);
  235. VariantDateToLLTime(date, &m_llStop);
  236. m_pTimeRange->SetStartStop(m_llStart, m_llStop);
  237. // OpenLogFile sets BeginEnd, StartStop values in the
  238. // time range control, if the file and range are valid.
  239. dwStatus = OpenLogFile ();
  240. if ( ERROR_SUCCESS == dwStatus ) {
  241. bIsValidLogFile = TRUE;
  242. bIsValidLogFileRange = TRUE;
  243. } else {
  244. bIsValidLogFile = FALSE;
  245. bIsValidLogFileRange = FALSE;
  246. m_llStart = MIN_TIME_VALUE;
  247. m_llStop = MAX_TIME_VALUE;
  248. if ( sysmonLogFiles == m_eDataSourceType ) {
  249. BuildLogFileList (
  250. m_hDlg,
  251. NULL,
  252. &ulLogListBufLen );
  253. szLogFileList = (LPWSTR) malloc(ulLogListBufLen * sizeof(WCHAR));
  254. if ( NULL != szLogFileList ) {
  255. BuildLogFileList (
  256. m_hDlg,
  257. szLogFileList,
  258. &ulLogListBufLen );
  259. }
  260. }
  261. if ( NULL != szLogFileList || sysmonSqlLog == m_eDataSourceType ) {
  262. DisplayDataSourceError (
  263. m_hDlg,
  264. dwStatus,
  265. m_eDataSourceType,
  266. szLogFileList,
  267. m_szSqlDsnName,
  268. m_szSqlLogSetName );
  269. if ( NULL != szLogFileList ) {
  270. delete szLogFileList;
  271. szLogFileList = NULL;
  272. ulLogListBufLen = 0;
  273. }
  274. }
  275. }
  276. } else {
  277. bIsValidLogFile = FALSE;
  278. bIsValidLogFileRange = FALSE;
  279. m_llStart = MIN_TIME_VALUE;
  280. m_llStop = MAX_TIME_VALUE;
  281. }
  282. // Set the start and stop time bars invisible or not, depending on time range
  283. pPrivObj->SetLogViewTempRange( m_llStart, m_llStop );
  284. SetTimeRangeCtrlState ( bIsValidLogFile, bIsValidLogFileRange );
  285. // Clear change flags
  286. m_bInitialTimeRangePending = !bIsValidLogFileRange;
  287. m_bLogFileChg = FALSE;
  288. m_bSqlDsnChg = FALSE;
  289. m_bSqlLogSetChg = FALSE;
  290. m_bRangeChg = FALSE;
  291. m_bDataSourceChg = FALSE;
  292. bReturn = TRUE;
  293. }
  294. return bReturn;
  295. }
  296. /*
  297. * CSourcePropPage::SetProperties
  298. *
  299. */
  300. BOOL CSourcePropPage::SetProperties(void)
  301. {
  302. ISystemMonitor* pObj = NULL;
  303. CImpISystemMonitor* pPrivObj = NULL;
  304. BOOL bIsValidLogFile = TRUE;
  305. BOOL bIsValidLogFileRange = TRUE;
  306. DWORD dwStatus = ERROR_SUCCESS;
  307. LPWSTR szLogFileList = NULL;
  308. ULONG ulLogListBufLen = 0;
  309. PLogItemInfo pInfo = NULL;
  310. PLogItemInfo pInfoNext = NULL;
  311. DATE date;
  312. BOOL bReturn = TRUE;
  313. HWND hwndLogFileList = NULL;
  314. INT iLogFileCnt;
  315. INT i;
  316. UINT uiMessage = 0;
  317. HRESULT hr = NOERROR;
  318. BOOL bNewFileIsValid = TRUE;
  319. BSTR bstrTemp = NULL;
  320. USES_CONVERSION
  321. hwndLogFileList = DialogControl(m_hDlg, IDC_LIST_LOGFILENAME);
  322. if ( 0 != m_cObjects ) {
  323. pObj = m_ppISysmon[0];
  324. if ( NULL != pObj ) {
  325. // Get pointer to actual object for internal methods
  326. pPrivObj = (CImpISystemMonitor*)pObj;
  327. }
  328. }
  329. if ( NULL != hwndLogFileList && NULL != pPrivObj ) {
  330. iLogFileCnt = LBNumItems(hwndLogFileList);
  331. // Validate properties
  332. if (m_eDataSourceType == sysmonLogFiles ) {
  333. if ( 0 == iLogFileCnt ) {
  334. uiMessage = IDS_NOLOGFILE_ERR;
  335. } else {
  336. // Check validity of existing files.
  337. // LogFilesAreValid displays any errors.
  338. LogFilesAreValid ( NULL, bNewFileIsValid, bReturn );
  339. }
  340. } else if ( m_eDataSourceType == sysmonSqlLog ){
  341. if ( _T('\0') == m_szSqlDsnName[0] ) {
  342. uiMessage = IDS_NO_SQL_DSN_ERR;
  343. } else if ( _T('\0') == m_szSqlLogSetName[0] ) {
  344. uiMessage = IDS_NO_SQL_LOG_SET_ERR;
  345. }
  346. }
  347. if ( 0 != uiMessage ) {
  348. MessageBox(m_hDlg, ResourceString(uiMessage), ResourceString(IDS_APP_NAME), MB_OK | MB_ICONEXCLAMATION);
  349. bReturn = FALSE;
  350. }
  351. if ( !bReturn ) {
  352. bIsValidLogFile = FALSE;
  353. // Todo: Set log file time range?
  354. }
  355. if ( m_eDataSourceType == sysmonLogFiles
  356. || m_eDataSourceType == sysmonSqlLog) {
  357. if ( bReturn && m_bInitialTimeRangePending ) {
  358. // If log file or SQL specified, but range has not been determined
  359. // Try to open it now and get the range
  360. dwStatus = OpenLogFile();
  361. if ( ERROR_SUCCESS == dwStatus ) {
  362. bIsValidLogFile = TRUE;
  363. bIsValidLogFileRange = TRUE;
  364. m_bInitialTimeRangePending = FALSE;
  365. } else {
  366. bReturn = FALSE;
  367. bIsValidLogFile = FALSE;
  368. bIsValidLogFileRange = FALSE;
  369. m_llStart = MIN_TIME_VALUE;
  370. m_llStop = MAX_TIME_VALUE;
  371. if ( sysmonLogFiles == m_eDataSourceType ) {
  372. BuildLogFileList (
  373. m_hDlg,
  374. NULL,
  375. &ulLogListBufLen );
  376. szLogFileList = (LPWSTR) malloc(ulLogListBufLen * sizeof(WCHAR));
  377. if ( NULL != szLogFileList ) {
  378. BuildLogFileList (
  379. m_hDlg,
  380. szLogFileList,
  381. &ulLogListBufLen );
  382. }
  383. }
  384. if ( NULL != szLogFileList || sysmonSqlLog == m_eDataSourceType ) {
  385. DisplayDataSourceError (
  386. m_hDlg,
  387. dwStatus,
  388. m_eDataSourceType,
  389. szLogFileList,
  390. m_szSqlDsnName,
  391. m_szSqlLogSetName );
  392. if ( NULL != szLogFileList ) {
  393. delete szLogFileList;
  394. szLogFileList = NULL;
  395. ulLogListBufLen = 0;
  396. }
  397. }
  398. }
  399. }
  400. // Set the start and stop time bars invisible or not, depending on time range
  401. pPrivObj->SetLogViewTempRange( m_llStart, m_llStop );
  402. SetTimeRangeCtrlState ( bIsValidLogFile, bIsValidLogFileRange );
  403. }
  404. }
  405. // Remove all deleted log files from the control.
  406. // Get first object
  407. if ( bReturn ) {
  408. if (m_bLogFileChg || m_bSqlDsnChg || m_bSqlLogSetChg ) {
  409. // Always set the log source to null data source before modifying the log file list
  410. // or database fields.
  411. // TodoLogFiles: This can leave the user with state different than before, in the
  412. // case of log file load failure.
  413. pObj->put_DataSourceType ( sysmonNullDataSource );
  414. m_bDataSourceChg = TRUE;
  415. }
  416. if ( m_bSqlDsnChg) {
  417. bstrTemp = SysAllocString(T2W(m_szSqlDsnName));
  418. if ( NULL != bstrTemp ) {
  419. hr = pObj->put_SqlDsnName(bstrTemp);
  420. } else {
  421. hr = E_OUTOFMEMORY;
  422. }
  423. SysFreeString (bstrTemp);
  424. bstrTemp = NULL;
  425. bReturn = SUCCEEDED ( hr );
  426. }
  427. if ( bReturn && m_bSqlLogSetChg) {
  428. bstrTemp = SysAllocString(T2W(m_szSqlLogSetName));
  429. if ( NULL != bstrTemp ) {
  430. hr = pObj->put_SqlLogSetName(bstrTemp);
  431. } else {
  432. hr = E_OUTOFMEMORY;
  433. }
  434. SysFreeString (bstrTemp);
  435. bstrTemp = NULL;
  436. bReturn = SUCCEEDED ( hr );
  437. }
  438. if (m_bLogFileChg) {
  439. // Remove all items in the delete list from the control.
  440. pInfo = m_pInfoDeleted;
  441. while ( NULL != pInfo ) {
  442. // If this counter exists in the control
  443. if ( NULL != pInfo->pItem ) {
  444. // Tell control to remove it
  445. // Always set the log source to CurrentActivity before modifying the log file list.
  446. pPrivObj->DeleteLogFile(pInfo->pItem);
  447. // Release the local reference
  448. pInfo->pItem->Release();
  449. }
  450. // Free the path string
  451. delete pInfo->pszPath;
  452. // Delete the Info structure and point to the next one
  453. pInfoNext = pInfo->pNextInfo;
  454. delete pInfo;
  455. pInfo = pInfoNext;
  456. }
  457. m_pInfoDeleted = NULL;
  458. // For each item
  459. for (i=0; i<iLogFileCnt; i++) {
  460. pInfo = (PLogItemInfo)LBData(hwndLogFileList,i);
  461. // If new item, create it now
  462. if (pInfo->pItem == NULL) {
  463. // The following code inits the pItem field of pInfo.
  464. #if UNICODE
  465. bstrTemp = SysAllocString(T2W(pInfo->pszPath));
  466. if ( NULL != bstrTemp ) {
  467. hr = pPrivObj->AddLogFile(bstrTemp, &pInfo->pItem);
  468. SysFreeString (bstrTemp);
  469. bstrTemp = NULL;
  470. } else {
  471. hr = E_OUTOFMEMORY;
  472. }
  473. #else
  474. INT nChar = lstrlen(pInfo->pszPath);
  475. LPWSTR pszPathW = new WCHAR [nChar + 1];
  476. if (pszPathW) {
  477. MultiByteToWideChar(CP_ACP, 0, pInfo->pszPath, nChar+1, pszPathW, nChar+1);
  478. bstrTemp = SysAllocString(pszPathW);
  479. if ( NULL != bstrTemp ) {
  480. hr = pPrivObj->AddLogFile(bstrTemp, &pInfo->pItem);
  481. SysFreeString (bstrTemp);
  482. bstrTemp = NULL;
  483. } else {
  484. hr = E_OUTOFMEMORY;
  485. }
  486. delete pszPathW;
  487. } else {
  488. hr = E_OUTOFMEMORY;
  489. }
  490. #endif
  491. }
  492. if ( FAILED ( hr) ) {
  493. break;
  494. }
  495. }
  496. bReturn = SUCCEEDED ( hr );
  497. }
  498. if ( bReturn && m_bDataSourceChg ) {
  499. // This covers CurrentActivity as well as log files, database
  500. hr = pObj->put_DataSourceType(m_eDataSourceType);
  501. bReturn = SUCCEEDED ( hr );
  502. if ( SUCCEEDED ( hr ) ) {
  503. m_bDataSourceChg = FALSE;
  504. m_bLogFileChg = FALSE;
  505. m_bSqlDsnChg = FALSE;
  506. m_bSqlLogSetChg = FALSE;
  507. } else {
  508. if ( sysmonLogFiles == m_eDataSourceType
  509. || sysmonSqlLog == m_eDataSourceType ) {
  510. // Display error messages, then retry in
  511. // Current Activity data source type.
  512. // TodoLogFiles: Message re: data source set to CurrentActivity if
  513. // put_DataSourceType failed.
  514. if ( sysmonLogFiles == m_eDataSourceType ) {
  515. BuildLogFileList (
  516. m_hDlg,
  517. NULL,
  518. &ulLogListBufLen );
  519. szLogFileList = (LPWSTR) malloc(ulLogListBufLen * sizeof(WCHAR));
  520. if ( NULL != szLogFileList ) {
  521. BuildLogFileList (
  522. m_hDlg,
  523. szLogFileList,
  524. &ulLogListBufLen );
  525. }
  526. }
  527. if ( NULL != szLogFileList || sysmonSqlLog == m_eDataSourceType ) {
  528. DisplayDataSourceError (
  529. m_hDlg,
  530. (DWORD)hr,
  531. m_eDataSourceType,
  532. szLogFileList,
  533. m_szSqlDsnName,
  534. m_szSqlLogSetName );
  535. if ( NULL != szLogFileList ) {
  536. delete szLogFileList;
  537. szLogFileList = NULL;
  538. ulLogListBufLen = 0;
  539. }
  540. }
  541. }
  542. // m_hDataSource should always be cleared unless in OpenLogFile method.
  543. assert ( H_REALTIME_DATASOURCE == m_hDataSource );
  544. // TodoLogFiles: Need separate method to handle all changes necesary
  545. // when the log source type changes.
  546. if ( sysmonCurrentActivity != m_eDataSourceType ) {
  547. m_eDataSourceType = sysmonCurrentActivity;
  548. CheckRadioButton(
  549. m_hDlg, IDC_SRC_REALTIME, IDC_SRC_SQL,
  550. IDC_SRC_REALTIME + m_eDataSourceType - 1);
  551. m_bDataSourceChg = TRUE;
  552. SetSourceControlStates();
  553. SetTimeRangeCtrlState (
  554. FALSE,
  555. FALSE );
  556. hr = pObj->put_DataSourceType ( m_eDataSourceType );
  557. bReturn = SUCCEEDED ( hr );
  558. m_bDataSourceChg = FALSE;
  559. m_bLogFileChg = FALSE;
  560. m_bSqlDsnChg = FALSE;
  561. m_bSqlLogSetChg = FALSE;
  562. } // else setting to Current Activity failed.
  563. }
  564. }
  565. if ( bReturn ) {
  566. if (m_eDataSourceType == sysmonLogFiles || m_eDataSourceType == sysmonSqlLog)
  567. pPrivObj->SetLogFileRange(m_llBegin, m_llEnd);
  568. else
  569. pObj->UpdateGraph();
  570. } else {
  571. SetFocus(GetDlgItem(m_hDlg, IDC_ADDFILE));
  572. }
  573. if (bReturn && m_bRangeChg
  574. && ( m_eDataSourceType == sysmonLogFiles
  575. || m_eDataSourceType == sysmonSqlLog)) {
  576. // With active logs, the begin/end points might have changed.
  577. pPrivObj->SetLogFileRange(m_llBegin, m_llEnd);
  578. // Always set Stop time first, to handle live logs.
  579. LLTimeToVariantDate(m_llStop, &date);
  580. pObj->put_LogViewStop(date);
  581. LLTimeToVariantDate(m_llStart, &date);
  582. pObj->put_LogViewStart(date);
  583. // Set the start and stop time bars visible in the graph
  584. pPrivObj->SetLogViewTempRange( m_llStart, m_llStop );
  585. m_bRangeChg = FALSE;
  586. }
  587. } else {
  588. bReturn = FALSE;
  589. }
  590. return bReturn;
  591. }
  592. void
  593. CSourcePropPage::LogFilesAreValid (
  594. PLogItemInfo pNewInfo,
  595. BOOL& rbNewIsValid,
  596. BOOL& rbExistingIsValid )
  597. {
  598. DWORD dwStatus = ERROR_SUCCESS;
  599. INT iIndex;
  600. INT iLogFileCnt = 0;
  601. HWND hwndLogFileList = NULL;
  602. TCHAR szLogFile[MAX_PATH];
  603. LPCTSTR pszTestFile = NULL;
  604. PLogItemInfo pInfo = NULL;
  605. TCHAR* pszMessage = NULL;
  606. TCHAR szSystemMessage[MAX_PATH];
  607. DWORD dwType = PDH_LOG_TYPE_BINARY;
  608. UINT uiErrorMessageID = 0;
  609. rbNewIsValid = TRUE;
  610. rbExistingIsValid = TRUE;
  611. hwndLogFileList = DialogControl(m_hDlg, IDC_LIST_LOGFILENAME);
  612. if ( NULL != hwndLogFileList ) {
  613. iLogFileCnt = LBNumItems(hwndLogFileList);
  614. }
  615. if ( NULL != pNewInfo && NULL != hwndLogFileList ) {
  616. if ( NULL != pNewInfo->pszPath ) {
  617. // Check for duplicates.
  618. for (iIndex = 0; iIndex < iLogFileCnt; iIndex++ ) {
  619. LBGetText(hwndLogFileList, iIndex, szLogFile);
  620. if ( 0 == lstrcmpi ( pNewInfo->pszPath, szLogFile ) ) {
  621. MessageBox(
  622. m_hDlg,
  623. ResourceString(IDS_DUPL_LOGFILE_ERR),
  624. ResourceString(IDS_APP_NAME),
  625. MB_OK | MB_ICONWARNING);
  626. iIndex = LB_ERR;
  627. rbNewIsValid = FALSE;
  628. break;
  629. }
  630. }
  631. // Validate added log file type if multiple log files
  632. if ( rbNewIsValid && 0 < iLogFileCnt ) {
  633. // Validate the new file
  634. dwType = PDH_LOG_TYPE_BINARY;
  635. pszTestFile = pNewInfo->pszPath;
  636. if ( NULL != pszTestFile ) {
  637. dwStatus = PdhGetLogFileType (
  638. pszTestFile,
  639. &dwType );
  640. if ( ERROR_SUCCESS == dwStatus ) {
  641. if ( PDH_LOG_TYPE_BINARY != dwType ) {
  642. if ( (DWORD)ePdhLogTypeRetiredBinary == dwType ) {
  643. uiErrorMessageID = IDS_MULTILOG_BIN_TYPE_ADD_ERR;
  644. } else {
  645. uiErrorMessageID = IDS_MULTILOG_TEXT_TYPE_ADD_ERR;
  646. }
  647. rbNewIsValid = FALSE;
  648. }
  649. } else {
  650. // bad dwStatus error message handled below
  651. rbNewIsValid = FALSE;
  652. }
  653. }
  654. }
  655. } else {
  656. rbNewIsValid = FALSE;
  657. assert ( FALSE );
  658. }
  659. }
  660. // Validate existing files if the new count will be > 1
  661. if ( rbNewIsValid
  662. && ( NULL != pNewInfo || iLogFileCnt > 1 ) )
  663. {
  664. dwType = PDH_LOG_TYPE_BINARY;
  665. for (iIndex=0; iIndex<iLogFileCnt; iIndex++) {
  666. pInfo = (PLogItemInfo)LBData(hwndLogFileList,iIndex);
  667. if ( NULL != pInfo ) {
  668. pszTestFile = pInfo->pszPath;
  669. if ( NULL != pszTestFile ) {
  670. dwStatus = PdhGetLogFileType (
  671. pszTestFile,
  672. &dwType );
  673. if ( PDH_LOG_TYPE_BINARY != dwType ) {
  674. rbExistingIsValid = FALSE;
  675. break;
  676. }
  677. }
  678. }
  679. }
  680. if ( ERROR_SUCCESS == dwStatus ) {
  681. if ( PDH_LOG_TYPE_BINARY != dwType ) {
  682. if ( (DWORD)ePdhLogTypeRetiredBinary == dwType ) {
  683. uiErrorMessageID = IDS_MULTILOG_BIN_TYPE_ERR;
  684. } else {
  685. uiErrorMessageID = IDS_MULTILOG_TEXT_TYPE_ERR;
  686. }
  687. rbExistingIsValid = FALSE;
  688. }
  689. } else {
  690. rbExistingIsValid = FALSE;
  691. }
  692. }
  693. if ( ( !rbNewIsValid || !rbExistingIsValid )
  694. && NULL != pszTestFile )
  695. {
  696. iIndex = LB_ERR;
  697. // Check dwStatus of PdhGetLogFileType call.
  698. if ( ERROR_SUCCESS == dwStatus ) {
  699. if ( PDH_LOG_TYPE_BINARY != dwType ) {
  700. assert ( 0 != uiErrorMessageID );
  701. pszMessage = new TCHAR [ ( 2*lstrlen(pszTestFile) ) + MAX_PATH];
  702. if ( NULL != pszMessage ) {
  703. _stprintf (
  704. pszMessage,
  705. ResourceString(uiErrorMessageID),
  706. pszTestFile,
  707. pszTestFile );
  708. MessageBox (
  709. m_hDlg,
  710. pszMessage,
  711. ResourceString(IDS_APP_NAME),
  712. MB_OK | MB_ICONSTOP );
  713. delete pszMessage;
  714. }
  715. }
  716. } else {
  717. pszMessage = new TCHAR [lstrlen(pszTestFile) + 2*MAX_PATH];
  718. if ( NULL != pszMessage ) {
  719. _stprintf (
  720. pszMessage,
  721. ResourceString(IDS_MULTILOG_CHECKTYPE_ERR),
  722. pszTestFile );
  723. FormatSystemMessage (
  724. dwStatus, szSystemMessage, MAX_PATH );
  725. lstrcat ( pszMessage, szSystemMessage );
  726. MessageBox (
  727. m_hDlg,
  728. pszMessage,
  729. ResourceString(IDS_APP_NAME),
  730. MB_OK | MB_ICONSTOP);
  731. delete pszMessage;
  732. }
  733. }
  734. }
  735. return;
  736. }
  737. INT
  738. CSourcePropPage::AddItemToFileListBox (
  739. IN PLogItemInfo pNewInfo )
  740. /*++
  741. Routine Description:
  742. AddItemToFileListBox adds a log file's path name to the dialog list box and
  743. attaches a pointer to the log file's LogItemInfo structure as item data.
  744. It also adjusts the horizontal scroll of the list box.
  745. Arguments:
  746. pInfo - Pointer to log file's LogItemInfo structure
  747. Return Value:
  748. List box index of added log file (LB_ERR on failure)
  749. --*/
  750. {
  751. INT iIndex = LB_ERR;
  752. HWND hwndLogFileList = NULL;
  753. DWORD dwItemExtent = 0;
  754. HDC hDC = NULL;
  755. BOOL bNewIsValid;
  756. BOOL bExistingAreValid;
  757. hwndLogFileList = DialogControl(m_hDlg, IDC_LIST_LOGFILENAME);
  758. if ( NULL != pNewInfo && NULL != hwndLogFileList ) {
  759. LogFilesAreValid ( pNewInfo, bNewIsValid, bExistingAreValid );
  760. if ( bNewIsValid && NULL != pNewInfo->pszPath ) {
  761. iIndex = (INT)LBAdd ( hwndLogFileList, pNewInfo->pszPath );
  762. LBSetSelection( hwndLogFileList, iIndex);
  763. if ( LB_ERR != iIndex && LB_ERRSPACE != iIndex ) {
  764. LBSetData(hwndLogFileList, iIndex, pNewInfo);
  765. hDC = GetDC ( hwndLogFileList );
  766. if ( NULL != hDC ) {
  767. dwItemExtent = (DWORD)TextWidth ( hDC, pNewInfo->pszPath );
  768. if (dwItemExtent > m_dwMaxHorizListExtent) {
  769. m_dwMaxHorizListExtent = dwItemExtent;
  770. LBSetHorzExtent ( hwndLogFileList, dwItemExtent );
  771. }
  772. ReleaseDC ( hwndLogFileList, hDC );
  773. }
  774. OnLogFileChange();
  775. } else {
  776. iIndex = LB_ERR ;
  777. }
  778. }
  779. }
  780. return iIndex;
  781. }
  782. BOOL
  783. CSourcePropPage::RemoveItemFromFileListBox (
  784. void )
  785. /*++
  786. Routine Description:
  787. RemoveItemFromFileListBox removes the currently selected log file from
  788. the dialog's log file name listbox. It adds the item to the deletion
  789. list, so the actual log file can be deleted from the control when
  790. (and if) the changes are applied.
  791. The routine selects selects the next log file in the listbox if there
  792. is one, and adjusts the horizontal scroll appropriately.
  793. Arguments:
  794. None.
  795. Return Value:
  796. None.
  797. --*/
  798. {
  799. BOOL bChanged = FALSE;
  800. HWND hWnd;
  801. INT iIndex;
  802. PLogItemInfo pInfo = NULL;
  803. LPTSTR szBuffer = NULL;
  804. DWORD dwItemExtent = 0;
  805. INT iCurrentBufLen = 0;
  806. INT iTextLen;
  807. HDC hDC = NULL;
  808. // Get selected index
  809. hWnd = DialogControl(m_hDlg, IDC_LIST_LOGFILENAME);
  810. iIndex = LBSelection(hWnd);
  811. if ( LB_ERR != iIndex ) {
  812. // Get selected item info
  813. pInfo = (PLogItemInfo)LBData(hWnd, iIndex);
  814. // Move it to the "Deleted" list.
  815. pInfo->pNextInfo = m_pInfoDeleted;
  816. m_pInfoDeleted = pInfo;
  817. // Remove the string from the list box.
  818. LBDelete(hWnd, iIndex);
  819. // Select next item if possible, else the previous
  820. if (iIndex == LBNumItems(hWnd)) {
  821. iIndex--;
  822. }
  823. LBSetSelection( hWnd, iIndex);
  824. hDC = GetDC ( hWnd );
  825. if ( NULL != hDC ) {
  826. // Clear the max horizontal extent and recalculate
  827. m_dwMaxHorizListExtent = 0;
  828. for ( iIndex = 0; iIndex < (INT)LBNumItems ( hWnd ); iIndex++ ) {
  829. iTextLen = (INT)LBGetTextLen ( hWnd, iIndex );
  830. if ( iTextLen >= iCurrentBufLen ) {
  831. if ( NULL != szBuffer ) {
  832. delete szBuffer;
  833. szBuffer = NULL;
  834. }
  835. iCurrentBufLen = iTextLen + 1;
  836. szBuffer = new TCHAR [iCurrentBufLen];
  837. }
  838. if ( NULL != szBuffer ) {
  839. LBGetText ( hWnd, iIndex, szBuffer );
  840. dwItemExtent = (DWORD)TextWidth ( hDC, szBuffer );
  841. if (dwItemExtent > m_dwMaxHorizListExtent) {
  842. m_dwMaxHorizListExtent = dwItemExtent;
  843. }
  844. }
  845. }
  846. LBSetHorzExtent ( hWnd, m_dwMaxHorizListExtent );
  847. ReleaseDC ( hWnd, hDC );
  848. }
  849. if ( NULL != szBuffer ) {
  850. delete szBuffer;
  851. }
  852. bChanged = TRUE;
  853. OnLogFileChange();
  854. }
  855. return bChanged;
  856. }
  857. void
  858. CSourcePropPage::OnLogFileChange ( void )
  859. {
  860. HWND hwndLogFileList = NULL;
  861. INT iLogFileCnt = 0;
  862. BOOL bIsValidDataSource = FALSE;
  863. m_bLogFileChg = TRUE;
  864. m_bInitialTimeRangePending = TRUE;
  865. hwndLogFileList = DialogControl(m_hDlg, IDC_LIST_LOGFILENAME);
  866. if ( NULL != hwndLogFileList ) {
  867. iLogFileCnt = LBNumItems(hwndLogFileList);
  868. }
  869. bIsValidDataSource = (iLogFileCnt > 0);
  870. if (m_eDataSourceType == sysmonLogFiles) {
  871. DialogEnable(m_hDlg, IDC_REMOVEFILE, ( bIsValidDataSource ) );
  872. }
  873. SetTimeRangeCtrlState( bIsValidDataSource, FALSE );
  874. }
  875. void
  876. CSourcePropPage::OnSqlDataChange ( void )
  877. {
  878. BOOL bIsValidDataSource = FALSE;
  879. assert ( sysmonSqlLog == m_eDataSourceType );
  880. m_bInitialTimeRangePending = TRUE;
  881. bIsValidDataSource = 0 < lstrlen ( m_szSqlDsnName ) && 0 < lstrlen ( m_szSqlLogSetName );
  882. SetTimeRangeCtrlState( bIsValidDataSource, FALSE );
  883. }
  884. void
  885. CSourcePropPage::DialogItemChange(WORD wID, WORD wMsg)
  886. {
  887. ISystemMonitor *pObj = NULL;
  888. CImpISystemMonitor *pPrivObj = NULL;
  889. HWND hwndCtrl = NULL;
  890. BOOL fChange = FALSE;
  891. DataSourceTypeConstants eNewDataSourceType;
  892. HWND hwndLogFileList = NULL;
  893. INT iLogFileCnt = 0;;
  894. BOOL bIsValidDataSource;
  895. switch(wID) {
  896. case IDC_SRC_REALTIME:
  897. case IDC_SRC_LOGFILE:
  898. case IDC_SRC_SQL:
  899. // Check which button is involved
  900. eNewDataSourceType = (DataSourceTypeConstants)(wID - IDC_SRC_REALTIME + 1);
  901. // If state changed
  902. if ( wMsg == BN_CLICKED
  903. && eNewDataSourceType != m_eDataSourceType) {
  904. // Set change flags and update the radio button
  905. m_bDataSourceChg = TRUE;
  906. fChange = TRUE;
  907. m_eDataSourceType = eNewDataSourceType;
  908. CheckRadioButton(
  909. m_hDlg, IDC_SRC_REALTIME, IDC_SRC_SQL,
  910. IDC_SRC_REALTIME + m_eDataSourceType - 1);
  911. SetSourceControlStates();
  912. pObj = m_ppISysmon[0];
  913. if ( NULL != m_ppISysmon[0] ) {
  914. pPrivObj = (CImpISystemMonitor*) pObj;
  915. }
  916. if ( NULL != pPrivObj ) {
  917. bIsValidDataSource = FALSE;
  918. hwndLogFileList = DialogControl(m_hDlg, IDC_LIST_LOGFILENAME);
  919. if ( NULL != hwndLogFileList ) {
  920. iLogFileCnt = LBNumItems(hwndLogFileList);
  921. }
  922. if ( sysmonLogFiles == m_eDataSourceType && iLogFileCnt > 0) {
  923. bIsValidDataSource = (iLogFileCnt > 0);
  924. if ( bIsValidDataSource ) {
  925. SetFocus(GetDlgItem(m_hDlg, IDC_ADDFILE));
  926. }
  927. } else if ( sysmonSqlLog == m_eDataSourceType ) {
  928. bIsValidDataSource = ( 0 < lstrlen ( m_szSqlDsnName ) )
  929. && ( 0 < lstrlen ( m_szSqlLogSetName ) );
  930. } // else current activity, so no valid data source
  931. if ( bIsValidDataSource ) {
  932. // Set the start and stop time bars visible in the graph
  933. pPrivObj->SetLogViewTempRange( m_llStart, m_llStop );
  934. } else {
  935. // Set the start and stop time bars invisible in the graph
  936. pPrivObj->SetLogViewTempRange( MIN_TIME_VALUE, MAX_TIME_VALUE );
  937. }
  938. }
  939. m_bDataSourceChg = TRUE;
  940. }
  941. break;
  942. case IDC_REMOVEFILE:
  943. fChange = RemoveItemFromFileListBox();
  944. break;
  945. case IDC_ADDFILE:
  946. {
  947. TCHAR szDefaultFolderBuff[MAX_PATH + 1];
  948. LPWSTR szBrowseBuffer = NULL;
  949. INT iFolderBufLen;
  950. PDH_STATUS pdhstat;
  951. LogItemInfo* pInfo = NULL;
  952. DWORD cchLen = 0;
  953. DWORD cchBrowseBuffer = 0;
  954. szDefaultFolderBuff[0] = L'\0';
  955. iFolderBufLen = MAX_PATH;
  956. if ( ERROR_SUCCESS != LoadDefaultLogFileFolder(szDefaultFolderBuff, &iFolderBufLen) ) {
  957. if ( iFolderBufLen > lstrlen ( ResourceString ( IDS_DEFAULT_LOG_FILE_FOLDER ) ) ) {
  958. lstrcpy ( szDefaultFolderBuff, ResourceString ( IDS_DEFAULT_LOG_FILE_FOLDER ) );
  959. }
  960. }
  961. //
  962. // Expand environment strings.
  963. //
  964. cchLen = ExpandEnvironmentStrings ( szDefaultFolderBuff, NULL, 0 );
  965. if ( 0 < cchLen ) {
  966. //
  967. // cchLen includes space for null.
  968. //
  969. cchBrowseBuffer = max ( cchLen, MAX_PATH + 1 );
  970. szBrowseBuffer = new WCHAR [ cchBrowseBuffer ];
  971. szBrowseBuffer[0] = L'\0';
  972. if ( NULL != szBrowseBuffer ) {
  973. cchLen = ExpandEnvironmentStrings (
  974. szDefaultFolderBuff,
  975. szBrowseBuffer,
  976. cchBrowseBuffer );
  977. if ( 0 < cchLen && cchLen <= cchBrowseBuffer ) {
  978. SetCurrentDirectory(szBrowseBuffer);
  979. } else {
  980. }
  981. }
  982. }
  983. if ( NULL != szBrowseBuffer ) {
  984. szBrowseBuffer[0] = L'\0';
  985. pdhstat = PdhSelectDataSource(
  986. m_hDlg,
  987. PDH_FLAGS_FILE_BROWSER_ONLY,
  988. szBrowseBuffer,
  989. &cchBrowseBuffer);
  990. if ( ERROR_SUCCESS != pdhstat || szBrowseBuffer[0] == L'\0' ) {
  991. delete [] szBrowseBuffer;
  992. szBrowseBuffer = NULL;
  993. break;
  994. }
  995. // Load file name into edit control
  996. pInfo = new LogItemInfo;
  997. if ( NULL != pInfo ) {
  998. ZeroMemory ( pInfo, sizeof(LogItemInfo) );
  999. //
  1000. // Make own copy of path name string
  1001. //
  1002. pInfo->pszPath = new TCHAR [lstrlen( szBrowseBuffer ) + 1];
  1003. // TodoLogFiles: Multi-log file support
  1004. if ( NULL != pInfo->pszPath ) {
  1005. INT iIndex = 0;
  1006. lstrcpy(pInfo->pszPath, szBrowseBuffer);
  1007. iIndex = AddItemToFileListBox ( pInfo );
  1008. fChange = ( LB_ERR != iIndex );
  1009. if (!fChange) {
  1010. // Todo: error message
  1011. delete [] pInfo->pszPath;
  1012. delete pInfo;
  1013. }
  1014. } else {
  1015. // Todo: error message
  1016. delete pInfo;
  1017. }
  1018. }
  1019. // Todo: error message
  1020. }
  1021. if ( NULL != szBrowseBuffer ) {
  1022. delete [] szBrowseBuffer;
  1023. }
  1024. break;
  1025. }
  1026. /*
  1027. // Doesn't do anything
  1028. case IDC_LIST_LOGFILENAME:
  1029. // If selection changed
  1030. if (wMsg == LBN_SELCHANGE) {
  1031. // TodoLogFiles: Selection change won't matter when multi-file support
  1032. fChange = TRUE;
  1033. OnLogFileChange();
  1034. // Get selected index
  1035. hwndCtrl = DialogControl(m_hDlg, IDC_LIST_LOGFILENAME);
  1036. iIndex = LBSelection(hwndCtrl);
  1037. }
  1038. break;
  1039. */
  1040. case IDC_DSN_COMBO:
  1041. {
  1042. TCHAR szDsnName[SQL_MAX_DSN_LENGTH + 1];
  1043. INT iSel;
  1044. HWND hDsnCombo;
  1045. szDsnName[0] = _T('\0');
  1046. hDsnCombo = GetDlgItem ( m_hDlg, IDC_DSN_COMBO);
  1047. if ( NULL != hDsnCombo ) {
  1048. iSel = (INT)CBSelection ( hDsnCombo );
  1049. if ( LB_ERR != iSel ) {
  1050. CBString(
  1051. hDsnCombo,
  1052. iSel,
  1053. szDsnName);
  1054. if ( 0 != lstrcmpi ( m_szSqlDsnName, szDsnName ) ) {
  1055. lstrcpyn (
  1056. m_szSqlDsnName,
  1057. szDsnName,
  1058. min ( SQL_MAX_DSN_LENGTH, lstrlen(szDsnName)+1 ) );
  1059. m_bSqlDsnChg = TRUE;
  1060. InitSqlLogSetList();
  1061. OnSqlDataChange();
  1062. fChange = TRUE;
  1063. }
  1064. }
  1065. }
  1066. }
  1067. break;
  1068. case IDC_LOGSET_COMBO:
  1069. {
  1070. TCHAR szLogSetName[MAX_PATH];
  1071. INT iSel;
  1072. HWND hLogSetCombo;
  1073. szLogSetName[0] = _T('\0');
  1074. hLogSetCombo = GetDlgItem ( m_hDlg, IDC_LOGSET_COMBO);
  1075. if ( NULL != hLogSetCombo ) {
  1076. iSel = (INT)CBSelection ( hLogSetCombo );
  1077. if ( LB_ERR != iSel ) {
  1078. CBString (
  1079. hLogSetCombo,
  1080. iSel,
  1081. szLogSetName );
  1082. if ( ( 0 != lstrcmpi ( m_szSqlLogSetName, szLogSetName ) )
  1083. && ( 0 != lstrcmpi ( szLogSetName, ResourceString ( IDS_LOGSET_NOT_FOUND ) ) ) ) {
  1084. lstrcpyn (
  1085. m_szSqlLogSetName,
  1086. szLogSetName,
  1087. min ( MAX_PATH - 1, lstrlen(szLogSetName)+1 ) );
  1088. m_bSqlLogSetChg = TRUE;
  1089. OnSqlDataChange();
  1090. fChange = TRUE;
  1091. }
  1092. }
  1093. }
  1094. }
  1095. break;
  1096. case IDC_TIMESELECTBTN:
  1097. {
  1098. DWORD dwStatus = ERROR_SUCCESS;
  1099. BOOL bAttemptedReload = FALSE;
  1100. hwndCtrl = DialogControl(m_hDlg, IDC_LIST_LOGFILENAME);
  1101. if ( NULL != hwndCtrl ) {
  1102. {
  1103. CWaitCursor cursorWait;
  1104. dwStatus = OpenLogFile ();
  1105. }
  1106. if ( SMON_STATUS_LOG_FILE_SIZE_LIMIT == dwStatus ) {
  1107. TCHAR szMessage[2*MAX_PATH];
  1108. BSTR bstrPath;
  1109. int iResult;
  1110. pObj = m_ppISysmon[0];
  1111. pObj->get_LogFileName ( &bstrPath );
  1112. // Todo: Still use LogfileName from object? Build log file set?
  1113. if ( bstrPath ) {
  1114. if ( bstrPath[0] ) {
  1115. lstrcpy ( szMessage, ResourceString(IDS_LARGE_LOG_FILE_RELOAD) );
  1116. iResult = MessageBox(
  1117. m_hDlg,
  1118. szMessage,
  1119. ResourceString(IDS_APP_NAME),
  1120. MB_YESNO | MB_ICONEXCLAMATION);
  1121. if ( IDYES == iResult ) {
  1122. CWaitCursor cursorWait;
  1123. dwStatus = OpenLogFile ();
  1124. bAttemptedReload = TRUE;
  1125. }
  1126. }
  1127. SysFreeString(bstrPath);
  1128. }
  1129. }
  1130. if ( ERROR_SUCCESS == dwStatus ) {
  1131. m_bInitialTimeRangePending = FALSE;
  1132. // Show graph log view start/stop time bars
  1133. pObj = m_ppISysmon[0];
  1134. pPrivObj = (CImpISystemMonitor*)pObj;
  1135. pPrivObj->SetLogViewTempRange( m_llStart, m_llStop );
  1136. SetTimeRangeCtrlState (
  1137. TRUE,
  1138. TRUE );
  1139. m_bRangeChg = TRUE;
  1140. fChange = TRUE;
  1141. } else { // OpenLogFile failure
  1142. if ( ( SMON_STATUS_LOG_FILE_SIZE_LIMIT == dwStatus ) && !bAttemptedReload ) {
  1143. // Message already displayed, user chose not to continue.
  1144. } else {
  1145. LPWSTR szLogFileList = NULL;
  1146. ULONG ulLogListBufLen = 0;
  1147. if ( sysmonLogFiles == m_eDataSourceType ) {
  1148. BuildLogFileList (
  1149. m_hDlg,
  1150. NULL,
  1151. &ulLogListBufLen );
  1152. szLogFileList = (LPWSTR) malloc(ulLogListBufLen * sizeof(WCHAR));
  1153. if ( NULL != szLogFileList ) {
  1154. BuildLogFileList (
  1155. m_hDlg,
  1156. szLogFileList,
  1157. &ulLogListBufLen );
  1158. }
  1159. }
  1160. if ( NULL != szLogFileList || sysmonSqlLog == m_eDataSourceType ) {
  1161. DisplayDataSourceError (
  1162. m_hDlg,
  1163. dwStatus,
  1164. m_eDataSourceType,
  1165. szLogFileList,
  1166. m_szSqlDsnName,
  1167. m_szSqlLogSetName );
  1168. if ( NULL != szLogFileList ) {
  1169. delete szLogFileList;
  1170. szLogFileList = NULL;
  1171. ulLogListBufLen = 0;
  1172. }
  1173. }
  1174. }
  1175. }
  1176. }
  1177. break;
  1178. }
  1179. case IDC_TIMERANGE:
  1180. m_llStart = m_pTimeRange->GetStart();
  1181. m_llStop = m_pTimeRange->GetStop();
  1182. // Show graph log view start/stop time bars
  1183. pObj = m_ppISysmon[0];
  1184. pPrivObj = (CImpISystemMonitor*)pObj;
  1185. pPrivObj->SetLogViewTempRange( m_llStart, m_llStop );
  1186. fChange = TRUE;
  1187. m_bRangeChg = TRUE;
  1188. break;
  1189. }
  1190. if (fChange)
  1191. SetChange();
  1192. }
  1193. DWORD
  1194. CSourcePropPage::OpenLogFile (void)
  1195. {
  1196. DWORD dwStatus = ERROR_SUCCESS;
  1197. DWORD nBufSize;
  1198. DWORD nLogEntries = 0;
  1199. PDH_TIME_INFO TimeInfo;
  1200. LPTSTR szLogFileList = NULL;
  1201. LPTSTR szCurrentLogFile;
  1202. ULONG LogFileListSize = 0;
  1203. HWND hwndLogFileList = NULL;
  1204. INT iLogFileCount;
  1205. INT iLogFileIndex;
  1206. PLogItemInfo pInfo;
  1207. BOOLEAN bSqlLogSet =
  1208. (BST_CHECKED == IsDlgButtonChecked(m_hDlg,IDC_SRC_SQL));
  1209. TCHAR szDsnName[SQL_MAX_DSN_LENGTH + 1];
  1210. TCHAR szLogSetName[SQL_MAX_DSN_LENGTH + 1];
  1211. INT iSel;
  1212. HWND hDsnCombo;
  1213. HWND hLogSetCombo;
  1214. memset (&TimeInfo, 0, sizeof(TimeInfo));
  1215. hwndLogFileList = DialogControl(m_hDlg, IDC_LIST_LOGFILENAME);
  1216. if ( NULL != hwndLogFileList ) {
  1217. iLogFileCount = LBNumItems(hwndLogFileList);
  1218. }
  1219. if (bSqlLogSet) {
  1220. LogFileListSize = 0;
  1221. szDsnName[0] = _T('\0');
  1222. szLogSetName[0] = _T('\0');
  1223. hDsnCombo = GetDlgItem ( m_hDlg, IDC_DSN_COMBO);
  1224. if ( NULL != hDsnCombo ) {
  1225. iSel = (INT)CBSelection ( hDsnCombo );
  1226. if ( LB_ERR != iSel ) {
  1227. CBString (
  1228. hDsnCombo,
  1229. iSel,
  1230. szDsnName);
  1231. hLogSetCombo = GetDlgItem ( m_hDlg, IDC_LOGSET_COMBO);
  1232. if ( NULL != hLogSetCombo ) {
  1233. iSel = (INT)CBSelection ( hLogSetCombo );
  1234. if ( LB_ERR != iSel ) {
  1235. CBString(
  1236. hLogSetCombo,
  1237. iSel,
  1238. szLogSetName);
  1239. // Size includes 5 characters "SQL:" "!"and 2 nulls
  1240. LogFileListSize = lstrlen(szDsnName) + lstrlen(szLogSetName) + 7;
  1241. }
  1242. }
  1243. }
  1244. }
  1245. } else {
  1246. if ( NULL != hwndLogFileList ) {
  1247. for (iLogFileIndex = 0; iLogFileIndex < iLogFileCount; iLogFileIndex ++) {
  1248. pInfo = (PLogItemInfo) LBData(hwndLogFileList, iLogFileIndex);
  1249. if (pInfo && pInfo->pszPath) {
  1250. LogFileListSize += (lstrlen(pInfo->pszPath) + 1);
  1251. }
  1252. }
  1253. LogFileListSize ++;
  1254. }
  1255. }
  1256. szLogFileList = (LPTSTR) malloc(LogFileListSize * sizeof(TCHAR));
  1257. if (szLogFileList) {
  1258. if (bSqlLogSet) {
  1259. ZeroMemory(szLogFileList, LogFileListSize * sizeof(TCHAR));
  1260. _stprintf(szLogFileList, _T("SQL:%s!%s"), szDsnName, szLogSetName);
  1261. } else {
  1262. if ( NULL != hwndLogFileList ) {
  1263. szCurrentLogFile = szLogFileList;
  1264. for (iLogFileIndex = 0;
  1265. iLogFileIndex < iLogFileCount;
  1266. iLogFileIndex ++) {
  1267. pInfo = (PLogItemInfo) LBData(hwndLogFileList, iLogFileIndex);
  1268. if (pInfo && pInfo->pszPath) {
  1269. lstrcpy(szCurrentLogFile, pInfo->pszPath);
  1270. szCurrentLogFile += lstrlen(pInfo->pszPath);
  1271. * szCurrentLogFile = _T('\0');
  1272. szCurrentLogFile ++;
  1273. }
  1274. }
  1275. * szCurrentLogFile = _T('\0');
  1276. }
  1277. }
  1278. if ( m_hDataSource != H_REALTIME_DATASOURCE
  1279. && m_hDataSource != H_WBEM_DATASOURCE)
  1280. {
  1281. PdhCloseLog(m_hDataSource, 0);
  1282. m_hDataSource = H_REALTIME_DATASOURCE;
  1283. }
  1284. dwStatus = PdhBindInputDataSource(& m_hDataSource, szLogFileList);
  1285. if ( ERROR_SUCCESS == dwStatus ) {
  1286. // Get time and sample count info
  1287. nBufSize = sizeof(TimeInfo);
  1288. dwStatus = PdhGetDataSourceTimeRangeH(
  1289. m_hDataSource, &nLogEntries, &TimeInfo, & nBufSize);
  1290. PdhCloseLog(m_hDataSource, 0);
  1291. m_hDataSource = H_REALTIME_DATASOURCE;
  1292. }
  1293. free(szLogFileList);
  1294. szLogFileList = NULL;
  1295. } else {
  1296. dwStatus = ERROR_NOT_ENOUGH_MEMORY;
  1297. }
  1298. if (ERROR_NOT_ENOUGH_MEMORY == dwStatus ) {
  1299. dwStatus = SMON_STATUS_LOG_FILE_SIZE_LIMIT;
  1300. }
  1301. if ( ERROR_SUCCESS == dwStatus ) {
  1302. // Check that at least 2 samples exist:
  1303. // If 0 samples, StartTime is 0, EndTime is 0
  1304. // If 1 sample, StartTime == EndTime
  1305. if ( ( TimeInfo.StartTime < TimeInfo.EndTime )
  1306. && ( 1 < TimeInfo.SampleCount ) ){
  1307. // Load log time range into time range control
  1308. m_llBegin = TimeInfo.StartTime;
  1309. m_llEnd = TimeInfo.EndTime;
  1310. // Limit view range to actual log file range
  1311. if (m_llStop > m_llEnd ) {
  1312. m_llStop = m_llEnd;
  1313. } else if (m_llStop < m_llBegin ) {
  1314. m_llStop = m_llBegin;
  1315. }
  1316. if (m_llStart < m_llBegin)
  1317. m_llStart = m_llBegin;
  1318. if (m_llStart > m_llStop)
  1319. m_llStart = m_llStop;
  1320. m_pTimeRange->SetBeginEnd(m_llBegin, m_llEnd);
  1321. m_pTimeRange->SetStartStop(m_llStart, m_llStop);
  1322. } else {
  1323. dwStatus = SMON_STATUS_TOO_FEW_SAMPLES;
  1324. }
  1325. }
  1326. return dwStatus;
  1327. }
  1328. void
  1329. CSourcePropPage::SetTimeRangeCtrlState (
  1330. BOOL bIsValidLogFile,
  1331. BOOL bIsValidLogFileRange )
  1332. {
  1333. // Enable time range button if valid log file, even if log data is invalid.
  1334. DialogEnable ( m_hDlg, IDC_TIMESELECTBTN, bIsValidLogFile );
  1335. // Set time range controls visible or not, depending on valid log file and data.
  1336. DialogEnable ( m_hDlg, IDC_TIMERANGE, bIsValidLogFile && bIsValidLogFileRange );
  1337. DialogEnable ( m_hDlg, IDC_STATIC_TOTAL, bIsValidLogFile && bIsValidLogFileRange );
  1338. DialogEnable ( m_hDlg, IDC_STATIC_SELECTED, bIsValidLogFile && bIsValidLogFileRange );
  1339. }
  1340. void
  1341. CSourcePropPage::InitSqlDsnList(void)
  1342. {
  1343. HENV henv;
  1344. RETCODE retcode;
  1345. INT DsnCount = 0;
  1346. HWND hWnd = NULL;
  1347. TCHAR szTmpName[SQL_MAX_DSN_LENGTH + 1];
  1348. hWnd = GetDlgItem(m_hDlg, IDC_DSN_COMBO);
  1349. if ( NULL != hWnd ) {
  1350. if (SQL_SUCCEEDED(SQLAllocHandle(SQL_HANDLE_ENV, NULL, & henv))) {
  1351. (void) SQLSetEnvAttr(henv,
  1352. SQL_ATTR_ODBC_VERSION,
  1353. (SQLPOINTER) SQL_OV_ODBC3,
  1354. SQL_IS_INTEGER);
  1355. // Todo: NULL hWnd
  1356. CBReset(hWnd);
  1357. ZeroMemory ( szTmpName, sizeof(szTmpName) );
  1358. retcode = SQLDataSources(henv,
  1359. SQL_FETCH_FIRST_SYSTEM,
  1360. szTmpName,
  1361. sizeof(szTmpName),
  1362. NULL,
  1363. NULL,
  1364. 0,
  1365. NULL);
  1366. while (SQL_SUCCEEDED(retcode)) {
  1367. CBAdd(hWnd, szTmpName);
  1368. ZeroMemory ( szTmpName, sizeof(szTmpName) );
  1369. retcode = SQLDataSources(henv,
  1370. SQL_FETCH_NEXT,
  1371. szTmpName,
  1372. sizeof(szTmpName),
  1373. NULL,
  1374. NULL,
  1375. 0,
  1376. NULL);
  1377. }
  1378. DsnCount = CBNumItems(hWnd) - 1;
  1379. if (DsnCount >= 0) {
  1380. if ( m_szSqlDsnName[0] != _T('\0')) {
  1381. while (DsnCount >= 0) {
  1382. CBString(hWnd, DsnCount, szTmpName);
  1383. if (lstrcmpi(m_szSqlDsnName, szTmpName) == 0) {
  1384. CBSetSelection(hWnd, DsnCount);
  1385. break;
  1386. }
  1387. else {
  1388. DsnCount --;
  1389. }
  1390. }
  1391. // Todo: Clear m_szSqlDsnName if not in list?
  1392. }
  1393. else {
  1394. DsnCount = -1;
  1395. }
  1396. }
  1397. SQLFreeHandle(SQL_HANDLE_ENV, henv);
  1398. }
  1399. }
  1400. }
  1401. void
  1402. CSourcePropPage::InitSqlLogSetList(void)
  1403. {
  1404. PDH_STATUS pdhStatus = ERROR_SUCCESS;
  1405. INT iLogSetIndex = 0;
  1406. LPTSTR pLogSetList = NULL;
  1407. DWORD dwBufferLen = 0;
  1408. LPTSTR pLogSetPtr = NULL;
  1409. HWND hwndLogSetCombo = NULL;
  1410. LPTSTR szTmpName = NULL;
  1411. INT iBufAllocCount = 0;
  1412. INT iMaxNameLen = 0;
  1413. INT iCurrentNameLen = 0;
  1414. if ( _T('\0') == m_szSqlDsnName[0] ) {
  1415. goto Cleanup;
  1416. }
  1417. hwndLogSetCombo = GetDlgItem(m_hDlg, IDC_LOGSET_COMBO);
  1418. if ( NULL == hwndLogSetCombo ) {
  1419. goto Cleanup;
  1420. }
  1421. do {
  1422. pdhStatus = PdhEnumLogSetNames(
  1423. m_szSqlDsnName, pLogSetList, & dwBufferLen);
  1424. if (pdhStatus == PDH_INSUFFICIENT_BUFFER || pdhStatus == PDH_MORE_DATA)
  1425. {
  1426. iBufAllocCount += 1;
  1427. if (pLogSetList) {
  1428. delete(pLogSetList);
  1429. pLogSetList = NULL;
  1430. }
  1431. pLogSetList = (LPTSTR) new TCHAR[dwBufferLen];
  1432. if (pLogSetList == NULL) {
  1433. pdhStatus = PDH_MEMORY_ALLOCATION_FAILURE;
  1434. }
  1435. }
  1436. }
  1437. while ( ( PDH_INSUFFICIENT_BUFFER == pdhStatus || PDH_MORE_DATA == pdhStatus )
  1438. && iBufAllocCount < 10 );
  1439. if (pdhStatus == ERROR_SUCCESS && pLogSetList != NULL) {
  1440. CBReset(hwndLogSetCombo);
  1441. for ( pLogSetPtr = pLogSetList;
  1442. * pLogSetPtr != _T('\0');
  1443. pLogSetPtr += ( iCurrentNameLen + 1))
  1444. {
  1445. CBAdd(hwndLogSetCombo, pLogSetPtr);
  1446. iCurrentNameLen = lstrlen(pLogSetPtr);
  1447. if ( iMaxNameLen < iCurrentNameLen ) {
  1448. iMaxNameLen = iCurrentNameLen;
  1449. }
  1450. }
  1451. iLogSetIndex = CBNumItems(hwndLogSetCombo) - 1;
  1452. if (iLogSetIndex >= 0) {
  1453. if ( m_szSqlLogSetName[0] != _T('\0')) {
  1454. szTmpName = new TCHAR[iMaxNameLen+1];
  1455. if ( NULL != szTmpName ) {
  1456. while (iLogSetIndex >= 0) {
  1457. CBString(hwndLogSetCombo, iLogSetIndex, szTmpName);
  1458. if (lstrcmpi( m_szSqlLogSetName, szTmpName) == 0) {
  1459. CBSetSelection(hwndLogSetCombo, iLogSetIndex);
  1460. break;
  1461. }
  1462. else {
  1463. iLogSetIndex --;
  1464. }
  1465. }
  1466. } else {
  1467. iLogSetIndex = -1;
  1468. }
  1469. } else {
  1470. iLogSetIndex = -1;
  1471. }
  1472. // Todo: Clear m_szSqlLogSetName if not in list?
  1473. } else {
  1474. if ( 0 == CBNumItems(hwndLogSetCombo) ) {
  1475. iMaxNameLen = lstrlen ( ResourceString(IDS_LOGSET_NOT_FOUND) );
  1476. szTmpName = new TCHAR[iMaxNameLen+1];
  1477. if ( NULL != szTmpName ) {
  1478. lstrcpy(szTmpName, ResourceString(IDS_LOGSET_NOT_FOUND));
  1479. CBReset(hwndLogSetCombo);
  1480. iLogSetIndex = (INT)CBAdd(hwndLogSetCombo, szTmpName);
  1481. CBSetSelection( hwndLogSetCombo, iLogSetIndex);
  1482. }
  1483. }
  1484. }
  1485. } else {
  1486. if ( 0 == CBNumItems(hwndLogSetCombo) ) {
  1487. iMaxNameLen = lstrlen ( ResourceString(IDS_LOGSET_NOT_FOUND) );
  1488. szTmpName = new TCHAR[iMaxNameLen+1];
  1489. if ( NULL != szTmpName ) {
  1490. lstrcpy(szTmpName, ResourceString(IDS_LOGSET_NOT_FOUND));
  1491. CBReset(hwndLogSetCombo);
  1492. iLogSetIndex = (INT)CBAdd(hwndLogSetCombo, szTmpName);
  1493. CBSetSelection( hwndLogSetCombo, iLogSetIndex);
  1494. }
  1495. }
  1496. }
  1497. Cleanup:
  1498. if (pLogSetList) {
  1499. delete pLogSetList;
  1500. }
  1501. if ( szTmpName ) {
  1502. delete szTmpName;
  1503. }
  1504. return;
  1505. }
  1506. HRESULT
  1507. CSourcePropPage::EditPropertyImpl( DISPID dispID )
  1508. {
  1509. HRESULT hr = E_NOTIMPL;
  1510. if ( DISPID_SYSMON_DATASOURCETYPE == dispID ) {
  1511. if ( sysmonCurrentActivity == m_eDataSourceType ) {
  1512. m_dwEditControl = IDC_SRC_REALTIME;
  1513. } else if ( sysmonLogFiles == m_eDataSourceType ) {
  1514. m_dwEditControl = IDC_SRC_LOGFILE;
  1515. } else if ( sysmonSqlLog == m_eDataSourceType ) {
  1516. m_dwEditControl = IDC_SRC_SQL;
  1517. }
  1518. hr = S_OK;
  1519. }
  1520. return hr;
  1521. }
  1522. void
  1523. CSourcePropPage::SetSourceControlStates ( void )
  1524. {
  1525. HWND hwndLogFileList = NULL;
  1526. INT iLogFileCnt = 0;
  1527. BOOL bIsValidDataSource = FALSE;
  1528. if ( sysmonCurrentActivity == m_eDataSourceType ) {
  1529. DialogEnable(m_hDlg, IDC_ADDFILE, FALSE);
  1530. DialogEnable(m_hDlg, IDC_REMOVEFILE, FALSE);
  1531. DialogEnable(m_hDlg, IDC_STATIC_DSN, FALSE);
  1532. DialogEnable(m_hDlg, IDC_DSN_COMBO, FALSE);
  1533. DialogEnable(m_hDlg, IDC_STATIC_LOGSET, FALSE);
  1534. DialogEnable(m_hDlg, IDC_LOGSET_COMBO, FALSE);
  1535. bIsValidDataSource = FALSE;
  1536. } else if ( sysmonLogFiles == m_eDataSourceType ) {
  1537. DialogEnable(m_hDlg, IDC_ADDFILE, TRUE);
  1538. DialogEnable(m_hDlg, IDC_STATIC_DSN, FALSE);
  1539. DialogEnable(m_hDlg, IDC_DSN_COMBO, FALSE);
  1540. DialogEnable(m_hDlg, IDC_STATIC_LOGSET, FALSE);
  1541. DialogEnable(m_hDlg, IDC_LOGSET_COMBO, FALSE);
  1542. hwndLogFileList = DialogControl(m_hDlg, IDC_LIST_LOGFILENAME);
  1543. if ( NULL != hwndLogFileList ) {
  1544. iLogFileCnt = LBNumItems(hwndLogFileList);
  1545. }
  1546. bIsValidDataSource = (iLogFileCnt > 0);
  1547. DialogEnable(m_hDlg, IDC_REMOVEFILE, ( bIsValidDataSource ) );
  1548. } else {
  1549. assert ( sysmonSqlLog == m_eDataSourceType );
  1550. DialogEnable(m_hDlg, IDC_ADDFILE, FALSE);
  1551. DialogEnable(m_hDlg, IDC_REMOVEFILE, FALSE);
  1552. DialogEnable(m_hDlg, IDC_STATIC_DSN, TRUE);
  1553. DialogEnable(m_hDlg, IDC_DSN_COMBO, TRUE);
  1554. DialogEnable(m_hDlg, IDC_STATIC_LOGSET, TRUE);
  1555. DialogEnable(m_hDlg, IDC_LOGSET_COMBO, TRUE);
  1556. bIsValidDataSource = 0 < lstrlen ( m_szSqlDsnName ) && 0 < lstrlen ( m_szSqlLogSetName );
  1557. }
  1558. m_bInitialTimeRangePending = TRUE;
  1559. SetTimeRangeCtrlState( bIsValidDataSource, FALSE );
  1560. }
  1561. DWORD
  1562. CSourcePropPage::BuildLogFileList (
  1563. HWND /*hwndDlg*/,
  1564. LPWSTR szLogFileList,
  1565. ULONG* pulBufLen )
  1566. {
  1567. DWORD dwStatus = ERROR_SUCCESS;
  1568. ULONG ulListLen;
  1569. HWND hwndLogFileList = NULL;
  1570. INT iLogFileCount;
  1571. INT iLogFileIndex;
  1572. PLogItemInfo pInfo = NULL;
  1573. LPCWSTR szThisLogFile = NULL;
  1574. LPWSTR szLogFileCurrent = NULL;
  1575. WCHAR cwComma = L',';
  1576. if ( NULL != pulBufLen ) {
  1577. ulListLen = 0;
  1578. hwndLogFileList = DialogControl(m_hDlg, IDC_LIST_LOGFILENAME);
  1579. if ( NULL != hwndLogFileList ) {
  1580. iLogFileCount = LBNumItems(hwndLogFileList);
  1581. if ( 0 < iLogFileCount ) {
  1582. for ( iLogFileIndex = 0; iLogFileIndex < iLogFileCount; iLogFileIndex++ ) {
  1583. pInfo = (PLogItemInfo)LBData(hwndLogFileList,iLogFileIndex);
  1584. szThisLogFile = pInfo->pszPath;
  1585. ulListLen += (lstrlen(szThisLogFile) + 1);
  1586. }
  1587. ulListLen ++; // for the single final NULL character.
  1588. if ( ulListLen <= *pulBufLen ) {
  1589. if ( NULL != szLogFileList ) {
  1590. ZeroMemory(szLogFileList, (ulListLen * sizeof(WCHAR)));
  1591. szLogFileCurrent = (LPTSTR) szLogFileList;
  1592. for ( iLogFileIndex = 0; iLogFileIndex < iLogFileCount; iLogFileIndex++ ) {
  1593. pInfo = (PLogItemInfo)LBData(hwndLogFileList,iLogFileIndex);
  1594. szThisLogFile = pInfo->pszPath;
  1595. lstrcpy(szLogFileCurrent, szThisLogFile);
  1596. szLogFileCurrent += lstrlen(szThisLogFile);
  1597. *szLogFileCurrent = L'\0';
  1598. if ( (iLogFileIndex + 1) < iLogFileCount ) {
  1599. // If comma delimited, replace the NULL char with a comma
  1600. *szLogFileCurrent = cwComma;
  1601. }
  1602. szLogFileCurrent ++;
  1603. }
  1604. }
  1605. } else if ( NULL != szLogFileList ) {
  1606. dwStatus = ERROR_MORE_DATA;
  1607. }
  1608. }
  1609. }
  1610. *pulBufLen = ulListLen;
  1611. } else {
  1612. dwStatus = ERROR_INVALID_PARAMETER;
  1613. assert ( FALSE );
  1614. }
  1615. return dwStatus;
  1616. }