/// <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("roleNames"); } // We know galleryServerRoles is actually a List<IGalleryServerRole> because we passed it to the constructor. List <IGalleryServerRole> galleryServerRoles = (List <IGalleryServerRole>)Items; IGalleryServerRoleCollection roles = new GalleryServerRoleCollection(); foreach (string roleName in roleNames) { IGalleryServerRole role = galleryServerRoles.Find(delegate(IGalleryServerRole galleryServerRole) { return(String.Compare(galleryServerRole.RoleName, roleName, StringComparison.OrdinalIgnoreCase) == 0); }); if (role == null) { 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)); } else { roles.Add(role); } } return(roles); }
/// <summary> /// Gets the Gallery Server roles that match the specified role names. The count of the returned collection will /// match the length of the roleNames array. 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 role names. /// </returns> public IGalleryServerRoleCollection GetRolesByRoleNames(string[] roleNames) { // 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; IGalleryServerRoleCollection roles = new GalleryServerRoleCollection(); foreach (string roleName in roleNames) { IGalleryServerRole role = galleryServerRoles.Find(delegate(IGalleryServerRole galleryServerRole) { return(String.Compare(galleryServerRole.RoleName, roleName, true) == 0); }); if (role == null) { // Purge the cache so if the user manually updates the table, we will notice it the next time Gallery Server requests the roles. HelperFunctions.PurgeCache(); throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, "Could not find a Gallery Server role named '{0}'. Verify the data table contains a record for this role and the current gallery, and that the cache is being properly managed.", roleName)); } else { roles.Add(role); } } return(roles); }
/// <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 (IGalleryServerRole role in Items) { copy.Add(role.Copy()); } return(copy); }
/// <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() { List <IGalleryServerRole> galleryServerRoles = (List <IGalleryServerRole>)Items; IGalleryServerRoleCollection roles = new GalleryServerRoleCollection(); roles.AddRange(galleryServerRoles.FindAll(delegate(IGalleryServerRole galleryServerRole) { return(galleryServerRole.AllowAdministerGallery == true); })); return(roles); }