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.

485 lines
12 KiB

  1. /*++
  2. Module Name:
  3. frsProp.cpp
  4. Abstract:
  5. --*/
  6. #include "stdafx.h"
  7. #include "resource.h"
  8. #include "utils.h"
  9. #include "frsProp.h"
  10. #include "mvEdit.h"
  11. #include "dfshelp.h"
  12. #include "CusTop.h"
  13. #include "ldaputils.h"
  14. CRealReplicaSetPropPage::CRealReplicaSetPropPage() :
  15. m_lNotifyHandle(0),
  16. m_lNotifyParam(0),
  17. CQWizardPageImpl<CRealReplicaSetPropPage>(false)
  18. {
  19. m_bstrTopologyPref = FRS_RSTOPOLOGYPREF_RING;
  20. }
  21. CRealReplicaSetPropPage::~CRealReplicaSetPropPage()
  22. {
  23. // do not call MMCFreeNotifyHandle(m_lNotifyHandle);
  24. //
  25. // It should only be called once, and is already called
  26. // by the main property page
  27. }
  28. HRESULT CRealReplicaSetPropPage::_GetMemberDNInfo(
  29. IN BSTR i_bstrMemberDN,
  30. OUT BSTR* o_pbstrServer
  31. )
  32. {
  33. RETURN_INVALIDARG_IF_NULL(i_bstrMemberDN);
  34. RETURN_INVALIDARG_IF_NULL(o_pbstrServer);
  35. VARIANT var;
  36. VariantInit(&var);
  37. HRESULT hr = m_piReplicaSet->GetMemberInfo(i_bstrMemberDN, &var);
  38. RETURN_IF_FAILED(hr);
  39. if (V_VT(&var) != (VT_ARRAY | VT_VARIANT))
  40. return E_INVALIDARG;
  41. SAFEARRAY *psa = V_ARRAY(&var);
  42. if (!psa) // no such member at all
  43. return S_FALSE;
  44. long lLowerBound = 0;
  45. long lUpperBound = 0;
  46. long lCount = 0;
  47. SafeArrayGetLBound(psa, 1, &lLowerBound);
  48. SafeArrayGetUBound(psa, 1, &lUpperBound);
  49. lCount = lUpperBound - lLowerBound + 1;
  50. VARIANT HUGEP *pArray;
  51. SafeArrayAccessData(psa, (void HUGEP **) &pArray);
  52. *o_pbstrServer = SysAllocString(pArray[4].bstrVal);
  53. SafeArrayUnaccessData(psa);
  54. VariantClear(&var); // it will in turn call SafeArrayDestroy(psa);
  55. RETURN_OUTOFMEMORY_IF_NULL(*o_pbstrServer);
  56. return hr;
  57. }
  58. LRESULT
  59. CRealReplicaSetPropPage::OnInitDialog(
  60. IN UINT i_uMsg,
  61. IN WPARAM i_wParam,
  62. LPARAM i_lParam,
  63. IN OUT BOOL& io_bHandled
  64. )
  65. {
  66. SetDlgItemText(IDC_FRSPROP_FILEFILTER, ((BSTR)m_bstrFileFilter) ? m_bstrFileFilter : _T(""));
  67. SetDlgItemText(IDC_FRSPROP_DIRFILTER, ((BSTR)m_bstrDirFilter) ? m_bstrDirFilter : _T(""));
  68. for (int i = 0; i < 4; i++)
  69. {
  70. if (!lstrcmpi(m_bstrTopologyPref, g_TopologyPref[i].pszTopologyPref))
  71. {
  72. CComBSTR bstrText;
  73. LoadStringFromResource(g_TopologyPref[i].nStringID, &bstrText);
  74. SetDlgItemText(IDC_FRSPROP_TOPOLOGYPREF, bstrText);
  75. }
  76. }
  77. if (0 != lstrcmpi(m_bstrTopologyPref, FRS_RSTOPOLOGYPREF_HUBSPOKE))
  78. {
  79. MyShowWindow(GetDlgItem(IDC_FRSPROP_HUBSERVER_LABEL), FALSE);
  80. MyShowWindow(GetDlgItem(IDC_FRSPROP_HUBSERVER), FALSE);
  81. }
  82. HRESULT hr = S_OK;
  83. if (CheckPolicyOnDisplayingInitialMaster())
  84. {
  85. CComBSTR bstrPrimaryServer;
  86. hr = _GetMemberDNInfo(m_bstrPrimaryMemberDN, &bstrPrimaryServer);
  87. SetDlgItemText(IDC_FRSPROP_PRIMARYMEMBER, (S_OK == hr) ? bstrPrimaryServer : _T(""));
  88. } else
  89. {
  90. MyShowWindow(GetDlgItem(IDC_FRSPROP_PRIMARYMEMBER_LABEL), FALSE);
  91. MyShowWindow(GetDlgItem(IDC_FRSPROP_PRIMARYMEMBER), FALSE);
  92. }
  93. CComBSTR bstrHubServer;
  94. hr = _GetMemberDNInfo(m_bstrHubMemberDN, &bstrHubServer);
  95. SetDlgItemText(IDC_FRSPROP_HUBSERVER, (S_OK == hr) ? bstrHubServer : _T(""));
  96. if (m_lNumOfMembers < 2)
  97. ::EnableWindow(GetDlgItem(IDC_FRSPROP_CUSTOMIZE), FALSE);
  98. ::EnableWindow(GetDlgItem(IDC_FRSPROP_RESETSCHEDULE), (m_lNumOfConnections > 0));
  99. return TRUE; // To let the dialg set the control
  100. }
  101. /*++
  102. This function is called when a user clicks the ? in the top right of a property sheet
  103. and then clciks a control, or when they hit F1 in a control.
  104. --*/
  105. LRESULT CRealReplicaSetPropPage::OnCtxHelp(
  106. IN UINT i_uMsg,
  107. IN WPARAM i_wParam,
  108. IN LPARAM i_lParam,
  109. IN OUT BOOL& io_bHandled
  110. )
  111. {
  112. LPHELPINFO lphi = (LPHELPINFO) i_lParam;
  113. if (!lphi || lphi->iContextType != HELPINFO_WINDOW || lphi->iCtrlId < 0)
  114. return FALSE;
  115. ::WinHelp((HWND)(lphi->hItemHandle),
  116. DFS_CTX_HELP_FILE,
  117. HELP_WM_HELP,
  118. (DWORD_PTR)(PVOID)g_aHelpIDs_IDD_FRS_PROP);
  119. return TRUE;
  120. }
  121. /*++
  122. This function handles "What's This" help when a user right clicks the control
  123. --*/
  124. LRESULT CRealReplicaSetPropPage::OnCtxMenuHelp(
  125. IN UINT i_uMsg,
  126. IN WPARAM i_wParam,
  127. IN LPARAM i_lParam,
  128. IN OUT BOOL& io_bHandled
  129. )
  130. {
  131. ::WinHelp((HWND)i_wParam,
  132. DFS_CTX_HELP_FILE,
  133. HELP_CONTEXTMENU,
  134. (DWORD_PTR)(PVOID)g_aHelpIDs_IDD_FRS_PROP);
  135. return TRUE;
  136. }
  137. void CRealReplicaSetPropPage::_Reset()
  138. {
  139. m_piReplicaSet = NULL;
  140. m_bstrTopologyPref.Empty();
  141. m_bstrFileFilter.Empty();
  142. m_bstrDirFilter.Empty();
  143. m_bstrPrimaryMemberDN.Empty();
  144. m_bstrHubMemberDN.Empty();
  145. }
  146. HRESULT CRealReplicaSetPropPage::Initialize(IN IReplicaSet* i_piReplicaSet)
  147. {
  148. RETURN_INVALIDARG_IF_NULL(i_piReplicaSet);
  149. _Reset();
  150. m_piReplicaSet = i_piReplicaSet;
  151. HRESULT hr = S_OK;
  152. do {
  153. hr = m_piReplicaSet->get_TopologyPref(&m_bstrTopologyPref);
  154. BREAK_IF_FAILED(hr);
  155. hr = m_piReplicaSet->get_FileFilter(&m_bstrFileFilter);
  156. BREAK_IF_FAILED(hr);
  157. hr = m_piReplicaSet->get_DirFilter(&m_bstrDirFilter);
  158. BREAK_IF_FAILED(hr);
  159. hr = m_piReplicaSet->get_PrimaryMemberDN(&m_bstrPrimaryMemberDN);
  160. BREAK_IF_FAILED(hr);
  161. hr = m_piReplicaSet->get_HubMemberDN(&m_bstrHubMemberDN);
  162. BREAK_IF_FAILED(hr);
  163. hr = m_piReplicaSet->get_NumOfMembers(&m_lNumOfMembers);
  164. BREAK_IF_FAILED(hr);
  165. hr = m_piReplicaSet->get_NumOfConnections(&m_lNumOfConnections);
  166. BREAK_IF_FAILED(hr);
  167. } while (0);
  168. if (FAILED(hr))
  169. _Reset();
  170. return hr;
  171. }
  172. LRESULT
  173. CRealReplicaSetPropPage::OnApply()
  174. {
  175. if (m_lNotifyHandle && m_lNotifyParam)
  176. MMCPropertyChangeNotify(m_lNotifyHandle, m_lNotifyParam);
  177. return TRUE;
  178. }
  179. LRESULT
  180. CRealReplicaSetPropPage::OnEditFileFilter(
  181. IN WORD i_wNotifyCode,
  182. IN WORD i_wID,
  183. IN HWND i_hWndCtl,
  184. IN OUT BOOL& io_bHandled
  185. )
  186. {
  187. CComBSTR bstrFileFilter = m_bstrFileFilter;
  188. if (S_OK == InvokeMultiValuedStringEditDlg(
  189. &bstrFileFilter,
  190. _T(","),
  191. IDS_MVSTRINGEDIT_TITLE_FILEFILTER,
  192. IDS_MVSTRINGEDIT_TEXT_FILEFILTER,
  193. MAX_PATH))
  194. {
  195. CWaitCursor wait;
  196. if (FALSE == PROPSTRNOCHNG((BSTR)m_bstrFileFilter, bstrFileFilter))
  197. {
  198. HRESULT hr = m_piReplicaSet->put_FileFilter(bstrFileFilter);
  199. if (SUCCEEDED(hr))
  200. {
  201. m_bstrFileFilter = bstrFileFilter;
  202. SetDlgItemText(IDC_FRSPROP_FILEFILTER, m_bstrFileFilter);
  203. } else
  204. {
  205. DisplayMessageBoxForHR(hr);
  206. }
  207. }
  208. }
  209. return TRUE;
  210. }
  211. LRESULT
  212. CRealReplicaSetPropPage::OnEditDirFilter(
  213. IN WORD i_wNotifyCode,
  214. IN WORD i_wID,
  215. IN HWND i_hWndCtl,
  216. IN OUT BOOL& io_bHandled
  217. )
  218. {
  219. CComBSTR bstrDirFilter = m_bstrDirFilter;
  220. if (S_OK == InvokeMultiValuedStringEditDlg(
  221. &bstrDirFilter,
  222. _T(","),
  223. IDS_MVSTRINGEDIT_TITLE_DIRFILTER,
  224. IDS_MVSTRINGEDIT_TEXT_DIRFILTER,
  225. MAX_PATH))
  226. {
  227. CWaitCursor wait;
  228. if (FALSE == PROPSTRNOCHNG((BSTR)m_bstrDirFilter, bstrDirFilter))
  229. {
  230. HRESULT hr = m_piReplicaSet->put_DirFilter(bstrDirFilter);
  231. if (SUCCEEDED(hr))
  232. {
  233. m_bstrDirFilter = bstrDirFilter;
  234. SetDlgItemText(IDC_FRSPROP_DIRFILTER, m_bstrDirFilter);
  235. } else
  236. {
  237. DisplayMessageBoxForHR(hr);
  238. }
  239. }
  240. }
  241. return TRUE;
  242. }
  243. LRESULT
  244. CRealReplicaSetPropPage::OnResetSchedule(
  245. IN WORD i_wNotifyCode,
  246. IN WORD i_wID,
  247. IN HWND i_hWndCtl,
  248. IN OUT BOOL& io_bHandled
  249. )
  250. {
  251. HRESULT hr = S_OK;
  252. do {
  253. CWaitCursor wait;
  254. //
  255. // get connection list
  256. //
  257. if (!m_lNumOfConnections)
  258. break; // no connection at all
  259. //
  260. // get FQDN of the first connection
  261. //
  262. CComBSTR bstrConnectionDN;
  263. VARIANT var;
  264. VariantInit(&var);
  265. hr = m_piReplicaSet->GetConnectionList(&var);
  266. BREAK_IF_FAILED(hr);
  267. if (V_VT(&var) == (VT_ARRAY | VT_VARIANT))
  268. {
  269. SAFEARRAY *psa = V_ARRAY(&var);
  270. long lLowerBound = 0;
  271. long lUpperBound = 0;
  272. SafeArrayGetLBound(psa, 1, &lLowerBound);
  273. SafeArrayGetUBound(psa, 1, &lUpperBound);
  274. if (m_lNumOfConnections != (lUpperBound - lLowerBound + 1))
  275. {
  276. hr = E_INVALIDARG;
  277. } else
  278. {
  279. VARIANT HUGEP *pArray;
  280. SafeArrayAccessData(psa, (void HUGEP **) &pArray);
  281. if (V_VT(&(pArray[0])) != VT_BSTR)
  282. {
  283. hr = E_INVALIDARG;
  284. } else
  285. {
  286. bstrConnectionDN = pArray[0].bstrVal;
  287. if (!bstrConnectionDN)
  288. hr = E_OUTOFMEMORY;
  289. }
  290. SafeArrayUnaccessData(psa);
  291. }
  292. } else
  293. {
  294. hr = E_INVALIDARG;
  295. }
  296. VariantClear(&var);
  297. BREAK_IF_FAILED(hr);
  298. //
  299. // get schedule info on the first connection
  300. //
  301. SCHEDULE *pSchedule = NULL;
  302. VARIANT varSchedule;
  303. VariantInit(&varSchedule);
  304. hr = m_piReplicaSet->GetConnectionSchedule(bstrConnectionDN, &varSchedule);
  305. if (SUCCEEDED(hr))
  306. {
  307. hr = VariantToSchedule(&varSchedule, &pSchedule);
  308. VariantClear(&varSchedule);
  309. }
  310. BREAK_IF_FAILED(hr);
  311. //
  312. // invoke the schedule dialog
  313. //
  314. hr = InvokeScheduleDlg(m_hWnd, pSchedule);
  315. if (S_OK == hr)
  316. {
  317. CWaitCursor wait;
  318. //
  319. // update schedule on all connections
  320. //
  321. VARIANT varNewSchedule;
  322. VariantInit(&varNewSchedule);
  323. hr = ScheduleToVariant(pSchedule, &varNewSchedule);
  324. BREAK_IF_FAILED(hr);
  325. if (SUCCEEDED(hr))
  326. {
  327. hr = m_piReplicaSet->SetScheduleOnAllConnections(&varNewSchedule);
  328. VariantClear(&varNewSchedule);
  329. }
  330. }
  331. free(pSchedule);
  332. } while (0);
  333. if (FAILED(hr))
  334. DisplayMessageBoxForHR(hr);
  335. return TRUE;
  336. }
  337. LRESULT
  338. CRealReplicaSetPropPage::OnCustomize(
  339. IN WORD i_wNotifyCode,
  340. IN WORD i_wID,
  341. IN HWND i_hWndCtl,
  342. IN OUT BOOL& io_bHandled
  343. )
  344. {
  345. CWaitCursor wait;
  346. HRESULT hr = S_OK;
  347. CCustomTopology CusTopDlg;
  348. CusTopDlg.put_ReplicaSet(m_piReplicaSet);
  349. hr = CusTopDlg.DoModal();
  350. if (S_OK != hr)
  351. return hr;
  352. hr = m_piReplicaSet->get_NumOfConnections(&m_lNumOfConnections);
  353. RETURN_IF_FAILED(hr);
  354. ::EnableWindow(GetDlgItem(IDC_FRSPROP_RESETSCHEDULE), (m_lNumOfConnections > 0));
  355. m_bstrTopologyPref.Empty();
  356. hr = m_piReplicaSet->get_TopologyPref(&m_bstrTopologyPref);
  357. RETURN_IF_FAILED(hr);
  358. for (int i = 0; i < 4; i++)
  359. {
  360. if (!lstrcmpi(m_bstrTopologyPref, g_TopologyPref[i].pszTopologyPref))
  361. {
  362. CComBSTR bstrText;
  363. LoadStringFromResource(g_TopologyPref[i].nStringID, &bstrText);
  364. SetDlgItemText(IDC_FRSPROP_TOPOLOGYPREF, bstrText);
  365. }
  366. }
  367. if (0 != lstrcmpi(m_bstrTopologyPref, FRS_RSTOPOLOGYPREF_HUBSPOKE))
  368. {
  369. MyShowWindow(GetDlgItem(IDC_FRSPROP_HUBSERVER_LABEL), FALSE);
  370. MyShowWindow(GetDlgItem(IDC_FRSPROP_HUBSERVER), FALSE);
  371. } else
  372. {
  373. MyShowWindow(GetDlgItem(IDC_FRSPROP_HUBSERVER_LABEL), TRUE);
  374. MyShowWindow(GetDlgItem(IDC_FRSPROP_HUBSERVER), TRUE);
  375. }
  376. m_bstrHubMemberDN.Empty();
  377. hr = m_piReplicaSet->get_HubMemberDN(&m_bstrHubMemberDN);
  378. RETURN_IF_FAILED(hr);
  379. CComBSTR bstrHubServer;
  380. hr = _GetMemberDNInfo(m_bstrHubMemberDN, &bstrHubServer);
  381. SetDlgItemText(IDC_FRSPROP_HUBSERVER, (S_OK == hr) ? bstrHubServer : _T(""));
  382. return TRUE;
  383. }
  384. LRESULT
  385. CRealReplicaSetPropPage::OnParentClosing(
  386. IN UINT i_uMsg,
  387. IN WPARAM i_wParam,
  388. LPARAM i_lParam,
  389. IN OUT BOOL& io_bHandled
  390. )
  391. {
  392. ::SendMessage(GetParent(), PSM_PRESSBUTTON, PSBTN_CANCEL, 0);
  393. return TRUE;
  394. }
  395. HRESULT
  396. CRealReplicaSetPropPage::SetNotifyData(
  397. IN LONG_PTR i_lNotifyHandle,
  398. IN LPARAM i_lParam
  399. )
  400. {
  401. m_lNotifyHandle = i_lNotifyHandle;
  402. m_lNotifyParam = i_lParam;
  403. return S_OK;
  404. }