/// <summary> /// end the session, and release all resources /// </summary> public void EndSession() { if (FAppDomainStatus == TSessionStatus.adsStopped) { TLogging.Log("EndSession (for client '" + this.ClientName + "'): Session has been stopped already!"); return; } TLogging.Log("EndSession (for client '" + this.ClientName + "'): Session is about to getting stopped!"); // TODORemoting // release all UIConnector objects TLogging.Log("EndSession (for client '" + this.ClientName + "'): Checking whether there is a HttpSession.Current object"); // clear the session object if (HttpContext.Current != null) { TLogging.Log("EndSession (for client '" + this.ClientName + "'): Clearing Session"); TSession.CloseSession(); } FClientDisconnectionFinishedTime = DateTime.Now; FAppDomainStatus = TSessionStatus.adsStopped; TLogging.LogAtLevel(1, "Session for client " + this.ClientName + " has been destroyed successfully!"); }
public string Logout() { string clientName = "unknown"; if (DomainManager.CurrentClient != null) { clientName = DomainManager.CurrentClient.ClientName; } TLogging.Log("Logout from session: ClientName=" + clientName, TLoggingType.ToLogfile | TLoggingType.ToConsole); if (DomainManager.CurrentClient == null) { TSession.CloseSession(); } else { DomainManager.CurrentClient.EndSession(); } Dictionary <string, object> result = new Dictionary <string, object>(); result.Add("resultcode", "success"); return(JsonConvert.SerializeObject(result)); }
private eLoginEnum LoginInternal(string username, string password, Version AClientVersion, out Int32 AClientID, out string AWelcomeMessage, out Boolean ASystemEnabled, out Boolean AMustChangePassword) { ASystemEnabled = true; AWelcomeMessage = string.Empty; AClientID = -1; AMustChangePassword = false; Int64 SiteKey; try { if (username.ToUpper() == "SELFSERVICE") { throw new Exception("Login with user SELFSERVICE is not permitted"); } TConnectedClient CurrentClient = TClientManager.ConnectClient( username.ToUpper(), password.Trim(), HttpContext.Current.Request.UserHostName, HttpContext.Current.Request.UserHostAddress, AClientVersion, TClientServerConnectionType.csctRemote, out AClientID, out AWelcomeMessage, out ASystemEnabled, out SiteKey); TSession.SetVariable("LoggedIn", true); // the following values are stored in the session object DomainManager.GClientID = AClientID; DomainManager.CurrentClient = CurrentClient; DomainManager.GSiteKey = SiteKey; AMustChangePassword = (UserInfo.GetUserInfo().LoginMessage == SharedConstants.LOGINMUSTCHANGEPASSWORD); return(eLoginEnum.eLoginSucceeded); } catch (Exception e) { TLogging.Log(e.Message); TLogging.Log(e.StackTrace); TSession.SetVariable("LoggedIn", false); TSession.CloseSession(); return(TClientManager.LoginErrorFromException(e)); } }
/// <summary> /// initialise the server for each Web Request /// </summary> private static bool Init() { string ConfigFileName = string.Empty; // make sure the correct config file is used string Instance = HttpContext.Current.Request.Url.ToString().Replace("http://", "").Replace("https://", ""); Instance = Instance.Substring(0, Instance.IndexOf(".")).Replace("op_", "op").Replace("op", "op_"); // for demo etc if (!Instance.StartsWith("op_")) { Instance = "op_" + Instance; } ConfigFileName = "/home/" + Instance + "/etc/PetraServerConsole.config"; if (File.Exists(ConfigFileName)) { // we are in a multi tenant hosting scenario } else if (Environment.CommandLine.Contains("/appconfigfile=")) { // this happens when we use fastcgi-mono-server4 ConfigFileName = Environment.CommandLine.Substring( Environment.CommandLine.IndexOf("/appconfigfile=") + "/appconfigfile=".Length); if (ConfigFileName.IndexOf(" ") != -1) { ConfigFileName = ConfigFileName.Substring(0, ConfigFileName.IndexOf(" ")); } } else { // this is the normal behaviour when running with local http server ConfigFileName = AppDomain.CurrentDomain.BaseDirectory + Path.DirectorySeparatorChar + "web.config"; } TTypedDataTable.ResetStaticVariables(); TPdfPrinter.ResetStaticVariables(); THTTPUtils.ResetStaticVariables(); TSharedDataCache.TMPartner.ResetStaticVariables(); TServerManagerBase.ResetStaticVariables(); TClientManager.ResetStaticVariables(); TSession.InitThread("TOpenPetraOrgSessionManager.Init", ConfigFileName); if (HttpContext.Current != null) { HttpContext.Current.Server.ScriptTimeout = Convert.ToInt32( TimeSpan.FromMinutes(TAppSettingsManager.GetInt32("WebRequestTimeOutInMinutes", 15)). TotalSeconds); } // if the Login Method is called: reset cookie, ignore any old session if ((HttpContext.Current != null) && (HttpContext.Current.Request.PathInfo == "/Login")) { TSession.CloseSession(); TSession.InitThread("TOpenPetraOrgSessionManager.Init Reset", ConfigFileName); } Catalog.Init(); ErrorCodeInventory.Init(); ErrorCodeInventory.BuildErrorCodeInventory(typeof(Ict.Petra.Shared.PetraErrorCodes)); ErrorCodeInventory.BuildErrorCodeInventory(typeof(Ict.Common.Verification.TStringChecks)); TServerManager.TheServerManager = new TServerManager(); // initialise the cached tables and the delegates TSetupDelegates.Init(); TLogging.LogAtLevel(4, "Server has been initialised"); return(true); }
/// <summary> /// initialise the server once for everyone /// </summary> public static bool Init() { if (ConfigFileName == string.Empty) { // make sure the correct config file is used if (Environment.CommandLine.Contains("/appconfigfile=")) { // this happens when we use fastcgi-mono-server4 ConfigFileName = Environment.CommandLine.Substring( Environment.CommandLine.IndexOf("/appconfigfile=") + "/appconfigfile=".Length); if (ConfigFileName.IndexOf(" ") != -1) { ConfigFileName = ConfigFileName.Substring(0, ConfigFileName.IndexOf(" ")); } } else { // this is the normal behaviour when running with local http server ConfigFileName = AppDomain.CurrentDomain.BaseDirectory + Path.DirectorySeparatorChar + "web.config"; } } new TAppSettingsManager(ConfigFileName); new TLogging(TSrvSetting.ServerLogFile); TLogging.DebugLevel = TAppSettingsManager.GetInt16("Server.DebugLevel", 0); TSession.InitThread(); if (TLogging.DebugLevel >= 4) { TLogging.Log("TOpenPetraOrgSessionManager.Init"); TLogging.Log(HttpContext.Current.Request.PathInfo); } if (HttpContext.Current != null) { HttpContext.Current.Server.ScriptTimeout = Convert.ToInt32( TimeSpan.FromMinutes(TAppSettingsManager.GetInt32("WebRequestTimeOutInMinutes", 15)). TotalSeconds); } // if the Login Method is called: reset cookie, ignore any old session if ((HttpContext.Current != null) && (HttpContext.Current.Request.PathInfo == "/Login")) { TSession.CloseSession(); TSession.InitThread(); } if (TServerManager.TheServerManager == null) { Catalog.Init(); TServerManager.TheServerManager = new TServerManager(); try { // initialise the cached tables TSetupDelegates.Init(); } catch (Exception e) { TLogging.Log(e.Message); TLogging.Log(e.StackTrace); throw; } TLogging.Log("Server has been initialised"); return(true); } if (DomainManager.CurrentClient != null) { if (DomainManager.CurrentClient.FAppDomainStatus == TSessionStatus.adsStopped) { TLogging.Log("There is an attempt to reconnect to stopped session: " + DomainManager.CurrentClient.ClientName); if (HttpContext.Current.Request.PathInfo == "/IsUserLoggedIn") { // we want a clean json response saying the user is not logged in TSession.CloseSession(); return(true); } Dictionary <string, object> result = new Dictionary <string, object>(); result.Add("resultcode", "error"); result.Add("error", THTTPUtils.SESSION_ALREADY_CLOSED); HttpContext.Current.Response.Status = "403 " + THTTPUtils.SESSION_ALREADY_CLOSED; HttpContext.Current.Response.Write(JsonConvert.SerializeObject(result)); HttpContext.Current.Response.Flush(); HttpContext.Current.Response.Close(); HttpContext.Current.Response.End(); return(false); } // TLogging.Log("Init(): WebService Method name that got called: " + HttpContext.Current.Request.PathInfo); if (HttpContext.Current.Request.PathInfo != "/PollClientTasks") { DomainManager.CurrentClient.UpdateLastAccessTime(); } } return(false); }