public SessionInfo addSession(int user, string username, string fullname, string dbname) { using (EnEx ee = new EnEx ("SessionList::addSession(int user, string username, string fullname, string dbname)")) { lock(m_sessions_mutex){ // Only allow a max of 4000 sessions. if(m_sessions.Count >= 4000 ){ // Find the oldest session and delete it: SessionInfo oldest = null; foreach(KeyValuePair<String, SessionInfo> pair in m_sessions){ if(oldest == null){ oldest = pair.Value; } else { if(pair.Value.created < oldest.created){ oldest = pair.Value; } } } if(oldest != null){ SessionSerializer.EnsureSessionDir(); string fileName = "./sessions/" + oldest.sessionGUID; File.Delete( fileName ); m_sessions.Remove(oldest.sessionGUID); } } SessionInfo si = new SessionInfo(); si.userid = user; si.username = username; si.fullname = fullname; si.dbname = dbname; si.sessionGUID = generateUniqueId(); // Always add the current user id as a userProperty that can be referenced by SQL string userID; userID = user.ToString(); si.userProperties["CurrentUserID"] = userID; si.userProperties["CurrentUserName"] = username; si.userProperties["CurrentUserFullName"] = fullname; si.userProperties["CurrentUserDB"] = dbname; m_sessions[si.sessionGUID] = si; // Drop it on the queue to be serialized. m_serialize_queue.Add( si ); return si; } } }
public void loadUserProperties(SessionInfo si, IOConn ioc) { using (EnEx ee = new EnEx ("SessionList::loadUserProperties(SessionInfo si, IOConn ioc)")) { } }
public void Save(SessionInfo si) { using (EnEx ee = new EnEx ("SessionList::Save(SessionInfo si)")) { } }
public void initFromDB() { using (EnEx ee = new EnEx ("SessionList::initFromDB()")) { lock(m_sessions_mutex){ Log.Warn("Initializing SessionList from our stored sessions."); // Ensure that our directory exists SessionSerializer.EnsureSessionDir(); IEnumerable<string> files = Directory.EnumerateFiles ("./sessions"); foreach(string file in files){ string fileName = "./sessions/" + file; XmlDocument doc = new XmlDocument (); try { doc.Load (fileName); } catch (Exception e){ // Wasn't a valid xml file. Log a warning about it and delete the file: Log.Warn("File {0} is invalid while loading sessions. Deleting file.", fileName); File.Delete( fileName ); continue; } // We have a valid document, decrypt it, re-animate it and add it to our sessions list. XmlElement root = doc.DocumentElement; if(root.Name == "Encrypted"){ // This is an encrypted session doc, decrypt it before reading it: //MemBuf decryptedContents; decryptedContents.Decrypt( doc, TheMain::getInstance()->GetKeypair() ); //twine decString; decString.set( decryptedContents(), decryptedContents.length() ); //INFO(FL, "Decrypted Session:\n%s", decString() ); //xmlDocPtr decdoc = xmlParseDoc((xmlChar*) decString() ); //if(decdoc == NULL){ // WARN(FL, "Error reading decrypted xml document from original (%s)", fileName() ); // continue; //} //doc = decdoc; } SessionInfo si = new SessionInfo( doc ); m_sessions[si.sessionGUID] = si; } } } }