/// <summary>main function for generating the code</summary> public abstract void CreateCode(TCodeStorage AStorage, string AXamlFilename, string ATemplate);
/// <summary> /// constructor /// </summary> /// <param name="ACodeStorage"></param> public TParseYAMLFormsDefinition(ref TCodeStorage ACodeStorage) { this.FCodeStorage = ACodeStorage; }
/// <summary> /// construtor /// </summary> /// <param name="node"></param> /// <param name="ACodeStorage"></param> public TControlDef(XmlNode node, TCodeStorage ACodeStorage) { xmlNode = node; controlTypePrefix = GetLowerCasePrefix(xmlNode.Name); FCodeStorage = ACodeStorage; }
/// <summary> /// load the dataset tables /// </summary> public static SortedList <string, TTable> LoadDatasetTables(string AICTPath, string ADataSetTypeWithNamespace, TCodeStorage ACodeStorage, string APluginPath) { if (FDatasetTables == null) { FDatasetTables = new SortedList <string, SortedList <string, TTable> >(); } FCodeStorage = ACodeStorage; if (!ADataSetTypeWithNamespace.StartsWith("Ict.Petra.Shared") && !ADataSetTypeWithNamespace.StartsWith("Ict.Petra.Plugins")) { throw new Exception("the DatasetType must contain the full namespace, starting with Ict.Petra.Shared or Ict.Petra.Plugins"); } if (FDatasetTables.ContainsKey(ADataSetTypeWithNamespace)) { FCurrentDataset = FDatasetTables[ADataSetTypeWithNamespace]; return(FCurrentDataset); } string[] datasetTypeSplit = ADataSetTypeWithNamespace.Split(new char[] { '.' }); string module = datasetTypeSplit[3]; string datasetName = datasetTypeSplit[datasetTypeSplit.Length - 1]; // find the correct xml file for the dataset. // look in Ict/Petra/Shared/lib/MODULE/data string dataPath = AICTPath + "/Petra/Shared/lib/" + module + "/data/"; if (ADataSetTypeWithNamespace.StartsWith("Ict.Petra.Plugins")) { int start = "Ict.Petra.Plugins.".Length; int end = ADataSetTypeWithNamespace.IndexOf(".", start); string PluginName = ADataSetTypeWithNamespace.Substring(start, end - start); dataPath = AICTPath + "/Petra/Plugins/" + PluginName + "/data/"; } DirectoryInfo directory = new DirectoryInfo(dataPath); FileInfo[] xmlFiles = directory.GetFiles("*.xml"); XmlNode datasetNode = null; foreach (FileInfo fileinfo in xmlFiles) { if (datasetNode == null) { TXMLParser parser = new TXMLParser(dataPath + "/" + fileinfo.Name, false); datasetNode = parser.GetDocument().SelectSingleNode(String.Format("//DataSet[@name='{0}']", datasetName)); } } if ((datasetNode == null) && File.Exists(APluginPath)) { // also check the plugin directory of the yaml file, for plugins can have a file TypedDataSets.xml TXMLParser parser = new TXMLParser(APluginPath, false); datasetNode = parser.GetDocument().SelectSingleNode(String.Format("//DataSet[@name='{0}']", datasetName)); } if (datasetNode == null) { throw new Exception("cannot find the xml file for dataset " + ADataSetTypeWithNamespace); } SortedList <string, TTable> result = new SortedList <string, TTable>(); XmlNodeList tables = datasetNode.SelectNodes("Table|CustomTable"); foreach (XmlNode tableNode in tables) { TTable table = new TTable(); string tablename; if ((tableNode.Name == "Table") && TXMLParser.HasAttribute(tableNode, "sqltable")) { tablename = TTable.NiceTableName(tableNode.Attributes["sqltable"].Value); table.Assign(FPetraXMLStore.GetTable(tablename)); table.strVariableNameInDataset = TXMLParser.HasAttribute(tableNode, "name") ? tableNode.Attributes["name"].Value : tablename; if ((tableNode.SelectNodes("CustomField").Count > 0) || (tableNode.SelectNodes("Field").Count > 0)) { table.strDotNetName = datasetName + tablename; } } else if ((tableNode.Name == "Table") && TXMLParser.HasAttribute(tableNode, "customtable")) { table = new TTable(); tablename = tableNode.Attributes["customtable"].Value; table.strName = tablename; table.strDotNetName = tablename; table.strVariableNameInDataset = TXMLParser.HasAttribute(tableNode, "name") ? tableNode.Attributes["name"].Value : tablename; } else { table = new TTable(); tablename = tableNode.Attributes["name"].Value; table.strName = tablename; table.strDotNetName = datasetName + tablename; table.strVariableNameInDataset = tablename; } // add the custom fields if there are any XmlNodeList customFields = tableNode.SelectNodes("CustomField"); foreach (XmlNode customField in customFields) { TTableField newField = new TTableField(); newField.strName = customField.Attributes["name"].Value; newField.strNameDotNet = newField.strName; newField.strType = customField.Attributes["type"].Value; newField.strTypeDotNet = customField.Attributes["type"].Value; newField.strTableName = tablename; newField.strDescription = ""; newField.bNotNull = TXMLParser.HasAttribute(customField, "notnull") && TXMLParser.GetAttribute(customField, "notnull").ToLower() == "true"; table.grpTableField.Add(newField); } // add other fields from other tables that are defined in petra.xml XmlNodeList otherFields = tableNode.SelectNodes("Field"); foreach (XmlNode otherField in otherFields) { TTable otherTable = FPetraXMLStore.GetTable(otherField.Attributes["sqltable"].Value); TTableField newField = new TTableField(otherTable.GetField(otherField.Attributes["sqlfield"].Value)); if (TXMLParser.HasAttribute(otherField, "name")) { newField.strNameDotNet = otherField.Attributes["name"].Value; } newField.strTableName = tablename; table.grpTableField.Add(newField); } result.Add(table.strVariableNameInDataset, table); } FDatasetTables.Add(ADataSetTypeWithNamespace, result); FCurrentDataset = result; return(result); }
/// <summary> /// process the yaml document /// </summary> /// <returns></returns> public Boolean ProcessDocument() { string baseyaml; if (!TYml2Xml.ReadHeader(FYamlFilename, out baseyaml)) { Console.WriteLine("ProcessYAML: cannot recognise type of form"); } else { new TAppSettingsManager(false); //****************** //* parsing ******* //****************** XmlDocument myDoc = TYml2Xml.CreateXmlDocument(); TCodeStorage codeStorage = new TCodeStorage(myDoc, FXmlNodes); TParseYAMLFormsDefinition yamlParser = new TParseYAMLFormsDefinition(ref codeStorage); // should not need to be specific to special forms yamlParser.LoadRecursively(FYamlFilename, FSelectedLocalisation); // for debugging purposes, we can write the xml file that has been parsed from the yaml file // codeStorage.FXmlDocument.Save(FYamlFilename + ".xml"); //**************** //* output ******* //**************** TFormWriter writer = null; // get the appropriate derived class from IFormWriter (e.g. TFrmReportWriter) XmlNode rootNode = (XmlNode)yamlParser.FCodeStorage.FXmlNodes[TParseYAMLFormsDefinition.ROOTNODEYML]; string formType = TYml2Xml.GetAttribute(rootNode, "FormType"); if (formType == "abstract") { Console.WriteLine("Ignore yaml file because it has the formtype abstract: " + FYamlFilename); return(true); } // the Template attribute is also quite important, because it determines which code is written // FormType is mainly important for the difference of the controls of reports and normal screens writer = GetWriter(formType); if (writer == null) { Console.WriteLine("cannot find writer for {0}", formType); return(false); } string templateDir = TAppSettingsManager.GetValue("TemplateDir", true); string template = TYml2Xml.GetAttribute(rootNode, "Template"); if (template.Length > 0) { template = templateDir + Path.DirectorySeparatorChar + template + writer.CodeFileExtension; } string destinationFile = writer.CalculateDestinationFilename(FYamlFilename); string manualCodeFile = writer.CalculateManualCodeFilename(FYamlFilename); // need to know the path to the manual code file in order to call manual functions which would not be called if they do not exist codeStorage.ManualCodeFilename = manualCodeFile; writer.CreateCode(codeStorage, FYamlFilename, template); writer.CreateResourceFile(FYamlFilename, templateDir); writer.CreateDesignerFile(FYamlFilename, rootNode, templateDir); return(writer.WriteFile(destinationFile)); } return(false); }