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.

425 lines
11 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. nodes.cpp
  7. Replication partner leaf node
  8. FILE HISTORY:
  9. */
  10. #include "stdafx.h"
  11. #include "nodes.h"
  12. #include "repprtpp.h"
  13. #include "pushtrig.h"
  14. #include "fndrcdlg.h"
  15. #include "resource.h"
  16. CString g_strPartnerTypePushPull;
  17. CString g_strPartnerTypePush;
  18. CString g_strPartnerTypePull;
  19. CString g_strPartnerTypeUnknown;
  20. CReplicationPartner::CReplicationPartner(
  21. ITFSComponentData *pCompData,
  22. CWinsServerObj *pObj
  23. ): CWinsHandler(pCompData),
  24. m_strServerName(pObj->GetNetBIOSName()),
  25. m_strIPAddress(pObj->GetstrIPAddress())
  26. {
  27. m_bExpanded = FALSE;
  28. m_Server = *pObj;
  29. m_nState = loaded;
  30. m_verbDefault = MMC_VERB_PROPERTIES;
  31. if (g_strPartnerTypePushPull.IsEmpty())
  32. {
  33. g_strPartnerTypePushPull.LoadString(IDS_PUSHPULL);
  34. g_strPartnerTypePush.LoadString(IDS_PUSH);
  35. g_strPartnerTypePull.LoadString(IDS_PULL);
  36. g_strPartnerTypeUnknown.LoadString(IDS_NONE);
  37. }
  38. }
  39. HRESULT
  40. CReplicationPartner::InitializeNode
  41. (
  42. ITFSNode * pNode
  43. )
  44. {
  45. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  46. SetDisplayName(m_strServerName);
  47. if (m_Server.IsPull() && m_Server.IsPush())
  48. m_strType = g_strPartnerTypePushPull;
  49. else if(m_Server.IsPull() && !m_Server.IsPush())
  50. m_strType = g_strPartnerTypePull;
  51. else if(!m_Server.IsPull() && m_Server.IsPush())
  52. m_strType = g_strPartnerTypePush;
  53. else
  54. m_strType = g_strPartnerTypeUnknown;
  55. // Make the node immediately visible
  56. pNode->SetVisibilityState(TFS_VIS_SHOW);
  57. pNode->SetData(TFS_DATA_COOKIE, (LPARAM) pNode);
  58. pNode->SetData(TFS_DATA_USER, (LPARAM) this);
  59. pNode->SetData(TFS_DATA_TYPE, WINSSNAP_REPLICATION_PARTNER);
  60. pNode->SetData(TFS_DATA_IMAGEINDEX, ICON_IDX_PARTNER);
  61. pNode->SetData(TFS_DATA_OPENIMAGEINDEX, ICON_IDX_PARTNER);
  62. SetColumnStringIDs(&aColumns[WINSSNAP_REPLICATION_PARTNER][0]);
  63. SetColumnWidths(&aColumnWidths[WINSSNAP_REPLICATION_PARTNER][0]);
  64. return hrOK;
  65. }
  66. /*!--------------------------------------------------------------------------
  67. CActiveRegistration::AddMenuItems
  68. Implementation of ITFSResultHandler::AddMenuItems
  69. Author: EricDav
  70. ---------------------------------------------------------------------------*/
  71. STDMETHODIMP
  72. CReplicationPartner::AddMenuItems
  73. (
  74. ITFSComponent * pComponent,
  75. MMC_COOKIE cookie,
  76. LPDATAOBJECT pDataObject,
  77. LPCONTEXTMENUCALLBACK pContextMenuCallback,
  78. long * pInsertionAllowed
  79. )
  80. {
  81. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  82. HRESULT hr;
  83. CString strMenuItem;
  84. BOOL bEnablePush, bEnablePull;
  85. bEnablePush = bEnablePull = FALSE;
  86. if (m_strType.Compare(g_strPartnerTypePushPull) == 0)
  87. {
  88. bEnablePush = bEnablePull = TRUE;
  89. }
  90. else
  91. if (m_strType.Compare(g_strPartnerTypePush) == 0)
  92. {
  93. bEnablePush = TRUE;
  94. }
  95. else
  96. if (m_strType.Compare(g_strPartnerTypePull) == 0)
  97. {
  98. bEnablePull = TRUE;
  99. }
  100. // these menu items go in the new menu,
  101. // only visible from scope pane
  102. if (*pInsertionAllowed & CCM_INSERTIONALLOWED_TOP)
  103. {
  104. if (bEnablePush)
  105. {
  106. strMenuItem.LoadString(IDS_REP_SEND_PUSH_TRIGGER);
  107. hr = LoadAndAddMenuItem( pContextMenuCallback,
  108. strMenuItem,
  109. IDS_REP_SEND_PUSH_TRIGGER,
  110. CCM_INSERTIONPOINTID_PRIMARY_TOP,
  111. 0 );
  112. ASSERT( SUCCEEDED(hr) );
  113. }
  114. if (bEnablePull)
  115. {
  116. strMenuItem.LoadString(IDS_REP_SEND_PULL_TRIGGER);
  117. hr = LoadAndAddMenuItem( pContextMenuCallback,
  118. strMenuItem,
  119. IDS_REP_SEND_PULL_TRIGGER,
  120. CCM_INSERTIONPOINTID_PRIMARY_TOP,
  121. 0 );
  122. ASSERT( SUCCEEDED(hr) );
  123. }
  124. }
  125. return hrOK;
  126. }
  127. /*---------------------------------------------------------------------------
  128. Overridden base handler functions
  129. ---------------------------------------------------------------------------*/
  130. /*!--------------------------------------------------------------------------
  131. CActiveRegistration::GetString
  132. Implementation of ITFSNodeHandler::GetString
  133. Author: KennT
  134. ---------------------------------------------------------------------------*/
  135. STDMETHODIMP_(LPCTSTR)
  136. CReplicationPartner::GetString
  137. (
  138. ITFSComponent * pComponent,
  139. MMC_COOKIE cookie,
  140. int nCol
  141. )
  142. {
  143. if (nCol == 0 || nCol == -1)
  144. return GetDisplayName();
  145. switch(nCol)
  146. {
  147. case -1:
  148. case 0:
  149. return GetDisplayName();
  150. case 1:
  151. return m_strIPAddress;
  152. case 2:
  153. return m_strType;
  154. case 3:
  155. return m_strReplicationTime;
  156. default:
  157. return NULL;
  158. }
  159. }
  160. /*---------------------------------------------------------------------------
  161. CReplicationPartner::Command
  162. Description
  163. Author: EricDav
  164. ---------------------------------------------------------------------------*/
  165. STDMETHODIMP
  166. CReplicationPartner::Command
  167. (
  168. ITFSComponent * pComponent,
  169. MMC_COOKIE cookie,
  170. int nCommandID,
  171. LPDATAOBJECT pDataObject
  172. )
  173. {
  174. HRESULT hr;
  175. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  176. SPITFSNode spNode;
  177. m_spNodeMgr->FindNode(cookie, &spNode);
  178. // get the server node now
  179. SPITFSNode spRepNode, spServerNode;
  180. spNode->GetParent(&spRepNode);
  181. spRepNode->GetParent(&spServerNode);
  182. CWinsServerHandler *pServer = GETHANDLER(CWinsServerHandler, spServerNode);
  183. //
  184. // Object gets deleted when the page is destroyed
  185. //
  186. switch (nCommandID)
  187. {
  188. case IDS_REP_SEND_PUSH_TRIGGER:
  189. hr = OnSendPushTrigger(pServer);
  190. break;
  191. case IDS_REP_SEND_PULL_TRIGGER:
  192. hr = OnSendPullTrigger(pServer);
  193. break;
  194. default:
  195. break;
  196. }
  197. return hr;
  198. }
  199. /*---------------------------------------------------------------------------
  200. CActiveRegistration::CreatePropertyPages
  201. Description
  202. Author: EricDav
  203. ---------------------------------------------------------------------------*/
  204. STDMETHODIMP
  205. CReplicationPartner::CreatePropertyPages
  206. (
  207. ITFSComponent * pComponent,
  208. MMC_COOKIE cookie,
  209. LPPROPERTYSHEETCALLBACK lpProvider,
  210. LPDATAOBJECT pDataObject,
  211. LONG_PTR handle
  212. )
  213. {
  214. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  215. HRESULT hr = hrOK;
  216. SPITFSNode spNode;
  217. m_spNodeMgr->FindNode(cookie, &spNode);
  218. //
  219. // Object gets deleted when the page is destroyed
  220. //
  221. SPIComponentData spComponentData;
  222. m_spNodeMgr->GetComponentData(&spComponentData);
  223. CReplicationPartnerProperties * pProp =
  224. new CReplicationPartnerProperties(spNode, spComponentData, m_spTFSCompData, NULL);
  225. pProp->m_pageGeneral.m_uImage = (UINT) spNode->GetData(TFS_DATA_IMAGEINDEX);
  226. pProp->SetServer(&m_Server);
  227. Assert(lpProvider != NULL);
  228. return pProp->CreateModelessSheet(lpProvider, handle);
  229. }
  230. /*---------------------------------------------------------------------------
  231. Command handlers
  232. ---------------------------------------------------------------------------*/
  233. /*---------------------------------------------------------------------------
  234. CReplicationPartner::ToIPAddressString()
  235. Returns a CString IP address
  236. ---------------------------------------------------------------------------*/
  237. CString
  238. CReplicationPartner::ToIPAddressString()
  239. {
  240. CString strIP;
  241. DWORD dwFirst = GETIP_FIRST(m_dwIPAddress);
  242. DWORD dwSecond = GETIP_SECOND(m_dwIPAddress);
  243. DWORD dwThird = GETIP_THIRD(m_dwIPAddress);
  244. DWORD dwLast = GETIP_FOURTH(m_dwIPAddress);
  245. // wrap it into CString object
  246. TCHAR szStr[20];
  247. _itot(dwFirst, szStr, 10);
  248. CString strTemp(szStr);
  249. strIP = strTemp + _T(".");
  250. _itot(dwSecond, szStr, 10);
  251. strTemp = (CString)szStr;
  252. strIP += strTemp + _T(".");
  253. _itot(dwThird, szStr, 10);
  254. strTemp = (CString)szStr;
  255. strIP += strTemp + _T(".");
  256. _itot(dwLast, szStr, 10);
  257. strTemp = (CString)szStr;
  258. strIP += strTemp;
  259. return strIP;
  260. }
  261. /*---------------------------------------------------------------------------
  262. CReplicationPartner::OnResultPropertyChange
  263. Base class override
  264. ---------------------------------------------------------------------------*/
  265. HRESULT
  266. CReplicationPartner::OnResultPropertyChange
  267. (
  268. ITFSComponent * pComponent,
  269. LPDATAOBJECT pDataObject,
  270. MMC_COOKIE cookie,
  271. LPARAM arg,
  272. LPARAM param
  273. )
  274. {
  275. HRESULT hr = hrOK;
  276. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  277. SPITFSNode spNode;
  278. m_spNodeMgr->FindNode(cookie, &spNode);
  279. CReplicationPartnerProperties * pProp = reinterpret_cast<CReplicationPartnerProperties *>(param);
  280. LONG_PTR changeMask = 0;
  281. // tell the property page to do whatever now that we are back on the
  282. // main thread
  283. pProp->OnPropertyChange(TRUE, &changeMask);
  284. pProp->AcknowledgeNotify();
  285. if (changeMask)
  286. spNode->ChangeNode(changeMask);
  287. return hr;
  288. }
  289. /*---------------------------------------------------------------------------
  290. CReplicationPartner::OnSendPushTrigger()
  291. Sends Push replication trigger
  292. ---------------------------------------------------------------------------*/
  293. HRESULT
  294. CReplicationPartner::OnSendPushTrigger(CWinsServerHandler *pServer)
  295. {
  296. HRESULT hr = hrOK;
  297. DWORD err = ERROR_SUCCESS;
  298. CPushTrig cPushDlg;
  299. CThemeContextActivator themeActivator;
  300. if (cPushDlg.DoModal() != IDOK)
  301. return hr;
  302. err = ::SendTrigger(pServer->GetBinding(),
  303. (LONG) m_Server.GetIpAddress(),
  304. TRUE,
  305. cPushDlg.GetPropagate());
  306. if (err == ERROR_SUCCESS)
  307. {
  308. AfxMessageBox(IDS_REPL_QUEUED, MB_ICONINFORMATION);
  309. }
  310. else
  311. {
  312. WinsMessageBox(err);
  313. }
  314. return HRESULT_FROM_WIN32(err);
  315. }
  316. /*---------------------------------------------------------------------------
  317. CReplicationPartner::OnSendPullTrigger()
  318. Sends Pull replication trigger
  319. ---------------------------------------------------------------------------*/
  320. HRESULT
  321. CReplicationPartner::OnSendPullTrigger(CWinsServerHandler *pServer)
  322. {
  323. HRESULT hr = hrOK;
  324. DWORD err = ERROR_SUCCESS;
  325. CPullTrig cPullTrig;
  326. CThemeContextActivator themeActivator;
  327. if (cPullTrig.DoModal() != IDOK)
  328. return hr;
  329. err = ::SendTrigger(pServer->GetBinding(),
  330. (LONG) m_Server.GetIpAddress(),
  331. FALSE,
  332. FALSE);
  333. if (err == ERROR_SUCCESS)
  334. {
  335. AfxMessageBox(IDS_REPL_QUEUED, MB_ICONINFORMATION);
  336. }
  337. else
  338. {
  339. ::WinsMessageBox(err);
  340. }
  341. return HRESULT_FROM_WIN32(err);
  342. }