public void AddChild(UserGroupInfo child) { lock (Children) { Children.Add(child); } }
public void RemoveChild(UserGroupInfo child) { lock (Children) { Children.Remove(child); } }
/// <summary> /// Is the other group an ancestor of this one? /// </summary> public bool IsAncestor(UserGroupInfo other) { if ((Parent != null) && (Parent.Equals(other) || Parent.IsAncestor(other))) return true; return false; }
/// <summary> /// Is the other group an ancestor of this one? /// </summary> public bool IsAncestor(UserGroupInfo other) { if ((Parent != null) && (Parent.Equals(other) || Parent.IsAncestor(other))) { return(true); } return(false); }
/// <summary> /// Is the other group descendant of this one? /// </summary> public bool IsDescendant(UserGroupInfo other) { lock (Children) { foreach (UserGroupInfo child in Children) { if (child.Equals(other) || child.IsDescendant(other)) return true; } } return false; }
public void SetParent(UserGroupInfo parent) { this.Parent = parent; }
private void ReadUserSubTree(XmlElement xmlParent, UserGroupInfo parent) { foreach (XmlElement xmlChild in xmlParent.ChildNodes) { UserGroupInfo child; //names are case insensitive string name = xmlChild.GetAttribute("Name").ToLower(); if (allGroups.ContainsKey(name)) throw new Exception("duplicate usergroup name " + name); switch (xmlChild.Name) { case "Group": { child = new UserGroupInfo(nextUserOrGroupId, name); } break; case "User": { string password = xmlChild.GetAttribute("Password"); string liveId = xmlChild.GetAttribute("LiveId"); string LiveIdUniqueUserToken = xmlChild.GetAttribute("LiveIdUniqueUserToken"); DateTime activeFrom = DateTime.Parse(xmlChild.GetAttribute("ActiveFrom")); DateTime activeUntil = DateTime.Parse(xmlChild.GetAttribute("ActiveUntil")); child = new UserInfo(nextUserOrGroupId, name, password, activeFrom, activeUntil, liveId, LiveIdUniqueUserToken); if (xmlChild.ChildNodes.Count != 0) throw new Exception("User " + name + " has children"); } break; default: throw new Exception("bad node name in users file " + xmlChild.Name); } AddUserGroup(child, parent, false); nextUserOrGroupId++; ReadUserSubTree(xmlChild, child); } }
private void WriteUserSubTree(XmlElement xmlParent, UserGroupInfo parent, XmlDocument xmlDoc) { foreach (UserGroupInfo userGroup in parent.Children) { XmlElement xmlChild; if (userGroup is UserInfo) { xmlChild = xmlDoc.CreateElement("User"); UserInfo userInfo = (UserInfo)userGroup; xmlChild.SetAttribute("Password", userInfo.Password); xmlChild.SetAttribute("ActiveFrom", userInfo.ActiveFrom.ToString()); xmlChild.SetAttribute("ActiveUntil", userInfo.ActiveUntil.ToString()); xmlChild.SetAttribute("LiveId", userInfo.LiveId); xmlChild.SetAttribute("LiveIdUniqueUserToken", userInfo.LiveIdUniqueUserToken); } else { xmlChild = xmlDoc.CreateElement("Group"); } xmlChild.SetAttribute("Name", userGroup.Name); xmlParent.AppendChild(xmlChild); WriteUserSubTree(xmlChild, userGroup, xmlDoc); } }
private void AddUserGroup(UserGroupInfo groupToAdd, UserGroupInfo parent, bool writeToDisk = true) { //we lock allGroups even when allUsers is being accessed lock (allGroups) { //add to all groups allGroups.Add(groupToAdd.Name, groupToAdd); //add to all users if this is a user if (groupToAdd is UserInfo) allUsers.Add(groupToAdd.Name, (UserInfo)groupToAdd); //do the linking up and down groupToAdd.SetParent(parent); parent.AddChild(groupToAdd); if (writeToDisk) WriteUserTree(); } }
public bool Equals(UserGroupInfo other) { return this.Name.Equals(other.Name); }
private void ReadUserTree() { XmlDocument xmlDoc = new XmlDocument(); XmlReader xmlReader = XmlReader.Create(this.UsersFile, xmlReaderSettings); xmlDoc.Load(xmlReader); XmlElement rootXml = xmlDoc.FirstChild as XmlElement; //names are case insensitive string name = rootXml.GetAttribute("Name").ToLower(); rootGroup = new UserGroupInfo(nextUserOrGroupId, name); allGroups.Add(name, rootGroup); nextUserOrGroupId++; ReadUserSubTree(rootXml, rootGroup); xmlReader.Close(); }