public BaseSession(WebServer server) { if (server != null) { Session session; Random r = new Random(); lock (server._sessions) { do { Cookie = ""; for (int i = 0; i < 20; i++) Cookie += (char)('A' + r.Next(26)); } while (server._sessions.TryGetValue(Cookie, out session)); Object = new JObject(); server._sessions[Cookie] = (Session)this; } Server = server; } }
static void Main(string[] args) { Config.Load(args); bool windows = false; switch (Environment.OSVersion.Platform) { case PlatformID.Win32NT: case PlatformID.Win32S: case PlatformID.Win32Windows: windows = true; break; } // Default to UK culture and time (specify empty culture and/or tz to use machine values) if (Config.CommandLineFlags["culture"] != "") { CultureInfo c = new CultureInfo(Config.CommandLineFlags["culture"] ?? "en-GB"); Thread.CurrentThread.CurrentCulture = c; CultureInfo.DefaultThreadCurrentCulture = c; CultureInfo.DefaultThreadCurrentUICulture = c; } if (!string.IsNullOrEmpty(Config.CommandLineFlags["tz"])) { Utils._tz = TimeZoneInfo.FindSystemTimeZoneById(Config.CommandLineFlags["tz"] ?? (windows ? "GMT Standard Time" : "GB")); } string startPage = ""; bool serverRunning = false; if (windows) { if (Config.CommandLineFlags["nolaunch"] == null) { if (Config.CommandLineFlags["url"] != null) { startPage = Config.CommandLineFlags["url"]; } // Is server already running? try { using (var client = new TcpClient()) { var result = client.BeginConnect(Config.Default.DefaultServer.ServerName, Config.Default.Port, null, null); result.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(1)); serverRunning = client.Connected; } } catch { } if (!startPage.StartsWith("http")) { startPage = "http://" + Config.Default.DefaultServer.ServerName + ":" + Config.Default.Port + "/" + startPage; } } } if (serverRunning) { if (!string.IsNullOrEmpty(startPage)) { System.Diagnostics.Process.Start(startPage); } } else { WebServer server = new WebServer(); if (windows) { new Task(CheckForNewVersion).Start(); } if (!string.IsNullOrEmpty(startPage)) { System.Diagnostics.Process.Start(startPage); } server.Start(); } }