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.

254 lines
6.8 KiB

  1. /*---------------------------------------------------------------------------
  2. File: LogSettingsDlg.cpp
  3. Comments: This dialog allows the user to specify a log file, or to manually
  4. stop and restart the monitoring thread. This normally won't be needed, but
  5. it is useful for debugging.
  6. (c) Copyright 1999, Mission Critical Software, Inc., All Rights Reserved
  7. Proprietary and confidential to Mission Critical Software, Inc.
  8. REVISION LOG ENTRY
  9. Revision By: Christy Boles
  10. ---------------------------------------------------------------------------
  11. */// LogSettingsDlg.cpp : implementation file
  12. //
  13. #include "stdafx.h"
  14. #include "resource.h"
  15. #include "SetDlg.h"
  16. #include "Monitor.h"
  17. #include "Globals.h"
  18. #include <htmlhelp.h>
  19. #include "helpid.h"
  20. #ifdef _DEBUG
  21. #define new DEBUG_NEW
  22. #undef THIS_FILE
  23. static char THIS_FILE[] = __FILE__;
  24. #endif
  25. /////////////////////////////////////////////////////////////////////////////
  26. // CLogSettingsDlg property page
  27. IMPLEMENT_DYNCREATE(CLogSettingsDlg, CPropertyPage)
  28. CLogSettingsDlg::CLogSettingsDlg() : CPropertyPage(CLogSettingsDlg::IDD)
  29. {
  30. //{{AFX_DATA_INIT(CLogSettingsDlg)
  31. m_LogFile = _T("");
  32. m_Database = _T("");
  33. m_Import = FALSE;
  34. //}}AFX_DATA_INIT
  35. m_ThreadHandle = INVALID_HANDLE_VALUE;
  36. m_ThreadID = 0;
  37. gData.GetWaitInterval(&m_Interval);
  38. m_StartImmediately = FALSE;
  39. }
  40. CLogSettingsDlg::~CLogSettingsDlg()
  41. {
  42. }
  43. void CLogSettingsDlg::DoDataExchange(CDataExchange* pDX)
  44. {
  45. CPropertyPage::DoDataExchange(pDX);
  46. //{{AFX_DATA_MAP(CLogSettingsDlg)
  47. DDX_Control(pDX, IDC_IMPORT, m_ImportControl);
  48. DDX_Control(pDX, IDC_INTERVAL, m_IntervalEditControl);
  49. DDX_Control(pDX, IDC_LOGFILE, m_LogEditControl);
  50. DDX_Control(pDX, IDC_REFRESH_LABEL, m_RefreshLabel);
  51. DDX_Control(pDX, IDC_LOG_LABEL, m_LogLabel);
  52. DDX_Control(pDX, IDC_DB_LABEL, m_DBLabel);
  53. DDX_Control(pDX, IDC_DB, m_DBEditControl);
  54. DDX_Control(pDX, IDC_STOPMONITOR, m_StopButton);
  55. DDX_Control(pDX, IDC_STARTMONITOR, m_StartButton);
  56. DDX_Text(pDX, IDC_INTERVAL, m_Interval);
  57. DDX_Text(pDX, IDC_LOGFILE, m_LogFile);
  58. DDX_Text(pDX, IDC_DB, m_Database);
  59. DDX_Check(pDX, IDC_IMPORT, m_Import);
  60. //}}AFX_DATA_MAP
  61. }
  62. BEGIN_MESSAGE_MAP(CLogSettingsDlg, CPropertyPage)
  63. //{{AFX_MSG_MAP(CLogSettingsDlg)
  64. ON_BN_CLICKED(IDC_STARTMONITOR, OnStartMonitor)
  65. ON_BN_CLICKED(IDC_STOPMONITOR, OnStopMonitor)
  66. ON_EN_CHANGE(IDC_LOGFILE, OnChangeLogfile)
  67. ON_WM_HELPINFO()
  68. //}}AFX_MSG_MAP
  69. END_MESSAGE_MAP()
  70. /////////////////////////////////////////////////////////////////////////////
  71. // CLogSettingsDlg message handlers
  72. void CLogSettingsDlg::OnStartMonitor()
  73. {
  74. UpdateData(TRUE);
  75. // Kick off a thread to do the monitoring!
  76. //m_ServerList.DeleteAllItems();
  77. // make sure the filename is not empty
  78. m_LogFile.TrimLeft();
  79. m_LogFile.TrimRight();
  80. if ( m_LogFile.GetLength() == 0 )
  81. {
  82. CString message;
  83. message.LoadString(IDS_PromptEnterDispatchLogName);
  84. MessageBox(message);
  85. m_LogEditControl.SetFocus();
  86. return;
  87. }
  88. gData.SetDone(FALSE);
  89. if ( m_Interval > 0 )
  90. {
  91. gData.SetWaitInterval(m_Interval);
  92. }
  93. UpdateData(FALSE);
  94. SetDefID(IDC_STOPMONITOR);
  95. m_StopButton.EnableWindow(FALSE); // Disable the buttons, since they don't do anything useful in ADMT
  96. m_StopButton.SetFocus();
  97. m_StartButton.EnableWindow(FALSE);
  98. // disable the interval and other controls
  99. m_LogLabel.EnableWindow(FALSE);
  100. m_LogEditControl.EnableWindow(FALSE);
  101. m_RefreshLabel.EnableWindow(FALSE);
  102. m_IntervalEditControl.EnableWindow(FALSE);
  103. m_DBLabel.EnableWindow(FALSE);
  104. m_DBEditControl.EnableWindow(FALSE);
  105. m_ImportControl.EnableWindow(FALSE);
  106. gData.SetLogPath(m_LogFile.GetBuffer(0));
  107. gData.SetDatabaseName(m_Database.GetBuffer(0));
  108. gData.SetImportStats(m_Import);
  109. m_ThreadHandle = CreateThread(NULL,0,&ResultMonitorFn,NULL,0,&m_ThreadID);
  110. CloseHandle(m_ThreadHandle);
  111. m_ThreadHandle = CreateThread(NULL,0,&LogReaderFn,NULL,0,&m_ThreadID);
  112. CloseHandle(m_ThreadHandle);
  113. m_ThreadHandle = INVALID_HANDLE_VALUE;
  114. }
  115. void CLogSettingsDlg::OnStopMonitor()
  116. {
  117. UpdateData(FALSE);
  118. SetDefID(IDC_STARTMONITOR);
  119. m_StartButton.EnableWindow(TRUE);
  120. m_StartButton.SetFocus();
  121. m_StopButton.EnableWindow(FALSE);
  122. // enable the interval and other controls
  123. m_LogLabel.EnableWindow(TRUE);
  124. m_LogEditControl.EnableWindow(TRUE);
  125. m_RefreshLabel.EnableWindow(TRUE);
  126. m_IntervalEditControl.EnableWindow(TRUE);
  127. m_DBLabel.EnableWindow(TRUE);
  128. m_DBEditControl.EnableWindow(TRUE);
  129. m_ImportControl.EnableWindow(TRUE);
  130. if( m_ThreadHandle != INVALID_HANDLE_VALUE )
  131. {
  132. gData.SetDone(TRUE);
  133. CloseHandle(m_ThreadHandle);
  134. m_ThreadID = 0;
  135. }
  136. }
  137. BOOL CLogSettingsDlg::OnSetActive()
  138. {
  139. BOOL rc = CPropertyPage::OnSetActive();
  140. CancelToClose( );
  141. return rc;
  142. }
  143. BOOL CLogSettingsDlg::OnInitDialog()
  144. {
  145. CPropertyPage::OnInitDialog();
  146. if ( m_StartImmediately )
  147. OnStartMonitor();
  148. return TRUE; // return TRUE unless you set the focus to a control
  149. // EXCEPTION: OCX Property Pages should return FALSE
  150. }
  151. void CLogSettingsDlg::OnChangeLogfile()
  152. {
  153. UpdateData(TRUE);
  154. CString temp = m_LogFile;
  155. temp.TrimLeft();
  156. temp.TrimRight();
  157. UpdateData(FALSE);
  158. }
  159. void CLogSettingsDlg::OnOK()
  160. {
  161. gData.SetDone(TRUE);
  162. CPropertyPage::OnOK();
  163. }
  164. BOOL CLogSettingsDlg::OnQueryCancel()
  165. {
  166. return CPropertyPage::OnQueryCancel();
  167. }
  168. BOOL CLogSettingsDlg::OnApply()
  169. {
  170. ComputerStats stats;
  171. CString strTitle;
  172. CString strText;
  173. gData.GetComputerStats(&stats);
  174. // only when all agents have either finished or failed do we allow the user to close the agent monitor
  175. if ( (stats.numError + stats.numFinished) < stats.total )
  176. {
  177. strTitle.LoadString(IDS_MessageTitle);
  178. strText.LoadString(IDS_AgentsStillRunningCannotExit);
  179. int result = MessageBox(strText,strTitle,MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2);
  180. if (result == IDYES)
  181. {
  182. gData.SetDone(TRUE);
  183. gData.SetForcedToStopMonitoring(TRUE);
  184. return CPropertyPage::OnApply();
  185. }
  186. }
  187. else
  188. {
  189. gData.SetDone(TRUE);
  190. return CPropertyPage::OnApply();
  191. }
  192. return FALSE;
  193. }
  194. BOOL CLogSettingsDlg::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
  195. {
  196. LPNMHDR lpnm = (LPNMHDR) lParam;
  197. switch (lpnm->code)
  198. {
  199. case PSN_HELP :
  200. helpWrapper(m_hWnd, IDH_WINDOW_AGENT_MONITOR_SETTING);
  201. break;
  202. }
  203. return CPropertyPage::OnNotify(wParam, lParam, pResult);
  204. }
  205. BOOL CLogSettingsDlg::OnHelpInfo(HELPINFO* pHelpInfo)
  206. {
  207. helpWrapper(m_hWnd, IDH_WINDOW_AGENT_MONITOR_SETTING);
  208. return CPropertyPage::OnHelpInfo(pHelpInfo);
  209. }