Exemplo n.º 1
0
        /// <summary>
        /// Removes a user group.
        /// </summary>
        /// <param name="group">The group to remove.</param>
        /// <returns><c>true</c> if the group is removed, <c>false</c> otherwise.</returns>
        /// <exception cref="ArgumentNullException">If <b>group</b> is <c>null</c>.</exception>
        public bool RemoveUserGroup(UserGroup group)
        {
            if (group == null)
            {
                throw new ArgumentNullException("group");
            }

            lock (this) {
                UserGroup[] allGroups = GetUserGroups();

                List <UserGroup> result = new List <UserGroup>(allGroups.Length);

                UserGroupComparer comp = new UserGroupComparer();

                foreach (UserGroup g in allGroups)
                {
                    if (comp.Compare(g, group) != 0)
                    {
                        result.Add(g);
                    }
                }

                DumpUserGroups(result.ToArray());

                groupsCache = null;
                usersCache  = null;

                return(result.Count == allGroups.Length - 1);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Modifies a user group.
        /// </summary>
        /// <param name="group">The group to modify.</param>
        /// <param name="description">The new description of the group.</param>
        /// <returns>The correct <see cref="T:UserGroup"/> object or <c>null</c>.</returns>
        /// <exception cref="ArgumentNullException">If <b>group</b> or <b>description</b> are <c>null</c>.</exception>
        public UserGroup ModifyUserGroup(UserGroup group, string description)
        {
            if (group == null)
            {
                throw new ArgumentNullException("group");
            }
            if (description == null)
            {
                throw new ArgumentNullException("description");
            }

            lock (this)
            {
                var allGroups = GetUserGroups();

                groupsCache = null;

                var comp = new UserGroupComparer();
                //for (var i = 0; i < allGroups.Length; i++)
                foreach (var dbGroup in allGroups)
                {
                    if (comp.Compare(dbGroup, group) == 0)
                    {
                        dbGroup.Description = description;
                        DumpUserGroups(allGroups);
                        return(dbGroup);
                    }
                }

                return(null);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Modifies a user group.
        /// </summary>
        /// <param name="group">The group to modify.</param>
        /// <param name="description">The new description of the group.</param>
        /// <returns>The correct <see cref="T:UserGroup"/> object or <c>null</c>.</returns>
        /// <exception cref="ArgumentNullException">If <b>group</b> or <b>description</b> are <c>null</c>.</exception>
        public UserGroup ModifyUserGroup(UserGroup group, string description)
        {
            if (group == null)
            {
                throw new ArgumentNullException("group");
            }

            if (description == null)
            {
                throw new ArgumentNullException("description");
            }

            lock (this) {
                UserGroup[] allGroups = GetUserGroups();

                groupsCache = null;

                UserGroupComparer comp = new UserGroupComparer();
                for (int i = 0; i < allGroups.Length; i++)
                {
                    if (comp.Compare(allGroups[i], group) == 0)
                    {
                        allGroups[i].Description = description;
                        DumpUserGroups(allGroups);
                        return(allGroups[i]);
                    }
                }

                return(null);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Finds a user group.
        /// </summary>
        /// <param name="name">The name of the group to find.</param>
        /// <returns>The <see cref="T:UserGroup" /> or <c>null</c> if no data is found.</returns>
        private UserGroup FindGroup(string name)
        {
            lock (this) {
                UserGroup[]       allUsers = GetUserGroups();
                UserGroupComparer comp     = new UserGroupComparer();
                UserGroup         target   = new UserGroup(name, "", this);

                foreach (UserGroup g in allUsers)
                {
                    if (comp.Compare(g, target) == 0)
                    {
                        return(g);
                    }
                }

                return(null);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Removes a user group.
        /// </summary>
        /// <param name="group">The group to remove.</param>
        /// <returns><c>true</c> if the group is removed, <c>false</c> otherwise.</returns>
        /// <exception cref="ArgumentNullException">If <b>group</b> is <c>null</c>.</exception>
        public bool RemoveUserGroup(UserGroup group)
        {
            if (group == null)
            {
                throw new ArgumentNullException("group");
            }

            lock (this)
            {
                var allGroups = GetUserGroups();

                var result = new List <UserGroup>();

                var comp = new UserGroupComparer();

                var removed = false;
                foreach (UserGroup g in allGroups)
                {
                    if (comp.Compare(g, group) != 0)
                    {
                        result.Add(g);
                    }
                    else
                    {
                        removed = true;
                    }
                }

                DumpUserGroups(result);

                groupsCache = null;
                usersCache  = null;

                return(removed);
            }
        }
        /// <summary>
        /// Finds a user group.
        /// </summary>
        /// <param name="name">The name of the group to find.</param>
        /// <returns>The <see cref="T:UserGroup" /> or <c>null</c> if no data is found.</returns>
        private UserGroup FindGroup(string name)
        {
            lock(this) {
                UserGroup[] allUsers = GetUserGroups();
                UserGroupComparer comp = new UserGroupComparer();
                UserGroup target = new UserGroup(name, "", this);

                foreach(UserGroup g in allUsers) {
                    if(comp.Compare(g, target) == 0) return g;
                }

                return null;
            }
        }
        /// <summary>
        /// Removes a user group.
        /// </summary>
        /// <param name="group">The group to remove.</param>
        /// <returns><c>true</c> if the group is removed, <c>false</c> otherwise.</returns>
        /// <exception cref="ArgumentNullException">If <b>group</b> is <c>null</c>.</exception>
        public bool RemoveUserGroup(UserGroup group)
        {
            if(group == null) throw new ArgumentNullException("group");

            lock(this) {
                UserGroup[] allGroups = GetUserGroups();

                List<UserGroup> result = new List<UserGroup>(allGroups.Length);

                UserGroupComparer comp = new UserGroupComparer();

                foreach(UserGroup g in allGroups) {
                    if(comp.Compare(g, group) != 0) {
                        result.Add(g);
                    }
                }

                DumpUserGroups(result.ToArray());

                groupsCache = null;
                usersCache = null;

                return result.Count == allGroups.Length - 1;
            }
        }
        /// <summary>
        /// Modifies a user group.
        /// </summary>
        /// <param name="group">The group to modify.</param>
        /// <param name="description">The new description of the group.</param>
        /// <returns>The correct <see cref="T:UserGroup"/> object or <c>null</c>.</returns>
        /// <exception cref="ArgumentNullException">If <b>group</b> or <b>description</b> are <c>null</c>.</exception>
        public UserGroup ModifyUserGroup(UserGroup group, string description)
        {
            if(group == null) throw new ArgumentNullException("group");
            if(description == null) throw new ArgumentNullException("description");

            lock(this) {
                UserGroup[] allGroups = GetUserGroups();

                groupsCache = null;

                UserGroupComparer comp = new UserGroupComparer();
                for(int i = 0; i < allGroups.Length; i++) {
                    if(comp.Compare(allGroups[i], group) == 0) {
                        allGroups[i].Description = description;
                        DumpUserGroups(allGroups);
                        return allGroups[i];
                    }
                }

                return null;
            }
        }