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.

327 lines
8.5 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. Servpp.h
  7. Server properties implementation file
  8. FILE HISTORY:
  9. */
  10. #include "stdafx.h"
  11. #include "Servpp.h"
  12. #include "server.h"
  13. #ifdef _DEBUG
  14. #define new DEBUG_NEW
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18. BOOL IsLocalSystemAccount(LPCTSTR pszAccount)
  19. {
  20. BOOL fLocal = FALSE;
  21. CString strLocalSystemAccount;
  22. if (pszAccount != NULL)
  23. {
  24. strLocalSystemAccount.LoadString(IDS_LOCAL_SYSTEM_ACCOUNT);
  25. if (strLocalSystemAccount.CompareNoCase(pszAccount) == 0)
  26. fLocal = TRUE;
  27. }
  28. return fLocal;
  29. }
  30. /////////////////////////////////////////////////////////////////////////////
  31. //
  32. // CMachineProperties holder
  33. //
  34. /////////////////////////////////////////////////////////////////////////////
  35. CMachineProperties::CMachineProperties
  36. (
  37. ITFSNode * pNode,
  38. IComponentData * pComponentData,
  39. ITFSComponentData * pTFSCompData,
  40. ISpdInfo * pSpdInfo,
  41. LPCTSTR pszSheetName,
  42. BOOL fSpdInfoLoaded
  43. ) : CPropertyPageHolderBase(pNode, pComponentData, pszSheetName),
  44. m_fSpdInfoLoaded(fSpdInfoLoaded)
  45. {
  46. //ASSERT(pFolderNode == GetContainerNode());
  47. m_bAutoDeletePages = FALSE; // we have the pages as embedded members
  48. AddPageToList((CPropertyPageBase*) &m_pageRefresh);
  49. Assert(pTFSCompData != NULL);
  50. m_spTFSCompData.Set(pTFSCompData);
  51. m_spSpdInfo.Set(pSpdInfo);
  52. }
  53. CMachineProperties::~CMachineProperties()
  54. {
  55. RemovePageFromList((CPropertyPageBase*) &m_pageRefresh, FALSE);
  56. }
  57. /////////////////////////////////////////////////////////////////////////////
  58. // CMachinePropRefresh property page
  59. IMPLEMENT_DYNCREATE(CMachinePropRefresh, CPropertyPageBase)
  60. CMachinePropRefresh::CMachinePropRefresh() : CPropertyPageBase(CMachinePropRefresh::IDD)
  61. {
  62. //{{AFX_DATA_INIT(CMachinePropRefresh)
  63. // NOTE: the ClassWizard will add member initialization here
  64. //}}AFX_DATA_INIT
  65. }
  66. CMachinePropRefresh::~CMachinePropRefresh()
  67. {
  68. }
  69. void CMachinePropRefresh::DoDataExchange(CDataExchange* pDX)
  70. {
  71. CPropertyPageBase::DoDataExchange(pDX);
  72. //{{AFX_DATA_MAP(CMachinePropRefresh)
  73. DDX_Control(pDX, IDC_EDIT_SECONDS, m_editSeconds);
  74. DDX_Control(pDX, IDC_EDIT_MINUTES, m_editMinutes);
  75. DDX_Control(pDX, IDC_SPIN_SECONDS, m_spinSeconds);
  76. DDX_Control(pDX, IDC_SPIN_MINUTES, m_spinMinutes);
  77. DDX_Control(pDX, IDC_CHECK_ENABLE_STATS, m_checkEnableStats);
  78. //}}AFX_DATA_MAP
  79. }
  80. BEGIN_MESSAGE_MAP(CMachinePropRefresh, CPropertyPageBase)
  81. //{{AFX_MSG_MAP(CMachinePropRefresh)
  82. ON_BN_CLICKED(IDC_CHECK_ENABLE_STATS, OnCheckEnableStats)
  83. ON_EN_CHANGE(IDC_EDIT_MINUTES, OnChangeEditMinutes)
  84. ON_EN_CHANGE(IDC_EDIT_SECONDS, OnChangeEditSeconds)
  85. //}}AFX_MSG_MAP
  86. END_MESSAGE_MAP()
  87. /////////////////////////////////////////////////////////////////////////////
  88. // CMachinePropRefresh message handlers
  89. BOOL CMachinePropRefresh::OnInitDialog()
  90. {
  91. CPropertyPageBase::OnInitDialog();
  92. m_spinMinutes.SetRange(0, AUTO_REFRESH_MINUTES_MAX);
  93. m_spinSeconds.SetRange(0, AUTO_REFRESH_SECONDS_MAX);
  94. m_checkEnableStats.SetCheck(m_bAutoRefresh);
  95. // update the refresh interval
  96. int nMinutes, nSeconds;
  97. DWORD dwRefreshInterval = m_dwRefreshInterval;
  98. nMinutes = dwRefreshInterval / MILLISEC_PER_MINUTE;
  99. dwRefreshInterval -= nMinutes * MILLISEC_PER_MINUTE;
  100. nSeconds = dwRefreshInterval / MILLISEC_PER_SECOND;
  101. dwRefreshInterval -= nSeconds * MILLISEC_PER_SECOND;
  102. m_spinMinutes.SetPos(nMinutes);
  103. m_spinSeconds.SetPos(nSeconds);
  104. m_editMinutes.LimitText(2);
  105. m_editSeconds.LimitText(2);
  106. // set the button states
  107. UpdateButtons();
  108. SetDirty(FALSE);
  109. return TRUE; // return TRUE unless you set the focus to a control
  110. // EXCEPTION: OCX Property Pages should return FALSE
  111. }
  112. void CMachinePropRefresh::UpdateButtons()
  113. {
  114. int nCheck = m_checkEnableStats.GetCheck();
  115. GetDlgItem(IDC_EDIT_MINUTES)->EnableWindow(nCheck != 0);
  116. GetDlgItem(IDC_EDIT_SECONDS)->EnableWindow(nCheck != 0);
  117. GetDlgItem(IDC_SPIN_MINUTES)->EnableWindow(nCheck != 0);
  118. GetDlgItem(IDC_SPIN_SECONDS)->EnableWindow(nCheck != 0);
  119. }
  120. void CMachinePropRefresh::OnCheckEnableStats()
  121. {
  122. SetDirty(TRUE);
  123. UpdateButtons();
  124. }
  125. void CMachinePropRefresh::OnChangeEditMinutes()
  126. {
  127. ValidateMinutes();
  128. SetDirty(TRUE);
  129. }
  130. void CMachinePropRefresh::OnChangeEditSeconds()
  131. {
  132. ValidateSeconds();
  133. SetDirty(TRUE);
  134. }
  135. void CMachinePropRefresh::ValidateMinutes()
  136. {
  137. CString strValue;
  138. int nValue;
  139. if (m_editMinutes.GetSafeHwnd() != NULL)
  140. {
  141. m_editMinutes.GetWindowText(strValue);
  142. if (!strValue.IsEmpty())
  143. {
  144. nValue = _ttoi(strValue);
  145. if ((nValue >= 0) &&
  146. (nValue <= AUTO_REFRESH_MINUTES_MAX))
  147. {
  148. // everything is good
  149. return;
  150. }
  151. if (nValue > AUTO_REFRESH_MINUTES_MAX)
  152. nValue = AUTO_REFRESH_MINUTES_MAX;
  153. else
  154. if (nValue < 0)
  155. nValue = 0;
  156. // set the new value and beep
  157. CString strText;
  158. LPTSTR pBuf = strText.GetBuffer(5);
  159. _itot(nValue, pBuf, 10);
  160. strText.ReleaseBuffer();
  161. MessageBeep(MB_ICONEXCLAMATION);
  162. m_editMinutes.SetWindowText(strText);
  163. m_editMinutes.SetSel(0, -1);
  164. m_editMinutes.SetFocus();
  165. }
  166. }
  167. }
  168. void CMachinePropRefresh::ValidateSeconds()
  169. {
  170. CString strValue;
  171. int nValue;
  172. if (m_editSeconds.GetSafeHwnd() != NULL)
  173. {
  174. m_editSeconds.GetWindowText(strValue);
  175. if (!strValue.IsEmpty())
  176. {
  177. nValue = _ttoi(strValue);
  178. if ((nValue >= 0) &&
  179. (nValue <= AUTO_REFRESH_SECONDS_MAX))
  180. {
  181. // everything is good
  182. return;
  183. }
  184. if (nValue > AUTO_REFRESH_SECONDS_MAX)
  185. nValue = AUTO_REFRESH_SECONDS_MAX;
  186. else
  187. if (nValue < 0)
  188. nValue = 0;
  189. CString strText;
  190. LPTSTR pBuf = strText.GetBuffer(5);
  191. _itot(nValue, pBuf, 10);
  192. strText.ReleaseBuffer();
  193. MessageBeep(MB_ICONEXCLAMATION);
  194. m_editSeconds.SetWindowText(strText);
  195. m_editSeconds.SetSel(0, -1);
  196. m_editSeconds.SetFocus();
  197. }
  198. }
  199. }
  200. BOOL CMachinePropRefresh::OnApply()
  201. {
  202. if (!IsDirty())
  203. return TRUE;
  204. UpdateData();
  205. m_bAutoRefresh = (m_checkEnableStats.GetCheck() == 1) ? TRUE : FALSE;
  206. int nMinutes = m_spinMinutes.GetPos();
  207. int nSeconds = m_spinSeconds.GetPos();
  208. //use minutes as seconds.
  209. m_dwRefreshInterval = nMinutes * MILLISEC_PER_MINUTE;
  210. m_dwRefreshInterval += nSeconds * MILLISEC_PER_SECOND;
  211. if (m_bAutoRefresh && m_dwRefreshInterval == 0)
  212. {
  213. CString strMessage;
  214. AfxMessageBox(IDS_ERR_AUTO_REFRESH_ZERO);
  215. m_editMinutes.SetSel(0, -1);
  216. m_editMinutes.SetFocus();
  217. return FALSE;
  218. }
  219. BOOL bRet = CPropertyPageBase::OnApply();
  220. if (bRet == FALSE)
  221. {
  222. // Something bad happened... grab the error code
  223. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  224. ::IpsmMessageBox(GetHolder()->GetError());
  225. }
  226. return bRet;
  227. }
  228. BOOL CMachinePropRefresh::OnPropertyChange(BOOL bScope, LONG_PTR *ChangeMask)
  229. {
  230. SPITFSNode spNode;
  231. CIpsmServer * pServer;
  232. DWORD dwError;
  233. // do stuff here.
  234. BEGIN_WAIT_CURSOR;
  235. spNode = GetHolder()->GetNode();
  236. pServer = GETHANDLER(CIpsmServer, spNode);
  237. pServer->SetAutoRefresh(spNode, m_bAutoRefresh, m_dwRefreshInterval);
  238. SPITFSNodeMgr spNodeMgr;
  239. SPITFSNode spRootNode;
  240. spNode->GetNodeMgr(&spNodeMgr);
  241. spNodeMgr->GetRootNode(&spRootNode);
  242. spRootNode->SetData(TFS_DATA_DIRTY, TRUE);
  243. END_WAIT_CURSOR;
  244. return FALSE;
  245. }