private SessionList() { using (EnEx ee = new EnEx ("SessionList::SessionList()")) { m_sessions_mutex = new Mutex (); initFromDB (); } }
public HttpConn(HttpListenerContext httpContext, int compressionThreshold, bool keepalive) : base() { using (EnEx ee = new EnEx ("HttpCon::HttpConn()")) { m_httpContext = httpContext; m_compressionThreshold = compressionThreshold; m_keepalive = keepalive; m_doc = null; m_doc_loaded = false; m_sessionid = ""; m_sessionid_loaded = false; m_use_ssl = false; m_httpDomain = ""; m_sessionCookie = ""; m_compression_ok = false; if (m_compressionThreshold != 0) { // don't even check if it's not turned on. string enc = m_httpContext.Request.Headers ["Accept-Encoding"]; if (!String.IsNullOrEmpty (enc)) { if (enc.Contains ("gzip")) { m_compression_ok = true; } } } } }
/** * This static method should be used as the * argument to the Thread::start() routine * to start a Threadable object. The arg * value is expected to be a pointer to a * Threadable object. * <P> * Using this method ensures that PreExecute, Execute, * and PostExecute all get called correctly, even in the * case of exceptions. */ public static void Start(object arg) { using(EnEx ee = new EnEx("Threadable::Start()")){ // Cast the argument Threadable t = (Threadable)arg; // Set our thread id in the threadable object: t.ThreadID(System.Threading.Thread.CurrentThread.ManagedThreadId); // If PreExecute fails, then don't do anything else. // If PreExecute goes well, then guarantee to call // PostExecute, even if an exception happens in Execute(). try { t.PreExecute(); } catch (Exception e){ Log.Error("Exception during PreExecute: {0}", e.Message); return; } try { t.Execute(); } catch (Exception e) { Log.Error("Exception during Execute: {0}", e.Message); } try { t.PostExecute(); } catch (Exception e){ Log.Error("Exception during PostExecute: {0}", e.Message); } return; } }
/// <summary> /// Initializes a new instance of the <see cref="Helix.Glob.ActionLogic"/> class. /// </summary> /// <param name="action">Action.</param> public ActionLogic(XmlElement action) { using (EnEx ee = new EnEx ("ActionLogic::ActionLogic(XmlElement action)")) { m_requires_session = true; } }
public static SessionList getInstance() { using (EnEx ee = new EnEx ("SessionList::getInstance()")) { if (m_instance == null) { m_instance = new SessionList (); } return m_instance; } }
public static byte[] CompressData( byte[] raw ) { using (EnEx ee = new EnEx ("HttpCon::SendReturn()")) { using(MemoryStream memory = new MemoryStream()){ using(GZipStream gzip = new GZipStream(memory, CompressionMode.Compress, true)){ gzip.Write (raw, 0, raw.Length); } return memory.ToArray (); } } }
/// <summary> /// Initializes a new instance of the <see cref="Helix.Glob.IOConn"/> class. /// </summary> public IOConn() { using (EnEx ee = new EnEx ("IOConn::IOConn()")) { m_resp_doc = null; m_db = null; m_db_mutex = null; m_override_target = ""; m_has_responded = false; m_lr_taskid = ""; } }
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; } } }
/// <summary> /// We will serve the ../html/index.html page as a sample. /// </summary> /// <param name="ioc">Ioc.</param> public override void ExecuteRequest(IOConn ioc) { using (EnEx ee = new EnEx ("ActionLogic::ExecuteRequest(IOConn ioc)")) { // Send a simple welcome page back to the caller: String html = "../html/index.html"; DateTime lastModified = File.GetLastWriteTime( html ); Byte[] data = File.ReadAllBytes( html ); ioc.SendReturn(data, html, lastModified, DateTime.Now ); ioc.Close(); } }
public TheMain() { using (EnEx ee = new EnEx ("TheMain::TheMain()")) { // Turn on all logs for the moment. Our AdaptiveLogs will adjust this later when it starts up. Log.SetPanic (true); Log.SetError (true); Log.SetWarn (true); Log.SetInfo (true); Log.SetDebug (true); Log.SetTrace (true); Log.SetSqlTrace (true); // Find and load our configuration FindConfigFile (); LoadConfig (); // Tell everyone that we exist now _globalTheMain = this; } // End EnEx using }
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; } } } }
public bool hasSession(string sessionGUID) { using (EnEx ee = new EnEx ("SessionList::hasSession(string sessionGUID)")) { if(String.IsNullOrEmpty(sessionGUID)){ throw new Exception("Invalid sessionGUID"); } lock (m_sessions_mutex) { if (m_sessions.ContainsKey (sessionGUID) ) { return true; } else { return false; } } } }
public List<SessionInfo> getSessions() { using (EnEx ee = new EnEx ("SessionList::getSessions()")) { } }
public SessionInfo getSession(string sessionGUID) { using (EnEx ee = new EnEx ("SessionList::getSession(string sessionGUID)")) { if (String.IsNullOrEmpty (sessionGUID)) { throw new Exception ("Invalid sessionGUID"); } lock (m_sessions_mutex) { if (m_sessions.ContainsKey (sessionGUID)) { SessionInfo si = m_sessions [sessionGUID]; // Update the fact that the session has been accessed // and serialize the update. si.lastaccess.SetCurrent (); m_serialize_queue.Add (si); // then return the session return si; } else { throw new Exception ("sessionGUID not found"); } } } }
public void ShutdownThreads() { using (EnEx ee = new EnEx ("TheMain::ShutdownThreads()")) { int i; // The logger is always thread 0. Shut it down last // for every thread that we have, call it's shutdown method Log.Info ("Shutting down threads"); for (i = 1; i < (int)m_our_threads.Count; i++) { m_our_threads [i].Value.Shutdown (); } // for every thread that we have, join on the thread to ensure // that it is done. Log.Info ("Joining threads"); for (i = 1; i < (int)m_our_threads.Count; i++) { //m_our_threads[i].first->join(); m_our_threads [i].Key.Abort (); } // for every thread that we have, delete the thread and // the threadable object. Log.Info ("Deleteing threads"); //for(i = 1; i < (int)m_our_threads.size(); i++){ //delete m_our_threads[i].first; //delete m_our_threads[i].second; //} Log.Info ("Thread Shutdown complete"); } }
public void SaveConfig() { using(EnEx ee = new EnEx("TheMain::SaveConfig()")){ m_config.Save(m_config_file_name); } }
public void Save(SessionInfo si) { using (EnEx ee = new EnEx ("SessionList::Save(SessionInfo si)")) { } }
public string bytesToHexString(byte[] bytes) { using (EnEx ee = new EnEx ("SessionList::bytesToHexString(byte[] bytes)")) { } }
public string ServerVersion() { using (EnEx ee = new EnEx ("TheMain::ServerVersion()")) { return _globalServerVersion; } }
public void Shutdown() { using(EnEx ee = new EnEx("TheMain::Shutdown()") ){ m_shutdown = true; } }
public override void Execute() { using (EnEx ee = new EnEx ("HttpIOAdapter::Execute()")) { m_listener = new HttpListener (); string prefix; if (m_use_secure) { prefix = "https://"; } else { prefix = "http://"; } if (!String.IsNullOrEmpty(m_httpDomain)) { prefix += m_httpDomain; } else { prefix += "*"; } prefix += ":" + m_port + "/"; Log.Info ("Setting up HttpIOAdapter({0}) with prefix({1})", m_name, prefix); m_listener.Prefixes.Add (prefix); m_listener.Start (); Semaphore sem = new Semaphore (m_threads, m_threads); while (TheMain.GetInstance ().isShutdown () == false) { if (sem.WaitOne (500)) { // wait for an available thread. // Semaphore was signaled - there's an avaialble listen thread spot if (TheMain.GetInstance ().isShutdown ()) { // double-check just in case break; // exit loop if shutdown was triggered while we were waiting. } HttpState state = new HttpState (); state.listener = m_listener; state.sem = sem; m_listener.BeginGetContext (new AsyncCallback (HandleInbound), state); } else { // Semaphore wait timed out - loop again and check the shutdown flag } } m_listener.Stop (); } }
public string SystemName() { using (EnEx ee = new EnEx ("TheMain::SystemName()")) { return m_system_name; } }
public void StartThreadable(Threadable t) { using (EnEx ee = new EnEx ("TheMain::StartThreadable()")) { Thread td = new Thread (Threadable.Start); KeyValuePair<Thread, Threadable> kvp = new KeyValuePair<Thread, Threadable> (td, t); td.Start (t); m_our_threads.Add (kvp); } }
public void loadUserProperties(SessionInfo si, IOConn ioc) { using (EnEx ee = new EnEx ("SessionList::loadUserProperties(SessionInfo si, IOConn ioc)")) { } }
public void removeSession(IOConn ioc, string sessionGUID) { using (EnEx ee = new EnEx ("SessionList::removeSession(IOConn ioc, string sessionGUID)")) { lock(m_sessions_mutex){ Log.Debug("Attempting to remove session ({0})", sessionGUID ); if(m_sessions.ContainsKey(sessionGUID)0){ try { SessionSerializer.EnsureSessionDir(); string fileName = "./sessions/" + sessionGUID; Log.Debug("Removing session file ({0})", fileName ); File.Delete( fileName ); Log.Debug("Removing session ({0}) from session list", sessionGUID ); m_sessions.Remove(sessionGUID); } catch (Exception e){ Log.Error("Error deactivating session: {0}", e.Message); } } } } }
public void describeSessions(XmlElement node) { using (EnEx ee = new EnEx ("SessionList::describeSessions(XmlElement node)")) { XmlElement our_sessions = node.OwnerDocument.CreateElement ("SessionList"); node.AppendChild (our_sessions); foreach(SessionInfo si in getSessions()){ XmlElement session = node.OwnerDocument.CreateElement ("SessionInfo"); our_sessions.AppendChild (SessionInfo); session.SetAttribute ("userid", si.userid.ToString ()); session.SetAttribute ("dbname", si.dbname ); session.SetAttribute ("sessionGUID", si.sessionGUID ); session.SetAttribute ("created", si.created.ToString() ); session.SetAttribute ("lastaccess", si.lastaccess.ToString() ); } } }
public string ServerBuiltOn() { using (EnEx ee = new EnEx ("TheMain::ServerBuiltOn()")) { return _globalServerBuiltOn; } }
public void expireSessions(DateTime oldest, IOConn ioc, string dbname) { using (EnEx ee = new EnEx ("SessionList::expireSessions(DateTime oldest, IOConn ioc, string dbname)")) { foreach(SessionInfo si in getSessions()){ if(si.dbname == dbname && si.created < oldest ) { removeSession( ioc, si.sessionGUID ); } } } }
public string generateUniqueId() { using (EnEx ee = new EnEx ("SessionList::generateUniqueId()")) { } }
public void ShutdownLogger() { using (EnEx ee = new EnEx ("TheMain::ShutdownLogger()")) { // The Logger is always thread 0. Log.Panic ("Shutting down Logger. TheMain exiting."); m_our_threads [0].Value.Shutdown (); Thread.Sleep (1000);// sleep for 1 second to allow logs to shutdown. m_our_threads [0].Key.Abort (); //delete m_our_threads[0].first; //delete m_our_threads[0].second; // any logging at this point will go to stdout. // which means it will most likely be lost. // clear up the threads vector m_our_threads.Clear (); } }