示例#1
0
 /// <summary>
 /// This Constructor sets stateful information that is used in Method 'PerformDBReconnection'.
 /// </summary>
 /// <param name="ATheServerManager">Reference to the one instance of <see cref="TServerManager"/>.</param>
 /// <param name="ADBConnectionEstablishmentAtStartup">Set to true if the re-establishing of the Server's
 /// DB Polling Connection happens at Server startup time, otherwise to false.</param>
 /// <param name="ACallbackAtEndOfThread">Callback Method that gets called only when the Server's DB Polling
 /// Connection has been re-established.</param>
 public TDBReconnectionThread(
     TServerManager ATheServerManager, bool ADBConnectionEstablishmentAtStartup,
     TDBReconnectionThreadCallback ACallbackAtEndOfThread)
 {
     FTheServerManager = ATheServerManager;
     FDBConnectionEstablishmentAtStartup = ADBConnectionEstablishmentAtStartup;
     FCallbackAtEndOfThread = ACallbackAtEndOfThread;
 }
示例#2
0
        /// <summary>
        /// Initialize the Petra server and connect to the database
        /// </summary>
        /// <param name="AConfigName">just provide the server config file, plus AutoLogin and AutoLoginPasswd</param>
        public static TServerManager Connect(string AConfigName)
        {
            if (File.Exists(AConfigName))
            {
                new TAppSettingsManager(AConfigName);
            }
            else
            {
                new TAppSettingsManager();
            }

            new TLogging(TAppSettingsManager.GetValue("Server.LogFile"));

            CommonNUnitFunctions.InitRootPath();

            Catalog.Init();
            TServerManager ServerManager = new TServerManager();

            DBAccess.GDBAccessObj = new TDataBase();
            DBAccess.GDBAccessObj.EstablishDBConnection(TSrvSetting.RDMBSType,
                TSrvSetting.PostgreSQLServer, TSrvSetting.PostgreSQLServerPort,
                TSrvSetting.PostgreSQLDatabaseName,
                TSrvSetting.DBUsername, TSrvSetting.DBPassword, "");

            bool SystemEnabled;
            int ProcessID;
            TPetraPrincipal UserInfo = (TPetraPrincipal)TClientManager.PerformLoginChecks(TAppSettingsManager.GetValue("AutoLogin").ToUpper(),
                TAppSettingsManager.GetValue("AutoLoginPasswd"),
                "NUNITTEST", "127.0.0.1", out ProcessID, out SystemEnabled);

            if (FDomain != null)
            {
                FDomain.StopClientAppDomain();
            }

            TClientManager ClientManager = new TClientManager();
            DomainManager.UClientManagerCallForwarderRef = new TClientManagerCallForwarder(ClientManager);

            // do the same as in Ict.Petra.Server.App.Main.TRemoteLoader.LoadDomainManagerAssembly
            FDomain = new TClientDomainManager("0",
                TClientServerConnectionType.csctLocal,
                DomainManager.UClientManagerCallForwarderRef,
                new TSystemDefaultsCache(),
                new TCacheableTablesManager(null),
                UserInfo);
            FDomain.InitAppDomain(TSrvSetting.ServerSettings);

            new TCallForwarding();

            // we don't need to establish the database connection anymore
            // FDomain.EstablishDBConnection();

            return ServerManager;
        }
示例#3
0
 public void Init()
 {
     new TLogging("../../log/TestServer.log");
     FServerManager = TPetraServerConnector.Connect("../../etc/TestServer.config");
 }
示例#4
0
        public void Init()
        {
            new TLogging("../../log/TestServer.log");
            FServerManager = TPetraServerConnector.Connect("../../etc/TestServer.config");

            FCategories = new bool[20];

            for (int i = 0; i < 20; i++)
            {
                FCategories[i] = true;
            }
        }
示例#5
0
    /// <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());
        }
    }