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.

1134 lines
27 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. UpdateData();
  391. // get the persistence data for the server object
  392. bPullPersist = (m_buttonPullPersistence.GetCheck() == 0) ? FALSE : TRUE;
  393. bPushPersist = (m_buttonPushPersistence.GetCheck() == 0) ? FALSE : TRUE;
  394. if ( ( (m_nUpdateCount > 0) &
  395. (m_nUpdateCount < WINSCNF_MIN_VALID_UPDATE_CNT) ) &
  396. (!bPushPersist) )
  397. {
  398. CString strMessage, strValue;
  399. strValue.Format(_T("%d"), WINSCNF_MIN_VALID_UPDATE_CNT);
  400. AfxFormatString1(strMessage, IDS_ERR_UPDATE_COUNT, strValue);
  401. AfxMessageBox(strMessage);
  402. m_editUpdateCount.SetFocus();
  403. return;
  404. }
  405. int nPullRep = m_pServer->GetPullReplicationInterval();
  406. int nIndex = m_comboType.GetCurSel();
  407. switch (m_comboType.GetItemData(nIndex))
  408. {
  409. // pull/push partner
  410. case 0:
  411. m_pServer->SetPull(TRUE);
  412. m_pServer->SetPush(TRUE);
  413. break;
  414. // push partner
  415. case 1:
  416. m_pServer->SetPull(FALSE);
  417. m_pServer->SetPush(TRUE);
  418. break;
  419. // pull partner
  420. case 2:
  421. default:
  422. m_pServer->SetPull(TRUE);
  423. m_pServer->SetPush(FALSE);
  424. break;
  425. }
  426. // get the replication interval
  427. DWORD dwRepInt;
  428. CalculateRepInt(dwRepInt);
  429. m_pServer->GetPullReplicationInterval() = dwRepInt;
  430. // get the start time
  431. CTime timeStart;
  432. CalculateStartInt(timeStart);
  433. m_pServer->GetPullStartTime() = timeStart;
  434. m_pServer->GetPushUpdateCount() = m_nUpdateCount;
  435. //SetPersistence(bPersist);
  436. m_pServer->SetPullPersistence(bPullPersist);
  437. m_pServer->SetPushPersistence(bPushPersist);
  438. }
  439. int
  440. CRepPartnerPropAdv::ToInt(CString strNumber)
  441. {
  442. int nNumber = _ttoi(strNumber);
  443. return nNumber;
  444. }
  445. DWORD
  446. CRepPartnerPropAdv::UpdateReg()
  447. {
  448. UpdateData();
  449. DWORD err;
  450. SPITFSNode spNode;
  451. CReplicationPartner * pRepParItem;
  452. // get the replication partner node & handler
  453. spNode = GetHolder()->GetNode();
  454. pRepParItem = GETHANDLER(CReplicationPartner, spNode);
  455. // if none, delete the key from registry, no need to worry about the
  456. // persistence it gets deleted anyway
  457. if (!m_pServer->IsPush() && !m_pServer->IsPull())
  458. {
  459. err = RemovePushPartner();
  460. if (err)
  461. goto Error;
  462. err = RemovePullPartner();
  463. }
  464. // if only push
  465. else if (m_pServer->IsPush() && !m_pServer->IsPull())
  466. {
  467. // update the push stuff
  468. err = UpdatePushParameters();
  469. if (err)
  470. goto Error;
  471. // remove if configured as a pull partner
  472. err = RemovePullPartner();
  473. }
  474. //if only pull
  475. else if (!m_pServer->IsPush() && m_pServer->IsPull())
  476. {
  477. // update the pull stuff
  478. err = UpdatePullParameters();
  479. if (err)
  480. goto Error;
  481. // remove if configured as a push partner
  482. err = RemovePushPartner();
  483. }
  484. // if both push and pull
  485. else if (m_pServer->IsPush() && m_pServer->IsPull())
  486. {
  487. // update the push stuff
  488. err = UpdatePushParameters();
  489. if (err)
  490. goto Error;
  491. err = UpdatePullParameters();
  492. }
  493. Error:
  494. if (err == ERROR_SUCCESS)
  495. {
  496. // update our local cahced node with the changes from the property page
  497. pRepParItem->m_Server = *m_pServer;
  498. }
  499. return err;
  500. }
  501. DWORD
  502. CRepPartnerPropAdv::UpdatePullParameters()
  503. {
  504. SPITFSNode spNode, spRepNode;
  505. CReplicationPartnersHandler * pRep;
  506. // first get the replication partner node & handler
  507. spNode = GetHolder()->GetNode();
  508. // Now get the replication partners node & handle
  509. spNode->GetParent(&spRepNode);
  510. pRep = GETHANDLER(CReplicationPartnersHandler, spRepNode);
  511. // build the server name
  512. CString strServerName;
  513. pRep->GetServerName(spRepNode, strServerName);
  514. strServerName = _T("\\\\") + strServerName;
  515. DWORD dwResult, dwRepInt, dwValue;
  516. DWORD err = ERROR_SUCCESS;
  517. // make sure it is setup as a pull partner
  518. RegKey rk;
  519. CString strKey = pRep->lpstrPullRoot + _T("\\") + (CString) m_pServer->GetstrIPAddress();
  520. err = rk.Create(HKEY_LOCAL_MACHINE, strKey, 0, KEY_ALL_ACCESS, NULL, strServerName);
  521. if (err)
  522. goto Error;
  523. err = rk.SetValue(pRep->lpstrNetBIOSName, m_pServer->GetNetBIOSName());
  524. if (err)
  525. {
  526. Trace1("CRepPartnerPropAdv::UpdatePullParameters - error writing netbios name! %d\n", err);
  527. goto Error;
  528. }
  529. err = rk.QueryValue(WINSCNF_SELF_FND_NM, (DWORD&) dwResult);
  530. if (err)
  531. {
  532. Trace0("CRepPartnerPropAdv::UpdatePullParameters - No selfFind value, setting to 0\n");
  533. dwValue = 0;
  534. err = rk.SetValue(WINSCNF_SELF_FND_NM, dwValue);
  535. }
  536. dwRepInt = (LONG) m_pServer->GetPullReplicationInterval();
  537. if ((LONG) m_pServer->GetPullReplicationInterval() > 0)
  538. {
  539. err = rk.SetValue(WINSCNF_RPL_INTERVAL_NM, (DWORD&) dwRepInt);
  540. if (err)
  541. {
  542. Trace1("CRepPartnerPropAdv::UpdatePullParameters - error writing Pull time interval! %d\n", err);
  543. goto Error;
  544. }
  545. }
  546. if (m_pServer->GetPullStartTime().GetTime() > (time_t) 0)
  547. {
  548. err = rk.SetValue(WINSCNF_SP_TIME_NM, m_pServer->GetPullStartTime().IntlFormat(CIntlTime::TFRQ_MILITARY_TIME));
  549. if (err)
  550. {
  551. Trace1("CRepPartnerPropAdv::UpdatePullParameters - error writing Pull SpTime! %d\n", err);
  552. goto Error;
  553. }
  554. }
  555. else
  556. {
  557. err = rk.DeleteValue(WINSCNF_SP_TIME_NM);
  558. }
  559. // set the value to 0 or 1 depending on the PushPersistence
  560. dwValue = m_pServer->GetPullPersistence() ? 1 : 0;
  561. // Set the Persist key
  562. err = rk.SetValue(pRep->lpstrPersistence, (DWORD &)dwValue);
  563. if (err)
  564. {
  565. Trace1("CRepPartnerPropAdv::UpdatePullParameters - Error writing persistence! %d\n", err);
  566. }
  567. Error:
  568. return err;
  569. }
  570. DWORD
  571. CRepPartnerPropAdv::UpdatePushParameters()
  572. {
  573. SPITFSNode spNode, spRepNode;
  574. CReplicationPartnersHandler * pRep;
  575. // first get the replication partner node & handler
  576. spNode = GetHolder()->GetNode();
  577. // Now get the replication partners node & handle
  578. spNode->GetParent(&spRepNode);
  579. pRep = GETHANDLER(CReplicationPartnersHandler, spRepNode);
  580. // build the server name
  581. CString strServerName;
  582. pRep->GetServerName(spRepNode, strServerName);
  583. strServerName = _T("\\\\") + strServerName;
  584. DWORD dwResult, dwValue;
  585. DWORD err = ERROR_SUCCESS;
  586. RegKey rk;
  587. // make sure it is setup as a push partner
  588. CString strKey = pRep->lpstrPushRoot + _T("\\") + (CString) m_pServer->GetstrIPAddress();
  589. err = rk.Create(HKEY_LOCAL_MACHINE, strKey, 0, KEY_ALL_ACCESS, NULL, strServerName);
  590. if (err)
  591. goto Error;
  592. err = rk.SetValue(pRep->lpstrNetBIOSName, m_pServer->GetNetBIOSName());
  593. if (err)
  594. {
  595. Trace1("CRepPartnerPropAdv::UpdatePushParameters - error writing netbios name! %d\n", err);
  596. goto Error;
  597. }
  598. err = rk.QueryValue(WINSCNF_SELF_FND_NM, (DWORD&) dwResult);
  599. if (err)
  600. {
  601. Trace0("CRepPartnerPropAdv::UpdatePushParameters - No selfFind value, setting to 0\n");
  602. dwValue = 0;
  603. err = rk.SetValue(WINSCNF_SELF_FND_NM, dwValue);
  604. }
  605. // set the push update count
  606. if (m_nUpdateCount == 0)
  607. {
  608. err = rk.DeleteValue(WINSCNF_UPDATE_COUNT_NM);
  609. }
  610. else
  611. {
  612. err = rk.SetValue(WINSCNF_UPDATE_COUNT_NM, (DWORD&) m_nUpdateCount);
  613. if (err)
  614. {
  615. Trace1("CRepPartnerPropAdv::UpdatePushParameters - Error writing update count! %d\n", err);
  616. goto Error;
  617. }
  618. }
  619. // set the value to 0 or 1 depending on the PushPersistence
  620. dwValue = m_pServer->GetPushPersistence() ? 1 : 0;
  621. // Set the Persist key is present
  622. err = rk.SetValue(pRep->lpstrPersistence, (DWORD &) dwValue);
  623. if (err)
  624. {
  625. Trace1("CRepPartnerPropAdv::UpdatePushParameters - Error writing persistence! %d\n", err);
  626. }
  627. Error:
  628. return err;
  629. }
  630. DWORD
  631. CRepPartnerPropAdv::RemovePullPartner()
  632. {
  633. SPITFSNode spNode, spRepNode;
  634. CReplicationPartnersHandler * pRep;
  635. DWORD err, errDel = 0;
  636. CString csKeyName;
  637. // first get the replication partner node & handler
  638. spNode = GetHolder()->GetNode();
  639. // Now get the replication partners node & handle
  640. spNode->GetParent(&spRepNode);
  641. pRep = GETHANDLER(CReplicationPartnersHandler, spRepNode);
  642. // build the server name
  643. CString strServerName;
  644. pRep->GetServerName(spRepNode, strServerName);
  645. strServerName = _T("\\\\") + strServerName;
  646. RegKey rkPull;
  647. // get the pull root key
  648. CString strKey = pRep->lpstrPullRoot + _T("\\") + (CString) m_pServer->GetstrIPAddress();
  649. err = rkPull.Create(HKEY_LOCAL_MACHINE, (CString) pRep->lpstrPullRoot, 0, KEY_ALL_ACCESS, NULL, strServerName);
  650. if (err)
  651. return err;
  652. RegKeyIterator iterPullkey;
  653. err = iterPullkey.Init(&rkPull);
  654. err = iterPullkey.Next (&csKeyName, NULL);
  655. while (!err)
  656. {
  657. if (csKeyName == m_pServer->GetstrIPAddress())
  658. {
  659. errDel = RegDeleteKey (HKEY(rkPull), csKeyName);
  660. iterPullkey.Reset();
  661. }
  662. err = iterPullkey.Next (&csKeyName, NULL);
  663. }
  664. if (errDel)
  665. err = errDel;
  666. else
  667. err = ERROR_SUCCESS;
  668. return err;
  669. }
  670. DWORD
  671. CRepPartnerPropAdv::RemovePushPartner()
  672. {
  673. SPITFSNode spNode, spRepNode;
  674. CReplicationPartnersHandler * pRep;
  675. DWORD err, errDel = 0;
  676. CString csKeyName;
  677. // first get the replication partner node & handler
  678. spNode = GetHolder()->GetNode();
  679. // Now get the replication partners node & handle
  680. spNode->GetParent(&spRepNode);
  681. pRep = GETHANDLER(CReplicationPartnersHandler, spRepNode);
  682. // build the server name
  683. CString strServerName;
  684. pRep->GetServerName(spRepNode, strServerName);
  685. strServerName = _T("\\\\") + strServerName;
  686. RegKey rkPush;
  687. CString strKey = pRep->lpstrPushRoot + _T("\\") + (CString) m_pServer->GetstrIPAddress();
  688. err = rkPush.Create(HKEY_LOCAL_MACHINE, (CString) pRep->lpstrPushRoot, 0, KEY_ALL_ACCESS, NULL, strServerName);
  689. if (err)
  690. return err;
  691. RegKeyIterator iterPushkey;
  692. err = iterPushkey.Init(&rkPush);
  693. err = iterPushkey.Next (&csKeyName, NULL);
  694. while (!err)
  695. {
  696. if (csKeyName == m_pServer->GetstrIPAddress())
  697. {
  698. errDel = RegDeleteKey (HKEY(rkPush), csKeyName);
  699. iterPushkey.Reset();
  700. }
  701. err = iterPushkey.Next (&csKeyName, NULL);
  702. }
  703. if (errDel)
  704. err = errDel;
  705. else
  706. err = ERROR_SUCCESS;
  707. return err;
  708. }
  709. void
  710. CRepPartnerPropAdv::CalculateRepInt(DWORD& dwRepInt)
  711. {
  712. UpdateData();
  713. int nDays = m_spinRepDay.GetPos();
  714. int nHour = m_spinRepHour.GetPos();
  715. int nMinute = m_spinRepMinute.GetPos();
  716. DWORD nVerifyInt = nDays * SEC_PER_DAY +
  717. nHour * SEC_PER_HOUR +
  718. nMinute * SEC_PER_MINUTE;
  719. dwRepInt = nVerifyInt;
  720. }
  721. void
  722. CRepPartnerPropAdv::CalculateStartInt(CTime & time)
  723. {
  724. CTime tempTime;
  725. UpdateData();
  726. int nHour = m_spinStartHour.GetPos();
  727. int nMinute = m_spinStartMinute.GetPos();
  728. int nSecond = m_spinStartSecond.GetPos();
  729. if (nHour || nMinute || nSecond)
  730. {
  731. CTime curTime = CTime::GetCurrentTime();
  732. int nYear = curTime.GetYear();
  733. int nMonth = curTime.GetMonth();
  734. int nDay = curTime.GetDay();
  735. CTime tempTime(nYear, nMonth, nDay, nHour, nMinute, nSecond);
  736. time = tempTime;
  737. }
  738. else
  739. {
  740. CTime tempTime(0);
  741. time = tempTime;
  742. }
  743. }
  744. BOOL
  745. CRepPartnerPropAdv::OnApply()
  746. {
  747. // if not dirtied return
  748. if ( !IsDirty())
  749. return TRUE;
  750. UpdateRep();
  751. DWORD err = UpdateReg();
  752. if (!err)
  753. {
  754. UpdateUI();
  755. }
  756. else
  757. {
  758. WinsMessageBox(err);
  759. return FALSE;
  760. }
  761. return CPropertyPageBase::OnApply();
  762. }
  763. void
  764. CRepPartnerPropAdv::UpdateUI()
  765. {
  766. SPITFSNode spNode;
  767. CReplicationPartner *pRepParItem;
  768. spNode = GetHolder()->GetNode();
  769. pRepParItem = GETHANDLER(CReplicationPartner, spNode);
  770. //change the type depending on the type set
  771. pRepParItem->SetType(m_strType);
  772. VERIFY(SUCCEEDED(spNode->ChangeNode(RESULT_PANE_CHANGE_ITEM)));
  773. }
  774. void CRepPartnerPropAdv::OnChangeEditRepHour()
  775. {
  776. SetDirty(TRUE);
  777. }
  778. void CRepPartnerPropAdv::OnSelchangeComboType()
  779. {
  780. SetDirty(TRUE);
  781. UpdateData();
  782. // depending on the type selected enable or disable
  783. // the set of controls
  784. int nIndex = m_comboType.GetCurSel();
  785. switch (m_comboType.GetItemData(nIndex))
  786. {
  787. // pull/push partner
  788. case 0:
  789. EnablePullControls(TRUE);
  790. EnablePushControls(TRUE);
  791. break;
  792. // push partner
  793. case 1:
  794. EnablePullControls(FALSE);
  795. EnablePushControls(TRUE);
  796. break;
  797. // pull partner
  798. case 2:
  799. default:
  800. EnablePullControls(TRUE);
  801. EnablePushControls(FALSE);
  802. break;
  803. }
  804. }
  805. void
  806. CRepPartnerPropAdv::EnablePushControls(BOOL bEnable )
  807. {
  808. m_buttonPush.EnableWindow(bEnable);
  809. m_editUpdateCount.EnableWindow(bEnable);
  810. m_spinUpdateCount.EnableWindow(bEnable);
  811. m_staticUpdate.EnableWindow(bEnable);
  812. CConfiguration Config;
  813. GetConfig(Config);
  814. if (Config.m_dwMajorVersion < 5)
  815. {
  816. // no persistent connections for anything less that NT5
  817. m_buttonPushPersistence.EnableWindow(FALSE);
  818. }
  819. else
  820. {
  821. m_buttonPushPersistence.EnableWindow(bEnable);
  822. }
  823. m_GroupPush.EnableWindow(bEnable);
  824. }
  825. void
  826. CRepPartnerPropAdv::EnablePullControls(BOOL bEnable)
  827. {
  828. m_spinRepDay.EnableWindow(bEnable);
  829. m_spinRepHour.EnableWindow(bEnable);
  830. m_spinRepMinute.EnableWindow(bEnable);
  831. m_spinStartHour.EnableWindow(bEnable);
  832. m_spinStartMinute.EnableWindow(bEnable);
  833. m_spinStartSecond.EnableWindow(bEnable);
  834. m_editRepDay.EnableWindow(bEnable);
  835. m_editRepHour.EnableWindow(bEnable);
  836. m_editRepMinute.EnableWindow(bEnable);
  837. m_editStartHour.EnableWindow(bEnable);
  838. m_editStartMinute.EnableWindow(bEnable);
  839. m_editStartSecond.EnableWindow(bEnable);
  840. m_buttonPull.EnableWindow(bEnable);
  841. m_GroupPull.EnableWindow(bEnable);
  842. m_staticRepTime.EnableWindow(bEnable);
  843. m_staticStartTime.EnableWindow(bEnable);
  844. CConfiguration Config;
  845. GetConfig(Config);
  846. if (Config.m_dwMajorVersion < 5)
  847. {
  848. // no persistent connections for anything less that NT5
  849. m_buttonPullPersistence.EnableWindow(FALSE);
  850. }
  851. else
  852. {
  853. m_buttonPullPersistence.EnableWindow(bEnable);
  854. }
  855. }
  856. void
  857. CRepPartnerPropAdv::SetState(CString & strType, BOOL bPush, BOOL bPull)
  858. {
  859. int nIndex = m_comboType.FindStringExact(-1, strType);
  860. m_comboType.SetCurSel(nIndex);
  861. EnablePullControls(bPull);
  862. EnablePushControls(bPush);
  863. }
  864. /////////////////////////////////////////////////////////////////////////////
  865. //
  866. // CReplicationPartnerProperties holder
  867. //
  868. /////////////////////////////////////////////////////////////////////////////
  869. CReplicationPartnerProperties::CReplicationPartnerProperties
  870. (
  871. ITFSNode * pNode,
  872. IComponentData * pComponentData,
  873. ITFSComponentData * pTFSCompData,
  874. LPCTSTR pszSheetName
  875. ) : CPropertyPageHolderBase(pNode, pComponentData, pszSheetName)
  876. {
  877. m_bAutoDeletePages = FALSE; // we have the pages as embedded members
  878. AddPageToList((CPropertyPageBase*) &m_pageGeneral);
  879. AddPageToList((CPropertyPageBase*) &m_pageAdvanced);
  880. Assert(pTFSCompData != NULL);
  881. m_spTFSCompData.Set(pTFSCompData);
  882. }
  883. CReplicationPartnerProperties::~CReplicationPartnerProperties()
  884. {
  885. RemovePageFromList((CPropertyPageBase*) &m_pageGeneral, FALSE);
  886. RemovePageFromList((CPropertyPageBase*) &m_pageAdvanced, FALSE);
  887. }