Beispiel #1
0
        /// <summary>
        /// Moves an <see cref="AccessTypeDefinition"/> to the specified <paramref name="index"/>.
        /// </summary>
        /// <param name="index">The zero-based index to which the <paramref name="accessType"/> should be moved.</param>
        /// <param name="accessType">The <see cref="AccessTypeDefinition"/> to be moved. Must not be <see langword="null" />.</param>
        /// <remarks> Does not alter the <see cref="Permission"/> entries of the <see cref="AccessControlEntry"/> objects associated
        /// with the <see cref="SecurableClassDefinition"/>.
        /// </remarks>
        /// <exception cref="ArgumentException">
        /// The <paramref name="accessType"/> does not exist on the <see cref="SecurableClassDefinition"/>.
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// <para><paramref name="index"/> is less than 0.</para>
        /// <para> -or-</para>
        /// <para><paramref name="index"/> is greater than the top index of the <see cref="AccessTypes"/>.</para>
        /// </exception>
        public void MoveAccessType(int index, AccessTypeDefinition accessType)
        {
            ArgumentUtility.CheckNotNull("accessType", accessType);
            if (index < 0 || index >= AccessTypeReferences.Count)
            {
                throw CreateArgumentOutOfRangeException(
                          "index", index, "The index must not be less than 0 or greater than the top index of the access types for the securable class definition.");
            }

            var accessTypeReference = AccessTypeReferences.SingleOrDefault(r => r.AccessType == accessType);

            if (accessTypeReference == null)
            {
                throw CreateArgumentException(
                          "accessType", "The access type '{0}' is not associated with the securable class definition.", accessType.Name);
            }

            AccessTypeReferences.Remove(accessTypeReference);
            AccessTypeReferences.Insert(index, accessTypeReference);
            for (int i = 0; i < AccessTypeReferences.Count; i++)
            {
                AccessTypeReferences[i].Index = i;
            }

            RegisterForCommit();
        }
Beispiel #2
0
        /// <summary>
        /// Inserts an <see cref="AccessTypeDefinition"/> at the specified <paramref name="index"/>.
        /// </summary>
        /// <param name="index">The zero-based index at which the <paramref name="accessType"/> should be inserted.</param>
        /// <param name="accessType">The <see cref="AccessTypeDefinition"/> to be inserted. Must not be <see langword="null" />.</param>
        /// <remarks> Also updates all <see cref="AccessControlEntry"/> objects associated with the <see cref="SecurableClassDefinition"/>
        /// to include a <see cref="Permission"/> entry for the new <see cref="AccessTypeDefinition"/>.
        /// </remarks>
        /// <exception cref="ArgumentException">
        /// The <paramref name="accessType"/> already exists on the <see cref="SecurableClassDefinition"/>.
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// <para><paramref name="index"/> is less than 0.</para>
        /// <para> -or-</para>
        /// <para><paramref name="index"/> is greater than the total number of <see cref="AccessTypes"/>.</para>
        /// </exception>
        public void InsertAccessType(int index, AccessTypeDefinition accessType)
        {
            ArgumentUtility.CheckNotNull("accessType", accessType);
            if (index < 0 || index > AccessTypeReferences.Count)
            {
                throw CreateArgumentOutOfRangeException(
                          "index", index, "The index must not be less than 0 or greater than the total number of access types for the securable class definition.");
            }

            if (AccessTypeReferences.Where(r => r.AccessType == accessType).Any())
            {
                throw CreateArgumentException(
                          "accessType", "The access type '{0}' has already been added to the securable class definition.", accessType.Name);
            }

            var reference = AccessTypeReference.NewObject();

            reference.AccessType = accessType;
            AccessTypeReferences.Insert(index, reference);
            for (int i = 0; i < AccessTypeReferences.Count; i++)
            {
                AccessTypeReferences[i].Index = i;
            }

            foreach (var ace in GetAccessControlLists().SelectMany(acl => acl.AccessControlEntries))
            {
                ace.AddAccessType(accessType);
            }

            RegisterForCommit();
        }
Beispiel #3
0
        /// <summary>
        /// Removes an <see cref="AccessTypeDefinition"/> from of the <see cref="AccessTypes"/> list.
        /// </summary>
        /// <param name="accessType">The <see cref="AccessTypeDefinition"/> to be removed. Must not be <see langword="null" />.</param>
        /// <remarks> Also updates all <see cref="AccessControlEntry"/> objects associated with the <see cref="SecurableClassDefinition"/>
        /// to remove the <see cref="Permission"/> entry for the <see cref="AccessTypeDefinition"/>.
        /// </remarks>
        /// <exception cref="ArgumentException">
        /// The <paramref name="accessType"/> does not exist on the <see cref="SecurableClassDefinition"/>.
        /// </exception>
        public void RemoveAccessType(AccessTypeDefinition accessType)
        {
            ArgumentUtility.CheckNotNull("accessType", accessType);

            var accessTypeReference = AccessTypeReferences.SingleOrDefault(r => r.AccessType == accessType);

            if (accessTypeReference == null)
            {
                throw CreateArgumentException(
                          "accessType", "The access type '{0}' is not associated with the securable class definition.", accessType.Name);
            }

            accessTypeReference.Delete();
            for (int i = 0; i < AccessTypeReferences.Count; i++)
            {
                AccessTypeReferences[i].Index = i;
            }

            foreach (var ace in GetAccessControlLists().SelectMany(acl => acl.AccessControlEntries))
            {
                ace.RemoveAccessType(accessType);
            }

            RegisterForCommit();
        }
Beispiel #4
0
        private AccessTypeDefinition CreateAccessTypeDefinition(XmlNamespaceManager namespaceManager, XmlNode accessTypeDefinitionNode)
        {
            AccessTypeDefinition accessTypeDefinition = AccessTypeDefinition.NewObject();

            accessTypeDefinition.Name           = accessTypeDefinitionNode.Attributes["name"].Value;
            accessTypeDefinition.MetadataItemID = new Guid(accessTypeDefinitionNode.Attributes["id"].Value);
            accessTypeDefinition.Value          = int.Parse(accessTypeDefinitionNode.Attributes["value"].Value);
            accessTypeDefinition.Index          = _accessTypeDefinitionCount;
            _accessTypeDefinitionCount++;

            return(accessTypeDefinition);
        }
Beispiel #5
0
        /// <summary>
        /// Adds an <see cref="AccessTypeDefinition"/> at end of the <see cref="AccessTypes"/> list.
        /// </summary>
        /// <param name="accessType">The <see cref="AccessTypeDefinition"/> to be added. Must not be <see langword="null" />.</param>
        /// <remarks> Also updates all <see cref="AccessControlEntry"/> objects associated with the <see cref="SecurableClassDefinition"/>
        /// to include a <see cref="Permission"/> entry for the new <see cref="AccessTypeDefinition"/>.
        /// </remarks>
        /// <exception cref="ArgumentException">
        /// The <paramref name="accessType"/> already exists on the <see cref="SecurableClassDefinition"/>.
        /// </exception>
        public void AddAccessType(AccessTypeDefinition accessType)
        {
            ArgumentUtility.CheckNotNull("accessType", accessType);

            InsertAccessType(AccessTypeReferences.Count, accessType);
        }