예제 #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();
        }
예제 #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();
        }