/// <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 } }
/// <summary> /// code for generating typed datasets /// </summary> /// <param name="AInputXmlfile"></param> /// <param name="AOutputPath"></param> /// <param name="ANameSpace"></param> /// <param name="store"></param> /// <param name="groups"></param> /// <param name="AFilename"></param> public static void CreateTypedDataSets(String AInputXmlfile, String AOutputPath, String ANameSpace, TDataDefinitionStore store, string[] groups, string AFilename) { Console.WriteLine("processing dataset " + ANameSpace); string templateDir = TAppSettingsManager.GetValue("TemplateDir", true); ProcessTemplate Template = new ProcessTemplate(templateDir + Path.DirectorySeparatorChar + "ORM" + Path.DirectorySeparatorChar + "DataSet.cs"); Template.AddSnippetsFromOtherFile(templateDir + Path.DirectorySeparatorChar + "ORM" + Path.DirectorySeparatorChar + "DataTable.cs"); DataSetTableIdCounter = Convert.ToInt16(TAppSettingsManager.GetValue("StartTableId")); // load default header with license and copyright Template.SetCodelet("GPLFILEHEADER", ProcessTemplate.LoadEmptyFileComment(templateDir)); Template.SetCodelet("NAMESPACE", ANameSpace); // if no dataset is defined yet in the xml file, the following variables can be empty Template.AddToCodelet("USINGNAMESPACES", ""); Template.AddToCodelet("CONTENTDATASETSANDTABLESANDROWS", ""); TXMLParser parserDataSet = new TXMLParser(AInputXmlfile, false); XmlDocument myDoc = parserDataSet.GetDocument(); XmlNode startNode = myDoc.DocumentElement; if (startNode.Name.ToLower() == "petradatasets") { XmlNode cur = TXMLParser.NextNotBlank(startNode.FirstChild); while ((cur != null) && (cur.Name.ToLower() == "importunit")) { Template.AddToCodelet("USINGNAMESPACES", "using " + TXMLParser.GetAttribute(cur, "name") + ";" + Environment.NewLine); cur = TXMLParser.GetNextEntity(cur); } while ((cur != null) && (cur.Name.ToLower() == "dataset")) { ProcessTemplate snippetDataset = Template.GetSnippet("TYPEDDATASET"); string datasetname = TXMLParser.GetAttribute(cur, "name"); snippetDataset.SetCodelet("DATASETNAME", datasetname); // INITCONSTRAINTS and INITRELATIONS can be empty snippetDataset.AddToCodelet("INITCONSTRAINTS", ""); snippetDataset.AddToCodelet("INITRELATIONS", ""); SortedList <string, TDataSetTable> tables = new SortedList <string, TDataSetTable>(); XmlNode curChild = cur.FirstChild; while (curChild != null) { if ((curChild.Name.ToLower() == "table") && TXMLParser.HasAttribute(curChild, "sqltable")) { bool OverloadTable = false; string tabletype = TTable.NiceTableName(TXMLParser.GetAttribute(curChild, "sqltable")); string variablename = (TXMLParser.HasAttribute(curChild, "name") ? TXMLParser.GetAttribute(curChild, "name") : tabletype); TDataSetTable table = new TDataSetTable( TXMLParser.GetAttribute(curChild, "sqltable"), tabletype, variablename, store.GetTable(tabletype)); XmlNode tableNodes = curChild.FirstChild; while (tableNodes != null) { if (tableNodes.Name.ToLower() == "customfield") { // eg. BestAddress in PartnerEditTDS.PPartnerLocation TTableField customField = new TTableField(); customField.strName = TXMLParser.GetAttribute(tableNodes, "name"); customField.strTypeDotNet = TXMLParser.GetAttribute(tableNodes, "type"); customField.strDescription = TXMLParser.GetAttribute(tableNodes, "comment"); customField.strDefault = TXMLParser.GetAttribute(tableNodes, "initial"); table.grpTableField.Add(customField); OverloadTable = true; } if (tableNodes.Name.ToLower() == "field") { // eg. UnitName in PartnerEditTDS.PPerson TTableField field = new TTableField(store.GetTable(TXMLParser.GetAttribute(tableNodes, "sqltable")). GetField(TXMLParser.GetAttribute(tableNodes, "sqlfield"))); if (TXMLParser.HasAttribute(tableNodes, "name")) { field.strNameDotNet = TXMLParser.GetAttribute(tableNodes, "name"); } if (TXMLParser.HasAttribute(tableNodes, "comment")) { field.strDescription = TXMLParser.GetAttribute(tableNodes, "comment"); } table.grpTableField.Add(field); OverloadTable = true; } if (tableNodes.Name.ToLower() == "primarykey") { TConstraint primKeyConstraint = table.GetPrimaryKey(); primKeyConstraint.strThisFields = StringHelper.StrSplit(TXMLParser.GetAttribute(tableNodes, "thisFields"), ","); OverloadTable = true; } tableNodes = tableNodes.NextSibling; } if (OverloadTable) { tabletype = datasetname + TTable.NiceTableName(table.strName); if (TXMLParser.HasAttribute(curChild, "name")) { tabletype = datasetname + TXMLParser.GetAttribute(curChild, "name"); } table.strDotNetName = tabletype; table.strVariableNameInDataset = variablename; // set tableid table.iOrder = DataSetTableIdCounter++; // TODO: can we derive from the base table, and just overload a few functions? CodeGenerationTable.InsertTableDefinition(snippetDataset, table, store.GetTable(table.tableorig), "TABLELOOP", true); CodeGenerationTable.InsertRowDefinition(snippetDataset, table, store.GetTable(table.tableorig), "TABLELOOP"); } tables.Add(variablename, table); AddTableToDataset(tabletype, variablename, snippetDataset); } else if ((curChild.Name.ToLower() == "table") && TXMLParser.HasAttribute(curChild, "customtable")) { // this refers to a custom table of another dataset, eg. BestAddressTDSLocation // for the moment, such a table cannot have additional fields if (curChild.HasChildNodes) { throw new Exception( String.Format( "CreateTypedDataSets(): At the moment, a custom table referenced from another dataset cannot have additional fields. Dataset: {0}, Table: {1}", datasetname, TXMLParser.HasAttribute(curChild, "customtable"))); } // customtable has to contain the name of the dataset, eg. BestAddressTDSLocation string tabletype = TXMLParser.GetAttribute(curChild, "customtable"); string variablename = (TXMLParser.HasAttribute(curChild, "name") ? TXMLParser.GetAttribute(curChild, "name") : tabletype); AddTableToDataset(tabletype, variablename, snippetDataset); } if (curChild.Name.ToLower() == "customrelation") { ProcessTemplate tempSnippet = Template.GetSnippet("INITRELATIONS"); tempSnippet.SetCodelet("RELATIONNAME", TXMLParser.GetAttribute(curChild, "name")); tempSnippet.SetCodelet("TABLEVARIABLENAMEPARENT", TXMLParser.GetAttribute(curChild, "parentTable")); tempSnippet.SetCodelet("TABLEVARIABLENAMECHILD", TXMLParser.GetAttribute(curChild, "childTable")); tempSnippet.SetCodelet("COLUMNNAMESPARENT", StringCollectionToValuesFormattedForArray(tables, TXMLParser.GetAttribute(curChild, "parentTable"), StringHelper.StrSplit(TXMLParser.GetAttribute(curChild, "parentFields"), ","))); tempSnippet.SetCodelet("COLUMNNAMESCHILD", StringCollectionToValuesFormattedForArray(tables, TXMLParser.GetAttribute(curChild, "childTable"), StringHelper.StrSplit(TXMLParser.GetAttribute(curChild, "childFields"), ","))); tempSnippet.SetCodelet("CREATECONSTRAINTS", TXMLParser.GetBoolAttribute(curChild, "createConstraints") ? "true" : "false"); snippetDataset.InsertSnippet("INITRELATIONS", tempSnippet); } if (curChild.Name.ToLower() == "customtable") { string variablename = TXMLParser.GetAttribute(curChild, "name"); string tabletype = datasetname + TXMLParser.GetAttribute(curChild, "name"); XmlNode customTableNodes = curChild.FirstChild; TDataSetTable customTable = new TDataSetTable( tabletype, tabletype, variablename, null); // set TableId customTable.iOrder = DataSetTableIdCounter++; customTable.strDescription = TXMLParser.GetAttribute(curChild, "comment"); customTable.strName = tabletype; customTable.strDotNetName = tabletype; customTable.strVariableNameInDataset = variablename; while (customTableNodes != null) { if (customTableNodes.Name.ToLower() == "customfield") { TTableField customField = new TTableField(); customField.strName = TXMLParser.GetAttribute(customTableNodes, "name"); customField.strTypeDotNet = TXMLParser.GetAttribute(customTableNodes, "type"); customField.strDescription = TXMLParser.GetAttribute(customTableNodes, "comment"); customField.strDefault = TXMLParser.GetAttribute(customTableNodes, "initial"); customTable.grpTableField.Add(customField); } if (customTableNodes.Name.ToLower() == "field") { // eg. SelectedSiteKey in PartnerEditTDS.MiscellaneousData TTableField field = new TTableField(store.GetTable(TXMLParser.GetAttribute(customTableNodes, "sqltable")). GetField(TXMLParser.GetAttribute(customTableNodes, "sqlfield"))); if (TXMLParser.HasAttribute(customTableNodes, "name")) { field.strNameDotNet = TXMLParser.GetAttribute(customTableNodes, "name"); } if (TXMLParser.HasAttribute(customTableNodes, "comment")) { field.strDescription = TXMLParser.GetAttribute(customTableNodes, "comment"); } customTable.grpTableField.Add(field); } if (customTableNodes.Name.ToLower() == "primarykey") { TConstraint primKeyConstraint = new TConstraint(); primKeyConstraint.strName = "PK"; primKeyConstraint.strType = "primarykey"; primKeyConstraint.strThisFields = StringHelper.StrSplit(TXMLParser.GetAttribute(customTableNodes, "thisFields"), ","); customTable.grpConstraint.Add(primKeyConstraint); } customTableNodes = customTableNodes.NextSibling; } tables.Add(tabletype, customTable); AddTableToDataset(tabletype, variablename, snippetDataset); CodeGenerationTable.InsertTableDefinition(snippetDataset, customTable, null, "TABLELOOP", true); CodeGenerationTable.InsertRowDefinition(snippetDataset, customTable, null, "TABLELOOP"); } curChild = curChild.NextSibling; } foreach (TDataSetTable table in tables.Values) { // todo? also other constraints, not only from original table? foreach (TConstraint constraint in table.grpConstraint) { if ((constraint.strType == "foreignkey") && tables.ContainsKey(constraint.strOtherTable)) { TDataSetTable otherTable = (TDataSetTable)tables[constraint.strOtherTable]; ProcessTemplate tempSnippet = Template.GetSnippet("INITCONSTRAINTS"); tempSnippet.SetCodelet("TABLEVARIABLENAME1", table.tablealias); tempSnippet.SetCodelet("TABLEVARIABLENAME2", otherTable.tablealias); tempSnippet.SetCodelet("CONSTRAINTNAME", TTable.NiceKeyName(constraint)); tempSnippet.SetCodelet("COLUMNNAMES1", StringCollectionToValuesFormattedForArray(constraint.strThisFields)); tempSnippet.SetCodelet("COLUMNNAMES2", StringCollectionToValuesFormattedForArray(constraint.strOtherFields)); snippetDataset.InsertSnippet("INITCONSTRAINTS", tempSnippet); } } } Template.InsertSnippet("CONTENTDATASETSANDTABLESANDROWS", snippetDataset); cur = TXMLParser.GetNextEntity(cur); } } Template.FinishWriting(AOutputPath + Path.DirectorySeparatorChar + AFilename + "-generated.cs", ".cs", true); }
/// <summary> /// Drives a Test Client. /// </summary> public void Run() { XmlNode curEvent; XmlNode oldEvent; String action; Int64 breakTime; Int32 NetClientPort; Int32 APClientPort; String parameters; System.Diagnostics.Process UProgressProcess; DateTime TimeFinished; curEvent = curGroup.FirstChild; breakTime = 0; if ((curEvent != null) && (curEvent.Name.ToLower() == "event")) { breakTime = main.RandomBreak(curEvent); } while ((curEvent != null) && (curEvent.Name.ToLower() == "event") && main.ServerStillRunning()) { if (breakTime > 0) { System.Console.WriteLine("{0}: Client {1} is sleeping for about " + Convert.ToString( breakTime / 1000) + " seconds ...", DateTime.Now.ToLongTimeString(), Id); Thread.Sleep((int)breakTime); } // System.Console.WriteLine('continue client ' + Id.Tostring() + ' at time ' + DateTime.Now.ToString()); // we need the breaktime already, to tell the client how long it should run oldEvent = curEvent; curEvent = curEvent.NextSibling; if (curEvent == null) { // start again curEvent = curGroup.FirstChild; if (TXMLParser.GetBoolAttribute(curGroup, "loop", true) == false) { curEvent = null; } } if (curEvent != null) { breakTime = main.RandomBreak(curEvent); } action = TXMLParser.GetAttribute(oldEvent, "action"); if (action == "connect") { System.Console.WriteLine("{0}: connecting client {1}", DateTime.Now.ToLongTimeString(), Id); NetClientPort = 2080 + Id * 2; APClientPort = 2081 + Id * 2; TimeFinished = DateTime.Now.AddMilliseconds(breakTime); parameters = "-C:" + Global.Configfile + ' ' + "-NetClientPort:" + NetClientPort.ToString() + ' ' + "-APClientPort:" + APClientPort.ToString() + ' ' + "-AutoLogin:TESTUSER" + Id.ToString() + ' ' + "-AutoLoginPasswd:test" + ' ' + "-DisconnectTime:" + new TVariant(TimeFinished).EncodeToString() + ' ' + "-RunAutoTests:true" + ' ' + "-AutoTestConfigFile:" + TXMLParser.GetAttribute(oldEvent, "testing") + ' ' + "-AutoTestParameters:" + TXMLParser.GetAttribute(oldEvent, "params") + ' ' + "-SingleClient:" + SingleClient.ToString(); // add fixed disconnection datetime; or create a testing file? // add testing file try { System.Console.WriteLine("{0}: starting {1}", DateTime.Now.ToLongTimeString(), parameters); UProgressProcess = new System.Diagnostics.Process(); UProgressProcess.EnableRaisingEvents = false; UProgressProcess.StartInfo.FileName = Global.Filename; UProgressProcess.StartInfo.Arguments = parameters; UProgressProcess.EnableRaisingEvents = true; if ((!UProgressProcess.Start())) { return; } } catch (Exception Exp) { System.Console.WriteLine("{0}: Trouble in TestClient.Run", DateTime.Now.ToLongTimeString()); System.Console.WriteLine("{0}: {1}", DateTime.Now.ToLongTimeString(), Exp.Message); return; } } else if (action == "disconnect") { System.Console.WriteLine("{0}: disconnecting client {1}", DateTime.Now.ToLongTimeString(), Id); } } }