Example #1
0
        /// <summary>
        /// Make sure the list of ASP.NET roles is synchronized with the Gallery Server roles. If any are missing from
        /// either, add it.
        /// </summary>
        public static void ValidateRoles()
        {
            List <IGalleryServerRole>    validatedRoles = new List <IGalleryServerRole>();
            IGalleryServerRoleCollection galleryRoles   = Factory.LoadGalleryServerRoles();
            bool needToPurgeCache = false;

            foreach (string roleName in GetAllRoles())
            {
                IGalleryServerRole galleryRole = galleryRoles.GetRoleByRoleName(roleName);
                if (galleryRole == null)
                {
                    // This is an ASP.NET role that doesn't exist in our list of gallery server roles. Add it with minimum permissions
                    // applied to zero albums.
                    IGalleryServerRole newRole = Factory.CreateGalleryServerRoleInstance(roleName, false, false, false, false, false, false, false, false, false, false, false);
                    newRole.Save();
                    needToPurgeCache = true;
                }
                validatedRoles.Add(galleryRole);
            }

            // Now check to see if there are gallery roles that are not ASP.NET roles. Add if necessary.
            foreach (IGalleryServerRole galleryRole in galleryRoles)
            {
                if (!validatedRoles.Contains(galleryRole))
                {
                    // Need to create an ASP.NET role for this gallery role.
                    CreateRole(galleryRole.RoleName);
                    needToPurgeCache = true;
                }
            }

            if (needToPurgeCache)
            {
                HelperFunctions.PurgeCache();
            }
        }