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.

243 lines
7.5 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. // Copyright (c) 2002 Microsoft Corporation. All rights reserved.
  3. // Copyright (c) 2002 OSR Open Systems Resources, Inc.
  4. //
  5. // LogSessionPropSht.cpp : implementation file
  6. //////////////////////////////////////////////////////////////////////////////
  7. #include "stdafx.h"
  8. #include <tchar.h>
  9. #include <wmistr.h>
  10. #include <initguid.h>
  11. extern "C" {
  12. #include <evntrace.h>
  13. }
  14. #include <traceprt.h>
  15. #include "traceview.h"
  16. #include "resource.h"
  17. #include "logsession.h"
  18. #include "DisplayDlg.h"
  19. #include "LogSessionInformationDlg.h"
  20. #include "ProviderSetupDlg.h"
  21. #include "LogSessionPropSht.h"
  22. #include "utils.h"
  23. IMPLEMENT_DYNAMIC(CLogSessionPropSht, CPropertySheet)
  24. BEGIN_MESSAGE_MAP(CLogSessionPropSht, CPropertySheet)
  25. //{{AFX_MSG_MAP(CLogSessionPropSht)
  26. ON_BN_CLICKED(IDOK, OnBnClickedOk)
  27. ON_BN_CLICKED(IDCANCEL, OnBnClickedCancel)
  28. ON_BN_CLICKED(ID_WIZFINISH, OnBnClickedFinish)
  29. //}}AFX_MSG_MAP
  30. END_MESSAGE_MAP()
  31. CLogSessionPropSht::CLogSessionPropSht(CWnd* pWndParent, CLogSession *pLogSession)
  32. : CPropertySheet(IDS_LOG_SESSION_OPTIONS_TITLE, pWndParent)
  33. {
  34. CString str;
  35. ASSERT(pLogSession != NULL);
  36. AddPage(&m_providerSetupPage);
  37. AddPage(&m_logSessionInformationDlg);
  38. //
  39. // Initialize the log session settings from the log session
  40. // this way we display the correct settings for the log session.
  41. // A new session is setup with defaults, so this will work no matter.
  42. //
  43. m_pLogSession = pLogSession;
  44. m_bAppend = pLogSession->m_bAppend;
  45. m_bRealTime = pLogSession->m_bRealTime;
  46. m_bWriteLogFile = pLogSession->m_bWriteLogFile;
  47. m_logFileName = pLogSession->m_logFileName;
  48. m_displayName = pLogSession->m_displayName;
  49. //
  50. // If this session is already in a group, then display the output
  51. // file option settings. Otherwise go with defaults.
  52. //
  53. if(NULL != pLogSession->GetDisplayWnd()) {
  54. m_bWriteListingFile = pLogSession->GetDisplayWnd()->m_bWriteListingFile;
  55. m_listingFileName = pLogSession->GetDisplayWnd()->m_listingFileName;
  56. m_bWriteSummaryFile = pLogSession->GetDisplayWnd()->m_bWriteSummaryFile;
  57. m_summaryFileName = pLogSession->GetDisplayWnd()->m_summaryFileName;
  58. } else {
  59. m_bWriteListingFile = FALSE;
  60. m_listingFileName = (LPCTSTR)pLogSession->GetDisplayName();
  61. m_listingFileName +=_T(".out");
  62. m_bWriteSummaryFile = FALSE;
  63. m_summaryFileName = (LPCTSTR)pLogSession->GetDisplayName();
  64. m_summaryFileName +=_T(".sum");
  65. }
  66. m_logSessionValues.Copy(pLogSession->m_logSessionValues);
  67. }
  68. BOOL CLogSessionPropSht::OnInitDialog()
  69. {
  70. CString str;
  71. BOOL bResult = CPropertySheet::OnInitDialog();
  72. //
  73. // add the window to the property sheet.
  74. //
  75. CRect rectWnd;
  76. GetWindowRect(rectWnd);
  77. SetWindowPos(NULL, 0, 0,
  78. rectWnd.Width(),
  79. rectWnd.Height(),
  80. SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
  81. CenterWindow();
  82. //
  83. // We set both pages active here, so that the data for
  84. // those property pages gets updated at the start. Otherwise
  85. // if a page is not updated and the user clicks finish then
  86. // improper data could get copied back to the log session.
  87. //
  88. if(IsWizard()) {
  89. SetActivePage(&m_logSessionInformationDlg);
  90. SetActivePage(&m_providerSetupPage);
  91. } else {
  92. SetActivePage(&m_providerSetupPage);
  93. SetActivePage(&m_logSessionInformationDlg);
  94. }
  95. return bResult;
  96. }
  97. void CLogSessionPropSht::OnBnClickedOk()
  98. {
  99. CString str;
  100. m_logSessionInformationDlg.UpdateData(TRUE);
  101. //
  102. // If the state changed while the dialog was active, ignore the entries
  103. //
  104. if(m_pLogSession->m_logSessionValues[State].Compare(m_logSessionValues[State])) {
  105. EndDialog(2);
  106. return;
  107. }
  108. //
  109. // Get the log session name
  110. //
  111. m_logSessionInformationDlg.m_logSessionName.GetWindowText(m_displayName);
  112. if(m_displayName.IsEmpty()) {
  113. AfxMessageBox(_T("Missing Log Session Name"));
  114. SetActivePage(&m_logSessionInformationDlg);
  115. SetWizardButtons(PSWIZB_FINISH);
  116. return;
  117. }
  118. //
  119. // get the logfile name
  120. //
  121. m_logSessionInformationDlg.m_logFileName.GetWindowText(m_logFileName);
  122. //
  123. // set the logfile write check
  124. //
  125. m_bWriteLogFile = ((CButton *)m_logSessionInformationDlg.GetDlgItem(IDC_WRITE_LOGFILE_CHECK))->GetCheck();
  126. //
  127. // The user must specify a valid log file name if selecting
  128. // to write a log file
  129. //
  130. if((m_bWriteLogFile) && (m_logFileName.IsEmpty())) {
  131. AfxMessageBox(_T("Missing Log File Name"));
  132. SetActivePage(&m_logSessionInformationDlg);
  133. SetWizardButtons(PSWIZB_FINISH);
  134. return;
  135. }
  136. //
  137. // update the append boolean
  138. //
  139. m_bAppend = ((CButton *)m_logSessionInformationDlg.GetDlgItem(IDC_APPEND_CHECK))->GetCheck();
  140. //
  141. // update the real time boolean
  142. //
  143. m_bRealTime = ((CButton *)m_logSessionInformationDlg.GetDlgItem(IDC_REALTIME_CHECK))->GetCheck();
  144. //
  145. // Move the data from the prop pages back to the log session.
  146. // Storing this data local and waiting until here to copy it
  147. // back to the log session instance allows for a complete and
  148. // smooth cancel anywhere in the process of these property sheets.
  149. //
  150. m_pLogSession->m_bAppend = m_bAppend;
  151. m_pLogSession->m_bRealTime = m_bRealTime;
  152. m_pLogSession->m_bWriteLogFile = m_bWriteLogFile;
  153. m_pLogSession->m_logFileName = m_logFileName;
  154. m_pLogSession->m_displayName = m_displayName;
  155. if(NULL != m_pLogSession->GetDisplayWnd()) {
  156. m_pLogSession->GetDisplayWnd()->m_bWriteListingFile = m_bWriteListingFile;
  157. m_pLogSession->GetDisplayWnd()->m_bWriteSummaryFile = m_bWriteSummaryFile;
  158. m_pLogSession->GetDisplayWnd()->m_listingFileName = m_listingFileName;
  159. m_pLogSession->GetDisplayWnd()->m_summaryFileName = m_summaryFileName;
  160. }
  161. //
  162. // Copy the log session values back over if the state of the
  163. // session hasn't changed while the dialogs were active
  164. //
  165. for(ULONG ii = 1; ii < MaxLogSessionOptions; ii++) {
  166. m_pLogSession->m_logSessionValues[ii] = (LPCTSTR)m_logSessionValues[ii];
  167. }
  168. //
  169. // Make sure a provider was entered if real time
  170. //
  171. if(m_pLogSession->m_bRealTime) {
  172. if(m_pLogSession->m_traceSessionArray.GetSize() == 0) {
  173. SetActivePage(&m_providerSetupPage);
  174. SetWizardButtons(PSWIZB_FINISH);
  175. AfxMessageBox(_T("At Least One Provider Must Be Specified For Each Log Session"));
  176. return;
  177. }
  178. }
  179. //
  180. // Make sure a provider was entered if the log file doesn't exist
  181. //
  182. CFileStatus status;
  183. if(!CFile::GetStatus(m_logFileName, status )) {
  184. if(m_pLogSession->m_traceSessionArray.GetSize() == 0) {
  185. SetActivePage(&m_providerSetupPage);
  186. SetWizardButtons(PSWIZB_FINISH);
  187. AfxMessageBox(_T("Log File Does Not Exist\nAt Least One Provider Must Be Specified For Active Tracing"));
  188. return;
  189. }
  190. }
  191. //
  192. // Update active session
  193. //
  194. if(m_pLogSession->m_bSessionActive) {
  195. m_pLogSession->GetDisplayWnd()->UpdateSession(m_pLogSession);
  196. }
  197. EndDialog(1);
  198. }
  199. void CLogSessionPropSht::OnBnClickedFinish()
  200. {
  201. OnBnClickedOk();
  202. }
  203. void CLogSessionPropSht::OnBnClickedCancel()
  204. {
  205. EndDialog(2);
  206. }