Пример #1
0
        /// <summary>
        /// Gets a list of users in the specified role for the configured application name.
        /// </summary>
        /// <param name="roleName">The name of the role to which the users belong.</param>
        /// <returns>An array of users belonging to the specified role.</returns>
        public override string[] GetUsersInRole(string roleName)
        {
            // Create an array of user names belonging to the specified role.
            List <string> users = new List <string>();

            DataSetRoles.RoleRow roleRow = this.dataSetRoles.Role.FindByApplicationRole(this.applicationName, roleName);
            foreach (DataSetRoles.UserRow userRow in roleRow.GetUserRows())
            {
                users.Add(userRow.User);
            }
            return(users.ToArray());
        }
Пример #2
0
        /// <summary>
        /// Gets an array of user names in a role where the user name contains the specified user name.
        /// </summary>
        /// <param name="roleName">The name of the role to search.</param>
        /// <param name="usernameToMatch">The user name to be searched for.</param>
        /// <returns>An array of user names in the role containing the specified user name.</returns>
        public override string[] FindUsersInRole(string roleName, string usernameToMatch)
        {
            // This creates an array of users in the given role that match the name given as a search criteria.
            List <string> users = new List <string>();

            DataSetRoles.RoleRow roleRow = this.dataSetRoles.Role.FindByApplicationRole(this.applicationName, roleName);
            if (roleRow != null)
            {
                foreach (DataSetRoles.UserRow userRow in roleRow.GetUserRows())
                {
                    if (userRow.User.Contains(usernameToMatch))
                    {
                        users.Add(userRow.User);
                    }
                }
            }
            return(users.ToArray());
        }
Пример #3
0
        /// <summary>
        /// Removes a role from the data source for the specified application name.
        /// </summary>
        /// <param name="roleName">The name of the role to delete.</param>
        /// <param name="throwOnPopulatedRole">If true, throw an exception if the role has more than one member and do not
        /// delete the role.</param>
        /// <returns>true if the role was deleted successfully.</returns>
        public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
        {
            // Use the in-memory database to find the role for the specified application name.
            DataSetRoles.RoleRow roleRow = this.dataSetRoles.Role.FindByApplicationRole(this.applicationName, roleName);
            if (roleRow != null)
            {
                // This allows an exception to be thrown if there are still members in this role.
                if (roleRow.GetUserRows().Length != 0 && throwOnPopulatedRole)
                {
                    throw new Exception(string.Format("The {0} role is still populated with users", roleName));
                }

                // Removing the role at this point will also remove all the members from the role.
                this.dataSetRoles.Role.RemoveRoleRow(roleRow);

                // Commit the changes to the database.
                this.dataSetRoles.WriteXml(this.fileName);
            }

            // This indicates to the caller whether the role was found or not.
            return(roleRow != null);
        }