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.

2108 lines
62 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2000 - 2001.
  5. //
  6. // File: NewObjectDlg.cpp
  7. //
  8. // Contents: Dialog Boxes for creating new objects
  9. //
  10. // History: 08-16-2001 Hiteshr Created
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "headers.h"
  14. /******************************************************************************
  15. Class: CSortListCtrl
  16. Purpose:Subclases ListCtrl class and handles initialization and sorting
  17. ******************************************************************************/
  18. BEGIN_MESSAGE_MAP(CSortListCtrl, CListCtrl)
  19. ON_NOTIFY_REFLECT(LVN_COLUMNCLICK, OnListCtrlColumnClicked)
  20. END_MESSAGE_MAP()
  21. void
  22. CSortListCtrl::
  23. Initialize()
  24. {
  25. TRACE_METHOD_EX(DEB_SNAPIN,CSortListCtrl,Initialize)
  26. //
  27. //Add Imagelist
  28. //
  29. ListView_SetImageList(GetSafeHwnd(),
  30. LoadImageList(::AfxGetInstanceHandle (),
  31. MAKEINTRESOURCE(IDB_ICONS)),
  32. LVSIL_SMALL);
  33. //Add ListBox Extended Style
  34. if(m_bCheckBox)
  35. {
  36. SetExtendedStyle(LVS_EX_FULLROWSELECT|
  37. LVS_EX_INFOTIP|
  38. LVS_EX_CHECKBOXES);
  39. }
  40. else
  41. {
  42. SetExtendedStyle(LVS_EX_FULLROWSELECT|
  43. LVS_EX_INFOTIP);
  44. }
  45. //Add List box Columns
  46. AddColumnToListView(this,
  47. m_pColForLv);
  48. }
  49. void
  50. CSortListCtrl::
  51. OnListCtrlColumnClicked(NMHDR* pNotifyStruct, LRESULT* /*pResult*/)
  52. {
  53. TRACE_METHOD_EX(DEB_SNAPIN,CSortListCtrl,OnListCtrlColumnClicked)
  54. if(!pNotifyStruct)
  55. {
  56. ASSERT(pNotifyStruct);
  57. return;
  58. }
  59. LPNM_LISTVIEW pnmlv = (LPNM_LISTVIEW)pNotifyStruct;
  60. if (m_iLastColumnClick == pnmlv->iSubItem)
  61. m_iSortDirection = -m_iSortDirection;
  62. else
  63. m_iSortDirection = 1;
  64. m_iLastColumnClick = pnmlv->iSubItem;
  65. ::SortListControl(this,
  66. m_iLastColumnClick,
  67. m_iSortDirection,
  68. m_uiFlags,
  69. m_bActionItem);
  70. EnsureListViewSelectionIsVisible(this);
  71. }
  72. void
  73. CSortListCtrl::
  74. Sort()
  75. {
  76. TRACE_METHOD_EX(DEB_SNAPIN,CSortListCtrl,Sort)
  77. ::SortListControl(this,
  78. m_iLastColumnClick,
  79. m_iSortDirection,
  80. m_uiFlags,
  81. m_bActionItem);
  82. EnsureListViewSelectionIsVisible(this);
  83. }
  84. /******************************************************************************
  85. Class: CHelpEnabledDialog
  86. Purpose:Dialog box class with support for displaying help
  87. ******************************************************************************/
  88. BEGIN_MESSAGE_MAP(CHelpEnabledDialog, CDialog)
  89. ON_WM_CONTEXTMENU()
  90. ON_MESSAGE(WM_HELP, OnHelp)
  91. END_MESSAGE_MAP()
  92. BOOL
  93. CHelpEnabledDialog::
  94. OnHelp(WPARAM /*wParam*/, LPARAM lParam)
  95. {
  96. DWORD_PTR pHelpMap = NULL;
  97. if(FindDialogContextTopic(m_nDialogId, &pHelpMap))
  98. {
  99. ASSERT(pHelpMap);
  100. ::WinHelp((HWND)((LPHELPINFO)lParam)->hItemHandle,
  101. g_szContextHelpFileName,
  102. HELP_WM_HELP,
  103. pHelpMap);
  104. return TRUE;
  105. }
  106. return FALSE;
  107. }
  108. void
  109. CHelpEnabledDialog::
  110. OnContextMenu(CWnd* /*pWnd*/, CPoint /*point*/)
  111. {
  112. DWORD_PTR pHelpMap = NULL;
  113. if(FindDialogContextTopic(m_nDialogId, &pHelpMap))
  114. {
  115. ::WinHelp(m_hWnd,
  116. g_szContextHelpFileName,
  117. HELP_CONTEXTMENU,
  118. (DWORD_PTR)pHelpMap);
  119. }
  120. }
  121. INT_PTR
  122. CHelpEnabledDialog::
  123. DoModal()
  124. {
  125. CThemeContextActivator activator;
  126. return CDialog::DoModal();
  127. }
  128. /******************************************************************************
  129. Class: CNewBaseDlg
  130. Purpose: Base Dialog Class For creation of new objects
  131. ******************************************************************************/
  132. BEGIN_MESSAGE_MAP(CNewBaseDlg, CHelpEnabledDialog)
  133. //{{AFX_MSG_MAP(CNewBaseDlg)
  134. ON_EN_CHANGE(IDC_EDIT_NAME, OnEditChangeName)
  135. //}}AFX_MSG_MAP
  136. END_MESSAGE_MAP()
  137. //+----------------------------------------------------------------------------
  138. // Function:Constructor
  139. //-----------------------------------------------------------------------------
  140. CNewBaseDlg
  141. ::CNewBaseDlg(IN CComponentDataObject* pComponentData,
  142. IN CBaseContainerNode * pBaseContainerNode,
  143. IN ATTR_MAP* pAttrMap,
  144. IN ULONG IDD_DIALOG,
  145. IN OBJECT_TYPE_AZ eObjectType)
  146. :CHelpEnabledDialog(IDD_DIALOG),
  147. m_pComponentData(pComponentData),
  148. m_pBaseContainerNode(pBaseContainerNode),
  149. m_eObjectType(eObjectType),
  150. m_pAttrMap(pAttrMap)
  151. {
  152. TRACE_CONSTRUCTOR_EX(DEB_SNAPIN,CNewBaseDlg);
  153. ASSERT(m_pComponentData);
  154. }
  155. //+----------------------------------------------------------------------------
  156. // Function:Destructor
  157. //-----------------------------------------------------------------------------
  158. CNewBaseDlg
  159. ::~CNewBaseDlg()
  160. {
  161. TRACE_DESTRUCTOR_EX(DEB_SNAPIN,CNewBaseDlg)
  162. }
  163. BOOL
  164. CNewBaseDlg
  165. ::OnInitDialog()
  166. {
  167. CDialog::OnInitDialog();
  168. //
  169. //Ok is Enabled only when there is text in Name edit box
  170. //
  171. CButton* pButtonOK = (CButton*)GetDlgItem(IDOK);
  172. pButtonOK->EnableWindow(FALSE);
  173. //When OK is disabled CANCEL is default button
  174. SetDefID(IDCANCEL);
  175. if(m_pAttrMap)
  176. {
  177. return InitDlgFromAttrMap(this,
  178. m_pAttrMap,
  179. NULL,
  180. FALSE);
  181. }
  182. return TRUE;
  183. }
  184. void
  185. CNewBaseDlg
  186. ::OnEditChangeName()
  187. {
  188. CButton* pBtnOK = (CButton*)GetDlgItem(IDOK);
  189. CButton* pBtnCancel = (CButton*)GetDlgItem(IDCANCEL);
  190. CString strName = GetNameText();
  191. if(!strName.IsEmpty())
  192. {
  193. pBtnOK->EnableWindow(TRUE);
  194. SetDefID(IDOK);
  195. }
  196. else
  197. {
  198. //When OK is disabled CANCEL is default button
  199. pBtnOK->EnableWindow(FALSE);
  200. SetDefID(IDCANCEL);
  201. }
  202. }
  203. CString
  204. CNewBaseDlg::GetNameText()
  205. {
  206. CEdit* pEditStoreName = (CEdit*)GetDlgItem(IDC_EDIT_NAME);
  207. ASSERT(pEditStoreName);
  208. CString strEditStoreName;
  209. pEditStoreName->GetWindowText(strEditStoreName);
  210. TrimWhiteSpace(strEditStoreName);
  211. return strEditStoreName;
  212. }
  213. void
  214. CNewBaseDlg::
  215. SetNameText(const CString& strName)
  216. {
  217. CEdit* pEditStoreName = (CEdit*)GetDlgItem(IDC_EDIT_NAME);
  218. ASSERT(pEditStoreName);
  219. pEditStoreName->SetWindowText(strName);
  220. }
  221. void
  222. CNewBaseDlg::OnOK()
  223. {
  224. CBaseAz* pNewObjectAz = NULL;
  225. HRESULT hr = S_OK;
  226. BOOL bErrorDisplayed= FALSE;
  227. do
  228. {
  229. //Create New Object
  230. CString strName = GetNameText();
  231. ASSERT(!strName.IsEmpty());
  232. CContainerAz* pContainerAz = GetContainerAzObject();
  233. if(!pContainerAz)
  234. {
  235. ASSERT(pContainerAz);
  236. return;
  237. }
  238. //Create Object
  239. hr = pContainerAz->CreateAzObject(m_eObjectType,
  240. strName,
  241. &pNewObjectAz);
  242. BREAK_ON_FAIL_HRESULT(hr);
  243. //Save the properties defined by attribute map
  244. if(m_pAttrMap)
  245. {
  246. hr = SaveAttrMapChanges(this,
  247. m_pAttrMap,
  248. pNewObjectAz,
  249. TRUE,
  250. &bErrorDisplayed,
  251. NULL);
  252. BREAK_ON_FAIL_HRESULT(hr);
  253. }
  254. //Set ObjectType Specific Properties
  255. hr = SetObjectTypeSpecificProperties(pNewObjectAz, bErrorDisplayed);
  256. BREAK_ON_FAIL_HRESULT(hr);
  257. //Do the submit on the object
  258. hr = pNewObjectAz->Submit();
  259. BREAK_ON_FAIL_HRESULT(hr);
  260. //Create correponding container/leaf node for the AzObject
  261. //and add it to the snapin
  262. VERIFY(SUCCEEDED(CreateObjectNodeAndAddToUI(pNewObjectAz)));
  263. }while(0);
  264. if(SUCCEEDED(hr))
  265. {
  266. CDialog::OnOK();
  267. }
  268. else
  269. {
  270. if(!bErrorDisplayed)
  271. DisplayError(hr);
  272. if(pNewObjectAz)
  273. delete pNewObjectAz;
  274. }
  275. }
  276. HRESULT
  277. CNewBaseDlg::
  278. CreateObjectNodeAndAddToUI(CBaseAz* pBaseAz)
  279. {
  280. TRACE_METHOD_EX(DEB_SNAPIN,CNewBaseDlg,CreateObjectNodeAndAddToUI)
  281. CTreeNode * pNewNode = NULL;
  282. if(!GetBaseContainerNode())
  283. {
  284. ASSERT(GetBaseContainerNode());
  285. return E_UNEXPECTED;
  286. }
  287. switch(m_eObjectType)
  288. {
  289. case APPLICATION_AZ:
  290. {
  291. CApplicationAz* pApplicationAz = dynamic_cast<CApplicationAz*>(pBaseAz);
  292. if(!pApplicationAz)
  293. {
  294. ASSERT(FALSE);
  295. return E_UNEXPECTED;
  296. }
  297. pNewNode = new CApplicationNode(GetBaseContainerNode()->GetComponentDataObject(),
  298. GetBaseContainerNode()->GetAdminManagerNode(),
  299. pApplicationAz);
  300. break;
  301. }
  302. case SCOPE_AZ:
  303. {
  304. CScopeAz* pScopeAz = dynamic_cast<CScopeAz*>(pBaseAz);
  305. if(!pScopeAz)
  306. {
  307. ASSERT(FALSE);
  308. return E_UNEXPECTED;
  309. }
  310. pNewNode = new CScopeNode(GetBaseContainerNode()->GetComponentDataObject(),
  311. GetBaseContainerNode()->GetAdminManagerNode(),
  312. pScopeAz);
  313. break;
  314. }
  315. case GROUP_AZ:
  316. {
  317. CGroupAz* pGroupAz = dynamic_cast<CGroupAz*>(pBaseAz);
  318. if(!pGroupAz)
  319. {
  320. ASSERT(FALSE);
  321. return E_UNEXPECTED;
  322. }
  323. pNewNode = new CGroupNode(GetBaseContainerNode()->GetComponentDataObject(),
  324. GetBaseContainerNode()->GetAdminManagerNode(),
  325. pGroupAz);
  326. break;
  327. }
  328. case TASK_AZ:
  329. {
  330. CTaskAz* pTaskAz = dynamic_cast<CTaskAz*>(pBaseAz);
  331. if(!pTaskAz)
  332. {
  333. ASSERT(FALSE);
  334. return E_UNEXPECTED;
  335. }
  336. pNewNode = new CTaskNode(GetBaseContainerNode()->GetComponentDataObject(),
  337. GetBaseContainerNode()->GetAdminManagerNode(),
  338. pTaskAz);
  339. break;
  340. }
  341. case ROLE_AZ:
  342. {
  343. CRoleAz* pRoleAz = dynamic_cast<CRoleAz*>(pBaseAz);
  344. if(!pRoleAz)
  345. {
  346. ASSERT(FALSE);
  347. return E_UNEXPECTED;
  348. }
  349. pNewNode = new CRoleNode(GetBaseContainerNode()->GetComponentDataObject(),
  350. GetBaseContainerNode()->GetAdminManagerNode(),
  351. pRoleAz);
  352. break;
  353. }
  354. case OPERATION_AZ:
  355. {
  356. COperationAz* pOperationAz = dynamic_cast<COperationAz*>(pBaseAz);
  357. if(!pOperationAz)
  358. {
  359. ASSERT(FALSE);
  360. return E_UNEXPECTED;
  361. }
  362. pNewNode = new COperationNode(GetBaseContainerNode()->GetComponentDataObject(),
  363. GetBaseContainerNode()->GetAdminManagerNode(),
  364. pOperationAz);
  365. break;
  366. }
  367. default:
  368. {
  369. ASSERT(FALSE);
  370. break;
  371. }
  372. }
  373. if(!pNewNode)
  374. {
  375. return E_OUTOFMEMORY;
  376. }
  377. VERIFY(GetBaseContainerNode()->AddChildToListAndUI(pNewNode,GetComponentData()));
  378. return S_OK;
  379. }
  380. VOID
  381. CNewBaseDlg::
  382. DisplayError(HRESULT hr)
  383. {
  384. ErrorMap * pErrorMap = GetErrorMap(m_eObjectType);
  385. if(!pErrorMap)
  386. {
  387. ASSERT(FALSE);
  388. return;
  389. }
  390. if(hr == HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS))
  391. {
  392. ::DisplayError(m_hWnd,pErrorMap->idNameAlreadyExist,GetNameText());
  393. return;
  394. }
  395. if(hr == HRESULT_FROM_WIN32(ERROR_INVALID_NAME))
  396. {
  397. ::DisplayError(m_hWnd,pErrorMap->idInvalidName,pErrorMap->pszInvalidChars);
  398. return;
  399. }
  400. //
  401. //Display Generic Error.
  402. //
  403. CString strObjectType;
  404. VERIFY(strObjectType.LoadString(pErrorMap->idObjectType));
  405. strObjectType.MakeLower();
  406. CString strError;
  407. GetSystemError(strError, hr);
  408. if(!strError.IsEmpty())
  409. {
  410. ::DisplayError(m_hWnd,
  411. IDS_CREATE_NEW_GENERIC_ERROR,
  412. (LPCTSTR)strError,
  413. (LPCTSTR)strObjectType);
  414. }
  415. return;
  416. }
  417. /******************************************************************************
  418. Class: CNewApplicationDlg
  419. Purpose: Dlg Class for creating new application
  420. ******************************************************************************/
  421. BEGIN_MESSAGE_MAP(CNewApplicationDlg, CNewBaseDlg)
  422. //{{AFX_MSG_MAP(CNewApplicationDlg)
  423. //}}AFX_MSG_MAP
  424. END_MESSAGE_MAP()
  425. DEBUG_DECLARE_INSTANCE_COUNTER(CNewApplicationDlg)
  426. CNewApplicationDlg
  427. ::CNewApplicationDlg(IN CComponentDataObject* pComponentData,
  428. IN CBaseContainerNode* pBaseContainerNode)
  429. :CNewBaseDlg(pComponentData,
  430. pBaseContainerNode,
  431. ATTR_MAP_NEW_APPLICATION,
  432. IDD_NEW_APPLICATION,
  433. APPLICATION_AZ)
  434. {
  435. TRACE_CONSTRUCTOR_EX(DEB_SNAPIN,CNewApplicationDlg);
  436. DEBUG_INCREMENT_INSTANCE_COUNTER(CNewApplicationDlg)
  437. }
  438. CNewApplicationDlg
  439. ::~CNewApplicationDlg()
  440. {
  441. TRACE_DESTRUCTOR_EX(DEB_SNAPIN,CNewApplicationDlg)
  442. DEBUG_DECREMENT_INSTANCE_COUNTER(CNewApplicationDlg)
  443. }
  444. /******************************************************************************
  445. Class: CNewScopeDlg
  446. Purpose: Dlg Class for creating new scope
  447. ******************************************************************************/
  448. BEGIN_MESSAGE_MAP(CNewScopeDlg, CNewBaseDlg)
  449. //{{AFX_MSG_MAP(CNewScopeDlg)
  450. //}}AFX_MSG_MAP
  451. END_MESSAGE_MAP()
  452. DEBUG_DECLARE_INSTANCE_COUNTER(CNewScopeDlg)
  453. CNewScopeDlg
  454. ::CNewScopeDlg(IN CComponentDataObject* pComponentData,
  455. IN CBaseContainerNode* pBaseContainerNode)
  456. :CNewBaseDlg(pComponentData,
  457. pBaseContainerNode,
  458. ATTR_MAP_NEW_SCOPE,
  459. IDD_NEW_SCOPE,
  460. SCOPE_AZ)
  461. {
  462. TRACE_CONSTRUCTOR_EX(DEB_SNAPIN,CNewScopeDlg);
  463. DEBUG_INCREMENT_INSTANCE_COUNTER(CNewScopeDlg)
  464. }
  465. CNewScopeDlg
  466. ::~CNewScopeDlg()
  467. {
  468. TRACE_DESTRUCTOR_EX(DEB_SNAPIN,CNewScopeDlg)
  469. DEBUG_DECREMENT_INSTANCE_COUNTER(CNewScopeDlg)
  470. }
  471. /******************************************************************************
  472. Class: CNewGroupDlg
  473. Purpose: Dlg Class for creating new group
  474. ******************************************************************************/
  475. BEGIN_MESSAGE_MAP(CNewGroupDlg, CNewBaseDlg)
  476. //{{AFX_MSG_MAP(CNewGroupDlg)
  477. //}}AFX_MSG_MAP
  478. END_MESSAGE_MAP()
  479. DEBUG_DECLARE_INSTANCE_COUNTER(CNewGroupDlg)
  480. CNewGroupDlg
  481. ::CNewGroupDlg(IN CComponentDataObject* pComponentData,
  482. IN CBaseContainerNode* pBaseContainerNode)
  483. :CNewBaseDlg(pComponentData,
  484. pBaseContainerNode,
  485. ATTR_MAP_NEW_GROUP,
  486. IDD_NEW_GROUP,
  487. GROUP_AZ)
  488. {
  489. TRACE_CONSTRUCTOR_EX(DEB_SNAPIN,CNewGroupDlg);
  490. DEBUG_INCREMENT_INSTANCE_COUNTER(CNewGroupDlg)
  491. }
  492. CNewGroupDlg
  493. ::~CNewGroupDlg()
  494. {
  495. TRACE_DESTRUCTOR_EX(DEB_SNAPIN,CNewGroupDlg)
  496. DEBUG_DECREMENT_INSTANCE_COUNTER(CNewGroupDlg)
  497. }
  498. BOOL
  499. CNewGroupDlg
  500. ::OnInitDialog()
  501. {
  502. //Do the base class initialization
  503. CNewBaseDlg::OnInitDialog();
  504. //Basic is the default group type
  505. CButton* pRadio = (CButton*)GetDlgItem(IDC_RADIO_GROUP_TYPE_BASIC);
  506. pRadio->SetCheck(TRUE);
  507. return TRUE;
  508. }
  509. //+----------------------------------------------------------------------------
  510. // Function:SetObjectTypeSpecificProperties
  511. // Synopsis:Sets some propertis which are specicic to the object
  512. // Arguments:pBaseAz: Pointer to baseAz object whose properties are
  513. // to be set
  514. // Returns:
  515. //-----------------------------------------------------------------------------
  516. HRESULT
  517. CNewGroupDlg
  518. ::SetObjectTypeSpecificProperties(CBaseAz* pBaseAz, BOOL&)
  519. {
  520. TRACE_METHOD_EX(DEB_SNAPIN,CNewGroupDlg,SetObjectTypeSpecificProperties);
  521. if(!pBaseAz)
  522. {
  523. ASSERT(pBaseAz);
  524. return E_POINTER;
  525. }
  526. CGroupAz* pGroupAz= dynamic_cast<CGroupAz*>(pBaseAz);
  527. if(!pGroupAz)
  528. {
  529. ASSERT(pGroupAz);
  530. return E_UNEXPECTED;
  531. }
  532. HRESULT hr = S_OK;
  533. //Set Group Type
  534. if(((CButton*)GetDlgItem(IDC_RADIO_GROUP_TYPE_BASIC))->GetCheck())
  535. hr = pGroupAz->SetGroupType(AZ_GROUPTYPE_BASIC);
  536. else
  537. hr = pGroupAz->SetGroupType(AZ_GROUPTYPE_LDAP_QUERY);
  538. CHECK_HRESULT(hr);
  539. return hr;
  540. }
  541. /******************************************************************************
  542. Class: CNewTaskDlg
  543. Purpose: Dlg Class for creating new Task/Role Definition
  544. ******************************************************************************/
  545. BEGIN_MESSAGE_MAP(CNewTaskDlg, CNewBaseDlg)
  546. //{{AFX_MSG_MAP(CNewTaskDlg)
  547. ON_BN_CLICKED(IDC_ADD_TASK, OnButtonAdd)
  548. ON_BN_CLICKED(IDC_REMOVE, OnButtonRemove)
  549. ON_BN_CLICKED(IDC_EDIT_SCRIPT,OnButtonEditScript)
  550. ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST_TASK_OPERATION, OnListCtrlItemChanged)
  551. ON_NOTIFY(LVN_DELETEITEM, IDC_LIST_TASK_OPERATION, OnListCtrlItemDeleted)
  552. //}}AFX_MSG_MAP
  553. END_MESSAGE_MAP()
  554. DEBUG_DECLARE_INSTANCE_COUNTER(CNewTaskDlg)
  555. CNewTaskDlg::
  556. CNewTaskDlg(IN CComponentDataObject* pComponentData,
  557. IN CBaseContainerNode* pBaseContainerNode,
  558. IN ULONG IDD_DIALOG,
  559. IN BOOL bRoleDefinition)
  560. :CNewBaseDlg(pComponentData,
  561. pBaseContainerNode,
  562. ATTR_MAP_NEW_TASK,
  563. IDD_DIALOG,
  564. TASK_AZ),
  565. m_listCtrl(COL_NAME | COL_TYPE | COL_DESCRIPTION,FALSE,Col_For_Task_Role),
  566. m_bRoleDefinition(bRoleDefinition)
  567. {
  568. TRACE_CONSTRUCTOR_EX(DEB_SNAPIN,CNewTaskDlg);
  569. DEBUG_INCREMENT_INSTANCE_COUNTER(CNewTaskDlg)
  570. }
  571. CNewTaskDlg
  572. ::~CNewTaskDlg()
  573. {
  574. TRACE_DESTRUCTOR_EX(DEB_SNAPIN,CNewTaskDlg)
  575. DEBUG_DECREMENT_INSTANCE_COUNTER(CNewTaskDlg)
  576. }
  577. VOID
  578. CNewTaskDlg::
  579. DisplayError(HRESULT hr)
  580. {
  581. ErrorMap * pErrorMap = GetErrorMap(TASK_AZ);
  582. if(!pErrorMap)
  583. {
  584. ASSERT(FALSE);
  585. return;
  586. }
  587. if(hr == HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS))
  588. {
  589. ::DisplayError(m_hWnd,
  590. pErrorMap->idNameAlreadyExist,
  591. GetNameText());
  592. return;
  593. }
  594. if(hr == HRESULT_FROM_WIN32(ERROR_INVALID_NAME))
  595. {
  596. if(m_bRoleDefinition)
  597. {
  598. ::DisplayError(m_hWnd,
  599. IDS_ROLE_DEFINITION_NAME_INVALID,
  600. pErrorMap->pszInvalidChars);
  601. }
  602. else
  603. {
  604. ::DisplayError(m_hWnd,
  605. pErrorMap->idInvalidName,
  606. pErrorMap->pszInvalidChars);
  607. }
  608. return;
  609. }
  610. //
  611. //Display Generic Error.
  612. //
  613. CString strObjectType;
  614. VERIFY(strObjectType.LoadString(pErrorMap->idObjectType));
  615. strObjectType.MakeLower();
  616. CString strError;
  617. GetSystemError(strError, hr);
  618. if(!strError.IsEmpty())
  619. {
  620. ::DisplayError(m_hWnd,
  621. IDS_CREATE_NEW_GENERIC_ERROR,
  622. (LPCTSTR)strError,
  623. (LPCTSTR)strObjectType);
  624. }
  625. return;
  626. }
  627. BOOL
  628. CNewTaskDlg
  629. ::OnInitDialog()
  630. {
  631. CNewBaseDlg::OnInitDialog();
  632. VERIFY(m_listCtrl.SubclassDlgItem(IDC_LIST_TASK_OPERATION,this));
  633. m_listCtrl.Initialize();
  634. //Remove button should be disabled in the begining
  635. CButton* pBtnRemove = (CButton*)GetDlgItem(IDC_REMOVE);
  636. pBtnRemove->EnableWindow(FALSE);
  637. return TRUE;
  638. }
  639. HRESULT
  640. CNewTaskDlg
  641. ::SetObjectTypeSpecificProperties(CBaseAz* pBaseAz, BOOL& refbErrorDisplayed)
  642. {
  643. TRACE_METHOD_EX(DEB_SNAPIN,CNewTaskDlg,SetObjectTypeSpecificProperties);
  644. if(!pBaseAz)
  645. {
  646. ASSERT(pBaseAz);
  647. return E_POINTER;
  648. }
  649. CTaskAz* pTaskAz= dynamic_cast<CTaskAz*>(pBaseAz);
  650. if(!pTaskAz)
  651. {
  652. ASSERT(pTaskAz);
  653. return E_UNEXPECTED;
  654. }
  655. HRESULT hr = S_OK;
  656. //Set the Role Definition Bit
  657. if(m_bRoleDefinition)
  658. {
  659. hr = pTaskAz->MakeRoleDefinition();
  660. if(FAILED(hr))
  661. return hr;
  662. }
  663. //Set Task and Operation Members
  664. int iCount = m_listCtrl.GetItemCount();
  665. for( int i = 0; i < iCount; ++i)
  666. {
  667. CBaseAz* pTaskOperatioAz = (CBaseAz*)m_listCtrl.GetItemData(i);
  668. if(pTaskOperatioAz)
  669. {
  670. if(pTaskOperatioAz->GetObjectType() == OPERATION_AZ)
  671. {
  672. hr = pTaskAz->AddMember(AZ_PROP_TASK_OPERATIONS,
  673. pTaskOperatioAz);
  674. }
  675. else if(pBaseAz->GetObjectType() == TASK_AZ)
  676. {
  677. hr = pTaskAz->AddMember(AZ_PROP_TASK_TASKS,
  678. pTaskOperatioAz);
  679. }
  680. if(FAILED(hr))
  681. return hr;
  682. }
  683. }
  684. //Set the Authorization Script Data
  685. hr = SaveAuthorizationScriptData(m_hWnd,
  686. *pTaskAz,
  687. m_strFilePath,
  688. m_strScriptLanguage,
  689. m_strScript,
  690. refbErrorDisplayed);
  691. return hr;
  692. }
  693. void
  694. CNewTaskDlg::OnButtonAdd()
  695. {
  696. //
  697. //Operations are contained only by Application object. If Current object
  698. //is a scope, get its parent.
  699. //Show AddOperation Dialog box and get list of Selected Operation
  700. CList<CBaseAz*,CBaseAz*> listObjectsSelected;
  701. if(!GetSelectedDefinitions(m_bRoleDefinition,
  702. GetContainerAzObject(),
  703. listObjectsSelected))
  704. {
  705. return;
  706. }
  707. if(!listObjectsSelected.IsEmpty())
  708. {
  709. //Add Selected Operation to list control
  710. AddBaseAzFromListToListCtrl(listObjectsSelected,
  711. &m_listCtrl,
  712. COL_NAME | COL_TYPE | COL_DESCRIPTION,
  713. TRUE);
  714. m_listCtrl.Sort();
  715. }
  716. }
  717. void
  718. CNewTaskDlg::OnButtonRemove()
  719. {
  720. DeleteSelectedRows(&m_listCtrl);
  721. }
  722. void
  723. CNewTaskDlg::OnButtonEditScript()
  724. {
  725. if(IsBizRuleWritable(m_hWnd,*GetContainerAzObject()))
  726. {
  727. GetScriptData(FALSE,
  728. *GetBaseContainerNode()->GetAdminManagerNode(),
  729. m_strFilePath,
  730. m_strScriptLanguage,
  731. m_strScript);
  732. }
  733. }
  734. void
  735. CNewTaskDlg
  736. ::OnListCtrlItemChanged(NMHDR* /*pNotifyStruct*/, LRESULT* pResult)
  737. {
  738. if(!pResult)
  739. return;
  740. *pResult = 0;
  741. SetRemoveButton();
  742. }
  743. void
  744. CNewTaskDlg
  745. ::OnListCtrlItemDeleted(NMHDR* pNotifyStruct, LRESULT* /*pResult*/)
  746. {
  747. LPNM_LISTVIEW pnmlv = (LPNM_LISTVIEW)pNotifyStruct;
  748. if(pnmlv->lParam)
  749. {
  750. delete (CBaseAz*)pnmlv->lParam;
  751. }
  752. }
  753. void
  754. CNewTaskDlg
  755. ::SetRemoveButton()
  756. {
  757. EnableButtonIfSelectedInListCtrl(&m_listCtrl,
  758. GetRemoveButton());
  759. }
  760. /******************************************************************************
  761. Class: CNewOperationDlg
  762. Purpose: Dlg Class for creating new Operation
  763. ******************************************************************************/
  764. DEBUG_DECLARE_INSTANCE_COUNTER(CNewOperationDlg)
  765. BEGIN_MESSAGE_MAP(CNewOperationDlg, CNewBaseDlg)
  766. //{{AFX_MSG_MAP(CNewTaskDlg)
  767. //}}AFX_MSG_MAP
  768. END_MESSAGE_MAP()
  769. CNewOperationDlg
  770. ::CNewOperationDlg(IN CComponentDataObject* pComponentData,
  771. IN CBaseContainerNode* pBaseContainerNode)
  772. :CNewBaseDlg(pComponentData,
  773. pBaseContainerNode,
  774. ATTR_MAP_NEW_OPERATION,
  775. IDD_NEW_OPERATION,
  776. OPERATION_AZ)
  777. {
  778. TRACE_CONSTRUCTOR_EX(DEB_SNAPIN,CNewOperationDlg);
  779. DEBUG_INCREMENT_INSTANCE_COUNTER(CNewOperationDlg)
  780. }
  781. CNewOperationDlg
  782. ::~CNewOperationDlg()
  783. {
  784. TRACE_DESTRUCTOR_EX(DEB_SNAPIN,CNewOperationDlg)
  785. DEBUG_DECREMENT_INSTANCE_COUNTER(CNewOperationDlg)
  786. }
  787. //+----------------------------------------------------------------------------
  788. // Function: OpenCreateAdminManager
  789. // Synopsis: Open an existing an existing Authorization Store or
  790. // creates a new Authorization Store and adds corresponding
  791. // AdminManager object to snapin
  792. // Arguments:IN hWnd: Handle of window for dialog box
  793. // IN bNew :If True create a new Authz store else open existing
  794. // one
  795. // IN bOpenFromSavedConsole: This is valid when bNew is False.
  796. // True if open is in resopnse to a console file.
  797. // IN lStoreType: XML or AD
  798. // IN strName: Name of store
  799. // IN strDesc: Description. Only valid in case of new
  800. // IN strScriptDir : Script directory
  801. // IN pRootData: Snapin Rootdata
  802. // IN pComponentData: ComponentData
  803. // Returns:
  804. //-----------------------------------------------------------------------------
  805. HRESULT OpenCreateAdminManager(IN BOOL bNew,
  806. IN BOOL bOpenFromSavedConsole,
  807. IN ULONG lStoreType,
  808. IN const CString& strStoreName,
  809. IN const CString& strDesc,
  810. IN const CString& strScriptDir,
  811. IN CRootData* pRootData,
  812. IN CComponentDataObject* pComponentData)
  813. {
  814. TRACE_FUNCTION_EX(DEB_SNAPIN, OpenCreateAdminManager)
  815. if(!IsValidStoreType(lStoreType) ||
  816. strStoreName.IsEmpty() ||
  817. !pRootData)
  818. {
  819. ASSERT(IsValidStoreType(lStoreType));
  820. ASSERT(!strStoreName.IsEmpty());
  821. ASSERT(pRootData);
  822. return E_INVALIDARG;
  823. }
  824. HRESULT hr = S_OK;
  825. CAdminManagerAz* pAdminManagerAz = NULL;
  826. do
  827. {
  828. //Create CAzAdminManager instance
  829. CComPtr<IAzAuthorizationStore> spAzAdminManager;
  830. hr = spAzAdminManager.CoCreateInstance(CLSID_AzAuthorizationStore,
  831. NULL,
  832. CLSCTX_INPROC_SERVER);
  833. BREAK_ON_FAIL_HRESULT(hr);
  834. pAdminManagerAz = new CAdminManagerAz(spAzAdminManager);
  835. if(!pAdminManagerAz)
  836. {
  837. hr = E_OUTOFMEMORY;
  838. break;
  839. }
  840. if(bNew)
  841. {
  842. //Create Policy Store
  843. hr = pAdminManagerAz->CreatePolicyStore(lStoreType,
  844. strStoreName);
  845. }else
  846. {
  847. //Open Policy Store
  848. hr = pAdminManagerAz->OpenPolicyStore(lStoreType,
  849. strStoreName);
  850. }
  851. BREAK_ON_FAIL_HRESULT(hr);
  852. if(bNew)
  853. {
  854. //Set Description
  855. if(!strDesc.IsEmpty())
  856. {
  857. hr = pAdminManagerAz->SetDescription(strDesc);
  858. BREAK_ON_FAIL_HRESULT(hr);
  859. }
  860. //All the changes are done. Submit
  861. hr = pAdminManagerAz->Submit();
  862. BREAK_ON_FAIL_HRESULT(hr);
  863. }
  864. //Create AdminManager Node and add to snapin
  865. CAdminManagerNode* pAdminManagerCont=
  866. new CAdminManagerNode((CRoleComponentDataObject*)pComponentData,
  867. pAdminManagerAz);
  868. if(!pAdminManagerCont)
  869. {
  870. hr = E_OUTOFMEMORY;
  871. DBG_OUT_HRESULT(hr);
  872. break;
  873. }
  874. //Set the Authorization Script Dir
  875. pAdminManagerCont->SetScriptDirectory(strScriptDir);
  876. VERIFY(pRootData->AddChildToListAndUI(pAdminManagerCont,pComponentData));
  877. pAdminManagerCont->SetAdminManagerNode(pAdminManagerCont);
  878. pAdminManagerCont->SetComponentDataObject((CRoleComponentDataObject*)pComponentData);
  879. //If user in opening a new store, select that store
  880. if(!bOpenFromSavedConsole)
  881. {
  882. if(pAdminManagerCont->GetScopeID())
  883. {
  884. pComponentData->GetConsole()->SelectScopeItem(pAdminManagerCont->GetScopeID());
  885. }
  886. }
  887. }while(0);
  888. if(FAILED(hr))
  889. {
  890. if(pAdminManagerAz)
  891. delete pAdminManagerAz;
  892. }
  893. return hr;
  894. }
  895. /******************************************************************************
  896. Class: CNewAuthorizationStoreDlg
  897. Purpose: Dialog Class For creation of new Autorization Store
  898. ******************************************************************************/
  899. BEGIN_MESSAGE_MAP(CNewAuthorizationStoreDlg, CNewBaseDlg)
  900. //{{AFX_MSG_MAP(CNewAuthorizationStoreDlg)
  901. ON_BN_CLICKED(IDC_BUTTON_BROWSE, OnButtonBrowse)
  902. ON_BN_CLICKED(IDC_RADIO_AD_STORE,OnRadioChange)
  903. ON_BN_CLICKED(IDC_RADIO_XML_STORE,OnRadioChange)
  904. //}}AFX_MSG_MAP
  905. END_MESSAGE_MAP()
  906. DEBUG_DECLARE_INSTANCE_COUNTER(CNewAuthorizationStoreDlg)
  907. CNewAuthorizationStoreDlg
  908. ::CNewAuthorizationStoreDlg(IN CComponentDataObject* pComponentData)
  909. :CNewBaseDlg(pComponentData,
  910. NULL,
  911. ATTR_MAP_NEW_ADMIN_MANAGER,
  912. IDD_NEW_AUTHORIZATION_STORE,
  913. ADMIN_MANAGER_AZ),
  914. m_bADAvailable(FALSE)
  915. {
  916. TRACE_CONSTRUCTOR_EX(DEB_SNAPIN,CNewAuthorizationStoreDlg);
  917. DEBUG_INCREMENT_INSTANCE_COUNTER(CNewAuthorizationStoreDlg)
  918. }
  919. CNewAuthorizationStoreDlg
  920. ::~CNewAuthorizationStoreDlg()
  921. {
  922. TRACE_DESTRUCTOR_EX(DEB_SNAPIN,CNewAuthorizationStoreDlg)
  923. DEBUG_DECREMENT_INSTANCE_COUNTER(CNewAuthorizationStoreDlg)
  924. }
  925. BOOL
  926. CNewAuthorizationStoreDlg
  927. ::OnInitDialog()
  928. {
  929. CWaitCursor waitCursor;
  930. //Initialize the base dialog
  931. CNewBaseDlg::OnInitDialog();
  932. //XML is the default store
  933. CButton* pRadioXML = (CButton*)GetDlgItem(IDC_RADIO_XML_STORE);
  934. pRadioXML->SetCheck(TRUE);
  935. //Check if active directory is available as store.
  936. m_bADAvailable = (GetRootData()->GetADState() != AD_NOT_AVAILABLE);
  937. //Set m_lLastRadioSelection to AD Store
  938. m_lLastRadioSelection = AZ_ADMIN_STORE_AD;
  939. //Get the default ad store name
  940. GetDefaultADContainerPath(GetRootData()->GetAdInfo(),FALSE,FALSE,m_strLastStoreName);
  941. //Initialize the store to Current Working direcotry
  942. CString strXMLStorePath = GetRootData()->GetXMLStorePath();
  943. SetNameText(strXMLStorePath);
  944. CEdit * pEdit = (CEdit*)GetDlgItem(IDC_EDIT_NAME);
  945. pEdit->SetFocus();
  946. pEdit->SetSel(strXMLStorePath.GetLength(),strXMLStorePath.GetLength(),FALSE);
  947. //We have changed the default focus
  948. return FALSE;
  949. }
  950. ULONG
  951. CNewAuthorizationStoreDlg::
  952. GetStoreType()
  953. {
  954. if(((CButton*)GetDlgItem(IDC_RADIO_AD_STORE))->GetCheck())
  955. return AZ_ADMIN_STORE_AD;
  956. else
  957. return AZ_ADMIN_STORE_XML;
  958. }
  959. void
  960. CNewAuthorizationStoreDlg::
  961. OnRadioChange()
  962. {
  963. LONG lCurRadioSelection = GetStoreType();
  964. if(m_lLastRadioSelection == lCurRadioSelection)
  965. {
  966. CString strTemp = GetNameText();
  967. SetNameText(m_strLastStoreName);
  968. m_strLastStoreName = strTemp;
  969. m_lLastRadioSelection = (lCurRadioSelection == AZ_ADMIN_STORE_XML) ? AZ_ADMIN_STORE_AD : AZ_ADMIN_STORE_XML;
  970. //AD option is selected and AD is not available on the machine. In this case don't support
  971. //browse functionality, however allow to enter ADAM store path by entering path directly.
  972. if((AZ_ADMIN_STORE_AD == lCurRadioSelection) &&
  973. !m_bADAvailable)
  974. {
  975. GetDlgItem(IDC_BUTTON_BROWSE)->EnableWindow(FALSE);
  976. }
  977. else
  978. GetDlgItem(IDC_BUTTON_BROWSE)->EnableWindow(TRUE);
  979. }
  980. }
  981. void
  982. CNewAuthorizationStoreDlg
  983. ::OnButtonBrowse()
  984. {
  985. CEdit * pEdit = (CEdit*)GetDlgItem(IDC_EDIT_NAME);
  986. if(GetStoreType() == AZ_ADMIN_STORE_XML)
  987. {
  988. CString strFileName;
  989. if(GetFolderName(m_hWnd,
  990. IDS_NEW_AUTHORIZATION_STORE,
  991. GetRootData()->GetXMLStorePath(),
  992. strFileName))
  993. {
  994. pEdit->SetWindowText(strFileName);
  995. //Set the focus to the edit control and set caret to
  996. //end of filepath so that user can continue typing file name
  997. pEdit->SetFocus();
  998. pEdit->SetSel(strFileName.GetLength(),strFileName.GetLength(),FALSE);
  999. }
  1000. }
  1001. else
  1002. {
  1003. CString strDsContainerName;
  1004. if(GetADContainerPath(m_hWnd,
  1005. IDS_NEW_AUTHORIZATION_STORE,
  1006. IDS_AD_CONTAINER_LOCATION,
  1007. strDsContainerName,
  1008. GetRootData()->GetAdInfo()))
  1009. {
  1010. pEdit->SetWindowText(strDsContainerName);
  1011. //Set the Focus to edit control and set caret to
  1012. //begining of editbox so that user add cn of the
  1013. //new store in the begining
  1014. pEdit->SetFocus();
  1015. }
  1016. }
  1017. }
  1018. void
  1019. CNewAuthorizationStoreDlg
  1020. ::OnOK()
  1021. {
  1022. TRACE_METHOD_EX(DEB_SNAPIN,CNewAuthorizationStoreDlg,OnOK)
  1023. HRESULT hr = S_OK;
  1024. //Get Store Name
  1025. CString strStoreName = GetNameText();
  1026. //Get Store Type
  1027. ULONG lStoreType = GetStoreType();
  1028. //NTRAID#NTBUG9-706617-2002/07/17-hiteshr Our validation code cannot validate
  1029. //ADAM dn. Do not do any validation.
  1030. //Validate the store name.
  1031. //if(!ValidateStoreTypeAndName(m_hWnd,lStoreType,strStoreName))
  1032. // return;
  1033. if(lStoreType == AZ_ADMIN_STORE_XML)
  1034. {
  1035. AddExtensionToFileName(strStoreName);
  1036. ConvertToExpandedAndAbsolutePath(strStoreName);
  1037. SetNameText(strStoreName);
  1038. //creating new store. set the XML store path location
  1039. SetXMLStoreDirectory(*GetRootData(),strStoreName);
  1040. }
  1041. CString strDesc;
  1042. ((CEdit*)GetDlgItem(IDC_EDIT_DESCRIPTION))->GetWindowText(strDesc);
  1043. hr = OpenCreateAdminManager(TRUE,
  1044. FALSE,
  1045. lStoreType,
  1046. strStoreName,
  1047. strDesc,
  1048. GetRootData()->GetXMLStorePath(), //Default path for VB script is same as path for XML store
  1049. GetRootData(),
  1050. GetComponentData());
  1051. if(SUCCEEDED(hr))
  1052. {
  1053. CDialog::OnOK();
  1054. }
  1055. else
  1056. {
  1057. if(hr == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND))
  1058. {
  1059. ::DisplayError(m_hWnd,
  1060. IDS_CREATE_NEW_PATH_NOT_FOUND);
  1061. }
  1062. else if((lStoreType == AZ_ADMIN_STORE_XML) && (hr == HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS)))
  1063. {
  1064. ::DisplayError(m_hWnd,IDS_ERROR_FILE_EXIST,(LPCTSTR)strStoreName);
  1065. }
  1066. else if(hr == HRESULT_FROM_WIN32(ERROR_INVALID_NAME))
  1067. {
  1068. ::DisplayError(m_hWnd,IDS_ERROR_INVALID_NAME);
  1069. }
  1070. else if((lStoreType == AZ_ADMIN_STORE_AD) && (hr == HRESULT_FROM_WIN32(ERROR_CURRENT_DOMAIN_NOT_ALLOWED)))
  1071. {
  1072. ::DisplayError(m_hWnd,IDS_ERROR_DOMAIN_NOT_ALLOWED);
  1073. }
  1074. else
  1075. {
  1076. DisplayError(hr);
  1077. }
  1078. }
  1079. }
  1080. /******************************************************************************
  1081. Class: COpenAuthorizationStoreDlg
  1082. Purpose: Dialog Class For Opening of existing Autorization Store
  1083. ******************************************************************************/
  1084. BEGIN_MESSAGE_MAP(COpenAuthorizationStoreDlg, CNewBaseDlg)
  1085. //{{AFX_MSG_MAP(COpenAuthorizationStoreDlg)
  1086. ON_BN_CLICKED(IDC_BUTTON_BROWSE, OnButtonBrowse)
  1087. ON_BN_CLICKED(IDC_RADIO_AD_STORE,OnRadioChange)
  1088. ON_BN_CLICKED(IDC_RADIO_XML_STORE,OnRadioChange)
  1089. //}}AFX_MSG_MAP
  1090. END_MESSAGE_MAP()
  1091. DEBUG_DECLARE_INSTANCE_COUNTER(COpenAuthorizationStoreDlg)
  1092. COpenAuthorizationStoreDlg
  1093. ::COpenAuthorizationStoreDlg(IN CComponentDataObject* pComponentData)
  1094. :CNewBaseDlg(pComponentData,
  1095. NULL,
  1096. ATTR_MAP_OPEN_ADMIN_MANAGER,
  1097. IDD_OPEN_AUTHORIZATION_STORE,
  1098. ADMIN_MANAGER_AZ),
  1099. m_bADAvailable(FALSE)
  1100. {
  1101. TRACE_CONSTRUCTOR_EX(DEB_SNAPIN,COpenAuthorizationStoreDlg);
  1102. DEBUG_INCREMENT_INSTANCE_COUNTER(COpenAuthorizationStoreDlg)
  1103. }
  1104. COpenAuthorizationStoreDlg
  1105. ::~COpenAuthorizationStoreDlg()
  1106. {
  1107. TRACE_DESTRUCTOR_EX(DEB_SNAPIN,COpenAuthorizationStoreDlg)
  1108. DEBUG_DECREMENT_INSTANCE_COUNTER(COpenAuthorizationStoreDlg)
  1109. }
  1110. ULONG
  1111. COpenAuthorizationStoreDlg
  1112. ::GetStoreType()
  1113. {
  1114. if(((CButton*)GetDlgItem(IDC_RADIO_AD_STORE))->GetCheck())
  1115. return AZ_ADMIN_STORE_AD;
  1116. else
  1117. return AZ_ADMIN_STORE_XML;
  1118. }
  1119. BOOL
  1120. COpenAuthorizationStoreDlg
  1121. ::OnInitDialog()
  1122. {
  1123. CWaitCursor waitCursor;
  1124. //
  1125. //XML is the default store
  1126. //
  1127. CButton* pRadioAD = (CButton*)GetDlgItem(IDC_RADIO_XML_STORE);
  1128. pRadioAD->SetCheck(TRUE);
  1129. //Check if active directory is available as store.
  1130. m_bADAvailable = (GetRootData()->GetADState() != AD_NOT_AVAILABLE);
  1131. //Set m_lLastRadioSelection to AD STore
  1132. m_lLastRadioSelection = AZ_ADMIN_STORE_AD;
  1133. return CNewBaseDlg::OnInitDialog();
  1134. }
  1135. void
  1136. COpenAuthorizationStoreDlg
  1137. ::OnButtonBrowse()
  1138. {
  1139. //Get Store Type
  1140. ULONG lStoreType = GetStoreType();
  1141. if(lStoreType == AZ_ADMIN_STORE_XML)
  1142. {
  1143. CString strFileName;
  1144. if(GetFileName(m_hWnd,
  1145. TRUE,
  1146. IDS_OPEN_AUTHORIZATION_STORE,
  1147. GetRootData()->GetXMLStorePath(),
  1148. L"*.xml\0*.xml\0\0",
  1149. strFileName))
  1150. {
  1151. ((CEdit*)GetDlgItem(IDC_EDIT_NAME))->SetWindowText(strFileName);
  1152. }
  1153. }
  1154. else
  1155. {
  1156. CString strDN;
  1157. BrowseAdStores(m_hWnd,
  1158. strDN,
  1159. GetRootData()->GetAdInfo());
  1160. if(!strDN.IsEmpty())
  1161. ((CEdit*)GetDlgItem(IDC_EDIT_NAME))->SetWindowText(strDN);
  1162. }
  1163. }
  1164. void
  1165. COpenAuthorizationStoreDlg::
  1166. OnRadioChange()
  1167. {
  1168. LONG lCurRadioSelection = GetStoreType();
  1169. if(m_lLastRadioSelection == lCurRadioSelection)
  1170. {
  1171. CString strTemp = GetNameText();
  1172. SetNameText(m_strLastStoreName);
  1173. m_strLastStoreName = strTemp;
  1174. m_lLastRadioSelection = (lCurRadioSelection == AZ_ADMIN_STORE_XML) ? AZ_ADMIN_STORE_AD : AZ_ADMIN_STORE_XML;
  1175. //AD option is selected and AD is not available on the machine. In this case don't support
  1176. //browse functionality, however allow to enter ADAM store path by entering path directly.
  1177. if((AZ_ADMIN_STORE_AD == lCurRadioSelection) &&
  1178. !m_bADAvailable)
  1179. {
  1180. GetDlgItem(IDC_BUTTON_BROWSE)->EnableWindow(FALSE);
  1181. }
  1182. else
  1183. GetDlgItem(IDC_BUTTON_BROWSE)->EnableWindow(TRUE);
  1184. }
  1185. }
  1186. void
  1187. COpenAuthorizationStoreDlg
  1188. ::OnOK()
  1189. {
  1190. TRACE_METHOD_EX(DEB_SNAPIN,COpenAuthorizationStoreDlg,OnOK)
  1191. HRESULT hr = S_OK;
  1192. //Get Store Name
  1193. CString strStoreName = GetNameText();
  1194. //Get Store Type
  1195. ULONG lStoreType = GetStoreType();
  1196. //Set the default xml store directory
  1197. if(AZ_ADMIN_STORE_XML == lStoreType)
  1198. {
  1199. ConvertToExpandedAndAbsolutePath(strStoreName);
  1200. SetNameText(strStoreName);
  1201. SetXMLStoreDirectory(*GetRootData(),strStoreName);
  1202. }
  1203. hr = OpenAdminManager(m_hWnd,
  1204. FALSE,
  1205. lStoreType,
  1206. strStoreName,
  1207. GetRootData()->GetXMLStorePath(),
  1208. GetRootData(),
  1209. GetComponentData());
  1210. if(SUCCEEDED(hr))
  1211. {
  1212. CDialog::OnOK();
  1213. }
  1214. }
  1215. /******************************************************************************
  1216. Class: CScriptDialog
  1217. Purpose: Dialog for Reading the script
  1218. ******************************************************************************/
  1219. BEGIN_MESSAGE_MAP(CScriptDialog, CHelpEnabledDialog)
  1220. //{{AFX_MSG_MAP(COpenAuthorizationStoreDlg)
  1221. ON_BN_CLICKED(IDC_BUTTON_BROWSE, OnBrowse)
  1222. ON_BN_CLICKED(IDC_BUTTON_RELOAD, OnReload)
  1223. ON_BN_CLICKED(IDC_CLEAR_SCRIPT, OnClear)
  1224. ON_BN_CLICKED(IDC_RADIO_VB_SCRIPT,OnRadioChange)
  1225. ON_BN_CLICKED(IDC_RADIO_JAVA_SCRIPT,OnRadioChange)
  1226. ON_EN_CHANGE(IDC_EDIT_PATH, OnEditChangePath)
  1227. ON_WM_CTLCOLOR()
  1228. //}}AFX_MSG_MAP
  1229. END_MESSAGE_MAP()
  1230. CScriptDialog::
  1231. CScriptDialog(BOOL bReadOnly,
  1232. CAdminManagerNode& adminManagerNode,
  1233. CString& strFileName,
  1234. CString& strScriptLanguage,
  1235. CString& strScript)
  1236. :CHelpEnabledDialog(IDD_SCRIPT),
  1237. m_adminManagerNode(adminManagerNode),
  1238. m_strFileName(strFileName),
  1239. m_strScriptLanguage(strScriptLanguage),
  1240. m_strScript(strScript),
  1241. m_strRetFileName(strFileName),
  1242. m_strRetScriptLanguage(strScriptLanguage),
  1243. m_strRetScript(strScript),
  1244. m_bDirty(FALSE),
  1245. m_bReadOnly(bReadOnly),
  1246. m_bInit(FALSE)
  1247. {
  1248. }
  1249. CScriptDialog::
  1250. ~CScriptDialog()
  1251. {
  1252. }
  1253. BOOL
  1254. CScriptDialog::
  1255. OnInitDialog()
  1256. {
  1257. TRACE_METHOD_EX(DEB_SNAPIN,CScriptDialog,OnInitDialog)
  1258. //If there is some script, set it else disable the clear script
  1259. //button
  1260. if(m_strScript.GetLength())
  1261. {
  1262. ((CEdit*)GetDlgItem(IDC_EDIT_CODE))->SetWindowText(m_strScript);
  1263. }
  1264. else
  1265. {
  1266. GetDlgItem(IDC_CLEAR_SCRIPT)->EnableWindow(FALSE);
  1267. }
  1268. CEdit* pEditPath = ((CEdit*)GetDlgItem(IDC_EDIT_PATH));
  1269. pEditPath->SetLimitText(AZ_MAX_TASK_BIZRULE_IMPORTED_PATH_LENGTH);
  1270. //If there is a file name, set it else disable the reload script
  1271. //button
  1272. if(m_strFileName.GetLength())
  1273. {
  1274. pEditPath->SetWindowText(m_strFileName);
  1275. }
  1276. else
  1277. {
  1278. GetDlgItem(IDC_BUTTON_RELOAD)->EnableWindow(FALSE);
  1279. }
  1280. if(!m_strScriptLanguage.IsEmpty() &&
  1281. (_wcsicmp(g_szJavaScript,m_strScriptLanguage) == 0))
  1282. {
  1283. CButton* pRadioJS = (CButton*)GetDlgItem(IDC_RADIO_JAVA_SCRIPT);
  1284. pRadioJS->SetCheck(TRUE);
  1285. }
  1286. else
  1287. {
  1288. CButton* pRadioVB = (CButton*)GetDlgItem(IDC_RADIO_VB_SCRIPT);
  1289. pRadioVB->SetCheck(TRUE);
  1290. }
  1291. if(m_bReadOnly)
  1292. {
  1293. GetDlgItem(IDC_RADIO_VB_SCRIPT)->EnableWindow(FALSE);
  1294. GetDlgItem(IDC_RADIO_JAVA_SCRIPT)->EnableWindow(FALSE);
  1295. GetDlgItem(IDC_BUTTON_BROWSE)->EnableWindow(FALSE);
  1296. GetDlgItem(IDC_BUTTON_RELOAD)->EnableWindow(FALSE);
  1297. GetDlgItem(IDC_CLEAR_SCRIPT)->EnableWindow(FALSE);
  1298. ((CEdit*)GetDlgItem(IDC_EDIT_PATH))->SetReadOnly(TRUE);
  1299. }
  1300. m_bInit = TRUE;
  1301. return TRUE;
  1302. }
  1303. void
  1304. CScriptDialog::
  1305. OnRadioChange()
  1306. {
  1307. m_bDirty = TRUE;
  1308. }
  1309. void
  1310. CScriptDialog::
  1311. MatchRadioWithExtension(const CString& strFileName)
  1312. {
  1313. //Get the extension of file
  1314. CString strExtension;
  1315. if(GetFileExtension(strFileName,strExtension))
  1316. {
  1317. //If file extension is vbs
  1318. if(_wcsicmp(strExtension,L"vbs") == 0)
  1319. {
  1320. ((CButton*)GetDlgItem(IDC_RADIO_VB_SCRIPT))->SetCheck(BST_CHECKED);
  1321. ((CButton*)GetDlgItem(IDC_RADIO_JAVA_SCRIPT))->SetCheck(BST_UNCHECKED);
  1322. }
  1323. else if(_wcsicmp(strExtension,L"js") == 0)
  1324. {
  1325. ((CButton*)GetDlgItem(IDC_RADIO_JAVA_SCRIPT))->SetCheck(BST_CHECKED);
  1326. ((CButton*)GetDlgItem(IDC_RADIO_VB_SCRIPT))->SetCheck(BST_UNCHECKED);
  1327. }
  1328. }
  1329. }
  1330. HBRUSH
  1331. CScriptDialog::
  1332. OnCtlColor(CDC* pDC,
  1333. CWnd* pWnd,
  1334. UINT nCtlColor)
  1335. {
  1336. // Call the base class implementation first! Otherwise, it may
  1337. // undo what we're trying to accomplish here.
  1338. HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
  1339. if (pWnd->GetDlgCtrlID() == IDC_EDIT_CODE && (CTLCOLOR_STATIC == nCtlColor))
  1340. {
  1341. // set the read-only edit box background to white
  1342. pDC->SetTextColor(GetSysColor(COLOR_WINDOWTEXT));
  1343. pDC->SetBkColor(GetSysColor(COLOR_WINDOW));
  1344. hbr = GetSysColorBrush(COLOR_WINDOW);
  1345. }
  1346. return hbr;
  1347. }
  1348. void
  1349. CScriptDialog
  1350. ::OnEditChangePath()
  1351. {
  1352. if(!m_bInit)
  1353. return;
  1354. m_bDirty = TRUE;
  1355. HANDLE handle = INVALID_HANDLE_VALUE;
  1356. do
  1357. {
  1358. //
  1359. //If Path is cleared, clear the script
  1360. //
  1361. if(!((CEdit*)GetDlgItem(IDC_EDIT_PATH))->GetWindowTextLength())
  1362. {
  1363. ((CEdit*)GetDlgItem(IDC_EDIT_CODE))->SetWindowText(L"");
  1364. m_strScript.Empty();
  1365. m_strFileName.Empty();
  1366. m_strScript.Empty();
  1367. GetDlgItem(IDC_CLEAR_SCRIPT)->EnableWindow(FALSE);
  1368. GetDlgItem(IDC_BUTTON_RELOAD)->EnableWindow(FALSE);
  1369. break;
  1370. }
  1371. //
  1372. //There is some text in the edit control. Try to load
  1373. //that file
  1374. //
  1375. ((CButton*)GetDlgItem(IDC_BUTTON_RELOAD))->EnableWindow(TRUE);
  1376. CString strFileName;
  1377. ((CEdit*)GetDlgItem(IDC_EDIT_PATH))->GetWindowText(strFileName);
  1378. //If its same as existig file return
  1379. if(_wcsicmp(strFileName,m_strFileName) == 0 )
  1380. break;
  1381. //Check if there is a file or directory with such name
  1382. WIN32_FIND_DATA FindFileData;
  1383. handle = FindFirstFile(strFileName,
  1384. &FindFileData);
  1385. //No such file or directory
  1386. if(INVALID_HANDLE_VALUE == handle)
  1387. break;
  1388. //We are only interested in files
  1389. if(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
  1390. break;
  1391. //Check if file has valid extension
  1392. CString strExtension;
  1393. if(GetFileExtension(strFileName,strExtension))
  1394. {
  1395. if(_wcsicmp(strExtension,L"vbs") == 0 || (_wcsicmp(strExtension,L"js") == 0))
  1396. {
  1397. m_strFileName = strFileName;
  1398. ReloadScript(strFileName);
  1399. MatchRadioWithExtension(strFileName);
  1400. }
  1401. }
  1402. }while(0);
  1403. if(INVALID_HANDLE_VALUE != handle)
  1404. {
  1405. FindClose(handle);
  1406. }
  1407. }
  1408. void
  1409. CScriptDialog::
  1410. OnClear()
  1411. {
  1412. ((CEdit*)GetDlgItem(IDC_EDIT_CODE))->SetWindowText(L"");
  1413. ((CEdit*)GetDlgItem(IDC_EDIT_PATH))->SetWindowText(L"");
  1414. m_strScript.Empty();
  1415. m_strFileName.Empty();
  1416. m_strScript.Empty();
  1417. //Disable the clear button since there is nothing to clear,
  1418. //but before disabling set focus to clear button
  1419. //NTRAID#NTBUG9-663854-2002/07/17-hiteshr
  1420. GetDlgItem(IDC_EDIT_PATH)->SetFocus();
  1421. GetDlgItem(IDC_CLEAR_SCRIPT)->EnableWindow(FALSE);
  1422. //Disable the Reload button since script path is cleared.
  1423. GetDlgItem(IDC_BUTTON_RELOAD)->EnableWindow(FALSE);
  1424. m_bDirty = TRUE;
  1425. }
  1426. void
  1427. CScriptDialog::
  1428. OnBrowse()
  1429. {
  1430. CString szFileFilter;
  1431. VERIFY (szFileFilter.LoadString (IDS_OPEN_SCRIPT_FILTER));
  1432. // replace "|" with 0;
  1433. const size_t nFilterLen = szFileFilter.GetLength();
  1434. PWSTR pszFileFilter = new WCHAR [nFilterLen + 1];
  1435. if ( pszFileFilter )
  1436. {
  1437. wcscpy (pszFileFilter, szFileFilter);
  1438. for (int nIndex = 0; nIndex < nFilterLen; nIndex++)
  1439. {
  1440. if ( L'|' == pszFileFilter[nIndex] )
  1441. pszFileFilter[nIndex] = 0;
  1442. }
  1443. CString strFileName;
  1444. if(GetFileName(m_hWnd,
  1445. TRUE,
  1446. IDS_SELECT_AUTHORIZATION_SCRIPT,
  1447. m_adminManagerNode.GetScriptDirectory(),
  1448. pszFileFilter,
  1449. strFileName))
  1450. {
  1451. m_adminManagerNode.SetScriptDirectory(GetDirectoryFromPath(strFileName));
  1452. //This will trigger OnEditChangePath which will load the file
  1453. ((CEdit*)GetDlgItem(IDC_EDIT_PATH))->SetWindowText(strFileName);
  1454. m_bDirty = TRUE;
  1455. }
  1456. delete []pszFileFilter;
  1457. }
  1458. }
  1459. void
  1460. CScriptDialog::
  1461. OnReload()
  1462. {
  1463. //Get FileName
  1464. CString strFileName;
  1465. ((CEdit*)GetDlgItem(IDC_EDIT_PATH))->GetWindowText(strFileName);
  1466. //Reload the script
  1467. ReloadScript(strFileName);
  1468. MatchRadioWithExtension(strFileName);
  1469. }
  1470. void
  1471. CScriptDialog::
  1472. OnOK()
  1473. {
  1474. if(m_bDirty)
  1475. {
  1476. CString strFileName;
  1477. ((CEdit*)GetDlgItem(IDC_EDIT_PATH))->GetWindowText(strFileName);
  1478. if(_wcsicmp(strFileName,m_strFileName) != 0 )
  1479. {
  1480. m_strFileName = strFileName;
  1481. if(!ReloadScript(m_strFileName))
  1482. return;
  1483. }
  1484. ((CEdit*)GetDlgItem(IDC_EDIT_CODE))->GetWindowText(m_strScript);
  1485. ((CEdit*)GetDlgItem(IDC_EDIT_PATH))->GetWindowText(m_strFileName);
  1486. //If FileName is not empty and Script is empty,
  1487. //reload the script
  1488. if(!m_strFileName.IsEmpty() && m_strScript.IsEmpty())
  1489. {
  1490. if(!ReloadScript(m_strFileName))
  1491. return;
  1492. //Successfully loaded the script
  1493. ((CEdit*)GetDlgItem(IDC_EDIT_CODE))->GetWindowText(m_strScript);
  1494. }
  1495. CButton* pRadioVB = (CButton*)GetDlgItem(IDC_RADIO_VB_SCRIPT);
  1496. if(!m_strScript.IsEmpty())
  1497. {
  1498. if(pRadioVB->GetCheck())
  1499. m_strScriptLanguage = g_szVBScript;
  1500. else
  1501. m_strScriptLanguage = g_szJavaScript;
  1502. }
  1503. else
  1504. m_strScriptLanguage.Empty();
  1505. //Copy to the Ret strings
  1506. m_strRetFileName = m_strFileName;
  1507. m_strRetScriptLanguage = m_strScriptLanguage;
  1508. m_strRetScript = m_strScript;
  1509. }
  1510. CDialog::OnOK();
  1511. }
  1512. BOOL
  1513. CScriptDialog::
  1514. ReloadScript(const CString& strFileName)
  1515. {
  1516. TRACE_METHOD_EX(DEB_SNAPIN,CScriptDialog,ReloadScript)
  1517. if(strFileName.IsEmpty())
  1518. {
  1519. ASSERT(FALSE);
  1520. return FALSE;
  1521. }
  1522. m_bDirty = TRUE;
  1523. BYTE* pBuffer = NULL;
  1524. LPWSTR pszScript = NULL;
  1525. BOOL bRet = FALSE;
  1526. do
  1527. {
  1528. CFile file;
  1529. CFileException fileException;
  1530. if(!file.Open((LPCTSTR)strFileName, CFile::modeRead, &fileException))
  1531. {
  1532. //Failed to open the file. Show special error message
  1533. //in case path is incorrect
  1534. if(CFileException::fileNotFound == fileException.m_cause ||
  1535. CFileException::badPath == fileException.m_cause)
  1536. {
  1537. DisplayError(m_hWnd,
  1538. IDS_SCRIPT_NOT_FOUND,
  1539. (LPCTSTR)strFileName);
  1540. }
  1541. else
  1542. {
  1543. //Show generic error
  1544. DisplayError(m_hWnd,
  1545. IDS_CANNOT_OPEN_FILE,
  1546. (LPCTSTR)strFileName);
  1547. }
  1548. break;
  1549. }
  1550. //File is successfully opened
  1551. //
  1552. //MAXIMUM possible file size is AZ_MAX_TASK_BIZRULE_LENGTH WIDECHAR
  1553. //Here we are considering 4bytes per Unicode which is maximum
  1554. //
  1555. if(file.GetLength() > AZ_MAX_TASK_BIZRULE_LENGTH*4)
  1556. {
  1557. DisplayError(m_hWnd,
  1558. IDS_ERROR_BIZRULE_EXCEED_MAX_LENGTH,
  1559. AZ_MAX_TASK_BIZRULE_LENGTH);
  1560. break;
  1561. }
  1562. if(file.GetLength() == 0)
  1563. {
  1564. DisplayError(m_hWnd,
  1565. IDS_ERROR_EMPTY_SCRIPT_FILE,
  1566. strFileName);
  1567. break;
  1568. }
  1569. //Allocate one extra byte for null termination.
  1570. pBuffer = (BYTE*)LocalAlloc(LPTR,file.GetLength() + sizeof(WCHAR));
  1571. if(!pBuffer)
  1572. break;
  1573. int nRead = file.Read(pBuffer,
  1574. file.GetLength());
  1575. if(!nRead)
  1576. {
  1577. ::DisplayError(m_hWnd,
  1578. IDS_CANNOT_READ_FILE_1,
  1579. (LPCTSTR)strFileName);
  1580. break;
  1581. }
  1582. //Check if the file is unicode. First Character
  1583. //in unicode file is 0xFEFF
  1584. if(nRead >= 2 && (*(PWCHAR)pBuffer == 0xFEFF))
  1585. {
  1586. ((LPWSTR)pBuffer)[nRead/sizeof(WCHAR)] = 0;
  1587. CString strScript = (LPWSTR)(pBuffer+2);
  1588. PreprocessScript(strScript);
  1589. ((CEdit*)GetDlgItem(IDC_EDIT_CODE))->SetWindowText(strScript);
  1590. //Enable the clear script button
  1591. GetDlgItem(IDC_CLEAR_SCRIPT)->EnableWindow(TRUE);
  1592. bRet = TRUE;
  1593. break;
  1594. }
  1595. //Get the Size required for unicode
  1596. int nWideChar = MultiByteToWideChar(CP_ACP,
  1597. MB_PRECOMPOSED,
  1598. (LPCSTR)pBuffer,
  1599. nRead,
  1600. NULL,
  1601. 0);
  1602. if(!nWideChar)
  1603. {
  1604. CString strError;
  1605. GetSystemError(strError,HRESULT_FROM_WIN32(GetLastError()));
  1606. ::DisplayError(m_hWnd,
  1607. IDS_FAILED_TO_READ_FILE,
  1608. (LPCTSTR)strError);
  1609. break;
  1610. }
  1611. if(nWideChar > AZ_MAX_TASK_BIZRULE_LENGTH)
  1612. {
  1613. DisplayError(m_hWnd,
  1614. IDS_ERROR_BIZRULE_EXCEED_MAX_LENGTH,
  1615. AZ_MAX_TASK_BIZRULE_LENGTH);
  1616. break;
  1617. }
  1618. //Allocate one WCHAR extra for NULL termination
  1619. pszScript = (LPWSTR)LocalAlloc(LPTR, (nWideChar+1)*sizeof(WCHAR));
  1620. if(!pszScript)
  1621. break;
  1622. if(MultiByteToWideChar( CP_ACP,
  1623. MB_PRECOMPOSED,
  1624. (LPCSTR)pBuffer,
  1625. nRead,
  1626. pszScript,
  1627. nWideChar))
  1628. {
  1629. pszScript[nWideChar] = 0;
  1630. CString strScript = pszScript;
  1631. PreprocessScript(strScript);
  1632. ((CEdit*)GetDlgItem(IDC_EDIT_CODE))->SetWindowText(strScript);
  1633. //Enable the clear script button
  1634. GetDlgItem(IDC_CLEAR_SCRIPT)->EnableWindow(TRUE);
  1635. bRet = TRUE;
  1636. }
  1637. else
  1638. {
  1639. CString strError;
  1640. GetSystemError(strError,HRESULT_FROM_WIN32(GetLastError()));
  1641. ::DisplayError(m_hWnd,
  1642. IDS_FAILED_TO_READ_FILE,
  1643. (LPCTSTR)strError);
  1644. break;
  1645. }
  1646. }while(0);
  1647. if(pBuffer)
  1648. LocalFree(pBuffer);
  1649. if(pszScript)
  1650. LocalFree(pszScript);
  1651. if(!bRet)
  1652. {
  1653. //IF failed to load the file, clear the script
  1654. ((CEdit*)GetDlgItem(IDC_EDIT_CODE))->SetWindowText(L"");
  1655. m_strScript.Empty();
  1656. //Disable the clear button since there is nothing to clear
  1657. GetDlgItem(IDC_CLEAR_SCRIPT)->EnableWindow(FALSE);
  1658. }
  1659. return bRet;
  1660. }
  1661. BOOL
  1662. GetScriptData(IN BOOL bReadOnly,
  1663. IN CAdminManagerNode& adminManagerNode,
  1664. IN OUT CString& strFileName,
  1665. IN OUT CString& strScriptLanguage,
  1666. IN OUT CString& strScript)
  1667. {
  1668. CScriptDialog dlgScript(bReadOnly,
  1669. adminManagerNode,
  1670. strFileName,
  1671. strScriptLanguage,
  1672. strScript);
  1673. if(IDOK == dlgScript.DoModal() && dlgScript.IsDirty())
  1674. return TRUE;
  1675. else
  1676. return FALSE;
  1677. }
  1678. //+----------------------------------------------------------------------------
  1679. // Function:SaveAuthorizationScriptData
  1680. // Synopsis:Saves the authorization script information for a task
  1681. //-----------------------------------------------------------------------------
  1682. HRESULT
  1683. SaveAuthorizationScriptData(IN HWND hWnd,
  1684. IN CTaskAz& refTaskAz,
  1685. IN const CString& strFilePath,
  1686. IN const CString& strScriptLanguage,
  1687. IN const CString& strScript,
  1688. IN BOOL& refbErrorDisplayed)
  1689. {
  1690. TRACE_FUNCTION_EX(DEB_SNAPIN,SaveAuthorizationScriptData)
  1691. HRESULT hr = S_OK;
  1692. if(!strScript.IsEmpty() &&
  1693. strScriptLanguage.IsEmpty())
  1694. {
  1695. ASSERT(FALSE);
  1696. return E_UNEXPECTED;
  1697. }
  1698. do
  1699. {
  1700. //NTRAID#NTBUG9-663899-2002/07/18-hiteshr
  1701. //If bizrule and bizrule language are already set, say to VBScript,
  1702. //changing bizrule language to jscript causes validataion of existing
  1703. //vb script with jscript engine which fails. As a work around, we
  1704. //first set bizrulelang and bizrule to empty, then set new bizrule
  1705. //and then bizrulelang
  1706. //Set bizrule language to empty
  1707. hr = refTaskAz.SetProperty(AZ_PROP_TASK_BIZRULE_LANGUAGE,
  1708. L"");
  1709. BREAK_ON_FAIL_HRESULT(hr);
  1710. //Set bizrule to empty
  1711. hr = refTaskAz.SetProperty(AZ_PROP_TASK_BIZRULE,
  1712. L"");
  1713. //Set bizrule language
  1714. hr = refTaskAz.SetProperty(AZ_PROP_TASK_BIZRULE_LANGUAGE,
  1715. strScriptLanguage);
  1716. BREAK_ON_FAIL_HRESULT(hr);
  1717. //Set bizrule
  1718. hr = refTaskAz.SetProperty(AZ_PROP_TASK_BIZRULE,
  1719. strScript);
  1720. BREAK_ON_FAIL_HRESULT(hr);
  1721. //Set bizrule file path
  1722. hr = refTaskAz.SetProperty(AZ_PROP_TASK_BIZRULE_IMPORTED_PATH,
  1723. strFilePath);
  1724. BREAK_ON_FAIL_HRESULT(hr);
  1725. }while(0);
  1726. if(FAILED(hr))
  1727. {
  1728. if(hr == OLESCRIPT_E_SYNTAX)
  1729. {
  1730. refbErrorDisplayed = TRUE;
  1731. DisplayError(hWnd, IDS_SCRIPT_SYNTAX_INCORRECT,strFilePath);
  1732. }
  1733. }
  1734. return hr;
  1735. }
  1736. //+----------------------------------------------------------------------------
  1737. // Function:GetAuthorizationScriptData
  1738. // Synopsis:Gets the authorization script data for a Task
  1739. //-----------------------------------------------------------------------------
  1740. HRESULT
  1741. GetAuthorizationScriptData(IN CTaskAz& refTaskAz,
  1742. OUT CString& strFilePath,
  1743. OUT CString& strScriptLanguage,
  1744. OUT CString& strScript)
  1745. {
  1746. HRESULT hr = S_OK;
  1747. do
  1748. {
  1749. hr = refTaskAz.GetProperty(AZ_PROP_TASK_BIZRULE_LANGUAGE,
  1750. &strScriptLanguage);
  1751. BREAK_ON_FAIL_HRESULT(hr);
  1752. hr = refTaskAz.GetProperty(AZ_PROP_TASK_BIZRULE,
  1753. &strScript);
  1754. BREAK_ON_FAIL_HRESULT(hr);
  1755. PreprocessScript(strScript);
  1756. hr = refTaskAz.GetProperty(AZ_PROP_TASK_BIZRULE_IMPORTED_PATH,
  1757. &strFilePath);
  1758. BREAK_ON_FAIL_HRESULT(hr);
  1759. }while(0);
  1760. return hr;
  1761. }
  1762. /******************************************************************************
  1763. Class: COptionDlg
  1764. Purpose: Dialog for Selecting authorization manager options
  1765. ******************************************************************************/
  1766. BEGIN_MESSAGE_MAP(COptionDlg, CHelpEnabledDialog)
  1767. //{{AFX_MSG_MAP(CNewBaseDlg)
  1768. //}}AFX_MSG_MAP
  1769. END_MESSAGE_MAP()
  1770. BOOL
  1771. COptionDlg::
  1772. OnInitDialog()
  1773. {
  1774. TRACE_METHOD_EX(DEB_SNAPIN,COptionDlg,OnInitDialog)
  1775. if(m_refDeveloperMode)
  1776. {
  1777. ((CButton*)GetDlgItem(IDC_RADIO_DEVELOPER))->SetCheck(TRUE);
  1778. }
  1779. else
  1780. {
  1781. ((CButton*)GetDlgItem(IDC_RADIO_ADMINISTRATOR))->SetCheck(TRUE);
  1782. }
  1783. return TRUE;
  1784. }
  1785. void
  1786. COptionDlg::
  1787. OnOK()
  1788. {
  1789. TRACE_METHOD_EX(DEB_SNAPIN,COptionDlg,OnOK)
  1790. if(((CButton*)GetDlgItem(IDC_RADIO_DEVELOPER))->GetCheck())
  1791. m_refDeveloperMode = TRUE;
  1792. else
  1793. m_refDeveloperMode = FALSE;
  1794. CDialog::OnOK();
  1795. }