Example #1
0
        /// <overloads>
        /// Gets the Gallery Server roles that match the specified parameters.
        /// </overloads>
        /// <summary>
        /// Gets the Gallery Server roles that match the specified <paramref name="roleNames"/>. It is not case sensitive,
        /// so that "ReadAll" matches "readall".
        /// </summary>
        /// <param name="roleNames">The name of the roles to return.</param>
        /// <returns>
        /// Returns the Gallery Server roles that match the specified <paramref name="roleNames"/>.
        /// </returns>
        /// <exception cref="InvalidGalleryServerRoleException">Thrown when one or more of the requested role names could not be found
        /// in the current collection.</exception>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="roleNames" /> is null.</exception>
        public IGalleryServerRoleCollection GetRoles(IEnumerable <string> roleNames)
        {
            if (roleNames == null)
            {
                throw new ArgumentNullException(nameof(roleNames));
            }

            IGalleryServerRoleCollection roles = new GalleryServerRoleCollection();

            foreach (var roleName in roleNames)
            {
                IGalleryServerRole role;

                if (_items.TryGetValue(roleName.ToLowerInvariant(), out role))
                {
                    roles.Add(role);
                }
                else
                {
                    throw new InvalidGalleryServerRoleException(String.Format(CultureInfo.CurrentCulture, "Could not find a Gallery Server role named '{0}'. Verify the data table contains a record for this role, and that the cache is being properly managed.", roleName));
                }
            }

            return(roles);
        }
Example #2
0
        /// <summary>
        /// Gets the Gallery Server roles with AllowAdministerGallery permission, including roles with AllowAdministerSite permission.
        /// </summary>
        /// <returns>Returns the Gallery Server roles with AllowAdministerGallery permission.</returns>
        public IGalleryServerRoleCollection GetRolesWithGalleryAdminPermission()
        {
            IGalleryServerRoleCollection roles = new GalleryServerRoleCollection();

            roles.AddRange(_items.Values.Where(r => r.AllowAdministerGallery));

            return(roles);
        }
Example #3
0
        ///// <summary>
        ///// Sort the objects in this collection by the <see cref="IGalleryServerRole.RoleName" /> property.
        ///// </summary>
        //public void Sort()
        //{
        //	// We know galleryServerRoles is actually a List<IGalleryServerRole> because we passed it to the constructor.
        //	System.Collections.Generic.List<IGalleryServerRole> galleryServerRoles = (System.Collections.Generic.List<IGalleryServerRole>)Items;

        //	galleryServerRoles.Sort();
        //}

        /// <summary>
        /// Creates a new collection containing deep copies of the items it contains.
        /// </summary>
        /// <returns>
        /// Returns a new collection containing deep copies of the items it contains.
        /// </returns>
        public IGalleryServerRoleCollection Copy()
        {
            IGalleryServerRoleCollection copy = new GalleryServerRoleCollection();

            foreach (var role in _items.Values)
            {
                copy.Add(role.Copy());
            }

            return(copy);
        }