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.

1136 lines
28 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 -99 **/
  4. /**********************************************************************/
  5. /*
  6. repprtpp.cpp
  7. Comment goes here
  8. FILE HISTORY:
  9. */
  10. #include "stdafx.h"
  11. #include "winssnap.h"
  12. #include "RepPrtpp.h"
  13. #include "nodes.h"
  14. #include "server.h"
  15. #include "tregkey.h"
  16. #include "reppart.h"
  17. #ifdef _DEBUG
  18. #define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CRepPartnerPropGen property page
  24. IMPLEMENT_DYNCREATE(CRepPartnerPropGen, CPropertyPageBase)
  25. CRepPartnerPropGen::CRepPartnerPropGen() : CPropertyPageBase(CRepPartnerPropGen::IDD)
  26. {
  27. //{{AFX_DATA_INIT(CRepPartnerPropGen)
  28. //}}AFX_DATA_INIT
  29. m_pServer = NULL;
  30. }
  31. CRepPartnerPropGen::~CRepPartnerPropGen()
  32. {
  33. }
  34. void CRepPartnerPropGen::DoDataExchange(CDataExchange* pDX)
  35. {
  36. CPropertyPageBase::DoDataExchange(pDX);
  37. //{{AFX_DATA_MAP(CRepPartnerPropGen)
  38. DDX_Control(pDX, IDC_EDIT_NAME, m_editName);
  39. DDX_Control(pDX, IDC_EDIT_IPADDRESS, m_editIpAdd);
  40. //}}AFX_DATA_MAP
  41. DDX_Control(pDX, IDC_IPADD, m_customIPAdd);
  42. }
  43. BEGIN_MESSAGE_MAP(CRepPartnerPropGen, CPropertyPageBase)
  44. //{{AFX_MSG_MAP(CRepPartnerPropGen)
  45. //}}AFX_MSG_MAP
  46. END_MESSAGE_MAP()
  47. /////////////////////////////////////////////////////////////////////////////
  48. // CRepPartnerPropGen message handlers
  49. BOOL
  50. CRepPartnerPropGen::OnInitDialog()
  51. {
  52. // get our server info from the holder
  53. m_pServer = ((CReplicationPartnerProperties *) GetHolder())->GetServer();
  54. // Initialize the IP address controls
  55. m_ipControl.Create(m_hWnd, IDC_IPADD);
  56. m_ipControl.SetFieldRange(0, 0, 255);
  57. CPropertyPageBase::OnInitDialog();
  58. CString strName, strIP;
  59. GetServerNameIP(strName, strIP);
  60. m_editName.SetWindowText(strName);
  61. m_editIpAdd.SetWindowText(strIP);
  62. m_ipControl.SetAddress(strIP);
  63. m_customIPAdd.SetWindowText(strIP);
  64. m_editName.SetReadOnly(TRUE);
  65. m_editIpAdd.SetReadOnly(TRUE);
  66. m_customIPAdd.SetReadOnly();
  67. // load the correct icon
  68. for (int i = 0; i < ICON_IDX_MAX; i++)
  69. {
  70. if (g_uIconMap[i][1] == m_uImage)
  71. {
  72. HICON hIcon = LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE(g_uIconMap[i][0]));
  73. if (hIcon)
  74. ((CStatic *) GetDlgItem(IDC_STATIC_ICON))->SetIcon(hIcon);
  75. break;
  76. }
  77. }
  78. SetDirty(FALSE);
  79. return TRUE;
  80. }
  81. void
  82. CRepPartnerPropGen::GetServerNameIP(CString &strName, CString& strIP)
  83. {
  84. HRESULT hr = hrOK;
  85. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  86. strIP = m_pServer->GetstrIPAddress();
  87. strName = m_pServer->GetNetBIOSName();
  88. }
  89. /////////////////////////////////////////////////////////////////////////////
  90. // CRepPartnerPropAdv property page
  91. IMPLEMENT_DYNCREATE(CRepPartnerPropAdv, CPropertyPageBase)
  92. CRepPartnerPropAdv::CRepPartnerPropAdv() : CPropertyPageBase(CRepPartnerPropAdv::IDD)
  93. {
  94. //{{AFX_DATA_INIT(CRepPartnerPropAdv)
  95. m_strType = _T("");
  96. m_nUpdateCount = 0;
  97. m_nRepDay = 0;
  98. m_nRepHour = 0;
  99. m_nRepMinute = 0;
  100. m_nStartHour = 0;
  101. m_nStartMinute = 0;
  102. m_nStartSecond = 0;
  103. //}}AFX_DATA_INIT
  104. m_pServer = NULL;
  105. }
  106. CRepPartnerPropAdv::~CRepPartnerPropAdv()
  107. {
  108. }
  109. void CRepPartnerPropAdv::DoDataExchange(CDataExchange* pDX)
  110. {
  111. CPropertyPageBase::DoDataExchange(pDX);
  112. //{{AFX_DATA_MAP(CRepPartnerPropAdv)
  113. DDX_Control(pDX, IDC_CHECK_PUSH_PERSISTENCE, m_buttonPushPersistence);
  114. DDX_Control(pDX, IDC_CHECK_PULL_PERSIST, m_buttonPullPersistence);
  115. DDX_Control(pDX, IDC_STATIC_PUSH_GROUP, m_GroupPush);
  116. DDX_Control(pDX, IDC_STATIC_PULL_GROUP, m_GroupPull);
  117. DDX_Control(pDX, IDC_STATIC_UPDATE, m_staticUpdate);
  118. DDX_Control(pDX, IDC_STATIC_START_TIME, m_staticStartTime);
  119. DDX_Control(pDX, IDC_STATIC_REP_TIME, m_staticRepTime);
  120. DDX_Control(pDX, IDC_SPIN_UPDATE_COUNT, m_spinUpdateCount);
  121. DDX_Control(pDX, IDC_SPIN_START_SECOND, m_spinStartSecond);
  122. DDX_Control(pDX, IDC_SPIN_START_MINUTE, m_spinStartMinute);
  123. DDX_Control(pDX, IDC_SPIN_START_HOUR, m_spinStartHour);
  124. DDX_Control(pDX, IDC_SPIN_REP_MINUTE, m_spinRepMinute);
  125. DDX_Control(pDX, IDC_SPIN_REP_HOUR, m_spinRepHour);
  126. DDX_Control(pDX, IDC_SPIN_REP_DAY, m_spinRepDay);
  127. DDX_Control(pDX, IDC_EDIT_UPDATE_COUNT, m_editUpdateCount);
  128. DDX_Control(pDX, IDC_EDIT_START_SECOND, m_editStartSecond);
  129. DDX_Control(pDX, IDC_EDIT_START_MINUTE, m_editStartMinute);
  130. DDX_Control(pDX, IDC_EDIT_START_HOUR, m_editStartHour);
  131. DDX_Control(pDX, IDC_EDIT_REP_MINUTE, m_editRepMinute);
  132. DDX_Control(pDX, IDC_EDIT_REP_HOUR, m_editRepHour);
  133. DDX_Control(pDX, IDC_EDIT_REP_DAY, m_editRepDay);
  134. DDX_Control(pDX, IDC_COMBO_TYPE, m_comboType);
  135. DDX_Control(pDX, IDC_BUTTON_PUSH_SET_DEFAULT, m_buttonPush);
  136. DDX_Control(pDX, IDC_BUTTON_PULL_SET_DEFAULT, m_buttonPull);
  137. DDX_CBStringExact(pDX, IDC_COMBO_TYPE, m_strType);
  138. DDX_Text(pDX, IDC_EDIT_UPDATE_COUNT, m_nUpdateCount);
  139. DDX_Text(pDX, IDC_EDIT_REP_DAY, m_nRepDay);
  140. DDV_MinMaxInt(pDX, m_nRepDay, 0, 365);
  141. DDX_Text(pDX, IDC_EDIT_REP_HOUR, m_nRepHour);
  142. DDV_MinMaxInt(pDX, m_nRepHour, 0, 23);
  143. DDX_Text(pDX, IDC_EDIT_REP_MINUTE, m_nRepMinute);
  144. DDV_MinMaxInt(pDX, m_nRepMinute, 0, 59);
  145. DDX_Text(pDX, IDC_EDIT_START_HOUR, m_nStartHour);
  146. DDV_MinMaxInt(pDX, m_nStartHour, 0, 23);
  147. DDX_Text(pDX, IDC_EDIT_START_MINUTE, m_nStartMinute);
  148. DDV_MinMaxInt(pDX, m_nStartMinute, 0, 59);
  149. DDX_Text(pDX, IDC_EDIT_START_SECOND, m_nStartSecond);
  150. DDV_MinMaxInt(pDX, m_nStartSecond, 0, 59);
  151. //}}AFX_DATA_MAP
  152. }
  153. BEGIN_MESSAGE_MAP(CRepPartnerPropAdv, CPropertyPageBase)
  154. //{{AFX_MSG_MAP(CRepPartnerPropAdv)
  155. ON_BN_CLICKED(IDC_BUTTON_PULL_SET_DEFAULT, OnButtonPullSetDefault)
  156. ON_BN_CLICKED(IDC_BUTTON_PUSH_SET_DEFAULT, OnButtonPushSetDefault)
  157. ON_CBN_SELCHANGE(IDC_COMBO_TYPE, OnSelchangeComboType)
  158. ON_EN_CHANGE(IDC_EDIT_REP_DAY, OnChangeEditRepHour)
  159. ON_EN_CHANGE(IDC_EDIT_REP_HOUR, OnChangeEditRepHour)
  160. ON_EN_CHANGE(IDC_EDIT_REP_MINUTE, OnChangeEditRepHour)
  161. ON_EN_CHANGE(IDC_EDIT_START_HOUR, OnChangeEditRepHour)
  162. ON_EN_CHANGE(IDC_EDIT_START_MINUTE, OnChangeEditRepHour)
  163. ON_EN_CHANGE(IDC_EDIT_START_SECOND, OnChangeEditRepHour)
  164. ON_EN_CHANGE(IDC_EDIT_UPDATE_COUNT, OnChangeEditRepHour)
  165. ON_BN_CLICKED(IDC_CHECK_PULL_PERSIST, OnChangeEditRepHour)
  166. ON_BN_CLICKED(IDC_CHECK_PUSH_PERSISTENCE, OnChangeEditRepHour)
  167. //}}AFX_MSG_MAP
  168. END_MESSAGE_MAP()
  169. /////////////////////////////////////////////////////////////////////////////
  170. // CRepPartnerPropAdv message handlers
  171. BOOL
  172. CRepPartnerPropAdv::OnInitDialog()
  173. {
  174. int ids;
  175. BOOL bPush, bPull;
  176. CPropertyPageBase::OnInitDialog();
  177. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  178. // get our server info from the holder
  179. m_pServer = ((CReplicationPartnerProperties *) GetHolder())->GetServer();
  180. // init push spin controls
  181. m_spinUpdateCount.SetRange(0, UD_MAXVAL);
  182. // init pull spin controls
  183. m_spinRepMinute.SetRange(0, 59);
  184. m_spinRepHour.SetRange(0, 23);
  185. m_spinRepDay.SetRange(0, UD_MAXVAL);
  186. m_spinStartSecond.SetRange(0, 59);
  187. m_spinStartMinute.SetRange(0, 59);
  188. m_spinStartHour.SetRange(0, 23);
  189. // fill the combobox
  190. CString st;
  191. int nIndex = 0;
  192. st.LoadString(IDS_PUSHPULL);
  193. nIndex = m_comboType.AddString(st);
  194. m_comboType.SetItemData(nIndex, 0);
  195. st.LoadString(IDS_PUSH);
  196. nIndex = m_comboType.AddString(st);
  197. m_comboType.SetItemData(nIndex, 1);
  198. st.LoadString(IDS_PULL);
  199. nIndex = m_comboType.AddString(st);
  200. m_comboType.SetItemData(nIndex, 2);
  201. bPush = m_pServer->IsPush();
  202. bPull = m_pServer->IsPull();
  203. if (bPush && bPull)
  204. ids = IDS_PUSHPULL;
  205. else if (bPush)
  206. ids = IDS_PUSH;
  207. else if (bPull)
  208. ids = IDS_PULL;
  209. else
  210. ids = IDS_NONE;
  211. st.LoadString(ids);
  212. SetState(st, bPush, bPull);
  213. FillPushParameters();
  214. FillPullParameters();
  215. SetDirty(FALSE);
  216. return TRUE;
  217. }
  218. void
  219. CRepPartnerPropAdv::FillPushParameters()
  220. {
  221. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  222. EnablePushControls(m_pServer->IsPush());
  223. DWORD nUpdate = (LONG) m_pServer->GetPushUpdateCount();
  224. m_spinUpdateCount.SetPos(nUpdate);
  225. // set the persistence parameter
  226. CConfiguration Config;
  227. GetConfig(Config);
  228. if (Config.m_dwMajorVersion < 5)
  229. {
  230. // no persistent connections for anything less that NT5
  231. m_buttonPushPersistence.SetCheck(FALSE);
  232. }
  233. else
  234. {
  235. BOOL bCheck = m_pServer->GetPushPersistence() ? TRUE : FALSE;
  236. m_buttonPushPersistence.SetCheck(bCheck);
  237. }
  238. }
  239. void
  240. CRepPartnerPropAdv::FillPullParameters()
  241. {
  242. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  243. EnablePullControls(m_pServer->IsPull());
  244. DWORD nPullRep = (LONG) m_pServer->GetPullReplicationInterval();
  245. DWORD dwPullTime, dwPullSpTime, dwUpdateCount;
  246. //if (nPullRep !=0 )
  247. {
  248. int nDays =0, nHours = 0, nMinutes = 0;
  249. nDays = nPullRep/ SEC_PER_DAY;
  250. nPullRep -= nDays * SEC_PER_DAY;
  251. if (nPullRep)
  252. {
  253. nHours = nPullRep / SEC_PER_HOUR;
  254. nPullRep -= nHours * SEC_PER_HOUR;
  255. if (nPullRep)
  256. {
  257. nMinutes = nPullRep / SEC_PER_MINUTE;
  258. nPullRep -= nMinutes * SEC_PER_MINUTE;
  259. }
  260. }
  261. m_spinRepDay.SetPos(nDays);
  262. m_spinRepHour.SetPos(nHours);
  263. m_spinRepMinute.SetPos(nMinutes);
  264. }
  265. int nHours = 0, nMinutes = 0, nSeconds = 0;
  266. if (m_pServer->GetPullStartTime())
  267. {
  268. nHours = m_pServer->GetPullStartTime().GetHour();
  269. nMinutes = m_pServer->GetPullStartTime().GetMinute();
  270. nSeconds = m_pServer->GetPullStartTime().GetSecond();
  271. }
  272. m_spinStartHour.SetPos(nHours);
  273. m_spinStartMinute.SetPos(nMinutes);
  274. m_spinStartSecond.SetPos(nSeconds);
  275. // set the persistence parameter
  276. CConfiguration Config;
  277. GetConfig(Config);
  278. if (Config.m_dwMajorVersion < 5)
  279. {
  280. // no persistent connections for anything less that NT5
  281. m_buttonPullPersistence.SetCheck(FALSE);
  282. }
  283. else
  284. {
  285. BOOL bCheck = m_pServer->GetPullPersistence() ? TRUE : FALSE;
  286. m_buttonPullPersistence.SetCheck(bCheck);
  287. }
  288. }
  289. CString
  290. CRepPartnerPropAdv::ToString(int nNumber)
  291. {
  292. TCHAR szStr[20];
  293. _itot(nNumber, szStr, 10);
  294. CString str(szStr);
  295. return str;
  296. }
  297. DWORD
  298. CRepPartnerPropAdv::GetConfig(CConfiguration & config)
  299. {
  300. // leaf node
  301. SPITFSNode spNode ;
  302. spNode = GetHolder()->GetNode();
  303. // scope pane rep node
  304. SPITFSNode spRepNode;
  305. spNode->GetParent(&spRepNode);
  306. // server node
  307. SPITFSNode spServerNode;
  308. spRepNode->GetParent(&spServerNode);
  309. CWinsServerHandler *pServer;
  310. pServer = GETHANDLER(CWinsServerHandler, spServerNode);
  311. config = pServer->GetConfig();
  312. return NOERROR;
  313. }
  314. // read from the preferences
  315. void
  316. CRepPartnerPropAdv::ReadFromServerPref
  317. (
  318. DWORD & dwPullTime,
  319. DWORD & dwPullSpTime,
  320. DWORD & dwUpdateCount,
  321. DWORD & dwPushPersistence,
  322. DWORD & dwPullPersistence
  323. )
  324. {
  325. CConfiguration Config;
  326. GetConfig(Config);
  327. dwPullTime = Config.m_dwPullTimeInterval;
  328. dwPullSpTime = Config.m_dwPullSpTime;
  329. dwUpdateCount = Config.m_dwPushUpdateCount;
  330. dwPushPersistence = Config.m_dwPushPersistence;
  331. dwPullPersistence = Config.m_dwPullPersistence;
  332. }
  333. void
  334. CRepPartnerPropAdv::OnButtonPullSetDefault()
  335. {
  336. // read from the preferences of the server and display the values
  337. DWORD dwPullTime, dwPullSpTime, dwUpdate, dwPushPersistence, dwPullPersistence;
  338. ReadFromServerPref(dwPullTime, dwPullSpTime, dwUpdate, dwPushPersistence, dwPullPersistence);
  339. // fill the controls
  340. CTime PullSpTime(dwPullSpTime);
  341. int nHours = 0, nMinutes = 0, nSeconds = 0;
  342. if (dwPullSpTime)
  343. {
  344. nHours = PullSpTime.GetHour();
  345. nMinutes = PullSpTime.GetMinute();
  346. nSeconds = PullSpTime.GetSecond();
  347. }
  348. m_spinStartHour.SetPos(nHours);
  349. m_spinStartMinute.SetPos(nMinutes);
  350. m_spinStartSecond.SetPos(nSeconds);
  351. int nDays = 0;
  352. nDays = dwPullTime / SEC_PER_DAY;
  353. dwPullTime -= nDays * SEC_PER_DAY;
  354. nHours = dwPullTime / SEC_PER_HOUR;
  355. dwPullTime -= nHours * SEC_PER_HOUR;
  356. nMinutes = dwPullTime / SEC_PER_MINUTE;
  357. dwPullTime -= nMinutes * SEC_PER_MINUTE;
  358. m_spinRepDay.SetPos(nDays);
  359. m_spinRepHour.SetPos(nHours);
  360. m_spinRepMinute.SetPos(nMinutes);
  361. // clear off the persistence check box
  362. m_buttonPullPersistence.SetCheck(dwPullPersistence);
  363. // mark the page dirty so changes get saved
  364. SetDirty(TRUE);
  365. }
  366. void
  367. CRepPartnerPropAdv::OnButtonPushSetDefault()
  368. {
  369. // read from the preferences of the server and display the values
  370. DWORD dwPullTime, dwPullSpTime, dwUpdate, dwPushPersistence, dwPullPersistence;
  371. ReadFromServerPref(dwPullTime, dwPullSpTime, dwUpdate, dwPushPersistence, dwPullPersistence);
  372. m_spinUpdateCount.SetPos(dwUpdate);
  373. m_buttonPushPersistence.SetCheck(dwPushPersistence);
  374. // mark the page dirty so changes get saved
  375. SetDirty(TRUE);
  376. }
  377. void
  378. CRepPartnerPropAdv::OnOK()
  379. {
  380. UpdateRep();
  381. UpdateReg();
  382. CPropertyPageBase::OnOK();
  383. }
  384. void
  385. CRepPartnerPropAdv::UpdateRep()
  386. {
  387. // get the replication partner server item
  388. BOOL bPullPersist;
  389. BOOL bPushPersist;
  390. CThemeContextActivator themeActivator;
  391. UpdateData();
  392. // get the persistence data for the server object
  393. bPullPersist = (m_buttonPullPersistence.GetCheck() == 0) ? FALSE : TRUE;
  394. bPushPersist = (m_buttonPushPersistence.GetCheck() == 0) ? FALSE : TRUE;
  395. if ( ( (m_nUpdateCount > 0) &
  396. (m_nUpdateCount < WINSCNF_MIN_VALID_UPDATE_CNT) ) &
  397. (!bPushPersist) )
  398. {
  399. CString strMessage, strValue;
  400. strValue.Format(_T("%d"), WINSCNF_MIN_VALID_UPDATE_CNT);
  401. AfxFormatString1(strMessage, IDS_ERR_UPDATE_COUNT, strValue);
  402. AfxMessageBox(strMessage);
  403. m_editUpdateCount.SetFocus();
  404. return;
  405. }
  406. int nPullRep = m_pServer->GetPullReplicationInterval();
  407. int nIndex = m_comboType.GetCurSel();
  408. switch (m_comboType.GetItemData(nIndex))
  409. {
  410. // pull/push partner
  411. case 0:
  412. m_pServer->SetPull(TRUE);
  413. m_pServer->SetPush(TRUE);
  414. break;
  415. // push partner
  416. case 1:
  417. m_pServer->SetPull(FALSE);
  418. m_pServer->SetPush(TRUE);
  419. break;
  420. // pull partner
  421. case 2:
  422. default:
  423. m_pServer->SetPull(TRUE);
  424. m_pServer->SetPush(FALSE);
  425. break;
  426. }
  427. // get the replication interval
  428. DWORD dwRepInt;
  429. CalculateRepInt(dwRepInt);
  430. m_pServer->GetPullReplicationInterval() = dwRepInt;
  431. // get the start time
  432. CTime timeStart;
  433. CalculateStartInt(timeStart);
  434. m_pServer->GetPullStartTime() = timeStart;
  435. m_pServer->GetPushUpdateCount() = m_nUpdateCount;
  436. //SetPersistence(bPersist);
  437. m_pServer->SetPullPersistence(bPullPersist);
  438. m_pServer->SetPushPersistence(bPushPersist);
  439. }
  440. int
  441. CRepPartnerPropAdv::ToInt(CString strNumber)
  442. {
  443. int nNumber = _ttoi(strNumber);
  444. return nNumber;
  445. }
  446. DWORD
  447. CRepPartnerPropAdv::UpdateReg()
  448. {
  449. UpdateData();
  450. DWORD err;
  451. SPITFSNode spNode;
  452. CReplicationPartner * pRepParItem;
  453. // get the replication partner node & handler
  454. spNode = GetHolder()->GetNode();
  455. pRepParItem = GETHANDLER(CReplicationPartner, spNode);
  456. // if none, delete the key from registry, no need to worry about the
  457. // persistence it gets deleted anyway
  458. if (!m_pServer->IsPush() && !m_pServer->IsPull())
  459. {
  460. err = RemovePushPartner();
  461. if (err)
  462. goto Error;
  463. err = RemovePullPartner();
  464. }
  465. // if only push
  466. else if (m_pServer->IsPush() && !m_pServer->IsPull())
  467. {
  468. // update the push stuff
  469. err = UpdatePushParameters();
  470. if (err)
  471. goto Error;
  472. // remove if configured as a pull partner
  473. err = RemovePullPartner();
  474. }
  475. //if only pull
  476. else if (!m_pServer->IsPush() && m_pServer->IsPull())
  477. {
  478. // update the pull stuff
  479. err = UpdatePullParameters();
  480. if (err)
  481. goto Error;
  482. // remove if configured as a push partner
  483. err = RemovePushPartner();
  484. }
  485. // if both push and pull
  486. else if (m_pServer->IsPush() && m_pServer->IsPull())
  487. {
  488. // update the push stuff
  489. err = UpdatePushParameters();
  490. if (err)
  491. goto Error;
  492. err = UpdatePullParameters();
  493. }
  494. Error:
  495. if (err == ERROR_SUCCESS)
  496. {
  497. // update our local cahced node with the changes from the property page
  498. pRepParItem->m_Server = *m_pServer;
  499. }
  500. return err;
  501. }
  502. DWORD
  503. CRepPartnerPropAdv::UpdatePullParameters()
  504. {
  505. SPITFSNode spNode, spRepNode;
  506. CReplicationPartnersHandler * pRep;
  507. // first get the replication partner node & handler
  508. spNode = GetHolder()->GetNode();
  509. // Now get the replication partners node & handle
  510. spNode->GetParent(&spRepNode);
  511. pRep = GETHANDLER(CReplicationPartnersHandler, spRepNode);
  512. // build the server name
  513. CString strServerName;
  514. pRep->GetServerName(spRepNode, strServerName);
  515. strServerName = _T("\\\\") + strServerName;
  516. DWORD dwResult, dwRepInt, dwValue;
  517. DWORD err = ERROR_SUCCESS;
  518. // make sure it is setup as a pull partner
  519. RegKey rk;
  520. CString strKey = pRep->lpstrPullRoot + _T("\\") + (CString) m_pServer->GetstrIPAddress();
  521. err = rk.Create(HKEY_LOCAL_MACHINE, strKey, 0, KEY_ALL_ACCESS, NULL, strServerName);
  522. if (err)
  523. goto Error;
  524. err = rk.SetValue(pRep->lpstrNetBIOSName, m_pServer->GetNetBIOSName());
  525. if (err)
  526. {
  527. Trace1("CRepPartnerPropAdv::UpdatePullParameters - error writing netbios name! %d\n", err);
  528. goto Error;
  529. }
  530. err = rk.QueryValue(WINSCNF_SELF_FND_NM, (DWORD&) dwResult);
  531. if (err)
  532. {
  533. Trace0("CRepPartnerPropAdv::UpdatePullParameters - No selfFind value, setting to 0\n");
  534. dwValue = 0;
  535. err = rk.SetValue(WINSCNF_SELF_FND_NM, dwValue);
  536. }
  537. dwRepInt = (LONG) m_pServer->GetPullReplicationInterval();
  538. if ((LONG) m_pServer->GetPullReplicationInterval() > 0)
  539. {
  540. err = rk.SetValue(WINSCNF_RPL_INTERVAL_NM, (DWORD&) dwRepInt);
  541. if (err)
  542. {
  543. Trace1("CRepPartnerPropAdv::UpdatePullParameters - error writing Pull time interval! %d\n", err);
  544. goto Error;
  545. }
  546. }
  547. if (m_pServer->GetPullStartTime().GetTime() > (time_t) 0)
  548. {
  549. err = rk.SetValue(WINSCNF_SP_TIME_NM, m_pServer->GetPullStartTime().IntlFormat(CIntlTime::TFRQ_MILITARY_TIME));
  550. if (err)
  551. {
  552. Trace1("CRepPartnerPropAdv::UpdatePullParameters - error writing Pull SpTime! %d\n", err);
  553. goto Error;
  554. }
  555. }
  556. else
  557. {
  558. err = rk.DeleteValue(WINSCNF_SP_TIME_NM);
  559. }
  560. // set the value to 0 or 1 depending on the PushPersistence
  561. dwValue = m_pServer->GetPullPersistence() ? 1 : 0;
  562. // Set the Persist key
  563. err = rk.SetValue(pRep->lpstrPersistence, (DWORD &)dwValue);
  564. if (err)
  565. {
  566. Trace1("CRepPartnerPropAdv::UpdatePullParameters - Error writing persistence! %d\n", err);
  567. }
  568. Error:
  569. return err;
  570. }
  571. DWORD
  572. CRepPartnerPropAdv::UpdatePushParameters()
  573. {
  574. SPITFSNode spNode, spRepNode;
  575. CReplicationPartnersHandler * pRep;
  576. // first get the replication partner node & handler
  577. spNode = GetHolder()->GetNode();
  578. // Now get the replication partners node & handle
  579. spNode->GetParent(&spRepNode);
  580. pRep = GETHANDLER(CReplicationPartnersHandler, spRepNode);
  581. // build the server name
  582. CString strServerName;
  583. pRep->GetServerName(spRepNode, strServerName);
  584. strServerName = _T("\\\\") + strServerName;
  585. DWORD dwResult, dwValue;
  586. DWORD err = ERROR_SUCCESS;
  587. RegKey rk;
  588. // make sure it is setup as a push partner
  589. CString strKey = pRep->lpstrPushRoot + _T("\\") + (CString) m_pServer->GetstrIPAddress();
  590. err = rk.Create(HKEY_LOCAL_MACHINE, strKey, 0, KEY_ALL_ACCESS, NULL, strServerName);
  591. if (err)
  592. goto Error;
  593. err = rk.SetValue(pRep->lpstrNetBIOSName, m_pServer->GetNetBIOSName());
  594. if (err)
  595. {
  596. Trace1("CRepPartnerPropAdv::UpdatePushParameters - error writing netbios name! %d\n", err);
  597. goto Error;
  598. }
  599. err = rk.QueryValue(WINSCNF_SELF_FND_NM, (DWORD&) dwResult);
  600. if (err)
  601. {
  602. Trace0("CRepPartnerPropAdv::UpdatePushParameters - No selfFind value, setting to 0\n");
  603. dwValue = 0;
  604. err = rk.SetValue(WINSCNF_SELF_FND_NM, dwValue);
  605. }
  606. // set the push update count
  607. if (m_nUpdateCount == 0)
  608. {
  609. err = rk.DeleteValue(WINSCNF_UPDATE_COUNT_NM);
  610. }
  611. else
  612. {
  613. err = rk.SetValue(WINSCNF_UPDATE_COUNT_NM, (DWORD&) m_nUpdateCount);
  614. if (err)
  615. {
  616. Trace1("CRepPartnerPropAdv::UpdatePushParameters - Error writing update count! %d\n", err);
  617. goto Error;
  618. }
  619. }
  620. // set the value to 0 or 1 depending on the PushPersistence
  621. dwValue = m_pServer->GetPushPersistence() ? 1 : 0;
  622. // Set the Persist key is present
  623. err = rk.SetValue(pRep->lpstrPersistence, (DWORD &) dwValue);
  624. if (err)
  625. {
  626. Trace1("CRepPartnerPropAdv::UpdatePushParameters - Error writing persistence! %d\n", err);
  627. }
  628. Error:
  629. return err;
  630. }
  631. DWORD
  632. CRepPartnerPropAdv::RemovePullPartner()
  633. {
  634. SPITFSNode spNode, spRepNode;
  635. CReplicationPartnersHandler * pRep;
  636. DWORD err, errDel = 0;
  637. CString csKeyName;
  638. // first get the replication partner node & handler
  639. spNode = GetHolder()->GetNode();
  640. // Now get the replication partners node & handle
  641. spNode->GetParent(&spRepNode);
  642. pRep = GETHANDLER(CReplicationPartnersHandler, spRepNode);
  643. // build the server name
  644. CString strServerName;
  645. pRep->GetServerName(spRepNode, strServerName);
  646. strServerName = _T("\\\\") + strServerName;
  647. RegKey rkPull;
  648. // get the pull root key
  649. CString strKey = pRep->lpstrPullRoot + _T("\\") + (CString) m_pServer->GetstrIPAddress();
  650. err = rkPull.Create(HKEY_LOCAL_MACHINE, (CString) pRep->lpstrPullRoot, 0, KEY_ALL_ACCESS, NULL, strServerName);
  651. if (err)
  652. return err;
  653. RegKeyIterator iterPullkey;
  654. err = iterPullkey.Init(&rkPull);
  655. err = iterPullkey.Next (&csKeyName, NULL);
  656. while (!err)
  657. {
  658. if (csKeyName == m_pServer->GetstrIPAddress())
  659. {
  660. errDel = RegDeleteKey (HKEY(rkPull), csKeyName);
  661. iterPullkey.Reset();
  662. }
  663. err = iterPullkey.Next (&csKeyName, NULL);
  664. }
  665. if (errDel)
  666. err = errDel;
  667. else
  668. err = ERROR_SUCCESS;
  669. return err;
  670. }
  671. DWORD
  672. CRepPartnerPropAdv::RemovePushPartner()
  673. {
  674. SPITFSNode spNode, spRepNode;
  675. CReplicationPartnersHandler * pRep;
  676. DWORD err, errDel = 0;
  677. CString csKeyName;
  678. // first get the replication partner node & handler
  679. spNode = GetHolder()->GetNode();
  680. // Now get the replication partners node & handle
  681. spNode->GetParent(&spRepNode);
  682. pRep = GETHANDLER(CReplicationPartnersHandler, spRepNode);
  683. // build the server name
  684. CString strServerName;
  685. pRep->GetServerName(spRepNode, strServerName);
  686. strServerName = _T("\\\\") + strServerName;
  687. RegKey rkPush;
  688. CString strKey = pRep->lpstrPushRoot + _T("\\") + (CString) m_pServer->GetstrIPAddress();
  689. err = rkPush.Create(HKEY_LOCAL_MACHINE, (CString) pRep->lpstrPushRoot, 0, KEY_ALL_ACCESS, NULL, strServerName);
  690. if (err)
  691. return err;
  692. RegKeyIterator iterPushkey;
  693. err = iterPushkey.Init(&rkPush);
  694. err = iterPushkey.Next (&csKeyName, NULL);
  695. while (!err)
  696. {
  697. if (csKeyName == m_pServer->GetstrIPAddress())
  698. {
  699. errDel = RegDeleteKey (HKEY(rkPush), csKeyName);
  700. iterPushkey.Reset();
  701. }
  702. err = iterPushkey.Next (&csKeyName, NULL);
  703. }
  704. if (errDel)
  705. err = errDel;
  706. else
  707. err = ERROR_SUCCESS;
  708. return err;
  709. }
  710. void
  711. CRepPartnerPropAdv::CalculateRepInt(DWORD& dwRepInt)
  712. {
  713. UpdateData();
  714. int nDays = m_spinRepDay.GetPos();
  715. int nHour = m_spinRepHour.GetPos();
  716. int nMinute = m_spinRepMinute.GetPos();
  717. DWORD nVerifyInt = nDays * SEC_PER_DAY +
  718. nHour * SEC_PER_HOUR +
  719. nMinute * SEC_PER_MINUTE;
  720. dwRepInt = nVerifyInt;
  721. }
  722. void
  723. CRepPartnerPropAdv::CalculateStartInt(CTime & time)
  724. {
  725. CTime tempTime;
  726. UpdateData();
  727. int nHour = m_spinStartHour.GetPos();
  728. int nMinute = m_spinStartMinute.GetPos();
  729. int nSecond = m_spinStartSecond.GetPos();
  730. if (nHour || nMinute || nSecond)
  731. {
  732. CTime curTime = CTime::GetCurrentTime();
  733. int nYear = curTime.GetYear();
  734. int nMonth = curTime.GetMonth();
  735. int nDay = curTime.GetDay();
  736. CTime tempTime(nYear, nMonth, nDay, nHour, nMinute, nSecond);
  737. time = tempTime;
  738. }
  739. else
  740. {
  741. CTime tempTime(0);
  742. time = tempTime;
  743. }
  744. }
  745. BOOL
  746. CRepPartnerPropAdv::OnApply()
  747. {
  748. // if not dirtied return
  749. if ( !IsDirty())
  750. return TRUE;
  751. UpdateRep();
  752. DWORD err = UpdateReg();
  753. if (!err)
  754. {
  755. UpdateUI();
  756. }
  757. else
  758. {
  759. WinsMessageBox(err);
  760. return FALSE;
  761. }
  762. return CPropertyPageBase::OnApply();
  763. }
  764. void
  765. CRepPartnerPropAdv::UpdateUI()
  766. {
  767. SPITFSNode spNode;
  768. CReplicationPartner *pRepParItem;
  769. spNode = GetHolder()->GetNode();
  770. pRepParItem = GETHANDLER(CReplicationPartner, spNode);
  771. //change the type depending on the type set
  772. pRepParItem->SetType(m_strType);
  773. VERIFY(SUCCEEDED(spNode->ChangeNode(RESULT_PANE_CHANGE_ITEM)));
  774. }
  775. void CRepPartnerPropAdv::OnChangeEditRepHour()
  776. {
  777. SetDirty(TRUE);
  778. }
  779. void CRepPartnerPropAdv::OnSelchangeComboType()
  780. {
  781. SetDirty(TRUE);
  782. UpdateData();
  783. // depending on the type selected enable or disable
  784. // the set of controls
  785. int nIndex = m_comboType.GetCurSel();
  786. switch (m_comboType.GetItemData(nIndex))
  787. {
  788. // pull/push partner
  789. case 0:
  790. EnablePullControls(TRUE);
  791. EnablePushControls(TRUE);
  792. break;
  793. // push partner
  794. case 1:
  795. EnablePullControls(FALSE);
  796. EnablePushControls(TRUE);
  797. break;
  798. // pull partner
  799. case 2:
  800. default:
  801. EnablePullControls(TRUE);
  802. EnablePushControls(FALSE);
  803. break;
  804. }
  805. }
  806. void
  807. CRepPartnerPropAdv::EnablePushControls(BOOL bEnable )
  808. {
  809. m_buttonPush.EnableWindow(bEnable);
  810. m_editUpdateCount.EnableWindow(bEnable);
  811. m_spinUpdateCount.EnableWindow(bEnable);
  812. m_staticUpdate.EnableWindow(bEnable);
  813. CConfiguration Config;
  814. GetConfig(Config);
  815. if (Config.m_dwMajorVersion < 5)
  816. {
  817. // no persistent connections for anything less that NT5
  818. m_buttonPushPersistence.EnableWindow(FALSE);
  819. }
  820. else
  821. {
  822. m_buttonPushPersistence.EnableWindow(bEnable);
  823. }
  824. m_GroupPush.EnableWindow(bEnable);
  825. }
  826. void
  827. CRepPartnerPropAdv::EnablePullControls(BOOL bEnable)
  828. {
  829. m_spinRepDay.EnableWindow(bEnable);
  830. m_spinRepHour.EnableWindow(bEnable);
  831. m_spinRepMinute.EnableWindow(bEnable);
  832. m_spinStartHour.EnableWindow(bEnable);
  833. m_spinStartMinute.EnableWindow(bEnable);
  834. m_spinStartSecond.EnableWindow(bEnable);
  835. m_editRepDay.EnableWindow(bEnable);
  836. m_editRepHour.EnableWindow(bEnable);
  837. m_editRepMinute.EnableWindow(bEnable);
  838. m_editStartHour.EnableWindow(bEnable);
  839. m_editStartMinute.EnableWindow(bEnable);
  840. m_editStartSecond.EnableWindow(bEnable);
  841. m_buttonPull.EnableWindow(bEnable);
  842. m_GroupPull.EnableWindow(bEnable);
  843. m_staticRepTime.EnableWindow(bEnable);
  844. m_staticStartTime.EnableWindow(bEnable);
  845. CConfiguration Config;
  846. GetConfig(Config);
  847. if (Config.m_dwMajorVersion < 5)
  848. {
  849. // no persistent connections for anything less that NT5
  850. m_buttonPullPersistence.EnableWindow(FALSE);
  851. }
  852. else
  853. {
  854. m_buttonPullPersistence.EnableWindow(bEnable);
  855. }
  856. }
  857. void
  858. CRepPartnerPropAdv::SetState(CString & strType, BOOL bPush, BOOL bPull)
  859. {
  860. int nIndex = m_comboType.FindStringExact(-1, strType);
  861. m_comboType.SetCurSel(nIndex);
  862. EnablePullControls(bPull);
  863. EnablePushControls(bPush);
  864. }
  865. /////////////////////////////////////////////////////////////////////////////
  866. //
  867. // CReplicationPartnerProperties holder
  868. //
  869. /////////////////////////////////////////////////////////////////////////////
  870. CReplicationPartnerProperties::CReplicationPartnerProperties
  871. (
  872. ITFSNode * pNode,
  873. IComponentData * pComponentData,
  874. ITFSComponentData * pTFSCompData,
  875. LPCTSTR pszSheetName
  876. ) : CPropertyPageHolderBase(pNode, pComponentData, pszSheetName)
  877. {
  878. m_bAutoDeletePages = FALSE; // we have the pages as embedded members
  879. m_bTheme = TRUE;
  880. AddPageToList((CPropertyPageBase*) &m_pageGeneral);
  881. AddPageToList((CPropertyPageBase*) &m_pageAdvanced);
  882. Assert(pTFSCompData != NULL);
  883. m_spTFSCompData.Set(pTFSCompData);
  884. }
  885. CReplicationPartnerProperties::~CReplicationPartnerProperties()
  886. {
  887. RemovePageFromList((CPropertyPageBase*) &m_pageGeneral, FALSE);
  888. RemovePageFromList((CPropertyPageBase*) &m_pageAdvanced, FALSE);
  889. }