}// PutValuesinPage void onAddClick(Object o, EventArgs e) { // See if we have any selected items if (m_lbAvailPerm.SelectedIndex >= 0) { // Create the permission and hold onto it PermissionPair pp = new PermissionPair(); pp.sPermName = (String)m_lbAvailPerm.SelectedItem; pp.perm = GetPermission((String)m_lbAvailPerm.SelectedItem, null); // If they clicked cancel, we'll abort this if (pp.perm == null) { return; } m_alPermissions.Add(pp); // Add this permission to the 'assigned permissions' list AddPermissionType(m_lbAvailPerm, m_lbAvailPerm.SelectedIndex, m_lbAssignedPerm); // Remove this permission from the 'available permissions' list m_lbAvailPerm.Items.RemoveAt(m_lbAvailPerm.SelectedIndex); } }// onAddClick
}// onPropertiesClick void onImport(Object o, EventArgs e) { OpenFileDialog fd = new OpenFileDialog(); fd.Title = CResourceStore.GetString("CNewPermSetWiz2:FDTitle"); fd.Filter = CResourceStore.GetString("XMLFDMask"); System.Windows.Forms.DialogResult dr = fd.ShowDialog(); if (dr == System.Windows.Forms.DialogResult.OK) { try { SecurityElement se = SecurityXMLStuff.GetSecurityElementFromXMLFile(fd.FileName); if (se == null) { throw new Exception("Null Element"); } Type type; String className = se.Attribute("class"); if (className == null) { throw new Exception("Bad classname"); } type = Type.GetType(className); IPermission perm = (IPermission)Activator.CreateInstance(type, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.CreateInstance, null, new Object[] { PermissionState.None }, null); if (perm == null) { throw new Exception("Unable to create class"); } perm.FromXml(se); // We should check to see if this permission is already being stored if (CheckForDuplicatePermission(ref perm)) { PermissionPair pp = new PermissionPair(); int nIndexOfPermName = className.LastIndexOf('.'); String sPermissionName = className.Substring(nIndexOfPermName + 1); pp.sPermName = sPermissionName; pp.perm = perm; m_alPermissions.Add(pp); m_lbAssignedPerm.Items.Add(pp.sPermName); RemoveThisTypeFromAvailablePermissions(perm); } } catch (Exception) { MessageBox(CResourceStore.GetString("Csinglecodegroupmemcondprop:BadXML"), CResourceStore.GetString("Csinglecodegroupmemcondprop:BadXMLTitle"), MB.ICONEXCLAMATION); } } }// onImport
}// onImport bool CheckForDuplicatePermission(ref IPermission perm) { String sItemToAdd = Security.GetDisplayStringForPermission(perm); // See if we know about this type if (sItemToAdd != null) { for (int i = 0; i < m_lbAssignedPerm.Items.Count; i++) { if (m_lbAssignedPerm.Items[i].Equals(sItemToAdd)) { // Ok, we're trying to import a permission that we already have selected. Pop // up a dialog box and find out what the user wants to do. CDuplicatePermissionDialog dpd = new CDuplicatePermissionDialog(sItemToAdd); System.Windows.Forms.DialogResult dr = dpd.ShowDialog(); if (dr == System.Windows.Forms.DialogResult.OK) { // Get the permission we're after int nIndex = 0; PermissionPair pp = (PermissionPair)m_alPermissions[nIndex]; while (!pp.sPermName.Equals(sItemToAdd)) { pp = (PermissionPair)m_alPermissions[++nIndex]; } if (dpd.Result == CDuplicatePermissionDialog.MERGE) { perm = perm.Union(pp.perm); } else if (dpd.Result == CDuplicatePermissionDialog.INTERSECT) { perm = perm.Intersect(pp.perm); } // else, replace... and we don't need to do anything about that // Now remove the current assigned permission m_alPermissions.RemoveAt(nIndex); m_lbAssignedPerm.Items.RemoveAt(i); } else { // We don't want to add this permission after all return(false); } break; } } } // We don't have this permission to worry about return(true); }// CheckForDuplicationPermissions
}// onRemoveClick void onPropertiesClick(Object o, EventArgs e) { // See if we have any selected items if (m_lbAssignedPerm.SelectedIndex >= 0) { int nIndex = 0; PermissionPair pp = (PermissionPair)m_alPermissions[nIndex]; while (!pp.sPermName.Equals((String)m_lbAssignedPerm.SelectedItem)) { pp = (PermissionPair)m_alPermissions[++nIndex]; } // Pull up a properties dialog for this permission pp.perm = GetPermission((String)m_lbAssignedPerm.SelectedItem, pp.perm); m_alPermissions[nIndex] = pp; } }// onPropertiesClick
private void Init(IPermission[] perms) { m_sTitle = CResourceStore.GetString("CNewPermSetWiz2:Title"); m_sHeaderTitle = CResourceStore.GetString("CNewPermSetWiz2:HeaderTitle"); m_sHeaderSubTitle = CResourceStore.GetString("CNewPermSetWiz2:HeaderSubTitle"); m_alPermissions = new ArrayList(); m_alRemovedPermissions = new ArrayList(); // We have permissions we need to add in if (perms != null) { for (int i = 0; i < perms.Length; i++) { PermissionPair pp = new PermissionPair(); pp.sPermName = Security.GetDisplayStringForPermission(perms[i]); pp.perm = perms[i]; m_alPermissions.Add(pp); } } }// CNewPermSetWiz2