/// Remote the remoteable objects static private void EstablishRemoting() { try { BinaryServerFormatterSinkProvider TCPSink = new BinaryServerFormatterSinkProvider(); TCPSink.TypeFilterLevel = TypeFilterLevel.Low; IServerChannelSinkProvider EncryptionSink = TCPSink; if (TAppSettingsManager.GetValue("Server.ChannelEncryption.PrivateKeyfile", "", false).Length > 0) { EncryptionSink = new EncryptionServerSinkProvider(); EncryptionSink.Next = TCPSink; } Hashtable ChannelProperties = new Hashtable(); ChannelProperties.Add("port", TSrvSetting.IPBasePort); TcpChannel Channel = new TcpChannel(ChannelProperties, null, EncryptionSink); ChannelServices.RegisterChannel(Channel, false); RemotingConfiguration.RegisterWellKnownServiceType(typeof(Tests.IctCommonRemoting.Server.TServerManager), "Servermanager", WellKnownObjectMode.Singleton); RemotingConfiguration.RegisterWellKnownServiceType(typeof(Ict.Common.Remoting.Server.TClientManager), "Clientmanager", WellKnownObjectMode.Singleton); TheCrossDomainMarshaller = new TCrossDomainMarshaller(); RemotingServices.Marshal(TheCrossDomainMarshaller, TClientManager.CROSSDOMAINURL); // register the services, independent of the appdomain which is per client } catch (RemotingException rex) { if (rex.Message.IndexOf("SocketException") > 1) { TLogging.Log("A SocketException has been thrown."); TLogging.Log("Most probably problem is that the address port is used twice!"); throw new EOPAppException(); } else { throw; } } catch (Exception) { throw; } }
/// <summary> /// Starts the Petra Server. /// /// </summary> /// <returns>void</returns> public void Startup() { try { // // Uncomment the following lines to see which DLL's are loaded into the Default AppDomain at application start. // It can help in identifying which DLL's are loaded later in addition to those that were loaded at application start. /* * Console.WriteLine("Loaded Assemblies in AppDomain " + Thread.GetDomain().FriendlyName + " (at Server start):"); * foreach (Assembly tmpAssembly in Thread.GetDomain().GetAssemblies()) * { * Console.WriteLine(tmpAssembly.FullName); * } */ new TAppSettingsManager(); TLanguageCulture.Init(); TheServerManager = new TServerManager(); // Ensure Logging and an 'ordered cooperative shutdown' in case of an Unhandled Exception TheServerManager.HookupProperShutdownProcessing(); Console.WriteLine(); TLogging.Log(TheServerManager.ServerInfoVersion); TLogging.Log(Catalog.GetString("Configuration file: " + TheServerManager.ConfigurationFileName)); // // Connect to main Database // try { TheServerManager.EstablishDBConnection(); } catch (FileNotFoundException ex) { TLogging.Log(ex.Message); TLogging.Log("Please check your OpenPetra.build.config file ..."); TLogging.Log("Maybe a nant initConfigFile helps ..."); throw new EOPAppException(); } catch (Exception ex) { TLogging.Log(ex.Message); throw; } // Setup Server Timed Processing try { TheServerManager.SetupServerTimedProcessing(); } catch (Exception) { throw; } // // Remote the remoteable objects // try { if (TAppSettingsManager.HasValue("LifetimeServices.LeaseTimeInSeconds")) { TLogging.Log(Catalog.GetString("Reading parameters for server remote configuration from config file...")); BinaryServerFormatterSinkProvider TCPSink = new BinaryServerFormatterSinkProvider(); TCPSink.TypeFilterLevel = TypeFilterLevel.Low; IServerChannelSinkProvider EncryptionSink = TCPSink; if (TAppSettingsManager.GetValue("Server.ChannelEncryption.PrivateKeyfile", "", false).Length > 0) { EncryptionSink = new EncryptionServerSinkProvider(); EncryptionSink.Next = TCPSink; } Hashtable ChannelProperties = new Hashtable(); ChannelProperties.Add("port", TAppSettingsManager.GetValue("Server.Port")); string SpecificIPAddress = TAppSettingsManager.GetValue("ListenOnIPAddress", "", false); if (SpecificIPAddress.Length > 0) { ChannelProperties.Add("machineName", SpecificIPAddress); } TcpChannel Channel = new TcpChannel(ChannelProperties, null, EncryptionSink); ChannelServices.RegisterChannel(Channel, false); RemotingConfiguration.RegisterWellKnownServiceType(typeof(Ict.Petra.Server.App.Core.TServerManager), "Servermanager", WellKnownObjectMode.Singleton); RemotingConfiguration.RegisterWellKnownServiceType(typeof(Ict.Common.Remoting.Server.TClientManager), "Clientmanager", WellKnownObjectMode.Singleton); RemotingConfiguration.RegisterWellKnownServiceType(typeof(TCrossDomainMarshaller), TClientManager.CROSSDOMAINURL, WellKnownObjectMode.Singleton); LifetimeServices.LeaseTime = TimeSpan.FromSeconds(TAppSettingsManager.GetDouble("LifetimeServices.LeaseTimeInSeconds", 5.0f)); LifetimeServices.RenewOnCallTime = TimeSpan.FromSeconds(TAppSettingsManager.GetDouble("LifetimeServices.RenewOnCallTime", 5.0f)); LifetimeServices.LeaseManagerPollTime = TimeSpan.FromSeconds(TAppSettingsManager.GetDouble("LifetimeServices.LeaseManagerPollTime", 1.0f)); } else { TLogging.Log(Catalog.GetString("Reading server remote configuration from config file...")); if (TheServerManager.ConfigurationFileName == "") { RemotingConfiguration.Configure(Environment.GetCommandLineArgs()[0] + ".config", false); } else { RemotingConfiguration.Configure(TheServerManager.ConfigurationFileName, false); } RemotingConfiguration.RegisterWellKnownServiceType(typeof(TCrossDomainMarshaller), TClientManager.CROSSDOMAINURL, WellKnownObjectMode.Singleton); } } catch (RemotingException rex) { if (rex.Message.IndexOf("SocketException") > 1) { TLogging.Log("A SocketException has been thrown."); TLogging.Log("Most probably problem is that the address port is used twice!"); throw new EOPAppException(); } else { throw; } } catch (Exception) { throw; } Thread.Sleep(50); TrackingServices.RegisterTrackingHandler(new TRemotingTracker()); // Display information that the Server is ready to accept .NET Remoting requests TLogging.Log(TheServerManager.ServerInfoState); // // Server startup done. // From now on just listen on .NET Remoting Framework object invocations or on // menu commands... // bool RunWithoutMenu = TAppSettingsManager.GetBoolean("RunWithoutMenu", false); if ((!RunWithoutMenu)) { Console.WriteLine(Environment.NewLine + Catalog.GetString("-> Press \"m\" for menu.")); WriteServerPrompt(); } // All exceptions that are raised from various parts of the Server are handled below. // Note: The Server stops after handling these exceptions!!! if (RunWithoutMenu) { RunInBackground(); } else { RunMenu(); } // THE VERY END OF THE SERVER :( } catch (System.Net.Sockets.SocketException exp) { TLogging.Log( Environment.NewLine + "Unable to start the Server: The IP Port " + TSrvSetting.IPBasePort.ToString() + " is being used by a different instance of the Server or some other application." + Environment.NewLine + exp.ToString()); } catch (System.Runtime.Remoting.RemotingException exp) { System.Diagnostics.Debug.WriteLine(exp.ToString()); TLogging.Log(Environment.NewLine + "Exception occured while setting up Remoting Framework:" + Environment.NewLine + exp.ToString()); } catch (EOPAppException) { // This Exception is used if no more messages shall be done ... } catch (Exception exp) { TLogging.Log(Environment.NewLine + "Exception occured:" + Environment.NewLine + exp.ToString()); } }