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.

482 lines
14 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1996-1997 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // OpenClus.cpp
  7. //
  8. // Abstract:
  9. // Implementation of the COpenClusterDialog class.
  10. //
  11. // Author:
  12. // David Potter (davidp) May 1, 1996
  13. //
  14. // Revision History:
  15. //
  16. // Notes:
  17. //
  18. /////////////////////////////////////////////////////////////////////////////
  19. #include "stdafx.h"
  20. #include "CluAdmin.h"
  21. #include "OpenClus.h"
  22. #include "ClusMru.h"
  23. #include "DDxDDv.h"
  24. #include "HelpData.h"
  25. #include <lmcons.h>
  26. #include <lmserver.h>
  27. #include <lmapibuf.h>
  28. #ifdef _DEBUG
  29. #define new DEBUG_NEW
  30. #undef THIS_FILE
  31. static char THIS_FILE[] = __FILE__;
  32. #endif
  33. /////////////////////////////////////////////////////////////////////////////
  34. // COpenClusterDialog dialog
  35. /////////////////////////////////////////////////////////////////////////////
  36. /////////////////////////////////////////////////////////////////////////////
  37. // Message Maps
  38. BEGIN_MESSAGE_MAP(COpenClusterDialog, CBaseDialog)
  39. //{{AFX_MSG_MAP(COpenClusterDialog)
  40. ON_BN_CLICKED(IDC_OCD_BROWSE, OnBrowse)
  41. ON_CBN_SELCHANGE(IDC_OCD_ACTION, OnSelChangeAction)
  42. //}}AFX_MSG_MAP
  43. END_MESSAGE_MAP()
  44. /////////////////////////////////////////////////////////////////////////////
  45. //++
  46. //
  47. // COpenClusterDialog::COpenClusterDialog
  48. //
  49. // Routine Description:
  50. // Constructor.
  51. //
  52. // Arguments:
  53. // pParentWnd [IN OUT] Parent window for the dialog.
  54. //
  55. // Return Value:
  56. // None.
  57. //
  58. //--
  59. /////////////////////////////////////////////////////////////////////////////
  60. COpenClusterDialog::COpenClusterDialog(CWnd * pParentWnd /*=NULL*/)
  61. : CBaseDialog(IDD, g_aHelpIDs_IDD_OPEN_CLUSTER, pParentWnd)
  62. {
  63. CClusterAdminApp * papp = GetClusterAdminApp();
  64. CRecentClusterList * prcl = papp->PrclRecentClusterList();
  65. //{{AFX_DATA_INIT(COpenClusterDialog)
  66. m_strName = _T("");
  67. //}}AFX_DATA_INIT
  68. m_nAction = -1;
  69. // If there are no items in the MRU list, set the default action
  70. // to Create New Cluster. Otherwise, set the default action to
  71. // Open Connection.
  72. if ( prcl->GetSize() == 0 )
  73. {
  74. m_nAction = OPEN_CLUSTER_DLG_CREATE_NEW_CLUSTER;
  75. } // if: nothing in the MRU list
  76. else
  77. {
  78. m_nAction = OPEN_CLUSTER_DLG_OPEN_CONNECTION;
  79. } // else: something in the MRU list
  80. } //*** COpenClusterDialog::COpenClusterDialog()
  81. /////////////////////////////////////////////////////////////////////////////
  82. //++
  83. //
  84. // COpenClusterDialog::DoDataExchange
  85. //
  86. // Routine Description:
  87. // Do data exchange between the dialog and the class.
  88. //
  89. // Arguments:
  90. // pDX [IN OUT] Data exchange object
  91. //
  92. // Return Value:
  93. // None.
  94. //
  95. //--
  96. /////////////////////////////////////////////////////////////////////////////
  97. void COpenClusterDialog::DoDataExchange(CDataExchange * pDX)
  98. {
  99. CBaseDialog::DoDataExchange(pDX);
  100. //{{AFX_DATA_MAP(COpenClusterDialog)
  101. DDX_Control(pDX, IDC_OCD_NAME_LABEL, m_staticName);
  102. DDX_Control(pDX, IDC_OCD_BROWSE, m_pbBrowse);
  103. DDX_Control(pDX, IDC_OCD_ACTION, m_cboxAction);
  104. DDX_Control(pDX, IDOK, m_pbOK);
  105. DDX_Control(pDX, IDC_OCD_NAME, m_cboxName);
  106. DDX_Text(pDX, IDC_OCD_NAME, m_strName);
  107. //}}AFX_DATA_MAP
  108. if ( pDX->m_bSaveAndValidate )
  109. {
  110. m_nAction = m_cboxAction.GetCurSel();
  111. if ( m_nAction != OPEN_CLUSTER_DLG_CREATE_NEW_CLUSTER )
  112. {
  113. DDV_RequiredText(pDX, IDC_OCD_NAME, IDC_OCD_NAME_LABEL, m_strName);
  114. DDV_MaxChars(pDX, m_strName, MAX_PATH - 1);
  115. } // if: not creating a new cluster
  116. } // if: saving data
  117. else
  118. {
  119. m_cboxAction.SetCurSel( m_nAction );
  120. OnSelChangeAction();
  121. } // else: setting data
  122. } //*** COpenClusterDialog::DoDataExchange
  123. /////////////////////////////////////////////////////////////////////////////
  124. //++
  125. //
  126. // COpenClusterDialog::OnInitDialog
  127. //
  128. // Routine Description:
  129. // Handler for the WM_INITDIALOG message.
  130. //
  131. // Arguments:
  132. // None.
  133. //
  134. // Return Value:
  135. // TRUE Focus not set yet.
  136. // FALSE Focus already set.
  137. //
  138. //--
  139. /////////////////////////////////////////////////////////////////////////////
  140. BOOL COpenClusterDialog::OnInitDialog(void)
  141. {
  142. CClusterAdminApp * papp = GetClusterAdminApp();
  143. CRecentClusterList * prcl = papp->PrclRecentClusterList();
  144. int iMRU;
  145. CString strName;
  146. CWaitCursor wc;
  147. // Call the base class method to get our control mappings.
  148. CBaseDialog::OnInitDialog();
  149. // Add the items to the Action combobox.
  150. strName.LoadString( IDS_OCD_CREATE_CLUSTER );
  151. m_cboxAction.AddString( strName );
  152. strName.LoadString( IDS_OCD_ADD_NODES );
  153. m_cboxAction.AddString( strName );
  154. strName.LoadString( IDS_OCD_OPEN_CONNECTION );
  155. m_cboxAction.AddString( strName );
  156. // Set the proper selection in the Action combobox.
  157. m_cboxAction.SetCurSel( m_nAction );
  158. OnSelChangeAction();
  159. // Set limits on the combobox edit control.
  160. m_cboxName.LimitText(MAX_PATH - 1);
  161. // Loop through the MRU items and add each one to the list in order.
  162. for (iMRU = 0 ; iMRU < prcl->GetSize() ; iMRU++)
  163. {
  164. if (!prcl->GetDisplayName(strName, iMRU, NULL, 0))
  165. break;
  166. try
  167. {
  168. m_cboxName.InsertString(iMRU, strName);
  169. if ((iMRU == 0) && (m_strName.GetLength() == 0))
  170. m_strName = strName;
  171. } // try
  172. catch (CException * pe)
  173. {
  174. pe->Delete();
  175. } // catch: CException
  176. } // for: each MRU item
  177. // Select an item in the list.
  178. if (m_strName.GetLength() > 0)
  179. {
  180. int istr;
  181. istr = m_cboxName.FindStringExact(-1, m_strName);
  182. if (istr == CB_ERR)
  183. m_cboxName.SetWindowText(m_strName);
  184. else
  185. m_cboxName.SetCurSel(istr);
  186. } // if: name already specified
  187. else if (prcl->GetDisplayName(strName, 0, NULL, 0))
  188. m_cboxName.SelectString(-1, strName);
  189. return TRUE; // return TRUE unless you set the focus to a control
  190. // EXCEPTION: OCX Property Pages should return FALSE
  191. } //*** COpenClusterDialog::OnInitDialog()
  192. /////////////////////////////////////////////////////////////////////////////
  193. //++
  194. //
  195. // COpenClusterDialog::OnBrowse
  196. //
  197. // Routine Description:
  198. // Handler for the BN_CLICKED message on the Browse button.
  199. //
  200. // Arguments:
  201. // None.
  202. //
  203. // Return Value:
  204. // None.
  205. //
  206. //--
  207. /////////////////////////////////////////////////////////////////////////////
  208. void COpenClusterDialog::OnBrowse(void)
  209. {
  210. ID id;
  211. int istr;
  212. CBrowseClusters dlg(this);
  213. id = (ID)dlg.DoModal();
  214. if (id == IDOK)
  215. {
  216. istr = m_cboxName.FindStringExact(-1, dlg.m_strCluster);
  217. if (istr == CB_ERR)
  218. m_cboxName.SetWindowText(dlg.m_strCluster);
  219. else
  220. m_cboxName.SetCurSel(istr);
  221. } // if: user selected a cluster name
  222. } //*** COpenClusterDialog::OnBrowse()
  223. /////////////////////////////////////////////////////////////////////////////
  224. //++
  225. //
  226. // COpenClusterDialog::OnSelChangeAction
  227. //
  228. // Routine Description:
  229. // Handler for the CBN_SELCHANGE message on the Action combobox.
  230. //
  231. // Arguments:
  232. // None.
  233. //
  234. // Return Value:
  235. // None.
  236. //
  237. //--
  238. /////////////////////////////////////////////////////////////////////////////
  239. void COpenClusterDialog::OnSelChangeAction( void )
  240. {
  241. if ( m_cboxAction.GetCurSel() == OPEN_CLUSTER_DLG_CREATE_NEW_CLUSTER )
  242. {
  243. m_staticName.EnableWindow( FALSE );
  244. m_cboxName.EnableWindow( FALSE );
  245. m_pbBrowse.EnableWindow( FALSE );
  246. } // if: create cluster option selected
  247. else
  248. {
  249. m_staticName.EnableWindow( TRUE );
  250. m_cboxName.EnableWindow( TRUE );
  251. m_pbBrowse.EnableWindow( TRUE );
  252. } // else: create cluster option NOT selected
  253. } //*** COpenClusterDialog::OnSelChangeAction()
  254. //*************************************************************************//
  255. /////////////////////////////////////////////////////////////////////////////
  256. // CBrowseClusters dialog
  257. /////////////////////////////////////////////////////////////////////////////
  258. /////////////////////////////////////////////////////////////////////////////
  259. // Message Maps
  260. BEGIN_MESSAGE_MAP(CBrowseClusters, CBaseDialog)
  261. //{{AFX_MSG_MAP(CBrowseClusters)
  262. ON_EN_CHANGE(IDC_BC_CLUSTER, OnChangeCluster)
  263. ON_LBN_SELCHANGE(IDC_BC_LIST, OnSelChangeList)
  264. //}}AFX_MSG_MAP
  265. END_MESSAGE_MAP()
  266. /////////////////////////////////////////////////////////////////////////////
  267. //++
  268. //
  269. // CBrowseClusters::CBrowseClusters
  270. //
  271. // Routine Description:
  272. // Constructor.
  273. //
  274. // Arguments:
  275. // pParentWnd [IN OUT] Parent window for the dialog.
  276. //
  277. // Return Value:
  278. // None.
  279. //
  280. //--
  281. /////////////////////////////////////////////////////////////////////////////
  282. CBrowseClusters::CBrowseClusters(CWnd * pParent /*=NULL*/)
  283. : CBaseDialog(IDD, g_aHelpIDs_IDD_BROWSE_CLUSTERS, pParent)
  284. {
  285. //{{AFX_DATA_INIT(CBrowseClusters)
  286. m_strCluster = _T("");
  287. //}}AFX_DATA_INIT
  288. } //*** CBrowseClusters::CBrowseClusters()
  289. /////////////////////////////////////////////////////////////////////////////
  290. //++
  291. //
  292. // CBrowseClusters::DoDataExchange
  293. //
  294. // Routine Description:
  295. // Do data exchange between the dialog and the class.
  296. //
  297. // Arguments:
  298. // pDX [IN OUT] Data exchange object
  299. //
  300. // Return Value:
  301. // None.
  302. //
  303. //--
  304. /////////////////////////////////////////////////////////////////////////////
  305. void CBrowseClusters::DoDataExchange(CDataExchange * pDX)
  306. {
  307. CBaseDialog::DoDataExchange(pDX);
  308. //{{AFX_DATA_MAP(CBrowseClusters)
  309. DDX_Control(pDX, IDOK, m_pbOK);
  310. DDX_Control(pDX, IDC_BC_LIST, m_lbList);
  311. DDX_Control(pDX, IDC_BC_CLUSTER, m_editCluster);
  312. DDX_Text(pDX, IDC_BC_CLUSTER, m_strCluster);
  313. //}}AFX_DATA_MAP
  314. } //*** CBrowseClusters::DoDataExchange()
  315. /////////////////////////////////////////////////////////////////////////////
  316. //++
  317. //
  318. // CBrowseClusters::OnInitDialog
  319. //
  320. // Routine Description:
  321. // Handler for the WM_INITDIALOG message.
  322. //
  323. // Arguments:
  324. // None.
  325. //
  326. // Return Value:
  327. // TRUE Focus not set yet.
  328. // FALSE Focus already set.
  329. //
  330. //--
  331. /////////////////////////////////////////////////////////////////////////////
  332. BOOL CBrowseClusters::OnInitDialog(void)
  333. {
  334. CWaitCursor wc;
  335. // Call the base class method.
  336. CBaseDialog::OnInitDialog();
  337. // Collect list of clusters from the network.
  338. {
  339. DWORD dwStatus;
  340. DWORD nEntriesRead;
  341. DWORD nTotalEntries;
  342. DWORD iEntry;
  343. SERVER_INFO_100 * pServerInfo = NULL;
  344. SERVER_INFO_100 * pCurServerInfo;
  345. dwStatus = NetServerEnum(
  346. NULL, // servername
  347. 100, // level
  348. (LPBYTE *) &pServerInfo,
  349. 1000000, // prefmaxlen
  350. &nEntriesRead, // entriesread
  351. &nTotalEntries, // totalentries
  352. SV_TYPE_CLUSTER_NT, // servertype
  353. NULL, // domain
  354. NULL // resume_handle
  355. );
  356. if (dwStatus == ERROR_SUCCESS)
  357. {
  358. ASSERT(pServerInfo != NULL);
  359. pCurServerInfo = pServerInfo;
  360. for (iEntry = 0 ; iEntry < nTotalEntries ; iEntry++, pCurServerInfo++)
  361. {
  362. if (m_lbList.FindStringExact(-1, pCurServerInfo->sv100_name) == LB_ERR)
  363. {
  364. try
  365. {
  366. m_lbList.AddString(pCurServerInfo->sv100_name);
  367. } // try
  368. catch (CException * pe)
  369. {
  370. pe->Delete();
  371. } // catch: CException
  372. } // if: cluster not in list yet
  373. } // for: each entry in the array
  374. } // if: successfully retrieved list of clusters
  375. NetApiBufferFree(pServerInfo);
  376. } // Collect list of clusters from the network
  377. // Enable/disable controls.
  378. OnChangeCluster();
  379. return TRUE; // return TRUE unless you set the focus to a control
  380. // EXCEPTION: OCX Property Pages should return FALSE
  381. } //*** CBrowseClusters::OnInitDialog()
  382. /////////////////////////////////////////////////////////////////////////////
  383. //++
  384. //
  385. // CBrowseClusters::OnChangeCluster
  386. //
  387. // Routine Description:
  388. // Handler for the EN_CHANGE message on the Cluster edit control.
  389. //
  390. // Arguments:
  391. // None.
  392. //
  393. // Return Value:
  394. // None.
  395. //
  396. //--
  397. /////////////////////////////////////////////////////////////////////////////
  398. void CBrowseClusters::OnChangeCluster(void)
  399. {
  400. BOOL bEnable;
  401. bEnable = m_editCluster.GetWindowTextLength() != 0;
  402. m_pbOK.EnableWindow(bEnable);
  403. } //*** CBrowseClusters::OnChangeCluster()
  404. /////////////////////////////////////////////////////////////////////////////
  405. //++
  406. //
  407. // CBrowseClusters::OnSelChangeList
  408. //
  409. // Routine Description:
  410. // Handler for the LBN_SELCHANGE message on the list box.
  411. //
  412. // Arguments:
  413. // None.
  414. //
  415. // Return Value:
  416. // None.
  417. //
  418. //--
  419. /////////////////////////////////////////////////////////////////////////////
  420. void CBrowseClusters::OnSelChangeList(void)
  421. {
  422. int istr;
  423. istr = m_lbList.GetCurSel();
  424. if (istr != LB_ERR)
  425. {
  426. CString strText;
  427. m_lbList.GetText(istr, strText);
  428. m_editCluster.SetWindowText(strText);
  429. } // if: there is a selection
  430. } //*** CBrowseClusters::OnSelChangeList()