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.

2237 lines
64 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2000 - 2001.
  5. //
  6. // File: Basecont.cpp
  7. //
  8. // Contents:
  9. //
  10. // History: 08-2001 Hiteshr Created
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "headers.h"
  14. /******************************************************************************
  15. Class: CBaseNode
  16. Purpose: This common base class for all snapins node
  17. ******************************************************************************/
  18. CBaseNode::
  19. CBaseNode(CRoleComponentDataObject * pComponentDataObject,
  20. CAdminManagerNode* pAdminManagerNode,
  21. CBaseAz* pBaseAz,
  22. BOOL bDeleteBaseAzInDestructor)
  23. :m_pComponentDataObject(pComponentDataObject),
  24. m_pAdminManagerNode(pAdminManagerNode),
  25. m_pBaseAz(pBaseAz),
  26. m_bDeleteBaseAzInDestructor(bDeleteBaseAzInDestructor)
  27. {
  28. ASSERT(m_pComponentDataObject);
  29. ASSERT(m_pAdminManagerNode);
  30. ASSERT(pBaseAz);
  31. }
  32. CSidHandler*
  33. CBaseNode::
  34. GetSidHandler()
  35. {
  36. return GetAdminManagerNode()->GetSidHandler();
  37. }
  38. CBaseNode::
  39. ~CBaseNode()
  40. {
  41. if(m_bDeleteBaseAzInDestructor)
  42. {
  43. delete m_pBaseAz;
  44. }
  45. }
  46. //+----------------------------------------------------------------------------
  47. // Function:DeleteAssociatedBaseAzObject
  48. // Synopsis:This function deletes the baseaz object associated with the node.
  49. // It actually deletes it from the core. m_pBaseAz which is a reference
  50. // to the object is deleted in destructor. Once the object is deleted
  51. // from core, any operation on m_pBaseAz will return error
  52. // INVALID_HANDLE, So no operation should be done on it. This method
  53. // is called from the Generic Node Delete routine.
  54. // Returns:
  55. //-----------------------------------------------------------------------------
  56. HRESULT
  57. CBaseNode::
  58. DeleteAssociatedBaseAzObject()
  59. {
  60. TRACE_METHOD_EX(DEB_SNAPIN,CBaseNode,DeleteAssociatedBaseAzObject)
  61. CBaseAz* pBaseAz = GetBaseAzObject();
  62. CContainerAz* pContainerAzParent = pBaseAz->GetParentAz();
  63. if(pContainerAzParent)
  64. {
  65. return pContainerAzParent->DeleteAzObject(pBaseAz->GetObjectType(),
  66. pBaseAz->GetName());
  67. }
  68. else
  69. {
  70. ASSERT(pContainerAzParent);
  71. return E_UNEXPECTED;
  72. }
  73. }
  74. /******************************************************************************
  75. Class: CBaseContainerNode
  76. Purpose: This is the base class for snapin nodes which can contain
  77. child nodes.
  78. ******************************************************************************/
  79. CBaseContainerNode::
  80. CBaseContainerNode(CRoleComponentDataObject * pComponentDataObject,
  81. CAdminManagerNode* pAdminManagerNode,
  82. CContainerAz* pContainerAz,
  83. OBJECT_TYPE_AZ* pChildObjectTypes,
  84. LPCONTEXTMENUITEM2 pContextMenu,
  85. BOOL bDeleteBaseAzInDestructor)
  86. :CBaseNode(pComponentDataObject,
  87. pAdminManagerNode,
  88. pContainerAz,
  89. bDeleteBaseAzInDestructor),
  90. m_pColumnSet(NULL),
  91. m_pChildObjectTypes(pChildObjectTypes),
  92. m_pContextMenu(pContextMenu)
  93. {
  94. }
  95. CBaseContainerNode::
  96. ~CBaseContainerNode()
  97. {
  98. }
  99. //+----------------------------------------------------------------------------
  100. // Function:AddChildNodes
  101. // Synopsis:This function add child nodes for object types listed in
  102. // m_pChildObjectTypes
  103. //-----------------------------------------------------------------------------
  104. HRESULT
  105. CBaseContainerNode::
  106. AddChildNodes()
  107. {
  108. //There are no child object types. Derived class must be handling
  109. //enumeration itself.
  110. if(!m_pChildObjectTypes)
  111. {
  112. return S_OK;
  113. }
  114. //Clear All Children
  115. RemoveAllChildrenFromList();
  116. HRESULT hr = S_OK;
  117. OBJECT_TYPE_AZ * pChildObjectTypes = m_pChildObjectTypes;
  118. OBJECT_TYPE_AZ eObjectType;
  119. while((eObjectType = *pChildObjectTypes++) != AZ_ENUM_END)
  120. {
  121. if(eObjectType == APPLICATION_AZ ||
  122. eObjectType == SCOPE_AZ ||
  123. eObjectType == GROUP_AZ ||
  124. eObjectType == TASK_AZ ||
  125. eObjectType == ROLE_AZ ||
  126. eObjectType == OPERATION_AZ)
  127. {
  128. hr = EnumAndAddAzObjectNodes(eObjectType);
  129. }
  130. else if(eObjectType == GROUP_COLLECTION_AZ ||
  131. eObjectType == TASK_COLLECTION_AZ ||
  132. eObjectType == ROLE_COLLECTION_AZ ||
  133. eObjectType == ROLE_DEFINITION_COLLECTION_AZ ||
  134. eObjectType == OPERATION_COLLECTION_AZ ||
  135. eObjectType == DEFINITION_COLLECTION_AZ)
  136. {
  137. hr = AddAzCollectionNode(eObjectType);
  138. }
  139. BREAK_ON_FAIL_HRESULT(hr);
  140. }
  141. if(FAILED(hr))
  142. {
  143. RemoveAllChildrenFromList();
  144. }
  145. return hr;
  146. }
  147. //+----------------------------------------------------------------------------
  148. // Function:AddAzCollectionNode
  149. // Synopsis:Adds a collection
  150. //-----------------------------------------------------------------------------
  151. HRESULT
  152. CBaseContainerNode
  153. ::AddAzCollectionNode(OBJECT_TYPE_AZ eObjectType)
  154. {
  155. CContainerAz* pContainerAz = GetContainerAzObject();
  156. ASSERT(pContainerAz);
  157. CCollectionNode* pCollectionNode = NULL;
  158. switch (eObjectType)
  159. {
  160. case GROUP_COLLECTION_AZ:
  161. {
  162. pCollectionNode = new CGroupCollectionNode(GetComponentDataObject(),GetAdminManagerNode(),pContainerAz);
  163. break;
  164. }
  165. case ROLE_DEFINITION_COLLECTION_AZ:
  166. {
  167. pCollectionNode = new CRoleDefinitionCollectionNode(GetComponentDataObject(),GetAdminManagerNode(),pContainerAz);
  168. break;
  169. }
  170. case TASK_COLLECTION_AZ:
  171. {
  172. pCollectionNode = new CTaskCollectionNode(GetComponentDataObject(),GetAdminManagerNode(),pContainerAz);
  173. break;
  174. }
  175. case ROLE_COLLECTION_AZ:
  176. {
  177. pCollectionNode = new CRoleCollectionNode(GetComponentDataObject(),GetAdminManagerNode(),pContainerAz);
  178. break;
  179. }
  180. case OPERATION_COLLECTION_AZ:
  181. {
  182. pCollectionNode = new COperationCollectionNode(GetComponentDataObject(),GetAdminManagerNode(),pContainerAz);
  183. break;
  184. }
  185. case DEFINITION_COLLECTION_AZ:
  186. {
  187. pCollectionNode = new CDefinitionCollectionNode(GetComponentDataObject(),GetAdminManagerNode(),pContainerAz);
  188. break;
  189. }
  190. default:
  191. {
  192. ASSERT(FALSE);
  193. return E_UNEXPECTED;
  194. }
  195. }
  196. if(!pCollectionNode)
  197. {
  198. return E_OUTOFMEMORY;
  199. }
  200. //Add Node to snapin
  201. VERIFY(AddChildToList(pCollectionNode));
  202. return S_OK;
  203. }
  204. //+----------------------------------------------------------------------------
  205. // Function:EnumAndAddAzObjectNodes
  206. // Synopsis:Get All the Child Objects of type eObjectType and adds them to
  207. // snapin
  208. //-----------------------------------------------------------------------------
  209. HRESULT
  210. CBaseContainerNode::
  211. EnumAndAddAzObjectNodes(OBJECT_TYPE_AZ eObjectType)
  212. {
  213. CList<CBaseAz*,CBaseAz*> listAzChildObject;
  214. //Get Child Object
  215. CContainerAz* pContainerAz = GetContainerAzObject();
  216. ASSERT(pContainerAz);
  217. HRESULT hr = pContainerAz->GetAzChildObjects(eObjectType,
  218. listAzChildObject);
  219. if(FAILED(hr))
  220. {
  221. DBG_OUT_HRESULT(hr);
  222. return hr;
  223. }
  224. hr = AddAzObjectNodesToList(eObjectType,
  225. listAzChildObject,
  226. this);
  227. CHECK_HRESULT(hr);
  228. return hr;
  229. }
  230. BOOL
  231. CBaseContainerNode::
  232. OnEnumerate(CComponentDataObject*, BOOL)
  233. {
  234. TRACE_METHOD_EX(DEB_SNAPIN, CBaseContainerNode, OnEnumerate)
  235. HRESULT hr = AddChildNodes();
  236. if(FAILED(hr))
  237. {
  238. //Display Error
  239. CString strError;
  240. GetSystemError(strError, hr);
  241. //Display Generic Error Message
  242. DisplayError(NULL,
  243. IDS_GENERIC_ENUMERATE_ERROR,
  244. (LPWSTR)(LPCWSTR)strError);
  245. return FALSE;
  246. }
  247. return TRUE;
  248. }
  249. HRESULT
  250. CBaseContainerNode::
  251. GetResultViewType(CComponentDataObject* ,
  252. LPOLESTR* ppViewType,
  253. long* pViewOptions)
  254. {
  255. TRACE_METHOD_EX(DEB_SNAPIN,CBaseContainerNode,GetResultViewType)
  256. if(!pViewOptions || !ppViewType)
  257. {
  258. ASSERT(FALSE);
  259. return E_POINTER;
  260. }
  261. *pViewOptions = MMC_VIEW_OPTIONS_MULTISELECT;
  262. *ppViewType = NULL;
  263. return S_FALSE;
  264. }
  265. BOOL
  266. CBaseContainerNode::
  267. OnAddMenuItem(LPCONTEXTMENUITEM2 ,
  268. long*)
  269. {
  270. TRACE_METHOD_EX(DEB_SNAPIN,CBaseContainerNode,OnAddMenuItem)
  271. BOOL bCanCreateChild = FALSE;
  272. HRESULT hr = GetContainerAzObject()->CanCreateChildObject(bCanCreateChild);
  273. if(SUCCEEDED(hr) && bCanCreateChild)
  274. return TRUE;
  275. else
  276. return FALSE;
  277. }
  278. CColumnSet*
  279. CBaseContainerNode::
  280. GetColumnSet()
  281. {
  282. TRACE_METHOD_EX(DEB_SNAPIN, CBaseContainerNode, GetColumnSet);
  283. if (m_pColumnSet == NULL)
  284. {
  285. m_pColumnSet = GetComponentDataObject()->GetColumnSet(L"---Default Column Set---");
  286. }
  287. ASSERT(m_pColumnSet);
  288. return m_pColumnSet;
  289. }
  290. LPCWSTR
  291. CBaseContainerNode::
  292. GetString(int nCol)
  293. {
  294. if(nCol == 0)
  295. return GetName();
  296. if( nCol == 1)
  297. return GetType();
  298. if( nCol == 2)
  299. return GetDesc();
  300. ASSERT(FALSE);
  301. return NULL;
  302. }
  303. int
  304. CBaseContainerNode::
  305. GetImageIndex(BOOL /*bOpenImage*/)
  306. {
  307. TRACE_METHOD_EX(DEB_SNAPIN,CBaseContainerNode,GetImageIndex)
  308. return GetBaseAzObject()->GetImageIndex();
  309. }
  310. HRESULT
  311. CBaseContainerNode::
  312. OnCommand(long nCommandID,
  313. DATA_OBJECT_TYPES,
  314. CComponentDataObject* pComponentData,
  315. CNodeList* pNodeList)
  316. {
  317. TRACE_METHOD_EX(DEB_SNAPIN,CAdminManagerNode,OnCommand)
  318. if(!pNodeList || !pComponentData)
  319. {
  320. ASSERT(pNodeList);
  321. ASSERT(pComponentData);
  322. return E_POINTER;
  323. }
  324. if(pNodeList->GetCount() > 1)
  325. {
  326. return E_FAIL;
  327. }
  328. DoCommand(nCommandID,pComponentData, pNodeList);
  329. return S_OK;
  330. }
  331. BOOL
  332. CBaseContainerNode::
  333. CanCloseSheets()
  334. {
  335. //This function is called when there are open property sheets,
  336. //and operation cannot be done without closing them.
  337. ::DisplayInformation(NULL,
  338. IDS_CLOSE_CONTAINER_PROPERTY_SHEETS,
  339. GetDisplayName());
  340. return FALSE;
  341. }
  342. BOOL
  343. CBaseContainerNode::
  344. OnSetDeleteVerbState(DATA_OBJECT_TYPES /*type*/,
  345. BOOL* pbHide,
  346. CNodeList* pNodeList)
  347. {
  348. if(!pbHide || !pNodeList)
  349. {
  350. ASSERT(pbHide);
  351. ASSERT(pNodeList);
  352. return FALSE;
  353. }
  354. BOOL bWrite = FALSE;
  355. HRESULT hr = GetBaseAzObject()->IsWritable(bWrite);
  356. if(FAILED(hr) || !bWrite || (pNodeList->GetCount() == 1 && !IsNodeDeleteable()))
  357. {
  358. *pbHide = TRUE;
  359. return FALSE;
  360. }
  361. else
  362. {
  363. *pbHide = FALSE;
  364. return TRUE;
  365. }
  366. return TRUE;
  367. }
  368. void
  369. CBaseContainerNode::
  370. OnDelete(CComponentDataObject* pComponentData,
  371. CNodeList* pNodeList)
  372. {
  373. GenericDeleteRoutine(this,pComponentData,pNodeList,TRUE);
  374. }
  375. /******************************************************************************
  376. Class: CAzContainerNode
  377. Purpose: Snapin Nodes for BaseAz Objects which can contain other child
  378. objects use CAzContainerNode as base class
  379. ******************************************************************************/
  380. CAzContainerNode::
  381. CAzContainerNode(CRoleComponentDataObject * pComponentDataObject,
  382. CAdminManagerNode* pAdminManagerNode,
  383. OBJECT_TYPE_AZ* pChildObjectTypes,
  384. LPCONTEXTMENUITEM2 pContextMenu,
  385. CContainerAz* pContainerAz)
  386. :CBaseContainerNode(pComponentDataObject,
  387. pAdminManagerNode,
  388. pContainerAz,
  389. pChildObjectTypes,
  390. pContextMenu)
  391. {
  392. SetDisplayName(GetName());
  393. }
  394. CAzContainerNode::~CAzContainerNode()
  395. {
  396. //Before delete the BaseAz object, delete all its child else
  397. //core will assert when we try to delete the child.
  398. RemoveAllChildrenFromList();
  399. }
  400. void
  401. GenericDeleteRoutine(CBaseNode* pBaseNode,
  402. CComponentDataObject* pComponentData,
  403. CNodeList* pNodeList,
  404. BOOL bConfirmDelete)
  405. {
  406. TRACE_FUNCTION_EX(DEB_SNAPIN,GenericDeleteRoutine)
  407. if (!pNodeList || !pComponentData)
  408. {
  409. ASSERT(pNodeList);
  410. ASSERT(pComponentData);
  411. return;
  412. }
  413. CTreeNode *pTreeNode = dynamic_cast<CTreeNode*>(pBaseNode);
  414. ASSERT(pTreeNode);
  415. //
  416. //If we are deleteing this node, check if there is any
  417. //propertysheet up.
  418. //Node has any property sheet up. Display error and quit
  419. //
  420. if(pNodeList->GetCount() == 1)
  421. {
  422. if (pTreeNode->IsSheetLocked())
  423. {
  424. ::DisplayInformation(NULL,
  425. IDS_CLOSE_CONTAINER_PROPERTY_SHEETS,
  426. pTreeNode->GetDisplayName());
  427. BringPropSheetToForeGround((CRoleComponentDataObject*)pComponentData,
  428. pTreeNode);
  429. return;
  430. }
  431. }
  432. //
  433. //Get Delete confirmation from user
  434. //
  435. if(bConfirmDelete)
  436. {
  437. if(pNodeList->GetCount() == 1)
  438. {
  439. CBaseAz* pBaseAz = pBaseNode->GetBaseAzObject();
  440. CString strType = pBaseAz->GetType();
  441. strType.MakeLower();
  442. if(IDNO == DisplayConfirmation(NULL,
  443. IDS_DELETE_CONFIRMATION,
  444. (LPCTSTR)strType,
  445. (LPCTSTR)pBaseAz->GetName()))
  446. {
  447. return;
  448. }
  449. }
  450. else
  451. {
  452. //Ask Confirmation to delete all the objects
  453. if(IDNO == DisplayConfirmation(NULL,
  454. IDS_DELETE_SELECTED_CONFIRMATION))
  455. {
  456. return;
  457. }
  458. }
  459. }
  460. if(pNodeList->GetCount() == 1)
  461. {
  462. //
  463. //Delete the BaseAzObject associated with the node
  464. //
  465. HRESULT hr = pBaseNode->DeleteAssociatedBaseAzObject();
  466. if(SUCCEEDED(hr))
  467. {
  468. pTreeNode->DeleteHelper(pComponentData);
  469. delete pTreeNode;
  470. }
  471. else
  472. {
  473. //Display Error
  474. CString strError;
  475. GetSystemError(strError, hr);
  476. //Display Generic Error Message
  477. DisplayError(NULL,
  478. IDS_DELETE_FAILED,
  479. (LPWSTR)(LPCWSTR)strError,
  480. (LPWSTR)(LPCWSTR)pTreeNode->GetDisplayName());
  481. return;
  482. }
  483. }
  484. else
  485. {
  486. POSITION pos = pNodeList->GetHeadPosition();
  487. while (pos != NULL)
  488. {
  489. CTreeNode* pChildTreeNode = pNodeList->GetNext(pos);
  490. //
  491. //Node has any property sheet up. Display error and quit
  492. //
  493. if (pChildTreeNode->IsSheetLocked())
  494. {
  495. ::DisplayInformation(NULL,
  496. IDS_CLOSE_CONTAINER_PROPERTY_SHEETS,
  497. pChildTreeNode->GetDisplayName());
  498. return;
  499. }
  500. CBaseNode* pChildBaseNode = dynamic_cast<CBaseNode*>(pChildTreeNode);
  501. ASSERT(pChildBaseNode);
  502. if(!pChildBaseNode->IsNodeDeleteable())
  503. continue;
  504. HRESULT hr = pChildBaseNode->DeleteAssociatedBaseAzObject();
  505. if(SUCCEEDED(hr))
  506. {
  507. pChildTreeNode->DeleteHelper(pComponentData);
  508. delete pChildTreeNode;
  509. }
  510. else
  511. {
  512. //Display Error
  513. CString strError;
  514. GetSystemError(strError, hr);
  515. //Display Generic Error Message
  516. if(IDNO == DisplayConfirmation(NULL,
  517. IDS_FAILURE_IN_MULTIPLE_DELETE,
  518. (LPWSTR)(LPCWSTR)strError,
  519. (LPWSTR)(LPCWSTR)pChildTreeNode->GetDisplayName()))
  520. {
  521. break;
  522. }
  523. }
  524. }
  525. }
  526. }
  527. BOOL
  528. CAzContainerNode::
  529. HasPropertyPages(DATA_OBJECT_TYPES ,
  530. BOOL* pbHideVerb,
  531. CNodeList* pNodeList)
  532. {
  533. if (pNodeList->GetCount() == 1) // single selection
  534. {
  535. *pbHideVerb = FALSE; // always show the verb
  536. return TRUE;
  537. }
  538. // Multiple selection
  539. *pbHideVerb = TRUE;
  540. return FALSE;
  541. }
  542. HRESULT
  543. CAzContainerNode::
  544. CreatePropertyPages(LPPROPERTYSHEETCALLBACK lpProvider,
  545. LONG_PTR handle,
  546. CNodeList* pNodeList)
  547. {
  548. HRESULT hr = S_OK;
  549. if (!pNodeList || pNodeList->GetCount() > 1)
  550. {
  551. ASSERT(FALSE);
  552. return E_UNEXPECTED;
  553. }
  554. if(!CanReadOneProperty(GetDisplayName(),
  555. GetBaseAzObject()))
  556. return E_FAIL;
  557. //Add Property Pages
  558. UINT nPageNum = 0;
  559. CRolePropertyPageHolder* pHolder = NULL;
  560. do
  561. {
  562. CComponentDataObject* pComponentDataObject = GetComponentDataObject();
  563. ASSERT(pComponentDataObject != NULL);
  564. pHolder = new CRolePropertyPageHolder(GetContainer(),
  565. this,
  566. pComponentDataObject);
  567. if(!pHolder)
  568. {
  569. hr = E_OUTOFMEMORY;
  570. break;
  571. }
  572. while(1)
  573. {
  574. hr = AddOnePageToList(pHolder, nPageNum);
  575. if(hr == HRESULT_FROM_WIN32(ERROR_NO_MORE_ITEMS))
  576. {
  577. hr = S_OK;
  578. break;
  579. }
  580. if(FAILED(hr))
  581. {
  582. break;
  583. }
  584. nPageNum++;
  585. }
  586. BREAK_ON_FAIL_HRESULT(hr);
  587. //
  588. //Add Security Page. Security Page is only supported by containers.
  589. //Depending on underlying store, application and scope may or may
  590. //not support Security
  591. //
  592. CContainerAz* pContainerAz = GetContainerAzObject();
  593. if(pContainerAz->IsSecurable())
  594. {
  595. Dbg(DEB_SNAPIN, "Adding Security Page\n");
  596. CSecurityPropertyPage * pSecPropPage =
  597. new CSecurityPropertyPage(pContainerAz,this);
  598. if(!pSecPropPage)
  599. {
  600. hr = E_OUTOFMEMORY;
  601. break;
  602. }
  603. pHolder->AddPageToList(pSecPropPage);
  604. nPageNum++;
  605. }
  606. //
  607. //Add Auditing Page
  608. //
  609. if(pContainerAz->IsAuditingSupported())
  610. {
  611. Dbg(DEB_SNAPIN, "Adding Auditing page\n");
  612. CAuditPropertyPage *pAuditPage =
  613. new CAuditPropertyPage(pContainerAz,this);
  614. if(!pAuditPage)
  615. {
  616. hr = E_OUTOFMEMORY;
  617. break;
  618. }
  619. pHolder->AddPageToList(pAuditPage);
  620. nPageNum++;
  621. }
  622. if(nPageNum)
  623. return pHolder->CreateModelessSheet(lpProvider, handle);
  624. }while(0);
  625. if(FAILED(hr) || !nPageNum)
  626. {
  627. if(pHolder)
  628. delete pHolder;
  629. }
  630. return hr;
  631. }
  632. void
  633. CAzContainerNode::
  634. OnPropertyChange(CComponentDataObject* pComponentData,
  635. BOOL bScopePane,
  636. long changeMask)
  637. {
  638. if(!pComponentData)
  639. {
  640. ASSERT(pComponentData);
  641. return;
  642. }
  643. //Reset the display name
  644. SetDisplayName(GetName());
  645. CTreeNode::OnPropertyChange(pComponentData,
  646. bScopePane,
  647. changeMask);
  648. }
  649. /******************************************************************************
  650. Class: CCollectionNode
  651. Purpose: Base Class for snapin nodes which are used to group objects of
  652. same type.
  653. ******************************************************************************/
  654. CCollectionNode
  655. ::CCollectionNode(CRoleComponentDataObject * pComponentDataObject,
  656. CAdminManagerNode* pAdminManagerNode,OBJECT_TYPE_AZ* pChildObjectTypes,
  657. LPCONTEXTMENUITEM2 pContextMenu,
  658. CContainerAz* pContainerAzObject,
  659. UINT nNameStringID,
  660. UINT nTypeStringID,
  661. UINT nDescStringID)
  662. :CBaseContainerNode(pComponentDataObject,
  663. pAdminManagerNode,
  664. pContainerAzObject,
  665. pChildObjectTypes,
  666. pContextMenu,
  667. FALSE)
  668. {
  669. m_strName.LoadString(nNameStringID);
  670. m_strType.LoadString(nTypeStringID);
  671. m_strDesc.LoadString(nDescStringID);
  672. SetDisplayName(m_strName);
  673. }
  674. CCollectionNode
  675. ::~CCollectionNode()
  676. {
  677. }
  678. /******************************************************************************
  679. Class: CAdminManagerNode
  680. Purpose: Snapin Node for AdminManager object
  681. ******************************************************************************/
  682. DEBUG_DECLARE_INSTANCE_COUNTER(CAdminManagerNode)
  683. OBJECT_TYPE_AZ
  684. CAdminManagerNode::childObjectTypes[] = {GROUP_COLLECTION_AZ,
  685. APPLICATION_AZ,
  686. AZ_ENUM_END,};
  687. CAdminManagerNode
  688. ::CAdminManagerNode(CRoleComponentDataObject * pComponentDataObject,
  689. CAdminManagerAz * pAdminManagerAz)
  690. :CAzContainerNode(pComponentDataObject,
  691. this,
  692. childObjectTypes,
  693. CAdminManagerNodeMenuHolder::GetContextMenuItem(),
  694. pAdminManagerAz)
  695. {
  696. TRACE_CONSTRUCTOR_EX(DEB_SNAPIN, CAdminManagerNode)
  697. DEBUG_INCREMENT_INSTANCE_COUNTER(CAdminManagerNode)
  698. SetDisplayName(GetName());
  699. }
  700. CAdminManagerNode::
  701. ~CAdminManagerNode()
  702. {
  703. TRACE_CONSTRUCTOR_EX(DEB_SNAPIN,CAdminManagerNode)
  704. DEBUG_DECREMENT_INSTANCE_COUNTER(CAdminManagerNode)
  705. }
  706. //+----------------------------------------------------------------------------
  707. // Function:CreateFromStream
  708. // Synopsis:Reads Data from .msc file and Creates AdminManagerNode
  709. //-----------------------------------------------------------------------------
  710. HRESULT
  711. CAdminManagerNode::
  712. CreateFromStream(IN IStream* pStm,
  713. IN CRootData* pRootData,
  714. IN CComponentDataObject * pComponentDataObject)
  715. {
  716. if(!pStm || !pRootData || !pComponentDataObject)
  717. {
  718. ASSERT(pStm);
  719. ASSERT(pRootData);
  720. ASSERT(pComponentDataObject);
  721. }
  722. HRESULT hr = S_OK;
  723. do
  724. {
  725. ULONG cbRead = 0;
  726. //Read the Store Type
  727. ULONG ulStoreType;
  728. hr = pStm->Read((void*)&ulStoreType,sizeof(ULONG), &cbRead);
  729. BREAK_ON_FAIL_HRESULT(hr);
  730. ASSERT(cbRead == sizeof(ULONG));
  731. //Read the Length of Store Name
  732. INT nLen;
  733. hr = pStm->Read((void*)&nLen,sizeof(INT), &cbRead);
  734. BREAK_ON_FAIL_HRESULT(hr);
  735. ASSERT(cbRead == sizeof(INT));
  736. //Read Store Name
  737. LPWSTR pszBuffer = (LPWSTR)LocalAlloc(LPTR,nLen*sizeof(WCHAR));
  738. if(!pszBuffer)
  739. return E_OUTOFMEMORY;
  740. hr = pStm->Read((void*)pszBuffer,sizeof(WCHAR)*nLen, &cbRead);
  741. BREAK_ON_FAIL_HRESULT(hr);
  742. ASSERT(cbRead == sizeof(WCHAR)*nLen);
  743. CString strStoreName = pszBuffer;
  744. LocalFree(pszBuffer);
  745. pszBuffer = NULL;
  746. //read authorization script directory
  747. //Read length of script directory
  748. INT nLenScriptDir;
  749. hr = pStm->Read((void*)&nLenScriptDir,sizeof(INT), &cbRead);
  750. BREAK_ON_FAIL_HRESULT(hr);
  751. ASSERT(cbRead == sizeof(INT));
  752. //Read authorization script directory
  753. CString strScriptDir;
  754. if(nLenScriptDir > 0)
  755. {
  756. pszBuffer = (LPWSTR)LocalAlloc(LPTR,nLenScriptDir*sizeof(WCHAR));
  757. if(!pszBuffer)
  758. return E_OUTOFMEMORY;
  759. hr = pStm->Read((void*)pszBuffer,sizeof(WCHAR)*nLenScriptDir, &cbRead);
  760. BREAK_ON_FAIL_HRESULT(hr);
  761. ASSERT(cbRead == sizeof(WCHAR)*nLenScriptDir);
  762. strScriptDir = pszBuffer;
  763. LocalFree(pszBuffer);
  764. }
  765. hr = OpenAdminManager(NULL,
  766. TRUE,
  767. ulStoreType,
  768. strStoreName,
  769. strScriptDir,
  770. pRootData,
  771. pComponentDataObject);
  772. }while(0);
  773. return hr;
  774. }
  775. //+----------------------------------------------------------------------------
  776. // Function:SaveToStream
  777. // Synopsis:Saves data for AdminManagerNode in .msc file
  778. //-----------------------------------------------------------------------------
  779. HRESULT
  780. CAdminManagerNode::
  781. SaveToStream(IStream* pStm)
  782. {
  783. if(!pStm)
  784. {
  785. ASSERT(pStm);
  786. return E_POINTER;
  787. }
  788. HRESULT hr = S_OK;
  789. do
  790. {
  791. CAdminManagerAz* pAdminMangerAz = (CAdminManagerAz*)GetContainerAzObject();
  792. ULONG cbWrite = 0;
  793. //Save the Type of Authorization Store
  794. ULONG ulStoreType = pAdminMangerAz->GetStoreType();
  795. hr = pStm->Write((void*)&ulStoreType, sizeof(ULONG),&cbWrite);
  796. BREAK_ON_FAIL_HRESULT(hr);
  797. ASSERT(cbWrite == sizeof(ULONG));
  798. //Save the Length of Authorization Store Name
  799. const CString &strName = pAdminMangerAz->GetName();
  800. INT nLen = strName.GetLength() + 1; //Include NULL
  801. hr = pStm->Write((void*)&nLen, sizeof(INT),&cbWrite);
  802. BREAK_ON_FAIL_HRESULT(hr);
  803. ASSERT(cbWrite == sizeof(INT));
  804. //Save Authorization Store Name
  805. hr = pStm->Write((void*)(LPCTSTR)strName, sizeof(WCHAR)*nLen,&cbWrite);
  806. BREAK_ON_FAIL_HRESULT(hr);
  807. ASSERT(cbWrite == sizeof(WCHAR)*nLen);
  808. //
  809. //Save the Authorization script directory
  810. //
  811. //Save the length of Authorization script directory
  812. INT nLenScriptDir = m_strScriptDirectory.GetLength();
  813. if(nLenScriptDir)
  814. nLenScriptDir++; //save null also
  815. pStm->Write((void*)&nLenScriptDir, sizeof(INT),&cbWrite);
  816. BREAK_ON_FAIL_HRESULT(hr);
  817. ASSERT(cbWrite == sizeof(INT));
  818. if(nLenScriptDir)
  819. {
  820. //save the Authorization script directory
  821. pStm->Write((void*)(LPCTSTR)m_strScriptDirectory, sizeof(WCHAR)*nLenScriptDir,&cbWrite);
  822. BREAK_ON_FAIL_HRESULT(hr);
  823. ASSERT(cbWrite == sizeof(WCHAR)*nLenScriptDir);
  824. }
  825. }while(0);
  826. return hr;
  827. }
  828. const CString&
  829. CAdminManagerNode::
  830. GetScriptDirectory()
  831. {
  832. if(m_strScriptDirectory.IsEmpty())
  833. {
  834. m_strScriptDirectory = ((CRoleRootData*)GetRootContainer())->GetXMLStorePath();
  835. }
  836. return m_strScriptDirectory;
  837. }
  838. void
  839. CAdminManagerNode::
  840. DoCommand(long nCommandID,
  841. CComponentDataObject* pComponentData,
  842. CNodeList*)
  843. {
  844. if(IDM_ADMIN_NEW_APP == nCommandID)
  845. {
  846. CNewApplicationDlg dlgNewApplication(GetComponentDataObject(),
  847. this);
  848. dlgNewApplication.DoModal();
  849. }
  850. else if(IDM_ADMIN_CLOSE_ADMIN_MANAGER == nCommandID)
  851. {
  852. if (IsSheetLocked())
  853. {
  854. ::DisplayInformation(NULL,
  855. IDS_CLOSE_CONTAINER_PROPERTY_SHEETS,
  856. GetDisplayName());
  857. BringPropSheetToForeGround((CRoleComponentDataObject*)pComponentData,
  858. this);
  859. return;
  860. }
  861. DeleteHelper(pComponentData);
  862. delete this;
  863. }
  864. else if(IDM_ADMIN_RELOAD == nCommandID)
  865. {
  866. if (IsSheetLocked())
  867. {
  868. ::DisplayInformation(NULL,
  869. IDS_CLOSE_CONTAINER_PROPERTY_SHEETS,
  870. GetDisplayName());
  871. BringPropSheetToForeGround((CRoleComponentDataObject*)pComponentData,
  872. this);
  873. return;
  874. }
  875. CAdminManagerAz* pAdminMangerAz = (CAdminManagerAz*)GetContainerAzObject();
  876. HRESULT hr = pAdminMangerAz->UpdateCache();
  877. if(SUCCEEDED(hr))
  878. {
  879. //Call Refresh on Root which will refresh
  880. //all adminmanager objects under it.
  881. CNodeList tempNodeList;
  882. tempNodeList.AddTail(this);
  883. OnRefresh(GetComponentDataObject(), &tempNodeList);
  884. }
  885. }
  886. }
  887. HRESULT
  888. CAdminManagerNode::
  889. AddOnePageToList(CRolePropertyPageHolder *pHolder, UINT nPageNumber)
  890. {
  891. HRESULT hr = S_OK;
  892. if(!pHolder)
  893. {
  894. ASSERT(pHolder);
  895. return E_POINTER;
  896. }
  897. if(nPageNumber == 0)
  898. {
  899. CAdminManagerGeneralProperty * pGenPropPage =
  900. new CAdminManagerGeneralProperty(GetContainerAzObject(),this);
  901. if(!pGenPropPage)
  902. {
  903. hr = E_OUTOFMEMORY;
  904. return hr;
  905. }
  906. pHolder->AddPageToList(pGenPropPage);
  907. return hr;
  908. }
  909. if(nPageNumber == 1)
  910. {
  911. CAdminManagerAdvancedPropertyPage * pAdvPropPage =
  912. new CAdminManagerAdvancedPropertyPage(GetContainerAzObject(),this);
  913. if(!pAdvPropPage)
  914. {
  915. hr = E_OUTOFMEMORY;
  916. return hr;
  917. }
  918. pHolder->AddPageToList(pAdvPropPage);
  919. return hr;
  920. }
  921. return HRESULT_FROM_WIN32(ERROR_NO_MORE_ITEMS);
  922. }
  923. BOOL
  924. CAdminManagerNode::
  925. OnAddMenuItem(LPCONTEXTMENUITEM2 pContextMenuItem2,
  926. long * /*pInsertionAllowed*/)
  927. {
  928. TRACE_METHOD_EX(DEB_SNAPIN,CAdminManagerNode,OnAddMenuItem)
  929. if(pContextMenuItem2->lCommandID == IDM_ADMIN_NEW_APP)
  930. {
  931. BOOL bWrite = FALSE;
  932. HRESULT hr = GetBaseAzObject()->IsWritable(bWrite);
  933. if(SUCCEEDED(hr) && bWrite)
  934. {
  935. //Applications can be created only in developer mode
  936. if(((CRoleRootData*)GetRootContainer())->IsDeveloperMode())
  937. return TRUE;
  938. }
  939. }
  940. else if(pContextMenuItem2->lCommandID == IDM_ADMIN_CLOSE_ADMIN_MANAGER ||
  941. pContextMenuItem2->lCommandID == IDM_ADMIN_RELOAD)
  942. {
  943. return TRUE;
  944. }
  945. return FALSE;
  946. }
  947. HRESULT
  948. CAdminManagerNode::
  949. DeleteAssociatedBaseAzObject()
  950. {
  951. TRACE_METHOD_EX(DEB_SNAPIN,CAdminManagerNode,DeleteAssociatedBaseAzObject)
  952. //Delete the Admin Manager object
  953. CAdminManagerAz* pAdminManagerAz = (CAdminManagerAz*)GetContainerAzObject();
  954. HRESULT hr = pAdminManagerAz->DeleteSelf();
  955. if(SUCCEEDED(hr))
  956. {
  957. //This function is only called when AdminManager object
  958. //is deleted. Set the dirty flag so at the snapin exit time,
  959. //it will ask us to save it.
  960. CRootData* pRootData = (CRootData*)GetRootContainer();
  961. pRootData->SetDirtyFlag(TRUE);
  962. }
  963. return hr;
  964. }
  965. /******************************************************************************
  966. Class: CApplicationNode
  967. Purpose: Snapin Node for Application object
  968. ******************************************************************************/
  969. DEBUG_DECLARE_INSTANCE_COUNTER(CApplicationNode)
  970. OBJECT_TYPE_AZ CApplicationNode::childObjectTypes[] = {GROUP_COLLECTION_AZ,
  971. DEFINITION_COLLECTION_AZ,
  972. ROLE_COLLECTION_AZ,
  973. SCOPE_AZ,
  974. AZ_ENUM_END,};
  975. CApplicationNode
  976. ::CApplicationNode(CRoleComponentDataObject * pComponentDataObject,
  977. CAdminManagerNode* pAdminManagerNode,
  978. CApplicationAz * pAzBase)
  979. :CAzContainerNode(pComponentDataObject,
  980. pAdminManagerNode,
  981. childObjectTypes,
  982. CApplicationNodeMenuHolder::GetContextMenuItem(),
  983. pAzBase)
  984. {
  985. TRACE_CONSTRUCTOR_EX(DEB_SNAPIN, CApplicationNode)
  986. DEBUG_INCREMENT_INSTANCE_COUNTER(CApplicationNode)
  987. }
  988. CApplicationNode
  989. ::~CApplicationNode()
  990. {
  991. TRACE_CONSTRUCTOR_EX(DEB_SNAPIN,CApplicationNode)
  992. DEBUG_DECREMENT_INSTANCE_COUNTER(CApplicationNode)
  993. }
  994. void
  995. CApplicationNode
  996. ::DoCommand(LONG nCommandID,
  997. CComponentDataObject*,
  998. CNodeList*)
  999. {
  1000. if(IDM_APP_NEW_SCOPE == nCommandID)
  1001. {
  1002. CNewScopeDlg dlgNewScope(GetComponentDataObject(),
  1003. this);
  1004. dlgNewScope.DoModal();
  1005. }
  1006. }
  1007. HRESULT
  1008. CApplicationNode::
  1009. AddOnePageToList(CRolePropertyPageHolder *pHolder, UINT nPageNumber)
  1010. {
  1011. HRESULT hr = S_OK;
  1012. if(!pHolder)
  1013. {
  1014. ASSERT(pHolder);
  1015. return E_POINTER;
  1016. }
  1017. if(nPageNumber == 0)
  1018. {
  1019. //
  1020. //Add General Property Page
  1021. //
  1022. CApplicationGeneralPropertyPage * pGenPropPage =
  1023. new CApplicationGeneralPropertyPage(GetContainerAzObject(),this);
  1024. if(!pGenPropPage)
  1025. {
  1026. hr = E_OUTOFMEMORY;
  1027. return hr;
  1028. }
  1029. pHolder->AddPageToList(pGenPropPage);
  1030. return hr;
  1031. }
  1032. return HRESULT_FROM_WIN32(ERROR_NO_MORE_ITEMS);
  1033. }
  1034. /******************************************************************************
  1035. Class: CScopeNode
  1036. Purpose: Snapin Node for Scope object
  1037. ******************************************************************************/
  1038. DEBUG_DECLARE_INSTANCE_COUNTER(CScopeNode)
  1039. OBJECT_TYPE_AZ CScopeNode::childObjectTypes[] = {GROUP_COLLECTION_AZ,
  1040. DEFINITION_COLLECTION_AZ,
  1041. ROLE_COLLECTION_AZ,
  1042. AZ_ENUM_END,};
  1043. CScopeNode
  1044. ::CScopeNode(CRoleComponentDataObject * pComponentDataObject,
  1045. CAdminManagerNode* pAdminManagerNode,
  1046. CScopeAz * pAzBase)
  1047. :CAzContainerNode(pComponentDataObject,
  1048. pAdminManagerNode,
  1049. childObjectTypes,
  1050. CScopeNodeMenuHolder::GetContextMenuItem(),
  1051. pAzBase)
  1052. {
  1053. TRACE_CONSTRUCTOR_EX(DEB_SNAPIN, CScopeNode)
  1054. DEBUG_INCREMENT_INSTANCE_COUNTER(CScopeNode)
  1055. }
  1056. CScopeNode::~CScopeNode()
  1057. {
  1058. TRACE_CONSTRUCTOR_EX(DEB_SNAPIN,CScopeNode)
  1059. DEBUG_DECREMENT_INSTANCE_COUNTER(CScopeNode)
  1060. }
  1061. HRESULT
  1062. CScopeNode::
  1063. AddOnePageToList(CRolePropertyPageHolder *pHolder, UINT nPageNumber)
  1064. {
  1065. HRESULT hr = S_OK;
  1066. if(!pHolder)
  1067. {
  1068. ASSERT(pHolder);
  1069. return E_POINTER;
  1070. }
  1071. if(nPageNumber == 0)
  1072. {
  1073. //
  1074. //Add General Property Page
  1075. //
  1076. CScopeGeneralPropertyPage* pGenPropPage =
  1077. new CScopeGeneralPropertyPage(GetContainerAzObject(),this);
  1078. if(!pGenPropPage)
  1079. {
  1080. hr = E_OUTOFMEMORY;
  1081. return hr;
  1082. }
  1083. pHolder->AddPageToList(pGenPropPage);
  1084. return hr;
  1085. }
  1086. return HRESULT_FROM_WIN32(ERROR_NO_MORE_ITEMS);
  1087. }
  1088. /******************************************************************************
  1089. Class: CGroupCollectionNode
  1090. Purpose: Snapin Node under which all the groups will be listed
  1091. ******************************************************************************/
  1092. OBJECT_TYPE_AZ CGroupCollectionNode::childObjectTypes[] = {GROUP_AZ,AZ_ENUM_END,};
  1093. CGroupCollectionNode
  1094. ::CGroupCollectionNode(CRoleComponentDataObject * pComponentDataObject,
  1095. CAdminManagerNode* pAdminManagerNode,CContainerAz* pContainerAzObject)
  1096. :CCollectionNode(pComponentDataObject,
  1097. pAdminManagerNode,
  1098. childObjectTypes,
  1099. CGroupCollectionNodeMenuHolder::GetContextMenuItem(),
  1100. pContainerAzObject,
  1101. IDS_NAME,
  1102. IDS_TYPE,
  1103. IDS_DESC)
  1104. {
  1105. }
  1106. CGroupCollectionNode::~CGroupCollectionNode()
  1107. {
  1108. }
  1109. void CGroupCollectionNode
  1110. ::DoCommand(LONG nCommandID,
  1111. CComponentDataObject*,
  1112. CNodeList*)
  1113. {
  1114. if(IDM_GROUP_CONTAINER_NEW_GROUP == nCommandID)
  1115. {
  1116. CNewGroupDlg dlgNewGroup(GetComponentDataObject(),
  1117. this);
  1118. dlgNewGroup.DoModal();
  1119. }
  1120. }
  1121. /******************************************************************************
  1122. Class: CRoleCollectionNode
  1123. Purpose: Snapin Node under which all the Roles will be listed
  1124. ******************************************************************************/
  1125. OBJECT_TYPE_AZ CRoleCollectionNode::childObjectTypes[] = {ROLE_AZ,AZ_ENUM_END,};
  1126. CRoleCollectionNode
  1127. ::CRoleCollectionNode(CRoleComponentDataObject * pComponentDataObject,
  1128. CAdminManagerNode* pAdminManagerNode,CContainerAz* pContainerAzObject)
  1129. :CCollectionNode(pComponentDataObject,pAdminManagerNode,childObjectTypes,
  1130. CRoleCollectionNodeMenuHolder::GetContextMenuItem(),
  1131. pContainerAzObject,
  1132. IDS_NAME,
  1133. IDS_TYPE,
  1134. IDS_DESC)
  1135. {
  1136. }
  1137. CRoleCollectionNode::~CRoleCollectionNode()
  1138. {
  1139. }
  1140. BOOL
  1141. CRoleCollectionNode::
  1142. CreateNewRoleObject(CBaseAz* pRoleDefinitionAz)
  1143. {
  1144. if(!pRoleDefinitionAz)
  1145. {
  1146. ASSERT(pRoleDefinitionAz);
  1147. return FALSE;
  1148. }
  1149. CString strOrgRoleDefinition = pRoleDefinitionAz->GetName();
  1150. CString strRoleDefinition = strOrgRoleDefinition;
  1151. CRoleAz* pRoleAz = NULL;
  1152. CContainerAz* pContainerAz = GetContainerAzObject();
  1153. HRESULT hr = S_OK;
  1154. do
  1155. {
  1156. int i = 1;
  1157. while(1)
  1158. {
  1159. hr = pContainerAz->CreateAzObject(ROLE_AZ,
  1160. strRoleDefinition,
  1161. reinterpret_cast<CBaseAz**>(&pRoleAz));
  1162. if(FAILED(hr) && (hr == HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS)))
  1163. {
  1164. //Maximum required size for _itow is 33.
  1165. //When radix is 2, 32 char for 32bits + NULL terminator
  1166. WCHAR buffer[33];
  1167. _itow(i,buffer,10);
  1168. strRoleDefinition = strOrgRoleDefinition + L"(" + buffer + L")";
  1169. i++;
  1170. continue;
  1171. }
  1172. break;
  1173. }
  1174. BREAK_ON_FAIL_HRESULT(hr);
  1175. //Add RoleDefiniton to Role
  1176. hr = pRoleAz->AddMember(AZ_PROP_ROLE_TASKS,
  1177. pRoleDefinitionAz);
  1178. BREAK_ON_FAIL_HRESULT(hr);
  1179. //Do Submit
  1180. hr = pRoleAz->Submit();
  1181. BREAK_ON_FAIL_HRESULT(hr);
  1182. CRoleNode * pRoleNode = new CRoleNode(GetComponentDataObject(),GetAdminManagerNode(),pRoleAz);
  1183. if(!pRoleNode)
  1184. {
  1185. hr = E_OUTOFMEMORY;
  1186. break;
  1187. }
  1188. VERIFY(AddChildToListAndUI(pRoleNode,GetComponentDataObject()));
  1189. }while(0);
  1190. if(FAILED(hr))
  1191. {
  1192. if(pRoleAz)
  1193. delete pRoleAz;
  1194. CString strError;
  1195. GetSystemError(strError, hr);
  1196. DisplayError(NULL,
  1197. IDS_CREATE_ROLE_GENERIC_ERROR,
  1198. (LPWSTR)(LPCTSTR)strError);
  1199. return FALSE;
  1200. }
  1201. return TRUE;
  1202. }
  1203. void
  1204. CRoleCollectionNode::
  1205. DoCommand(LONG nCommandID,
  1206. CComponentDataObject*,
  1207. CNodeList*)
  1208. {
  1209. //Show Add Role Definitions dialog box and get selected
  1210. //Role Definitions
  1211. if(nCommandID != IDM_ROLE_CONTAINER_ASSIGN_ROLE)
  1212. {
  1213. ASSERT(FALSE);
  1214. return;
  1215. }
  1216. CList<CBaseAz*,CBaseAz*> listRoleDefSelected;
  1217. if(!GetSelectedTasks(NULL,
  1218. TRUE,
  1219. GetContainerAzObject(),
  1220. listRoleDefSelected))
  1221. {
  1222. return;
  1223. }
  1224. if(listRoleDefSelected.IsEmpty())
  1225. return;
  1226. POSITION pos = listRoleDefSelected.GetHeadPosition();
  1227. for(int i = 0; i < listRoleDefSelected.GetCount(); ++i)
  1228. {
  1229. CBaseAz* pBaseAz = listRoleDefSelected.GetNext(pos);
  1230. if(!CreateNewRoleObject(pBaseAz))
  1231. break;
  1232. }
  1233. RemoveItemsFromList(listRoleDefSelected);
  1234. }
  1235. /******************************************************************************
  1236. Class: CRoleDefinitionCollectionNode
  1237. Purpose: Snapin Node under which all the Role definitions will be listed
  1238. ******************************************************************************/
  1239. OBJECT_TYPE_AZ CRoleDefinitionCollectionNode::childObjectTypes[] = {ROLE_DEFINITION_AZ,AZ_ENUM_END,};
  1240. CRoleDefinitionCollectionNode
  1241. ::CRoleDefinitionCollectionNode(CRoleComponentDataObject * pComponentDataObject,
  1242. CAdminManagerNode* pAdminManagerNode,CContainerAz* pContainerAzObject)
  1243. :CCollectionNode(pComponentDataObject,pAdminManagerNode,
  1244. childObjectTypes,
  1245. CRoleDefinitionCollectionNodeMenuHolder::GetContextMenuItem(),
  1246. pContainerAzObject,
  1247. IDS_NAME,
  1248. IDS_TYPE,
  1249. IDS_DESC)
  1250. {
  1251. }
  1252. CRoleDefinitionCollectionNode::
  1253. ~CRoleDefinitionCollectionNode()
  1254. {
  1255. }
  1256. void CRoleDefinitionCollectionNode::
  1257. DoCommand(LONG nCommandID,
  1258. CComponentDataObject*,
  1259. CNodeList*)
  1260. {
  1261. if(IDM_ROLE_DEFINITION_CONTAINER_NEW_ROLE_DEFINITION == nCommandID)
  1262. {
  1263. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1264. CNewTaskDlg dlgNewTask(GetComponentDataObject(),
  1265. this,
  1266. IDD_NEW_ROLE_DEFINITION,
  1267. TRUE);
  1268. dlgNewTask.DoModal();
  1269. }
  1270. }
  1271. BOOL
  1272. CRoleDefinitionCollectionNode::
  1273. OnEnumerate(CComponentDataObject*, BOOL )
  1274. {
  1275. //Clear All Children
  1276. RemoveAllChildrenFromList();
  1277. CList<CBaseAz*,CBaseAz*> listAzChildObject;
  1278. CContainerAz* pContainerAz = GetContainerAzObject();
  1279. HRESULT hr = pContainerAz->GetAzChildObjects(TASK_AZ,
  1280. listAzChildObject);
  1281. if(FAILED(hr))
  1282. {
  1283. //Display Error
  1284. CString strError;
  1285. GetSystemError(strError, hr);
  1286. //Display Generic Error Message
  1287. DisplayError(NULL,
  1288. IDS_GENERIC_ENUMERATE_ERROR,
  1289. (LPWSTR)(LPCWSTR)strError);
  1290. return FALSE;
  1291. }
  1292. POSITION pos = listAzChildObject.GetHeadPosition();
  1293. for (int i=0;i < listAzChildObject.GetCount();i++)
  1294. {
  1295. CTaskAz* pTaskAz = static_cast<CTaskAz*>(listAzChildObject.GetNext(pos));
  1296. if(pTaskAz->IsRoleDefinition())
  1297. {
  1298. CTaskNode* pTaskAzNode =
  1299. new CTaskNode(GetComponentDataObject(), GetAdminManagerNode(),pTaskAz);
  1300. if(!pTaskAzNode)
  1301. {
  1302. hr = E_OUTOFMEMORY;
  1303. DBG_OUT_HRESULT(hr);
  1304. break;
  1305. }
  1306. VERIFY(AddChildToList(pTaskAzNode));
  1307. }
  1308. else
  1309. {
  1310. delete pTaskAz;
  1311. }
  1312. }
  1313. return TRUE;
  1314. }
  1315. /******************************************************************************
  1316. Class: CTaskCollectionNode
  1317. Purpose: Snapin Node under which all the Tasks will be listed
  1318. ******************************************************************************/
  1319. OBJECT_TYPE_AZ CTaskCollectionNode::childObjectTypes[] = {TASK_AZ,AZ_ENUM_END,};
  1320. CTaskCollectionNode
  1321. ::CTaskCollectionNode(CRoleComponentDataObject * pComponentDataObject,
  1322. CAdminManagerNode* pAdminManagerNode,CContainerAz* pContainerAzObject)
  1323. :CCollectionNode(pComponentDataObject,
  1324. pAdminManagerNode,childObjectTypes,
  1325. CTaskCollectionNodeMenuHolder::GetContextMenuItem(),
  1326. pContainerAzObject,
  1327. IDS_NAME,
  1328. IDS_TYPE,
  1329. IDS_DESC)
  1330. {
  1331. }
  1332. CTaskCollectionNode::~CTaskCollectionNode()
  1333. {
  1334. }
  1335. void CTaskCollectionNode::
  1336. DoCommand(LONG nCommandID,
  1337. CComponentDataObject*,
  1338. CNodeList*)
  1339. {
  1340. if(IDM_TASK_CONTAINER_NEW_TASK == nCommandID)
  1341. {
  1342. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1343. CNewTaskDlg dlgNewTask(GetComponentDataObject(),
  1344. this,
  1345. IDD_NEW_TASK,
  1346. FALSE);
  1347. dlgNewTask.DoModal();
  1348. }
  1349. }
  1350. BOOL
  1351. CTaskCollectionNode::
  1352. OnEnumerate(CComponentDataObject*, BOOL )
  1353. {
  1354. //Clear All Children
  1355. RemoveAllChildrenFromList();
  1356. CList<CBaseAz*,CBaseAz*> listAzChildObject;
  1357. CContainerAz* pContainerAz = GetContainerAzObject();
  1358. HRESULT hr = pContainerAz->GetAzChildObjects(TASK_AZ,
  1359. listAzChildObject);
  1360. if(FAILED(hr))
  1361. {
  1362. //Display Error
  1363. CString strError;
  1364. GetSystemError(strError, hr);
  1365. //Display Generic Error Message
  1366. DisplayError(NULL,
  1367. IDS_GENERIC_ENUMERATE_ERROR,
  1368. (LPWSTR)(LPCWSTR)strError);
  1369. return FALSE;
  1370. }
  1371. POSITION pos = listAzChildObject.GetHeadPosition();
  1372. for (int i=0;i < listAzChildObject.GetCount();i++)
  1373. {
  1374. CTaskAz* pTaskAz = static_cast<CTaskAz*>(listAzChildObject.GetNext(pos));
  1375. if(!pTaskAz->IsRoleDefinition())
  1376. {
  1377. CTaskNode* pTaskAzNode =
  1378. new CTaskNode(GetComponentDataObject(), GetAdminManagerNode(),pTaskAz);
  1379. if(!pTaskAzNode)
  1380. {
  1381. hr = E_OUTOFMEMORY;
  1382. DBG_OUT_HRESULT(hr);
  1383. break;
  1384. }
  1385. VERIFY(AddChildToList(pTaskAzNode));
  1386. }
  1387. else
  1388. {
  1389. delete pTaskAz;
  1390. }
  1391. }
  1392. return TRUE;
  1393. }
  1394. /******************************************************************************
  1395. Class: COperationCollectionNode
  1396. Purpose: Snapin Node under which all the Operations will be listed
  1397. ******************************************************************************/
  1398. OBJECT_TYPE_AZ COperationCollectionNode::childObjectTypes[] = {OPERATION_AZ,AZ_ENUM_END,};
  1399. COperationCollectionNode
  1400. ::COperationCollectionNode(CRoleComponentDataObject * pComponentDataObject,
  1401. CAdminManagerNode* pAdminManagerNode,CContainerAz* pContainerAzObject)
  1402. :CCollectionNode(pComponentDataObject,pAdminManagerNode,childObjectTypes,
  1403. COperationCollectionNodeMenuHolder::GetContextMenuItem(),
  1404. pContainerAzObject,
  1405. IDS_NAME,
  1406. IDS_TYPE,
  1407. IDS_DESC)
  1408. {
  1409. }
  1410. COperationCollectionNode::~COperationCollectionNode()
  1411. {
  1412. }
  1413. void COperationCollectionNode::
  1414. DoCommand(LONG nCommandID,
  1415. CComponentDataObject*,
  1416. CNodeList*)
  1417. {
  1418. if(IDM_OPERATION_CONTAINER_NEW_OPERATION == nCommandID)
  1419. {
  1420. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1421. CNewOperationDlg dlgNewOperation(GetComponentDataObject(),
  1422. this);
  1423. dlgNewOperation.DoModal();
  1424. }
  1425. }
  1426. /******************************************************************************
  1427. Class: CDefinitionCollectionNode
  1428. Purpose: Snapin Node under which all the Definions nodes will be listed
  1429. ******************************************************************************/
  1430. CDefinitionCollectionNode::
  1431. CDefinitionCollectionNode(CRoleComponentDataObject * pComponentDataObject,
  1432. CAdminManagerNode* pAdminManagerNode,CContainerAz* pContainerAzObject)
  1433. :CCollectionNode(pComponentDataObject,
  1434. pAdminManagerNode,
  1435. NULL,
  1436. NULL,
  1437. pContainerAzObject,
  1438. IDS_NAME,
  1439. IDS_TYPE,
  1440. IDS_DESC)
  1441. {
  1442. }
  1443. CDefinitionCollectionNode::
  1444. ~CDefinitionCollectionNode()
  1445. {
  1446. }
  1447. BOOL
  1448. CDefinitionCollectionNode::
  1449. OnEnumerate(CComponentDataObject*, BOOL /*bAsync*/ )
  1450. {
  1451. CContainerAz * pContainerAz = GetContainerAzObject();
  1452. if(!pContainerAz)
  1453. {
  1454. ASSERT(pContainerAz);
  1455. return FALSE;
  1456. }
  1457. HRESULT hr = S_OK;
  1458. do
  1459. {
  1460. hr = AddAzCollectionNode(ROLE_DEFINITION_COLLECTION_AZ);
  1461. BREAK_ON_FAIL_HRESULT(hr);
  1462. hr = AddAzCollectionNode(TASK_COLLECTION_AZ);
  1463. BREAK_ON_FAIL_HRESULT(hr);
  1464. if(pContainerAz->GetObjectType() == APPLICATION_AZ)
  1465. {
  1466. //Operation Node is only displayed in Developer Mode
  1467. if(((CRoleRootData*)GetRootContainer())->IsDeveloperMode())
  1468. {
  1469. hr = AddAzCollectionNode(OPERATION_COLLECTION_AZ);
  1470. }
  1471. }
  1472. }while(0);
  1473. if(FAILED(hr))
  1474. {
  1475. //Display Error
  1476. CString strError;
  1477. GetSystemError(strError, hr);
  1478. //Display Generic Error Message
  1479. DisplayError(NULL,
  1480. IDS_GENERIC_ENUMERATE_ERROR,
  1481. (LPWSTR)(LPCWSTR)strError);
  1482. RemoveAllChildrenFromList();
  1483. return FALSE;
  1484. }
  1485. return TRUE;
  1486. }
  1487. DEBUG_DECLARE_INSTANCE_COUNTER(CRoleNode)
  1488. CRoleNode::
  1489. CRoleNode(CRoleComponentDataObject * pComponentDataObject,
  1490. CAdminManagerNode* pAdminManagerNode,
  1491. CRoleAz * pRoleAz)
  1492. :CBaseNode(pComponentDataObject,
  1493. pAdminManagerNode,
  1494. pRoleAz,
  1495. iIconRole),
  1496. m_pColumnSet(NULL)
  1497. {
  1498. DEBUG_INCREMENT_INSTANCE_COUNTER(CRoleNode)
  1499. SetDisplayName(GetBaseAzObject()->GetName());
  1500. }
  1501. CRoleNode::
  1502. ~CRoleNode()
  1503. {
  1504. DEBUG_DECREMENT_INSTANCE_COUNTER(CRoleNode)
  1505. }
  1506. BOOL
  1507. CRoleNode::
  1508. OnEnumerate(CComponentDataObject* pComponentData, BOOL)
  1509. {
  1510. TRACE_METHOD_EX(DEB_SNAPIN, CRoleNode, OnEnumerate)
  1511. //Clear All Children
  1512. RemoveAllChildrenFromList();
  1513. CList<CBaseAz*,CBaseAz*> listObjectsAppMember;
  1514. //Get Application Group Members
  1515. HRESULT hr = GetBaseAzObject()->GetMembers(AZ_PROP_ROLE_APP_MEMBERS,
  1516. listObjectsAppMember);
  1517. if(SUCCEEDED(hr))
  1518. {
  1519. AddObjectsFromListToSnapin(listObjectsAppMember,
  1520. pComponentData,
  1521. FALSE);
  1522. }
  1523. //Get Member Windows Users/Groups
  1524. CList<CBaseAz*,CBaseAz*> listObjectsMember;
  1525. hr = GetBaseAzObject()->GetMembers(AZ_PROP_ROLE_MEMBERS,
  1526. listObjectsMember);
  1527. if(SUCCEEDED(hr))
  1528. {
  1529. AddObjectsFromListToSnapin(listObjectsMember,
  1530. pComponentData,
  1531. FALSE);
  1532. }
  1533. return TRUE; // there are already children, add them to the UI now
  1534. }
  1535. //+----------------------------------------------------------------------------
  1536. // Function:AssignUsersAndGroups
  1537. // Synopsis:Function assigns Users and Groups to Role
  1538. // Arguments:
  1539. // Returns:
  1540. //-----------------------------------------------------------------------------
  1541. void
  1542. CRoleNode::
  1543. AssignUsersAndGroups(IN CComponentDataObject* pComponentData,
  1544. ULONG nCommandID)
  1545. {
  1546. TRACE_METHOD_EX(DEB_SNAPIN,CRoleNode,AssignUsersAndGroups)
  1547. if(!pComponentData)
  1548. {
  1549. ASSERT(FALSE);
  1550. return ;
  1551. }
  1552. HRESULT hr = S_OK;
  1553. //Get the MMC Framework window handle
  1554. HWND hwnd;
  1555. hr = (pComponentData->GetConsole())->GetMainWindow(&hwnd);
  1556. if(FAILED(hr))
  1557. {
  1558. Dbg(DEB_SNAPIN,"Failed to get MainWindow handle\n");
  1559. return;
  1560. }
  1561. CList<CBaseAz*,CBaseAz*> listObjectsSelected;
  1562. if(nCommandID == IDM_ROLE_NODE_ASSIGN_APPLICATION_GROUPS)
  1563. {
  1564. //Display Add Groups dialog box and get list of users to add
  1565. if(!GetSelectedAzObjects(hwnd,
  1566. GROUP_AZ,
  1567. GetBaseAzObject()->GetParentAz(),
  1568. listObjectsSelected))
  1569. {
  1570. return;
  1571. }
  1572. }
  1573. else if(nCommandID == IDM_ROLE_NODE_ASSIGN_WINDOWS_GROUPS)
  1574. {
  1575. CSidHandler* pSidHandler = GetSidHandler();
  1576. ASSERT(pSidHandler);
  1577. //Display Object Picker and get list of Users to add
  1578. hr = pSidHandler->GetUserGroup(hwnd,
  1579. GetBaseAzObject(),
  1580. listObjectsSelected);
  1581. if(FAILED(hr))
  1582. {
  1583. return;
  1584. }
  1585. }
  1586. else
  1587. {
  1588. ASSERT(FALSE);
  1589. return;
  1590. }
  1591. //Determine which property to modify
  1592. ULONG lPropId = (nCommandID == IDM_ROLE_NODE_ASSIGN_APPLICATION_GROUPS)
  1593. ? AZ_PROP_ROLE_APP_MEMBERS
  1594. :AZ_PROP_ROLE_MEMBERS;
  1595. CList<CBaseAz*, CBaseAz*> listObjectsAdded;
  1596. //Add the list of Selected Users/Group to lPropId property of
  1597. //Role
  1598. while(listObjectsSelected.GetCount())
  1599. {
  1600. CBaseAz* pMember = listObjectsSelected.RemoveHead();
  1601. hr = GetBaseAzObject()->AddMember(lPropId,
  1602. pMember);
  1603. if(hr == HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS))
  1604. {
  1605. hr = S_OK;
  1606. delete pMember;
  1607. }
  1608. else if(SUCCEEDED(hr))
  1609. {
  1610. //Successfully Added. Add it to the list of objectsAdded.
  1611. listObjectsAdded.AddTail(pMember);
  1612. }
  1613. else
  1614. {
  1615. //Display Generic Error.
  1616. CString strError;
  1617. GetSystemError(strError, hr);
  1618. ::DisplayError(NULL,
  1619. IDS_ERROR_ADD_MEMBER_OBJECT,
  1620. (LPCTSTR)strError,
  1621. (LPCTSTR)pMember->GetName());
  1622. delete pMember;
  1623. hr = S_OK;
  1624. }
  1625. }
  1626. //Do the submit, if Atleast one object has been added
  1627. if(listObjectsAdded.GetCount())
  1628. {
  1629. hr = GetBaseAzObject()->Submit();
  1630. if(FAILED(hr))
  1631. {
  1632. RemoveItemsFromList(listObjectsAdded);
  1633. }
  1634. }
  1635. //For each objects in listObjectAdded, create a snapin node
  1636. //and add it to snapin
  1637. AddObjectsFromListToSnapin(listObjectsAdded,
  1638. pComponentData,
  1639. TRUE);
  1640. }
  1641. //+----------------------------------------------------------------------------
  1642. // Function:AddObjectsFromListToSnapin
  1643. // Synopsis:Take objects from List and creates corresponding snapin nodes for
  1644. // them.
  1645. //-----------------------------------------------------------------------------
  1646. void
  1647. CRoleNode::
  1648. AddObjectsFromListToSnapin(CList<CBaseAz*,CBaseAz*> &listObjects,
  1649. CComponentDataObject* pComponentData,
  1650. BOOL bAddToUI)
  1651. {
  1652. TRACE_METHOD_EX(DEB_SNAPIN,CRoleNode,AddObjectsFromListToSnapin)
  1653. if(!pComponentData)
  1654. {
  1655. ASSERT(pComponentData);
  1656. return;
  1657. }
  1658. HRESULT hr = S_OK;
  1659. while(listObjects.GetCount())
  1660. {
  1661. CBaseAz* pObjectToAdd = listObjects.RemoveHead();
  1662. if(pObjectToAdd->GetObjectType() == GROUP_AZ)
  1663. {
  1664. CGroupNode* pGroupNode = new CGroupNode(GetComponentDataObject(),
  1665. GetAdminManagerNode(),
  1666. pObjectToAdd,
  1667. (CRoleAz*)GetBaseAzObject());
  1668. if(!pGroupNode)
  1669. {
  1670. hr = E_OUTOFMEMORY;
  1671. break;
  1672. }
  1673. if(bAddToUI)
  1674. {
  1675. VERIFY(AddChildToListAndUI(pGroupNode,pComponentData));
  1676. }
  1677. else
  1678. {
  1679. VERIFY(AddChildToList(pGroupNode));
  1680. }
  1681. }
  1682. else
  1683. {
  1684. ASSERT(pObjectToAdd->GetObjectType() == SIDCACHE_AZ);
  1685. CSidCacheNode* pSidNode = new CSidCacheNode(GetComponentDataObject(),
  1686. GetAdminManagerNode(),
  1687. pObjectToAdd,
  1688. (CRoleAz*)GetBaseAzObject());
  1689. if(!pSidNode)
  1690. {
  1691. hr = E_OUTOFMEMORY;
  1692. break;
  1693. }
  1694. if(bAddToUI)
  1695. {
  1696. VERIFY(AddChildToListAndUI(pSidNode,pComponentData));
  1697. }
  1698. else
  1699. {
  1700. VERIFY(AddChildToList(pSidNode));
  1701. }
  1702. }
  1703. }
  1704. if(FAILED(hr))
  1705. {
  1706. RemoveItemsFromList(listObjects);
  1707. }
  1708. }
  1709. HRESULT
  1710. CRoleNode::
  1711. GetResultViewType(CComponentDataObject* /*pComponentData*/,
  1712. LPOLESTR* ppViewType,
  1713. long* pViewOptions)
  1714. {
  1715. TRACE_METHOD_EX(DEB_SNAPIN,CRoleNode,GetResultViewType)
  1716. if(!pViewOptions || !ppViewType)
  1717. {
  1718. ASSERT(FALSE);
  1719. return E_POINTER;
  1720. }
  1721. *pViewOptions = MMC_VIEW_OPTIONS_MULTISELECT;
  1722. *ppViewType = NULL;
  1723. return S_FALSE;
  1724. }
  1725. BOOL
  1726. CRoleNode::
  1727. OnAddMenuItem(LPCONTEXTMENUITEM2 pContextMenuItem2,
  1728. long*)
  1729. {
  1730. TRACE_METHOD_EX(DEB_SNAPIN,CRoleNode,OnAddMenuItem)
  1731. if(!pContextMenuItem2)
  1732. {
  1733. ASSERT(FALSE);
  1734. return FALSE;
  1735. }
  1736. BOOL bWrite = FALSE;
  1737. HRESULT hr = GetBaseAzObject()->IsWritable(bWrite);
  1738. if(SUCCEEDED(hr) && bWrite)
  1739. return TRUE;
  1740. else
  1741. return FALSE;
  1742. }
  1743. CColumnSet*
  1744. CRoleNode::
  1745. GetColumnSet()
  1746. {
  1747. TRACE_METHOD_EX(DEB_SNAPIN, CRoleNode, GetColumnSet);
  1748. if (m_pColumnSet == NULL)
  1749. {
  1750. m_pColumnSet = GetComponentDataObject()->GetColumnSet(L"---Default Column Set---");
  1751. }
  1752. ASSERT(m_pColumnSet);
  1753. return m_pColumnSet;
  1754. }
  1755. LPCWSTR CRoleNode::
  1756. GetString(int nCol)
  1757. {
  1758. if(nCol == 0)
  1759. return GetBaseAzObject()->GetName();
  1760. if( nCol == 1)
  1761. return GetBaseAzObject()->GetType();
  1762. if( nCol == 2)
  1763. return GetBaseAzObject()->GetDescription();
  1764. ASSERT(FALSE);
  1765. return NULL;
  1766. }
  1767. int
  1768. CRoleNode::
  1769. GetImageIndex(BOOL /*bOpenImage*/)
  1770. {
  1771. return GetBaseAzObject()->GetImageIndex();
  1772. }
  1773. HRESULT
  1774. CRoleNode::
  1775. OnCommand(long nCommandID,
  1776. DATA_OBJECT_TYPES,
  1777. CComponentDataObject* pComponentData,
  1778. CNodeList* pNodeList)
  1779. {
  1780. TRACE_METHOD_EX(DEB_SNAPIN,CAdminManagerNode,OnCommand)
  1781. if(!pComponentData || !pNodeList)
  1782. {
  1783. ASSERT(pComponentData);
  1784. ASSERT(pNodeList);
  1785. return E_POINTER;
  1786. }
  1787. if(pNodeList->GetCount() > 1)
  1788. {
  1789. return E_FAIL;
  1790. }
  1791. if((nCommandID == IDM_ROLE_NODE_ASSIGN_APPLICATION_GROUPS) ||
  1792. (nCommandID == IDM_ROLE_NODE_ASSIGN_WINDOWS_GROUPS))
  1793. {
  1794. AssignUsersAndGroups(pComponentData,
  1795. nCommandID);
  1796. return S_OK;
  1797. }
  1798. ASSERT(FALSE);
  1799. return E_UNEXPECTED;
  1800. }
  1801. //
  1802. //Helper Functions
  1803. //
  1804. BOOL
  1805. CRoleNode::
  1806. OnSetDeleteVerbState(DATA_OBJECT_TYPES /*type*/,
  1807. BOOL* pbHide,
  1808. CNodeList* /*pNodeList*/)
  1809. {
  1810. if(!pbHide)
  1811. {
  1812. ASSERT(pbHide);
  1813. return FALSE;
  1814. }
  1815. BOOL bWrite = FALSE;
  1816. HRESULT hr = GetBaseAzObject()->IsWritable(bWrite);
  1817. if(FAILED(hr) || !bWrite)
  1818. {
  1819. *pbHide = TRUE;
  1820. return FALSE;
  1821. }
  1822. else
  1823. {
  1824. *pbHide = FALSE;
  1825. return TRUE;
  1826. }
  1827. return TRUE;
  1828. }
  1829. void
  1830. CRoleNode::
  1831. OnDelete(CComponentDataObject* pComponentData,
  1832. CNodeList* pNodeList)
  1833. {
  1834. GenericDeleteRoutine(this,pComponentData,pNodeList,TRUE);
  1835. }
  1836. BOOL
  1837. CRoleNode::
  1838. HasPropertyPages(DATA_OBJECT_TYPES /*type*/,
  1839. BOOL* pbHideVerb,
  1840. CNodeList* pNodeList)
  1841. {
  1842. if (!pNodeList || !pbHideVerb)
  1843. {
  1844. ASSERT(pNodeList);
  1845. ASSERT(pbHideVerb);
  1846. return FALSE;
  1847. }
  1848. if (pNodeList->GetCount() == 1) // single selection
  1849. {
  1850. *pbHideVerb = FALSE; // always show the verb
  1851. return TRUE;
  1852. }
  1853. // Multiple selection
  1854. *pbHideVerb = TRUE;
  1855. return FALSE;
  1856. }
  1857. HRESULT
  1858. CRoleNode::
  1859. CreatePropertyPages(LPPROPERTYSHEETCALLBACK lpProvider,
  1860. LONG_PTR handle,
  1861. CNodeList* pNodeList)
  1862. {
  1863. if(!lpProvider || !pNodeList)
  1864. {
  1865. ASSERT(lpProvider);
  1866. ASSERT(pNodeList);
  1867. return E_POINTER;
  1868. }
  1869. if(!CanReadOneProperty(GetDisplayName(),
  1870. GetBaseAzObject()))
  1871. return E_FAIL;
  1872. HRESULT hr = S_OK;
  1873. if (pNodeList->GetCount() > 1)
  1874. {
  1875. return hr;
  1876. }
  1877. CRolePropertyPageHolder* pHolder = NULL;
  1878. do
  1879. {
  1880. CComponentDataObject* pComponentDataObject = GetComponentDataObject();
  1881. ASSERT(pComponentDataObject);
  1882. pHolder = new CRolePropertyPageHolder(GetContainer(),
  1883. this,
  1884. pComponentDataObject);
  1885. if(!pHolder)
  1886. {
  1887. hr = E_OUTOFMEMORY;
  1888. break;
  1889. }
  1890. //Add Property Pages
  1891. //Add General Property Page
  1892. CRoleGeneralPropertyPage * pGenPropPage =
  1893. new CRoleGeneralPropertyPage(GetBaseAzObject(),
  1894. this);
  1895. if(!pGenPropPage)
  1896. {
  1897. hr = E_OUTOFMEMORY;
  1898. break;
  1899. }
  1900. pHolder->AddPageToList(pGenPropPage);
  1901. return pHolder->CreateModelessSheet(lpProvider, handle);
  1902. }while(0);
  1903. if(FAILED(hr))
  1904. {
  1905. if(pHolder)
  1906. delete pHolder;
  1907. }
  1908. return hr;
  1909. }
  1910. void
  1911. CRoleNode
  1912. ::OnPropertyChange(CComponentDataObject* pComponentData,
  1913. BOOL bScopePane,
  1914. long changeMask)
  1915. {
  1916. if(!pComponentData)
  1917. {
  1918. ASSERT(pComponentData);
  1919. return;
  1920. }
  1921. SetDisplayName(GetBaseAzObject()->GetName());
  1922. CTreeNode::OnPropertyChange(pComponentData,
  1923. bScopePane,
  1924. changeMask);
  1925. }