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.

265 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 = CreateThread(NULL,0,&MonitorRunningAgents,NULL,0,&m_ThreadID);
  114. CloseHandle(m_ThreadHandle);
  115. m_ThreadHandle = INVALID_HANDLE_VALUE;
  116. }
  117. void CLogSettingsDlg::OnStopMonitor()
  118. {
  119. UpdateData(FALSE);
  120. SetDefID(IDC_STARTMONITOR);
  121. m_StartButton.EnableWindow(TRUE);
  122. m_StartButton.SetFocus();
  123. m_StopButton.EnableWindow(FALSE);
  124. // enable the interval and other controls
  125. m_LogLabel.EnableWindow(TRUE);
  126. m_LogEditControl.EnableWindow(TRUE);
  127. m_RefreshLabel.EnableWindow(TRUE);
  128. m_IntervalEditControl.EnableWindow(TRUE);
  129. m_DBLabel.EnableWindow(TRUE);
  130. m_DBEditControl.EnableWindow(TRUE);
  131. m_ImportControl.EnableWindow(TRUE);
  132. if( m_ThreadHandle != INVALID_HANDLE_VALUE )
  133. {
  134. gData.SetDone(TRUE);
  135. CloseHandle(m_ThreadHandle);
  136. m_ThreadID = 0;
  137. }
  138. }
  139. BOOL CLogSettingsDlg::OnSetActive()
  140. {
  141. BOOL rc = CPropertyPage::OnSetActive();
  142. CancelToClose( );
  143. return rc;
  144. }
  145. BOOL CLogSettingsDlg::OnInitDialog()
  146. {
  147. CPropertyPage::OnInitDialog();
  148. if ( m_StartImmediately )
  149. OnStartMonitor();
  150. return TRUE; // return TRUE unless you set the focus to a control
  151. // EXCEPTION: OCX Property Pages should return FALSE
  152. }
  153. void CLogSettingsDlg::OnChangeLogfile()
  154. {
  155. UpdateData(TRUE);
  156. CString temp = m_LogFile;
  157. temp.TrimLeft();
  158. temp.TrimRight();
  159. UpdateData(FALSE);
  160. }
  161. void CLogSettingsDlg::OnOK()
  162. {
  163. gData.SetDone(TRUE);
  164. CPropertyPage::OnOK();
  165. }
  166. BOOL CLogSettingsDlg::OnQueryCancel()
  167. {
  168. return CPropertyPage::OnQueryCancel();
  169. }
  170. BOOL CLogSettingsDlg::OnApply()
  171. {
  172. BOOL bNeedToConfirm = FALSE;
  173. BOOL bFirstPassDone = FALSE;
  174. ComputerStats stats;
  175. CString strTitle;
  176. CString strText;
  177. gData.GetFirstPassDone(&bFirstPassDone);
  178. gData.GetComputerStats(&stats);
  179. strTitle.LoadString(IDS_MessageTitle);
  180. if ( !bFirstPassDone )
  181. {
  182. strText.LoadString(IDS_JustStartingConfirmExit);
  183. bNeedToConfirm = TRUE;
  184. }
  185. if ( (stats.numError + stats.numFinished) < stats.total )
  186. {
  187. strText.LoadString(IDS_AgentsStillRunningConfirmExit);
  188. bNeedToConfirm = TRUE;
  189. }
  190. if ( bNeedToConfirm )
  191. {
  192. if ( IDYES == MessageBox(strText,strTitle,MB_ICONWARNING | MB_YESNO) )
  193. {
  194. gData.SetDone(TRUE);
  195. return CPropertyPage::OnApply();
  196. }
  197. }
  198. else
  199. {
  200. gData.SetDone(TRUE);
  201. return CPropertyPage::OnApply();
  202. }
  203. return FALSE;
  204. }
  205. BOOL CLogSettingsDlg::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
  206. {
  207. LPNMHDR lpnm = (LPNMHDR) lParam;
  208. switch (lpnm->code)
  209. {
  210. case PSN_HELP :
  211. helpWrapper(m_hWnd, IDH_WINDOW_AGENT_MONITOR_SETTING);
  212. break;
  213. }
  214. return CPropertyPage::OnNotify(wParam, lParam, pResult);
  215. }
  216. BOOL CLogSettingsDlg::OnHelpInfo(HELPINFO* pHelpInfo)
  217. {
  218. helpWrapper(m_hWnd, IDH_WINDOW_AGENT_MONITOR_SETTING);
  219. return CPropertyPage::OnHelpInfo(pHelpInfo);
  220. }