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.

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