[Bobbot-cvs] Bob/Storage/Xml StorageEngine.cs,1.2,1.3 XmlUser.cs,1.2,1.3
Status: Alpha
Brought to you by:
iainmckay
From: Iain M. <iai...@us...> - 2004-12-30 03:33:53
|
Update of /cvsroot/bobbot/Bob/Storage/Xml In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8381/Storage/Xml Modified Files: StorageEngine.cs XmlUser.cs Log Message: Many new changes. Most notably host-based recognition. Index: XmlUser.cs =================================================================== RCS file: /cvsroot/bobbot/Bob/Storage/Xml/XmlUser.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** XmlUser.cs 24 Dec 2004 00:36:36 -0000 1.2 --- XmlUser.cs 30 Dec 2004 03:33:42 -0000 1.3 *************** *** 77,84 **** type = Type.GetType(xmlProp.GetAttribute("type")); ! m_Properties.Add(xmlProp.GetAttribute("key"), new PropertyEntry( xmlProp.GetAttribute("key"), Convert.ChangeType(xmlProp.GetAttribute("value"), type), ! type)); } } --- 77,97 ---- type = Type.GetType(xmlProp.GetAttribute("type")); ! AddProperty( xmlProp.GetAttribute("key"), Convert.ChangeType(xmlProp.GetAttribute("value"), type), ! type); ! } ! } ! ! if(xmlElement["Hosts"] != null) ! { ! XmlNodeList xmlList = xmlElement["Hosts"].GetElementsByTagName("Host"); ! ! foreach(XmlElement xmlHost in xmlList) ! { ! if(xmlHost.InnerText == String.Empty) ! continue; ! ! m_Hosts.Add(xmlHost.InnerText); } } *************** *** 104,107 **** --- 117,123 ---- xmlElement.AppendChild(propGroup); + XmlNode hostGroup = xmlElement.OwnerDocument.CreateElement("Hosts"); + xmlElement.AppendChild(hostGroup); + foreach(DictionaryEntry entry in m_Properties) { *************** *** 116,119 **** --- 132,143 ---- } + foreach(string host in m_Hosts) + { + XmlElement hostElement = xmlElement.OwnerDocument.CreateElement("Host"); + hostElement.InnerXml = host; + + hostGroup.AppendChild(hostElement); + } + return true; } Index: StorageEngine.cs =================================================================== RCS file: /cvsroot/bobbot/Bob/Storage/Xml/StorageEngine.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** StorageEngine.cs 23 Dec 2004 22:56:12 -0000 1.2 --- StorageEngine.cs 30 Dec 2004 03:33:29 -0000 1.3 *************** *** 114,123 **** } ! public void DeleteUser(string name) { if(!UserExists(name)) ! return; m_Users.Remove(name); } --- 114,124 ---- } ! public bool DeleteUser(string name) { if(!UserExists(name)) ! return false; m_Users.Remove(name); + return true; } *************** *** 167,170 **** --- 168,189 ---- } + public User FindClosestUser(string toHost) + { + if(toHost == null) + throw new ArgumentNullException("toHost", "toHost cannot be null"); + + IUserCollection possibleUsers = FindUsersWithHost(toHost); + IUserCollection secondStage = new IUserCollection(); + IUserCollection thirdStage = new IUserCollection(); + + if((possibleUsers.Count == 0) || (possibleUsers.Count > 1)) + return null; + + IEnumerator myEnu = possibleUsers.GetEnumerator(); + myEnu.MoveNext(); + + return (User) ((DictionaryEntry) myEnu.Current).Value; + } + public IChannelCollection FindChannelsWithProperty(string prop) { *************** *** 202,205 **** --- 221,242 ---- return chanCollection; } + + public IUserCollection FindUsersWithHost(string host) + { + IUserCollection userCollection = new IUserCollection(); + + lock(m_Users) + { + foreach(DictionaryEntry entry in m_Users) + { + User user = (User) entry.Value; + + if(user.HasMatchingHost(host)) + userCollection.Add(user); + } + } + + return userCollection; + } #endregion |