/// Copy constructor public TSrvSetting(TSrvSetting ACopyFrom) { if (USingletonSrvSetting == null) { USingletonSrvSetting = this; } FConfigurationFile = ACopyFrom.FConfigurationFile; FExecutingOS = ACopyFrom.FExecutingOS; FRDBMSType = ACopyFrom.FRDBMSType; FDatabaseHostOrFile = ACopyFrom.FDatabaseHostOrFile; FDatabasePort = ACopyFrom.FDatabasePort; FDatabaseName = ACopyFrom.FDatabaseName; FDBUsername = ACopyFrom.FDBUsername; FDBPassword = ACopyFrom.FDBPassword; FIPBasePort = ACopyFrom.FIPBasePort; FServerLogFile = ACopyFrom.FServerLogFile; FHostName = ACopyFrom.FHostName; FHostIPAddresses = ACopyFrom.FHostIPAddresses; FClientIdleStatusAfterXMinutes = ACopyFrom.FClientIdleStatusAfterXMinutes; FClientKeepAliveCheckIntervalInSeconds = ACopyFrom.FClientKeepAliveCheckIntervalInSeconds; FClientKeepAliveTimeoutAfterXSecondsLAN = ACopyFrom.FClientKeepAliveTimeoutAfterXSecondsLAN; FClientKeepAliveTimeoutAfterXSecondsRemote = ACopyFrom.FClientKeepAliveTimeoutAfterXSecondsRemote; FClientConnectionTimeoutAfterXSeconds = ACopyFrom.FClientConnectionTimeoutAfterXSeconds; FClientAppDomainShutdownAfterKeepAliveTimeout = ACopyFrom.FClientAppDomainShutdownAfterKeepAliveTimeout; FApplicationVersion = ACopyFrom.FApplicationVersion; FSMTPServer = ACopyFrom.FSMTPServer; FAutomaticIntranetExportEnabled = ACopyFrom.FAutomaticIntranetExportEnabled; FRunAsStandalone = ACopyFrom.FRunAsStandalone; FIntranetDataDestinationEmail = ACopyFrom.FIntranetDataDestinationEmail; FIntranetDataSenderEmail = ACopyFrom.FIntranetDataSenderEmail; }
/// <summary> /// Creates a new static instance of TSrvSetting for this AppDomain and takes /// over all settings from the static TSrvSetting object in the Default /// AppDomain. /// /// @comment WARNING: If you need to rename this procedure or change its parameters, /// you also need to change the String with its name and the parameters in the /// .NET Reflection call in TClientAppDomainConnection! /// /// @comment The static TSrvSetting object in the Default AppDomain is /// inaccessible in this AppDomain! /// /// </summary> /// <returns>void</returns> public void InitAppDomain(TSrvSetting ASettings) { // Console.WriteLine('TClientDomainManager.InitAppDomain in AppDomain: ' + Thread.GetDomain().FriendlyName); new TSrvSetting(ASettings); new TAppSettingsManager(TSrvSetting.ConfigurationFile); TLogging.DebugLevel = TAppSettingsManager.GetInt16("Server.DebugLevel", 0); }
/// <summary> /// Loads the ClientDomain DLL into the Client's AppDomain, instantiates the /// main Class (TClientDomainManager) and initialises the AppDomain by calling /// several functions of that Class. /// /// </summary> /// <param name="AClientID">ClientID as assigned by the ClientManager</param> /// <param name="AClientServerConnectionType">Tells in which way the Client connected /// to the PetraServer</param> /// <param name="AClientManagerRef">A reference to the ClientManager object /// (Note: .NET Remoting will be working behind the scenes since calls to /// this Object will cross AppDomains!)</param> /// <param name="ASystemDefaultsCacheRef">A reference to the SystemDefaultsCache object /// (Note: .NET Remoting will be working behind the scenes since calls to /// this Object will cross AppDomains!)</param> /// <param name="ACacheableTablesManagerRef"></param> /// <param name="AUserInfo">An instantiated PetraPrincipal Object, containing User /// information</param> /// <param name="AServerSettings">A copy of the ServerSettings</param> /// <param name="ARemotingURLPollClientTasks">The .NET Remoting URL of the /// TPollClientTasks Class which the Client needs to calls to retrieve /// ClientTasks.</param> /// <param name="ARemotedPollClientTasksObject"></param> public void LoadDomainManagerAssembly(Int32 AClientID, TClientServerConnectionType AClientServerConnectionType, TClientManagerCallForwarder AClientManagerRef, object ASystemDefaultsCacheRef, object ACacheableTablesManagerRef, IPrincipal AUserInfo, TSrvSetting AServerSettings, out String ARemotingURLPollClientTasks, out ICrossDomainService ARemotedPollClientTasksObject) { // Console.WriteLine('TRemoteLoader.LoadDomainManagerAssembly in AppDomain: ' + AppDomain.CurrentDomain.ToString); Assembly LoadedAssembly = Assembly.Load(CLIENTDOMAIN_DLLNAME); FRemoteClientDomainManagerClass = LoadedAssembly.GetType(CLIENTDOMAIN_CLASSNAME); FRemoteClientDomainManagerObject = Activator.CreateInstance(FRemoteClientDomainManagerClass, (BindingFlags.Public | BindingFlags.Instance | BindingFlags.CreateInstance), null, new Object[] { AClientID.ToString(), AClientServerConnectionType, AClientManagerRef, ASystemDefaultsCacheRef, ACacheableTablesManagerRef, AUserInfo }, null); FRemoteClientDomainManagerClass.InvokeMember("InitAppDomain", (BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod), null, FRemoteClientDomainManagerObject, new Object[] { AServerSettings }); // Create and remote the TPollClientTasks Class ARemotingURLPollClientTasks = Convert.ToString(FRemoteClientDomainManagerClass.InvokeMember("GetPollClientTasksURL", (BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod), null, FRemoteClientDomainManagerObject, null, null)); ARemotedPollClientTasksObject = (ICrossDomainService)FRemoteClientDomainManagerClass.InvokeMember("GetRemotedPollClientTasksObject", (BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod), null, FRemoteClientDomainManagerObject, null, null); // Establish (separate) DataBase connection for the AppDomain Convert.ToString(FRemoteClientDomainManagerClass.InvokeMember("EstablishDBConnection", (BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod), null, FRemoteClientDomainManagerObject, null, null)); // Perform any other initialisation required by the AppDomain FRemoteClientDomainManagerClass.InvokeMember("PostAppDomainSetupInitialisation", (BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod), null, FRemoteClientDomainManagerObject, null, null); // LoadClientDomainManager.ClientTaskAdd('USERMESSAGE','This is just for testing purposes!', 'blabla_1', 'blabla_2', 'blabla_3', 'blabla_4', 1); }
/// <summary> /// Initialises the internal variables that hold the Server Settings, using the current config file. /// /// </summary> /// <returns>void</returns> public TSrvSetting() { if (USingletonSrvSetting == null) { USingletonSrvSetting = this; } FConfigurationFile = TAppSettingsManager.ConfigFileName; FExecutingOS = Utilities.DetermineExecutingOS(); // Server.RDBMSType FRDBMSType = CommonTypes.ParseDBType(TAppSettingsManager.GetValue("Server.RDBMSType", "postgresql")); FDatabaseHostOrFile = TAppSettingsManager.GetValue("Server.DBHostOrFile", "localhost"); FDatabasePort = TAppSettingsManager.GetValue("Server.DBPort", "5432"); FDatabaseName = TAppSettingsManager.GetValue("Server.DBName", "openpetra"); FDBUsername = TAppSettingsManager.GetValue("Server.DBUserName", "petraserver"); FDBPassword = TAppSettingsManager.GetValue("Server.DBPassword", string.Empty, false); if (FDBPassword == "PG_OPENPETRA_DBPWD") { // get the password from the file ~/.pgpass. This currently only works for PostgreSQL on Linux using (StreamReader sr = new StreamReader(Environment.GetFolderPath(Environment.SpecialFolder.Personal) + Path.DirectorySeparatorChar + ".pgpass")) { while (!sr.EndOfStream) { string line = sr.ReadLine(); if (line.StartsWith(FDatabaseHostOrFile + ":" + FDatabasePort + ":" + FDatabaseName + ":" + FDBUsername + ":") || line.StartsWith("*:" + FDatabasePort + ":" + FDatabaseName + ":" + FDBUsername + ":")) { FDBPassword = line.Substring(line.LastIndexOf(':') + 1); break; } } } } if (TAppSettingsManager.HasValue("Server.LogFile")) { FServerLogFile = TAppSettingsManager.GetValue("Server.LogFile", false); } else { // maybe the log file has already been set, eg. by the NUnit Server Test FServerLogFile = TLogging.GetLogFileName(); if (FServerLogFile.Length == 0) { // this is effectively the bin directory (current directory) FServerLogFile = "Server.log"; } } // Server.Port FIPBasePort = TAppSettingsManager.GetInt16("Server.Port", 9000); FRunAsStandalone = TAppSettingsManager.GetBoolean("Server.RunAsStandalone", false); // Server.ClientIdleStatusAfterXMinutes FClientIdleStatusAfterXMinutes = TAppSettingsManager.GetInt32("Server.ClientIdleStatusAfterXMinutes", 5); // Server.ClientKeepAliveCheckIntervalInSeconds FClientKeepAliveCheckIntervalInSeconds = TAppSettingsManager.GetInt32("Server.ClientKeepAliveCheckIntervalInSeconds", 60); // Server.ClientKeepAliveTimeoutAfterXSeconds_LAN FClientKeepAliveTimeoutAfterXSecondsLAN = TAppSettingsManager.GetInt32("Server.ClientKeepAliveTimeoutAfterXSeconds_LAN", 60); // Server.ClientKeepAliveTimeoutAfterXSeconds_Remote FClientKeepAliveTimeoutAfterXSecondsRemote = TAppSettingsManager.GetInt32("Server.ClientKeepAliveTimeoutAfterXSeconds_Remote", (ClientKeepAliveTimeoutAfterXSecondsLAN * 2)); // Server.ClientConnectionTimeoutAfterXSeconds FClientConnectionTimeoutAfterXSeconds = TAppSettingsManager.GetInt32("Server.ClientConnectionTimeoutAfterXSeconds", 20); // Server.ClientAppDomainShutdownAfterKeepAliveTimeout FClientAppDomainShutdownAfterKeepAliveTimeout = TAppSettingsManager.GetBoolean("Server.ClientAppDomainShutdownAfterKeepAliveTimeout", true); FSMTPServer = TAppSettingsManager.GetValue("Server.SMTPServer", "localhost"); // This is disabled in processing at the moment, so we reflect that here. When it works change to true FAutomaticIntranetExportEnabled = TAppSettingsManager.GetBoolean("Server.AutomaticIntranetExportEnabled", false); // The following setting specifies the email address where the Intranet Data emails are sent to when "Server.AutomaticIntranetExportEnabled" is true. FIntranetDataDestinationEmail = TAppSettingsManager.GetValue("Server.IntranetDataDestinationEmail", "???@???.org"); // The following setting is temporary - until we have created a GUI where users can specify the email address for the // responsible Personnel and Finance persons themselves. Those will be stored in SystemDefaults then. FIntranetDataSenderEmail = TAppSettingsManager.GetValue("Server.IntranetDataSenderEmail", "???@???.org"); // Determine network configuration of the Server Networking.DetermineNetworkConfig(out FHostName, out FHostIPAddresses); FApplicationVersion = TFileVersionInfo.GetApplicationVersion(); }