/// <summary> /// Connects to the PetraServer and provides a menu with a number of functions, /// including stopping the PetraServer. /// </summary> /// <returns>void</returns> public static void Start() { Ict.Petra.ServerAdmin.App.Core.TConnector TheConnector; IServerAdminInterface TRemote; String ClientID; Boolean SilentSysadm; SilentSysadm = false; try { new TLogging(); new TAppSettingsManager(); SilentSysadm = true; if (TAppSettingsManager.HasValue("DebugLevel")) { TLogging.DebugLevel = TAppSettingsManager.GetInt32("DebugLevel"); } if ((!TAppSettingsManager.HasValue("Command") || (TAppSettingsManager.GetValue("Command") == "Stop"))) { SilentSysadm = false; } if (TAppSettingsManager.HasValue("ServerAdmin.LogFile")) { new TLogging(TAppSettingsManager.GetValue("ServerAdmin.LogFile")); } if ((!SilentSysadm)) { Console.WriteLine(); TLogging.Log( "PETRAServerADMIN " + System.Reflection.Assembly.GetEntryAssembly().GetName().Version.ToString() + ' ' + "Build " + System.IO.File.GetLastWriteTime( Process.GetCurrentProcess().MainModule.FileName).ToString() + " (OS: " + CommonTypes.ExecutingOSEnumToString(Utilities.DetermineExecutingOS()) + ')'); TLogging.Log(Catalog.GetString("Configuration file: " + TAppSettingsManager.ConfigFileName)); // System.Reflection.Assembly.GetEntryAssembly.FullName does not return the file path TLogging.Log("Connecting to PETRAServer..."); Console.WriteLine(); } // Instantiate a TServerManager object, which has all logic for Server // startup and shutdown TheConnector = new Ict.Petra.ServerAdmin.App.Core.TConnector(); TheConnector.GetServerConnection(TAppSettingsManager.ConfigFileName, out TRemote); if (TAppSettingsManager.HasValue("Command")) { if (TAppSettingsManager.GetValue("Command") == "Stop") { ShutDown(TRemote, false); } else if (TAppSettingsManager.GetValue("Command") == "StopAndCloseClients") { ShutDownControlled(TRemote, false); } else if (TAppSettingsManager.GetValue("Command") == "ConnectedClients") { System.Console.WriteLine(TRemote.FormatClientList(false)); } else if (TAppSettingsManager.GetValue("Command") == "ConnectedClientsSysadm") { System.Console.WriteLine(TRemote.FormatClientListSysadm(false)); } else if (TAppSettingsManager.GetValue("Command") == "DisconnectedClients") { System.Console.WriteLine(TRemote.FormatClientList(true)); } else if (TAppSettingsManager.GetValue("Command") == "DisconnectClient") { ClientID = TAppSettingsManager.GetValue("ClientID"); DisconnectClient(TRemote, ClientID); } else if (TAppSettingsManager.GetValue("Command") == "LoadYmlGz") { RestoreDatabase(TRemote, TAppSettingsManager.GetValue("YmlGzFile")); } else if (TAppSettingsManager.GetValue("Command") == "RefreshAllCachedTables") { RefreshAllCachedTables(TRemote); } else if (TAppSettingsManager.GetValue("Command") == "AddUser") { AddUser(TRemote, TAppSettingsManager.GetValue("UserId")); } } else { Menu(TRemote); } // All exceptions that are raised are handled here // Note: ServerAdmin stops after handling these exceptions!!! } catch (RemotingException remexp) { if ((!SilentSysadm)) { Console.WriteLine("RemotingException occured while connecting/communicating to PETRAServer: " + remexp.Message); } return; } catch (Exception exp) { if ((!SilentSysadm)) { Console.WriteLine("Exception occured while connecting/communicating to PETRAServer: " + exp.ToString()); } return; } // THE VERY END OF SERVERADMIN :( }
/// <summary> /// Executes the tests (main method of this executable!). /// </summary> public static void RunTest() { XmlNode startNode; XmlNode curGroup; Thread groupThread; TestGroup myGroup; String testcase; new TAppSettingsManager(true); testcase = TAppSettingsManager.GetValue("testcase"); Global.StartClientID = TAppSettingsManager.GetInt16("startclientid"); rnd = new System.Random(DateTime.Now.Millisecond); // Init try { parser = new TXMLParser(TAppSettingsManager.GetValue("testscript"), false); startNode = parser.GetDocument().DocumentElement; } catch (Exception E) { System.Console.WriteLine("{0}: trouble in RunTest", DateTime.Now.ToLongTimeString()); System.Console.WriteLine("{0}: {1}", DateTime.Now.ToLongTimeString(), E.Message); return; } new TLogging(@"..\..\log\PetraMultiStart.log"); TheConnector = new Ict.Petra.ServerAdmin.App.Core.TConnector(); TheConnector.GetServerConnection(TAppSettingsManager.ConfigFileName, out TRemote); CreateTestUsers(); if (startNode.Name.ToLower() == "tests") { startNode = startNode.FirstChild; while ((startNode != null) && (startNode.Name.ToLower() == "test") && (TXMLParser.GetAttribute(startNode, "name") != testcase)) { startNode = startNode.NextSibling; } } if (startNode == null) { Console.WriteLine("{0}: cannot find testcase {1}", DateTime.Now.ToLongTimeString(), testcase); return; } while (true) { // restart the whole test scenario if (startNode.Name.ToLower() == "test") { Global.Filename = TXMLParser.GetAttribute(startNode, "app"); // kill instances of previous test KillAllProcesses(Global.Filename.Substring(0, Global.Filename.IndexOf('.'))); Global.Configfile = TXMLParser.GetAttribute(startNode, "config"); curGroup = startNode.FirstChild; while ((curGroup != null) && (curGroup.Name == "clientgroup")) { if (TXMLParser.GetBoolAttribute(curGroup, "active", true) != false) { myGroup = new TestGroup(curGroup); groupThread = new Thread(myGroup.Run); groupThread.Start(); } curGroup = curGroup.NextSibling; } } Thread.CurrentThread.Join(); System.Console.WriteLine("{0}: All threads have stopped", DateTime.Now.ToLongTimeString()); if (TXMLParser.GetBoolAttribute(startNode, "loop", true) == false) { return; } Thread.Sleep(5 * 60 * 1000); // wait for 5 minutes before restarting } }