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.

936 lines
26 KiB

  1. /*++
  2. Module Name:
  3. NewFrs.cpp
  4. Abstract:
  5. This module contains the implementation for CNewReplicaSetPage pages.
  6. These classes implement pages in the Create Replica Set wizard.
  7. --*/
  8. #include "stdafx.h"
  9. #include "resource.h" // To be able to use the resource symbols
  10. #include "DfsEnums.h" // for common enums, typedefs, etc
  11. #include "Utils.h" // For the LoadStringFromResource method
  12. #include "mmcrep.h"
  13. #include "newfrs.h"
  14. #include "custop.h" // RSTOPOLOGYPREF_STRING g_TopologyPref[];
  15. ////////////////////////////////////////////////
  16. //
  17. // CNewReplicaSetPage0: welcome page
  18. //
  19. CNewReplicaSetPage0::CNewReplicaSetPage0()
  20. : CQWizardPageImpl<CNewReplicaSetPage0>(false),
  21. m_hBigBoldFont(NULL)
  22. {
  23. }
  24. CNewReplicaSetPage0::~CNewReplicaSetPage0()
  25. {
  26. DestroyFonts(m_hBigBoldFont, NULL);
  27. }
  28. BOOL CNewReplicaSetPage0::OnSetActive()
  29. {
  30. ::PropSheet_SetWizButtons(GetParent(), PSWIZB_NEXT);
  31. return TRUE;
  32. }
  33. LRESULT CNewReplicaSetPage0::OnInitDialog(
  34. IN UINT i_uMsg,
  35. IN WPARAM i_wParam,
  36. IN LPARAM i_lParam,
  37. IN OUT BOOL& io_bHandled
  38. )
  39. {
  40. SetupFonts( _Module.GetResourceInstance(), NULL, &m_hBigBoldFont, NULL);
  41. SetControlFont(m_hBigBoldFont, m_hWnd, IDC_NEWFRS_WELCOME);
  42. return TRUE;
  43. }
  44. ////////////////////////////////////////////////
  45. //
  46. // CNewReplicaSetPage1: pick initial master page
  47. //
  48. CNewReplicaSetPage1::CNewReplicaSetPage1(CNewReplicaSet* i_pRepSet)
  49. : CQWizardPageImpl<CNewReplicaSetPage1>(false),
  50. m_pRepSet(i_pRepSet),
  51. m_nCount(0)
  52. {
  53. }
  54. BOOL CNewReplicaSetPage1::OnSetActive()
  55. {
  56. ::PropSheet_SetWizButtons(GetParent(), PSWIZB_BACK | PSWIZB_NEXT);
  57. HWND hwnd = GetDlgItem(IDC_NEWFRSWIZ_MASTER);
  58. int nIndex = -1;
  59. if ((BSTR)(m_pRepSet->m_bstrPrimaryServer))
  60. {
  61. while (-1 != (nIndex = ListView_GetNextItem(hwnd, nIndex, LVNI_ALL)))
  62. {
  63. CAlternateReplicaInfo *pInfo = (CAlternateReplicaInfo *)GetListViewItemData(hwnd, nIndex);
  64. if (!lstrcmpi(m_pRepSet->m_bstrPrimaryServer, pInfo->m_bstrDnsHostName))
  65. break;
  66. }
  67. }
  68. if (-1 == nIndex)
  69. nIndex = 0;
  70. ListView_SetItemState(hwnd, nIndex, LVIS_SELECTED | LVIS_FOCUSED, 0xffffffff);
  71. return TRUE;
  72. }
  73. LRESULT CNewReplicaSetPage1::OnInitDialog(
  74. IN UINT i_uMsg,
  75. IN WPARAM i_wParam,
  76. IN LPARAM i_lParam,
  77. IN OUT BOOL& io_bHandled
  78. )
  79. {
  80. HWND hwnd = GetDlgItem(IDC_NEWFRSWIZ_MASTER);
  81. HIMAGELIST hImageList = NULL;
  82. int nIconIDs[] = {IDI_16x16_SHARE, IDI_16x16_SHARENA};
  83. HRESULT hr = CreateSmallImageList(
  84. _Module.GetResourceInstance(),
  85. nIconIDs,
  86. sizeof(nIconIDs) / sizeof(nIconIDs[0]),
  87. &hImageList);
  88. if (SUCCEEDED(hr))
  89. {
  90. ListView_SetImageList(hwnd, hImageList, LVSIL_SMALL);
  91. AddLVColumns(hwnd, IDS_REPLICATION_COLUMN_1, 2);
  92. CComBSTR bstrYes, bstrNo;
  93. LoadStringFromResource(IDS_REPLICATION_YES, &bstrYes);
  94. LoadStringFromResource(IDS_REPLICATION_NO, &bstrNo);
  95. AltRepList* pList = &(m_pRepSet->m_AltRepList);
  96. AltRepList::iterator i;
  97. int nIndex = 0;
  98. BOOL bEligible = FALSE;
  99. for (i = pList->begin(); i != pList->end(); i++)
  100. {
  101. bEligible = (FRSSHARE_TYPE_OK == (*i)->m_nFRSShareType);
  102. LVITEM lvItem;
  103. lvItem.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
  104. lvItem.lParam = (LPARAM)(*i);
  105. lvItem.pszText = (*i)->m_bstrDisplayName;
  106. lvItem.iSubItem = 0;
  107. lvItem.iImage = (bEligible ? 0 : 1);
  108. nIndex = ListView_InsertItem(hwnd, &lvItem);
  109. lvItem.mask = LVIF_TEXT;
  110. lvItem.pszText = (bEligible ? bstrYes : bstrNo);
  111. lvItem.iItem = nIndex;
  112. lvItem.iSubItem = 1;
  113. ListView_SetItem(hwnd, &lvItem);
  114. //
  115. // count number of eligible members
  116. //
  117. if (bEligible)
  118. m_nCount++;
  119. }
  120. }
  121. return TRUE;
  122. }
  123. LRESULT CNewReplicaSetPage1::OnNotify(
  124. IN UINT i_uMsg,
  125. IN WPARAM i_wParam,
  126. IN LPARAM i_lParam,
  127. IN OUT BOOL& io_bHandled
  128. )
  129. {
  130. io_bHandled = FALSE; // So that the base class gets this notify too
  131. NMHDR* pNMHDR = (NMHDR*)i_lParam;
  132. if (NULL == pNMHDR)
  133. return TRUE;
  134. if (IDC_NEWFRSWIZ_MASTER != pNMHDR->idFrom)
  135. return TRUE;
  136. NM_LISTVIEW *pnmv = (NM_LISTVIEW *)i_lParam;
  137. switch(pNMHDR->code)
  138. {
  139. case LVN_ITEMCHANGED:
  140. case NM_CLICK:
  141. if (OnItemChanged(((NM_LISTVIEW *)i_lParam)->iItem))
  142. ::PropSheet_SetWizButtons(GetParent(), PSWIZB_BACK | PSWIZB_NEXT);
  143. else
  144. ::PropSheet_SetWizButtons(GetParent(), PSWIZB_BACK);
  145. return 0; // Should be returning 0
  146. case NM_DBLCLK: // Double click event
  147. if (OnItemChanged(((NM_LISTVIEW *)i_lParam)->iItem))
  148. {
  149. ::PropSheet_SetWizButtons(GetParent(), PSWIZB_BACK | PSWIZB_NEXT);
  150. ::PropSheet_PressButton(GetParent(), PSBTN_NEXT);
  151. }
  152. break;
  153. default:
  154. break;
  155. }
  156. return TRUE;
  157. }
  158. BOOL CNewReplicaSetPage1::OnItemChanged(int i_iItem)
  159. {
  160. HWND hwnd = GetDlgItem(IDC_NEWFRSWIZ_MASTER);
  161. CAlternateReplicaInfo *pInfo = (CAlternateReplicaInfo *)GetListViewItemData(hwnd, i_iItem);
  162. if (!pInfo)
  163. return FALSE;
  164. CComBSTR bstrText;
  165. if (FRSSHARE_TYPE_UNKNOWN == pInfo->m_nFRSShareType)
  166. FormatMessageString(&bstrText, pInfo->m_hrFRS, IDS_REPLICATION_UNKNOWN);
  167. int nID = 0;
  168. switch (pInfo->m_nFRSShareType)
  169. {
  170. case FRSSHARE_TYPE_NONTFRS:
  171. nID = IDS_REPLICATION_NONTFRS;
  172. break;
  173. case FRSSHARE_TYPE_NOTDISKTREE:
  174. nID = IDS_REPLICATION_NOTDISKTREE;
  175. break;
  176. case FRSSHARE_TYPE_NOTNTFS:
  177. nID = IDS_REPLICATION_NOTNTFS;
  178. break;
  179. case FRSSHARE_TYPE_CONFLICTSTAGING:
  180. nID = IDS_REPLICATION_CONFLICTSTAGING;
  181. break;
  182. case FRSSHARE_TYPE_NODOMAIN:
  183. nID = IDS_REPLICATION_NODOMAIN;
  184. break;
  185. case FRSSHARE_TYPE_NOTSMBDISK:
  186. nID = IDS_REPLICATION_NOTSMBDISK;
  187. break;
  188. case FRSSHARE_TYPE_OVERLAPPING:
  189. nID = IDS_REPLICATION_OVERLAPPING;
  190. break;
  191. default:
  192. break;
  193. }
  194. if (nID)
  195. LoadStringFromResource(nID, &bstrText);
  196. if (!bstrText)
  197. {
  198. SetDlgItemText(IDC_NEWFRSWIZ_MASTER_DESC, _T(""));
  199. return TRUE; // okay to enable Next button
  200. } else
  201. {
  202. SetDlgItemText(IDC_NEWFRSWIZ_MASTER_DESC, bstrText);
  203. return FALSE;
  204. }
  205. }
  206. BOOL CNewReplicaSetPage1::OnWizardBack()
  207. {
  208. _Reset();
  209. return TRUE;
  210. }
  211. BOOL CNewReplicaSetPage1::OnWizardNext()
  212. {
  213. _Reset();
  214. if (m_nCount < 2)
  215. {
  216. DisplayMessageBoxWithOK(IDS_REPLICA_SET_TOPOLOGY_MINIMUM);
  217. return FALSE;
  218. }
  219. HWND hwnd = GetDlgItem(IDC_NEWFRSWIZ_MASTER);
  220. int nIndex = ListView_GetNextItem(hwnd, -1, LVNI_SELECTED);
  221. if (-1 == nIndex)
  222. {
  223. DisplayMessageBoxWithOK(IDS_NEWFRSWIZ_NOSELECTION);
  224. return FALSE;
  225. }
  226. CAlternateReplicaInfo *pInfo = (CAlternateReplicaInfo *)GetListViewItemData(hwnd, nIndex);
  227. m_pRepSet->m_bstrPrimaryServer = pInfo->m_bstrDnsHostName;
  228. if (!(m_pRepSet->m_bstrPrimaryServer))
  229. {
  230. DisplayMessageBoxForHR(E_OUTOFMEMORY);
  231. return FALSE;
  232. }
  233. return TRUE;
  234. }
  235. void CNewReplicaSetPage1::_Reset()
  236. {
  237. m_pRepSet->m_bstrPrimaryServer.Empty();
  238. }
  239. ////////////////////////////////////////////////
  240. //
  241. // CNewReplicaSetPage2: TopologyPref page
  242. //
  243. CNewReplicaSetPage2::CNewReplicaSetPage2(CNewReplicaSet* i_pRepSet, BOOL i_bNewSchema)
  244. : CQWizardPageImpl<CNewReplicaSetPage2>(false),
  245. m_pRepSet(i_pRepSet),
  246. m_bNewSchema(i_bNewSchema)
  247. {
  248. }
  249. BOOL CNewReplicaSetPage2::OnSetActive()
  250. {
  251. ::PropSheet_SetWizButtons(GetParent(), PSWIZB_BACK | PSWIZB_FINISH);
  252. SendDlgItemMessage(IDC_NEWFRSWIZ_TOPOLOGYPREF, CB_SETCURSEL, 0, 0);
  253. SendDlgItemMessage(IDC_NEWFRSWIZ_HUBSERVER, CB_SETCURSEL, 0, 0);
  254. MyShowWindow(GetDlgItem(IDC_NEWFRSWIZ_HUBSERVER_LABEL), FALSE);
  255. MyShowWindow(GetDlgItem(IDC_NEWFRSWIZ_HUBSERVER), FALSE);
  256. return TRUE;
  257. }
  258. LRESULT CNewReplicaSetPage2::OnInitDialog(
  259. IN UINT i_uMsg,
  260. IN WPARAM i_wParam,
  261. IN LPARAM i_lParam,
  262. IN OUT BOOL& io_bHandled
  263. )
  264. {
  265. //
  266. // add strings to Topology combo box
  267. //
  268. CComBSTR bstrTopologyPref;
  269. int j = 0;
  270. for (j = 0; j < 3; j++)
  271. {
  272. bstrTopologyPref.Empty();
  273. LoadStringFromResource(g_TopologyPref[j].nStringID, &bstrTopologyPref);
  274. SendDlgItemMessage(IDC_NEWFRSWIZ_TOPOLOGYPREF, CB_INSERTSTRING, j, (LPARAM)(BSTR)bstrTopologyPref);
  275. }
  276. bstrTopologyPref.Empty();
  277. LoadStringFromResource(IDS_NEWFRSWIZ_CUSTOM, &bstrTopologyPref);
  278. SendDlgItemMessage(IDC_NEWFRSWIZ_TOPOLOGYPREF, CB_INSERTSTRING, j, (LPARAM)(BSTR)bstrTopologyPref);
  279. //
  280. // add strings to Hub combo box
  281. //
  282. AltRepList* pList = &(m_pRepSet->m_AltRepList);
  283. AltRepList::iterator i;
  284. for (i = pList->begin(); i != pList->end(); i++)
  285. {
  286. if (FRSSHARE_TYPE_OK == (*i)->m_nFRSShareType)
  287. {
  288. SendDlgItemMessage(
  289. IDC_NEWFRSWIZ_HUBSERVER,
  290. CB_ADDSTRING,
  291. 0, // not used
  292. (LPARAM)((BSTR)(*i)->m_bstrDnsHostName)
  293. );
  294. }
  295. }
  296. MyShowWindow(GetDlgItem(IDC_NEWFRSWIZ_OLDSCHEMA), !m_bNewSchema);
  297. return TRUE;
  298. }
  299. BOOL CNewReplicaSetPage2::OnTopologyPref(
  300. IN WORD wNotifyCode,
  301. IN WORD wID,
  302. IN HWND hWndCtl,
  303. IN BOOL& bHandled
  304. )
  305. {
  306. int index = SendDlgItemMessage(IDC_NEWFRSWIZ_TOPOLOGYPREF, CB_GETCURSEL, 0, 0);
  307. if (!lstrcmpi(FRS_RSTOPOLOGYPREF_HUBSPOKE, g_TopologyPref[index].pszTopologyPref))
  308. {
  309. MyShowWindow(GetDlgItem(IDC_NEWFRSWIZ_HUBSERVER_LABEL), TRUE);
  310. MyShowWindow(GetDlgItem(IDC_NEWFRSWIZ_HUBSERVER), TRUE);
  311. } else
  312. {
  313. MyShowWindow(GetDlgItem(IDC_NEWFRSWIZ_HUBSERVER_LABEL), FALSE);
  314. MyShowWindow(GetDlgItem(IDC_NEWFRSWIZ_HUBSERVER), FALSE);
  315. }
  316. return TRUE;
  317. }
  318. BOOL CNewReplicaSetPage2::OnWizardBack()
  319. {
  320. _Reset();
  321. return TRUE;
  322. }
  323. BOOL CNewReplicaSetPage2::OnWizardFinish()
  324. {
  325. CWaitCursor wait;
  326. _Reset();
  327. HRESULT hr = S_OK;
  328. int index = SendDlgItemMessage(IDC_NEWFRSWIZ_TOPOLOGYPREF, CB_GETCURSEL, 0, 0);
  329. m_pRepSet->m_bstrTopologyPref = g_TopologyPref[index].pszTopologyPref;
  330. if (!(m_pRepSet->m_bstrTopologyPref))
  331. {
  332. DisplayMessageBoxForHR(E_OUTOFMEMORY);
  333. return FALSE;
  334. }
  335. if (!lstrcmpi(FRS_RSTOPOLOGYPREF_HUBSPOKE, m_pRepSet->m_bstrTopologyPref))
  336. {
  337. hr = GetComboBoxText(GetDlgItem(IDC_NEWFRSWIZ_HUBSERVER), &(m_pRepSet->m_bstrHubServer));
  338. if (FAILED(hr))
  339. {
  340. DisplayMessageBoxForHR(hr);
  341. return FALSE;
  342. }
  343. }
  344. if (!lstrcmpi(FRS_RSTOPOLOGYPREF_CUSTOM, m_pRepSet->m_bstrTopologyPref))
  345. {
  346. DisplayMessageBox(::GetActiveWindow(), MB_OK | MB_ICONINFORMATION, 0, IDS_NEWFRSWIZ_CUSTOM_MSG);
  347. }
  348. m_pRepSet->m_bstrDirFilter.Empty();
  349. m_pRepSet->m_bstrFileFilter = DEFAULT_FILEFILTER;
  350. if (!(m_pRepSet->m_bstrFileFilter))
  351. {
  352. DisplayMessageBoxForHR(E_OUTOFMEMORY);
  353. return FALSE;
  354. }
  355. hr = _CreateReplicaSet();
  356. if (FAILED(hr))
  357. return FALSE; // error reported already
  358. m_pRepSet->m_hr = S_OK; // the only way out successfully
  359. return TRUE;
  360. }
  361. void CNewReplicaSetPage2::_Reset()
  362. {
  363. m_pRepSet->m_hr = S_FALSE;
  364. m_pRepSet->m_bstrTopologyPref.Empty();
  365. m_pRepSet->m_bstrHubServer.Empty();
  366. }
  367. HRESULT CNewReplicaSetPage2::_CreateReplicaSet()
  368. {
  369. HRESULT hr = S_OK;
  370. CComPtr<IReplicaSet> piReplicaSet;
  371. BOOL bUndo = FALSE;
  372. AltRepList* pList = &(m_pRepSet->m_AltRepList);
  373. AltRepList::iterator i;
  374. do {
  375. for (i = pList->begin(); i != pList->end(); i++)
  376. {
  377. if (FRSSHARE_TYPE_OK == (*i)->m_nFRSShareType)
  378. {
  379. (void) CreateAndHideStagingPath(
  380. (*i)->m_bstrDnsHostName,
  381. (*i)->m_bstrStagingPath
  382. );
  383. hr = ConfigAndStartNtfrs((*i)->m_bstrDnsHostName);
  384. if (FAILED(hr))
  385. {
  386. if (IDYES != DisplayMessageBox(
  387. m_hWnd,
  388. MB_YESNO,
  389. hr,
  390. IDS_MSG_FRS_BADSERVICE,
  391. (*i)->m_bstrDisplayName,
  392. (*i)->m_bstrDnsHostName))
  393. {
  394. bUndo = TRUE;
  395. break;
  396. }
  397. hr = S_OK;
  398. }
  399. }
  400. } // for
  401. BREAK_IF_FAILED(hr);
  402. //
  403. // Create replica set object with attribute:
  404. // TopologyPref/HubMember/PrimaryMember/FileFilter/DirFilter
  405. //
  406. hr = CoCreateInstance(CLSID_ReplicaSet, NULL, CLSCTX_INPROC_SERVER, IID_IReplicaSet, (void**)&piReplicaSet);
  407. BREAK_IF_FAILED(hr);
  408. hr = piReplicaSet->Create(
  409. m_pRepSet->m_bstrDomain,
  410. m_pRepSet->m_bstrReplicaSetDN,
  411. FRS_RSTYPE_DFS,
  412. m_pRepSet->m_bstrTopologyPref,
  413. NULL, // HubMemberDN, will set later after we know member DN
  414. NULL, // PrimaryMemberDN, will set later after we know member DN
  415. m_pRepSet->m_bstrFileFilter,
  416. m_pRepSet->m_bstrDirFilter
  417. );
  418. if (FAILED(hr))
  419. {
  420. piReplicaSet.Release(); // no need to call DeleteReplicaSet method when Undo
  421. break;
  422. }
  423. //
  424. // create each member
  425. //
  426. BOOL bPrimaryServerFound = FALSE;
  427. CComBSTR bstrPrimaryMemberDN;
  428. BOOL bHubSpoke = !lstrcmpi(FRS_RSTOPOLOGYPREF_HUBSPOKE, m_pRepSet->m_bstrTopologyPref);
  429. BOOL bHubServerFound = FALSE;
  430. CComBSTR bstrHubMemberDN;
  431. for (i = pList->begin(); i != pList->end(); i++)
  432. {
  433. if (FRSSHARE_TYPE_OK == (*i)->m_nFRSShareType)
  434. {
  435. CComBSTR bstrMemberDN;
  436. hr = piReplicaSet->AddMember(
  437. (*i)->m_bstrDnsHostName,
  438. (*i)->m_bstrRootPath,
  439. (*i)->m_bstrStagingPath,
  440. FALSE, // add connection later
  441. &bstrMemberDN);
  442. BREAK_IF_FAILED(hr);
  443. if (!bPrimaryServerFound &&
  444. !lstrcmpi((*i)->m_bstrDnsHostName, m_pRepSet->m_bstrPrimaryServer))
  445. {
  446. bPrimaryServerFound = TRUE;
  447. bstrPrimaryMemberDN = bstrMemberDN;
  448. BREAK_OUTOFMEMORY_IF_NULL((BSTR)bstrPrimaryMemberDN, &hr);
  449. }
  450. if (bHubSpoke && !bHubServerFound &&
  451. !lstrcmpi((*i)->m_bstrDnsHostName, m_pRepSet->m_bstrHubServer))
  452. {
  453. bHubServerFound = TRUE;
  454. bstrHubMemberDN = bstrMemberDN;
  455. BREAK_OUTOFMEMORY_IF_NULL((BSTR)bstrHubMemberDN, &hr);
  456. }
  457. }
  458. }
  459. BREAK_IF_FAILED(hr);
  460. //
  461. // set PrimaryMember and HubMember
  462. //
  463. hr = piReplicaSet->put_PrimaryMemberDN(bstrPrimaryMemberDN);
  464. BREAK_IF_FAILED(hr);
  465. if (bHubSpoke)
  466. {
  467. hr = piReplicaSet->put_HubMemberDN(bstrHubMemberDN);
  468. BREAK_IF_FAILED(hr);
  469. }
  470. //
  471. // build connection based on specified TopologyPref
  472. //
  473. hr = piReplicaSet->CreateConnections();
  474. BREAK_IF_FAILED(hr);
  475. } while (0);
  476. if (!bUndo && FAILED(hr))
  477. {
  478. DisplayMessageBox(m_hWnd, MB_OK, hr, IDS_NEWFRSWIZ_FAILURE);
  479. bUndo = TRUE;
  480. }
  481. if (bUndo)
  482. {
  483. //
  484. // Delete replica set
  485. //
  486. if ((IReplicaSet *)(piReplicaSet))
  487. {
  488. piReplicaSet->Delete();
  489. piReplicaSet.Release();
  490. }
  491. } else
  492. {
  493. m_pRepSet->m_piReplicaSet = piReplicaSet;
  494. }
  495. return hr;
  496. }
  497. /*
  498. ////////////////////////////////////////////////
  499. //
  500. // CNewReplicaSetPage3: file/dir filter page
  501. //
  502. CNewReplicaSetPage3::CNewReplicaSetPage3(CNewReplicaSet* i_pRepSet)
  503. : CQWizardPageImpl<CNewReplicaSetPage3>(false),
  504. m_pRepSet(i_pRepSet)
  505. {
  506. }
  507. BOOL CNewReplicaSetPage3::OnSetActive()
  508. {
  509. ::PropSheet_SetWizButtons(GetParent(), PSWIZB_BACK | PSWIZB_FINISH);
  510. SetDlgItemText(IDC_NEWFRSWIZ_FILEFILTER, DEFAULT_FILEFILTER);
  511. SetDlgItemText(IDC_NEWFRSWIZ_DIRFILTER, _T(""));
  512. return TRUE;
  513. }
  514. LRESULT CNewReplicaSetPage3::OnInitDialog(
  515. IN UINT i_uMsg,
  516. IN WPARAM i_wParam,
  517. IN LPARAM i_lParam,
  518. IN OUT BOOL& io_bHandled
  519. )
  520. {
  521. return TRUE;
  522. }
  523. BOOL CNewReplicaSetPage3::OnWizardBack()
  524. {
  525. _Reset();
  526. return TRUE;
  527. }
  528. BOOL CNewReplicaSetPage3::OnWizardFinish()
  529. {
  530. CWaitCursor wait;
  531. _Reset();
  532. ULONG ulTextLen = 0;
  533. HRESULT hr = GetInputText(
  534. GetDlgItem(IDC_NEWFRSWIZ_FILEFILTER),
  535. &(m_pRepSet->m_bstrFileFilter),
  536. &ulTextLen
  537. );
  538. if (SUCCEEDED(hr))
  539. hr = GetInputText(
  540. GetDlgItem(IDC_NEWFRSWIZ_DIRFILTER),
  541. &(m_pRepSet->m_bstrDirFilter),
  542. &ulTextLen
  543. );
  544. if (FAILED(hr))
  545. {
  546. DisplayMessageBoxForHR(hr);
  547. return FALSE;
  548. }
  549. hr = _CreateReplicaSet();
  550. if (FAILED(hr))
  551. return FALSE; // error reported already
  552. m_pRepSet->m_hr = S_OK; // the only way out successfully
  553. return TRUE;
  554. }
  555. void CNewReplicaSetPage3::_Reset()
  556. {
  557. m_pRepSet->m_hr = S_FALSE;
  558. m_pRepSet->m_bstrFileFilter.Empty();
  559. m_pRepSet->m_bstrDirFilter.Empty();
  560. }
  561. HRESULT CNewReplicaSetPage3::_CreateReplicaSet()
  562. {
  563. HRESULT hr = S_OK;
  564. CComPtr<IReplicaSet> piReplicaSet;
  565. BOOL bUndo = FALSE;
  566. AltRepList* pList = &(m_pRepSet->m_AltRepList);
  567. AltRepList::iterator i;
  568. do {
  569. for (i = pList->begin(); i != pList->end(); i++)
  570. {
  571. if (FRSSHARE_TYPE_OK == (*i)->m_nFRSShareType)
  572. {
  573. (void) CreateAndHideStagingPath(
  574. (*i)->m_bstrDnsHostName,
  575. (*i)->m_bstrStagingPath
  576. );
  577. hr = ConfigAndStartNtfrs((*i)->m_bstrDnsHostName);
  578. if (FAILED(hr))
  579. {
  580. if (IDYES != DisplayMessageBox(
  581. m_hWnd,
  582. MB_YESNO,
  583. hr,
  584. IDS_MSG_FRS_BADSERVICE,
  585. (*i)->m_bstrDisplayName,
  586. (*i)->m_bstrDnsHostName))
  587. {
  588. bUndo = TRUE;
  589. break;
  590. }
  591. hr = S_OK;
  592. }
  593. }
  594. } // for
  595. BREAK_IF_FAILED(hr);
  596. //
  597. // Create replica set object with attribute:
  598. // TopologyPref/HubMember/PrimaryMember/FileFilter/DirFilter
  599. //
  600. hr = CoCreateInstance(CLSID_ReplicaSet, NULL, CLSCTX_INPROC_SERVER, IID_IReplicaSet, (void**)&piReplicaSet);
  601. BREAK_IF_FAILED(hr);
  602. hr = piReplicaSet->Create(
  603. m_pRepSet->m_bstrDomain,
  604. m_pRepSet->m_bstrReplicaSetDN,
  605. FRS_RSTYPE_DFS,
  606. m_pRepSet->m_bstrTopologyPref,
  607. NULL, // HubMemberDN, will set later after we know member DN
  608. NULL, // PrimaryMemberDN, will set later after we know member DN
  609. m_pRepSet->m_bstrFileFilter,
  610. m_pRepSet->m_bstrDirFilter
  611. );
  612. if (FAILED(hr))
  613. {
  614. piReplicaSet.Release(); // no need to call DeleteReplicaSet method when Undo
  615. break;
  616. }
  617. //
  618. // create each member
  619. //
  620. BOOL bPrimaryServerFound = FALSE;
  621. CComBSTR bstrPrimaryMemberDN;
  622. BOOL bHubSpoke = !lstrcmpi(FRS_RSTOPOLOGYPREF_HUBSPOKE, m_pRepSet->m_bstrTopologyPref);
  623. BOOL bHubServerFound = FALSE;
  624. CComBSTR bstrHubMemberDN;
  625. for (i = pList->begin(); i != pList->end(); i++)
  626. {
  627. if (FRSSHARE_TYPE_OK == (*i)->m_nFRSShareType)
  628. {
  629. CComBSTR bstrMemberDN;
  630. hr = piReplicaSet->AddMember(
  631. (*i)->m_bstrDnsHostName,
  632. (*i)->m_bstrRootPath,
  633. (*i)->m_bstrStagingPath,
  634. FALSE, // add connection later
  635. &bstrMemberDN);
  636. BREAK_IF_FAILED(hr);
  637. if (!bPrimaryServerFound &&
  638. !lstrcmpi((*i)->m_bstrDnsHostName, m_pRepSet->m_bstrPrimaryServer))
  639. {
  640. bPrimaryServerFound = TRUE;
  641. bstrPrimaryMemberDN = bstrMemberDN;
  642. BREAK_OUTOFMEMORY_IF_NULL((BSTR)bstrPrimaryMemberDN, &hr);
  643. }
  644. if (bHubSpoke && !bHubServerFound &&
  645. !lstrcmpi((*i)->m_bstrDnsHostName, m_pRepSet->m_bstrHubServer))
  646. {
  647. bHubServerFound = TRUE;
  648. bstrHubMemberDN = bstrMemberDN;
  649. BREAK_OUTOFMEMORY_IF_NULL((BSTR)bstrHubMemberDN, &hr);
  650. }
  651. }
  652. }
  653. BREAK_IF_FAILED(hr);
  654. //
  655. // set PrimaryMember and HubMember
  656. //
  657. hr = piReplicaSet->put_PrimaryMemberDN(bstrPrimaryMemberDN);
  658. BREAK_IF_FAILED(hr);
  659. if (bHubSpoke)
  660. {
  661. hr = piReplicaSet->put_HubMemberDN(bstrHubMemberDN);
  662. BREAK_IF_FAILED(hr);
  663. }
  664. //
  665. // build connection based on specified TopologyPref
  666. //
  667. hr = piReplicaSet->CreateConnections();
  668. BREAK_IF_FAILED(hr);
  669. } while (0);
  670. if (!bUndo && FAILED(hr))
  671. {
  672. DisplayMessageBox(m_hWnd, MB_OK, hr, IDS_NEWFRSWIZ_FAILURE);
  673. bUndo = TRUE;
  674. }
  675. if (bUndo)
  676. {
  677. //
  678. // Delete replica set
  679. //
  680. if ((IReplicaSet *)(piReplicaSet))
  681. {
  682. piReplicaSet->Delete();
  683. piReplicaSet.Release();
  684. }
  685. } else
  686. {
  687. m_pRepSet->m_piReplicaSet = piReplicaSet;
  688. }
  689. return hr;
  690. }
  691. */
  692. /////////////////////////////////////////////////
  693. //
  694. // CNewReplicaSet
  695. //
  696. HRESULT CNewReplicaSet::Initialize(
  697. BSTR i_bstrDomain,
  698. BSTR i_bstrReplicaSetDN,
  699. DFS_REPLICA_LIST* i_pMmcRepList
  700. )
  701. {
  702. RETURN_INVALIDARG_IF_NULL(i_bstrDomain);
  703. RETURN_INVALIDARG_IF_NULL(i_bstrReplicaSetDN);
  704. RETURN_INVALIDARG_IF_NULL(i_pMmcRepList);
  705. _Reset();
  706. m_bstrDomain = i_bstrDomain;
  707. RETURN_OUTOFMEMORY_IF_NULL((BSTR)m_bstrDomain);
  708. m_bstrReplicaSetDN = i_bstrReplicaSetDN;
  709. RETURN_OUTOFMEMORY_IF_NULL((BSTR)m_bstrReplicaSetDN);
  710. HRESULT hr = S_OK;
  711. BOOL bTargetsOnSameServers = FALSE;
  712. CAlternateReplicaInfo* pInfo = NULL;
  713. DFS_REPLICA_LIST::iterator i;
  714. for (i = i_pMmcRepList->begin(); i != i_pMmcRepList->end(); i++)
  715. {
  716. hr = ((*i)->pReplica)->GetReplicationInfoEx(&pInfo);
  717. BREAK_IF_FAILED(hr);
  718. if (_InsertList(pInfo))
  719. bTargetsOnSameServers = TRUE; // should return S_FALSE
  720. pInfo = NULL;
  721. }
  722. if (FAILED(hr))
  723. _Reset();
  724. else if (bTargetsOnSameServers)
  725. hr = S_FALSE;
  726. return hr;
  727. }
  728. BOOL CNewReplicaSet::_InsertList(CAlternateReplicaInfo* pInfo)
  729. {
  730. BOOL bFound = FALSE;
  731. if (pInfo)
  732. {
  733. AltRepList::iterator i;
  734. for (i = m_AltRepList.begin(); i != m_AltRepList.end(); i++)
  735. {
  736. if (FRSSHARE_TYPE_OK == pInfo->m_nFRSShareType &&
  737. !lstrcmpi(pInfo->m_bstrDnsHostName, (*i)->m_bstrDnsHostName))
  738. {
  739. bFound = TRUE;
  740. break;
  741. }
  742. }
  743. if (!bFound)
  744. {
  745. m_AltRepList.push_back(pInfo);
  746. } else
  747. {
  748. if ( (FRSSHARE_TYPE_OK != (*i)->m_nFRSShareType &&
  749. FRSSHARE_TYPE_OK == pInfo->m_nFRSShareType) ||
  750. (FRSSHARE_TYPE_UNKNOWN == (*i)->m_nFRSShareType &&
  751. FRSSHARE_TYPE_UNKNOWN != pInfo->m_nFRSShareType &&
  752. FRSSHARE_TYPE_OK != pInfo->m_nFRSShareType) )
  753. { // replace the element
  754. CAlternateReplicaInfo* pTemp = *i;
  755. *i = pInfo;
  756. delete pTemp;
  757. } else
  758. { // no change
  759. delete pInfo;
  760. }
  761. }
  762. }
  763. return bFound;
  764. }
  765. void CNewReplicaSet::_Reset()
  766. {
  767. m_bstrDomain.Empty();
  768. m_bstrReplicaSetDN.Empty();
  769. m_bstrPrimaryServer.Empty();
  770. m_bstrTopologyPref.Empty();
  771. m_bstrHubServer.Empty();
  772. m_bstrFileFilter.Empty();
  773. m_bstrDirFilter.Empty();
  774. m_hr = S_FALSE;
  775. FreeAltRepList(&m_AltRepList);
  776. if ((IReplicaSet *)m_piReplicaSet)
  777. m_piReplicaSet.Release();
  778. }
  779. void FreeAltRepList(AltRepList* pList)
  780. {
  781. if (pList && !pList->empty())
  782. {
  783. AltRepList::iterator i;
  784. for (i = pList->begin(); i != pList->end(); i++)
  785. delete (*i);
  786. pList->clear();
  787. }
  788. }