/// <summary> /// generate the connector code for the client /// </summary> static public void GenerateConnectorCode(String AOutputPath, String ATemplateDir) { String OutputFile = AOutputPath + Path.DirectorySeparatorChar + "ClientGlue.Connector-generated.cs"; Console.WriteLine("working on " + OutputFile); ProcessTemplate Template = new ProcessTemplate(FTemplateDir + Path.DirectorySeparatorChar + "ClientServerGlue" + Path.DirectorySeparatorChar + "ClientGlue.Connector.cs"); // load default header with license and copyright Template.SetCodelet("GPLFILEHEADER", ProcessTemplate.LoadEmptyFileComment(FTemplateDir)); Template.SetCodelet("USINGNAMESPACES", string.Empty); if (FCompileForStandalone) { Template.AddToCodelet("USINGNAMESPACES", "using Ict.Common.DB;" + Environment.NewLine); Template.AddToCodelet("USINGNAMESPACES", "using Ict.Common.Remoting.Server;" + Environment.NewLine); Template.AddToCodelet("USINGNAMESPACES", "using Ict.Petra.Server.App.Core;" + Environment.NewLine); Template.AddToCodelet("USINGNAMESPACES", "using Ict.Petra.Server.App.Delegates;" + Environment.NewLine); Template.AddToCodelet("USINGNAMESPACES", "using Ict.Petra.Shared;" + Environment.NewLine); Template.AddToCodelet("USINGNAMESPACES", "using System.Security.Principal;" + Environment.NewLine); Template.InsertSnippet("CONNECTOR", Template.GetSnippet("CONNECTORSTANDALONE")); Template.InsertSnippet("STANDALONECLIENTMANAGER", Template.GetSnippet("STANDALONECLIENTMANAGER")); } else { Template.InsertSnippet("CONNECTOR", Template.GetSnippet("CONNECTORCLIENTSERVER")); Template.SetCodelet("STANDALONECLIENTMANAGER", string.Empty); Template.SetCodelet("HTTPREMOTING", "true"); } Template.FinishWriting(OutputFile, ".cs", true); }
/// <summary> /// generate code for cascading deletions etc /// </summary> /// <param name="AStore"></param> /// <param name="AFilePath"></param> /// <param name="ANamespaceName"></param> /// <param name="AFileName"></param> /// <returns></returns> public static Boolean WriteTypedDataCascading(TDataDefinitionStore AStore, string AFilePath, string ANamespaceName, string AFileName) { Console.WriteLine("writing namespace " + ANamespaceName); string templateDir = TAppSettingsManager.GetValue("TemplateDir", true); ProcessTemplate Template = new ProcessTemplate(templateDir + Path.DirectorySeparatorChar + "ORM" + Path.DirectorySeparatorChar + "DataCascading.cs"); Template.AddToCodelet("NAMESPACE", ANamespaceName); // load default header with license and copyright Template.SetCodelet("GPLFILEHEADER", ProcessTemplate.LoadEmptyFileComment(templateDir)); foreach (TTable currentTable in AStore.GetTables()) { ProcessTemplate snippet = Template.GetSnippet("TABLECASCADING"); if (InsertMainProcedures(AStore, currentTable, Template, snippet)) { Template.AddToCodelet("USINGNAMESPACES", CodeGenerationAccess.GetNamespace(currentTable.strGroup), false); Template.AddToCodelet("USINGNAMESPACES", CodeGenerationAccess.GetNamespace(currentTable.strGroup).Replace( ".Data;", ".Data.Access;"). Replace("Ict.Petra.Shared.", "Ict.Petra.Server."), false); Template.InsertSnippet("TABLECASCADINGLOOP", snippet); } } Template.FinishWriting(AFilePath + AFileName + "-generated.cs", ".cs", true); return(true); }
static private void WriteWebConnector(string connectorname, TypeDeclaration connectorClass, ProcessTemplate Template) { List <string> MethodNames = new List <string>(); foreach (MethodDeclaration m in CSParser.GetMethods(connectorClass)) { if (TCollectConnectorInterfaces.IgnoreMethod(m.Attributes, m.Modifier)) { continue; } string connectorNamespaceName = ((NamespaceDeclaration)connectorClass.Parent).Name; if (!FUsingNamespaces.ContainsKey(connectorNamespaceName)) { FUsingNamespaces.Add(connectorNamespaceName, connectorNamespaceName); } ProcessTemplate snippet = Template.GetSnippet("WEBCONNECTOR"); InsertWebConnectorMethodCall(snippet, connectorClass, m, ref MethodNames); Template.InsertSnippet("WEBCONNECTORS", snippet); } }
private static void InsertConstructors(ProcessTemplate template, TypeDeclaration t) { // foreach constructor create a method List <ConstructorDeclaration> constructors = CSParser.GetConstructors(t); if (constructors.Count == 0) { // will cause compile error if the constructor is missing, because it is not implementing the interface completely throw new Exception("missing a connector constructor in " + t.Name + "; details: " + t.ToString()); } // find constructor and copy the parameters foreach (ConstructorDeclaration m in constructors) { ProcessTemplate methodSnippet = ClientRemotingClassTemplate.GetSnippet("METHOD"); methodSnippet.SetCodelet("METHODNAME", t.Name.Substring(1, t.Name.Length - 1 - "UIConnector".Length)); methodSnippet.SetCodelet("RETURNTYPE", CSParser.GetImplementedInterface(t)); string ParameterDefinition = string.Empty; string ActualParameters = string.Empty; AutoGenerationTools.FormatParameters(m.Parameters, out ActualParameters, out ParameterDefinition); methodSnippet.SetCodelet("PARAMETERDEFINITION", ParameterDefinition); methodSnippet.SetCodelet("ACTUALPARAMETERS", ActualParameters); methodSnippet.SetCodelet("RETURN", "return "); template.InsertSnippet("METHODSANDPROPERTIES", methodSnippet); } }
private static ProcessTemplate GenerateUIConnector(ProcessTemplate ATemplate, TypeDeclaration connectorClass, string interfacename) { ProcessTemplate snippet = ATemplate.GetSnippet("UICONNECTORCLASS"); snippet.SetCodelet("UICONNECTORINTERFACE", interfacename); snippet.SetCodelet("UICONNECTORCLASSNAME", connectorClass.Name); snippet.SetCodelet("CONSTRUCTORS", string.Empty); int constructorCounter = 0; foreach (ConstructorDeclaration m in CSParser.GetConstructors(connectorClass)) { if (TCollectConnectorInterfaces.IgnoreMethod(m.Attributes, m.Modifier)) { continue; } constructorCounter++; ProcessTemplate snippetConstructor = ATemplate.GetSnippet("UICONNECTORCONSTRUCTOR"); string ParameterDefinition = string.Empty; string ActualParameters = string.Empty; AutoGenerationTools.FormatParameters(m.Parameters, out ActualParameters, out ParameterDefinition); snippetConstructor.SetCodelet("PARAMETERDEFINITION", ParameterDefinition); snippetConstructor.SetCodelet("UICONNECTORCLASSNAME", connectorClass.Name); snippetConstructor.SetCodelet("ACTUALPARAMETERS", ActualParameters); snippetConstructor.SetCodelet("ADDACTUALPARAMETERS", string.Empty); foreach (ParameterDeclarationExpression p in m.Parameters) { if (((ParameterModifiers.Ref & p.ParamModifier) > 0) || ((ParameterModifiers.Out & p.ParamModifier) > 0)) { throw new Exception("we do not support ref or out parameters in UIConnector constructor calls! " + connectorClass.Name); } snippetConstructor.AddToCodelet("ADDACTUALPARAMETERS", "ActualParameters.Add(\"" + p.ParameterName + "\", " + p.ParameterName + ");" + Environment.NewLine); } string methodname = m.Name; if (constructorCounter > 1) { methodname += constructorCounter.ToString(); } snippetConstructor.SetCodelet("METHODNAME", methodname); snippet.InsertSnippet("CONSTRUCTORS", snippetConstructor); } InsertMethodsAndProperties(snippet, connectorClass); return(snippet); }
/// <summary> /// write the code for reading and writing the controls with the parameters /// </summary> public static void GenerateReadSetControls(TFormWriter writer, XmlNode curNode, ProcessTemplate ATargetTemplate, string ATemplateControlType) { string controlName = curNode.Name; // check if this control is already part of an optional group of controls depending on a radiobutton TControlDef ctrl = writer.CodeStorage.GetControl(controlName); if (ctrl.GetAttribute("DependsOnRadioButton") == "true") { return; } if (ctrl.GetAttribute("NoParameter") == "true") { return; } string paramName = ReportControls.GetParameterName(curNode); if (paramName == null) { return; } bool clearIfSettingEmpty = ReportControls.GetClearIfSettingEmpty(curNode); ProcessTemplate snippetReadControls = writer.Template.GetSnippet(ATemplateControlType + "READCONTROLS"); snippetReadControls.SetCodelet("CONTROLNAME", controlName); snippetReadControls.SetCodelet("PARAMNAME", paramName); ATargetTemplate.InsertSnippet("READCONTROLS", snippetReadControls); ProcessTemplate snippetWriteControls = writer.Template.GetSnippet(ATemplateControlType + "SETCONTROLS"); snippetWriteControls.SetCodelet("CONTROLNAME", controlName); snippetWriteControls.SetCodelet("PARAMNAME", paramName); if (clearIfSettingEmpty) { snippetWriteControls.SetCodelet("CLEARIFSETTINGEMPTY", clearIfSettingEmpty.ToString().ToLower()); } ATargetTemplate.InsertSnippet("SETCONTROLS", snippetWriteControls); }
void ImplementWebConnector( SortedList <string, TypeDeclaration> connectors, ProcessTemplate ATemplate, string AFullNamespace) { string ConnectorNamespace = AFullNamespace. Replace("Instantiator.", string.Empty); List <TypeDeclaration> ConnectorClasses = TCollectConnectorInterfaces.FindTypesInNamespace(connectors, ConnectorNamespace); ConnectorNamespace = ConnectorNamespace. Replace("Ict.Petra.Shared.", "Ict.Petra.Server."); ATemplate.SetCodelet("CLIENTOBJECTFOREACHUICONNECTOR", string.Empty); foreach (TypeDeclaration connectorClass in ConnectorClasses) { foreach (MethodDeclaration m in CSParser.GetMethods(connectorClass)) { if (TCollectConnectorInterfaces.IgnoreMethod(m.Attributes, m.Modifier)) { continue; } ProcessTemplate snippet = ATemplate.GetSnippet("WEBCONNECTORMETHOD"); string ParameterDefinition = string.Empty; string ActualParameters = string.Empty; AutoGenerationTools.FormatParameters(m.Parameters, out ActualParameters, out ParameterDefinition); snippet.InsertSnippet("CHECKUSERMODULEPERMISSIONS", CreateModuleAccessPermissionCheck( ATemplate, connectorClass.Name, m)); string returntype = AutoGenerationTools.TypeToString(m.TypeReference, ""); snippet.SetCodelet("RETURN", returntype != "void" ? "return " : string.Empty); snippet.SetCodelet("METHODNAME", m.Name); snippet.SetCodelet("ACTUALPARAMETERS", ActualParameters); snippet.SetCodelet("PARAMETERDEFINITION", ParameterDefinition); snippet.SetCodelet("RETURNTYPE", returntype); snippet.SetCodelet("WEBCONNECTORCLASS", connectorClass.Name); if (!UsingConnectorNamespaces.Contains(ConnectorNamespace)) { UsingConnectorNamespaces.Add(ConnectorNamespace); } ATemplate.InsertSnippet("REMOTEDMETHODS", snippet); } } }
static private void InsertSubNamespaces(ProcessTemplate ATemplate, SortedList <string, TypeDeclaration> connectors, string AParentNamespaceName, string AFullNamespace, TNamespace AParentNamespace) { ATemplate.SetCodelet("SUBNAMESPACECLASSES", string.Empty); ATemplate.SetCodelet("SUBNAMESPACEPROPERTIES", string.Empty); ATemplate.SetCodelet("CONNECTORMETHODS", string.Empty); foreach (TNamespace sn in AParentNamespace.Children.Values) { ProcessTemplate templateProperty = ATemplate.GetSnippet("SUBNAMESPACEPROPERTY"); templateProperty.SetCodelet("NAMESPACENAME", AParentNamespaceName + sn.Name); templateProperty.SetCodelet("SUBNAMESPACENAME", sn.Name); templateProperty.SetCodelet("OBJECTNAME", sn.Name); ProcessTemplate templateClass = ATemplate.GetSnippet("NAMESPACECLASS"); templateClass.SetCodelet("NAMESPACENAME", AParentNamespaceName + sn.Name); InsertSubNamespaces(templateClass, connectors, AParentNamespaceName + sn.Name, AFullNamespace + "." + sn.Name, sn); ATemplate.InsertSnippet("SUBNAMESPACECLASSES", templateClass); ATemplate.InsertSnippet("SUBNAMESPACEPROPERTIES", templateProperty); } if (AParentNamespaceName.EndsWith("WebConnectors")) { ImplementWebConnector(connectors, ATemplate, AFullNamespace); } else { ImplementUIConnector(connectors, ATemplate, AFullNamespace); } }
private static void AddTableToDataset( string tabletype, string variablename, ProcessTemplate snippetDataset) { string typedTableDeklaration = "private " + tabletype + "Table Table" + variablename + ";" + Environment.NewLine; snippetDataset.AddToCodelet("TYPEDDATATABLES", typedTableDeklaration); ProcessTemplate tempSnippet; tempSnippet = snippetDataset.GetSnippet("TYPEDTABLEPROPERTY"); tempSnippet.SetCodelet("TABLETYPENAME", tabletype); tempSnippet.SetCodelet("TABLEVARIABLENAME", variablename); snippetDataset.InsertSnippet("TYPEDTABLEPROPERTY", tempSnippet); snippetDataset.AddToCodelet("INITTABLESFRESH", "this.Tables.Add(new " + tabletype + "Table(\"" + variablename + "\"));" + Environment.NewLine); tempSnippet = snippetDataset.GetSnippet("INITTABLESNOTALL"); tempSnippet.SetCodelet("TABLETYPENAME", tabletype); tempSnippet.SetCodelet("TABLEVARIABLENAME", variablename); snippetDataset.InsertSnippet("INITTABLESNOTALL", tempSnippet); tempSnippet = snippetDataset.GetSnippet("MAPTABLES"); tempSnippet.SetCodelet("TABLEVARIABLENAME", variablename); snippetDataset.InsertSnippet("MAPTABLES", tempSnippet); tempSnippet = snippetDataset.GetSnippet("INITVARSTABLE"); tempSnippet.SetCodelet("TABLETYPENAME", tabletype); tempSnippet.SetCodelet("TABLEVARIABLENAME", variablename); snippetDataset.InsertSnippet("INITVARSTABLE", tempSnippet); }
/// <summary> /// insert a method call /// </summary> private static void InsertWebConnectorMethodCall(ProcessTemplate snippet, TypeDeclaration connectorClass, MethodDeclaration m, ref List <string> AMethodNames) { PrepareParametersForMethod(snippet, m.TypeReference, m.Parameters, m.Name, ref AMethodNames); snippet.SetCodelet("METHODNAME", m.Name); snippet.SetCodelet("WEBCONNECTORCLASS", connectorClass.Name); snippet.InsertSnippet("CHECKUSERMODULEPERMISSIONS", CreateModuleAccessPermissionCheck( snippet, connectorClass.Name, m)); }
/// <summary> /// use CSParser to parse the Server files /// </summary> /// <param name="tn"></param> /// <param name="AOutputPath"></param> private void WriteInterfaces(TNamespace tn, String AOutputPath) { String OutputFile = AOutputPath + Path.DirectorySeparatorChar + tn.Name + ".Interfaces-generated.cs"; // open file Console.WriteLine("working on file " + OutputFile); ProcessTemplate Template = new ProcessTemplate(FTemplateDir + Path.DirectorySeparatorChar + "ClientServerGlue" + Path.DirectorySeparatorChar + "Interface.cs"); // load default header with license and copyright Template.SetCodelet("GPLFILEHEADER", ProcessTemplate.LoadEmptyFileComment(FTemplateDir)); Template.AddToCodelet("USINGNAMESPACES", AddNamespacesFromYmlFile(AOutputPath, tn.Name)); // get all csharp files that might hold implementations of remotable classes List <CSParser> CSFiles = null; if (AOutputPath.Contains("ICT/Petra/Plugins")) { // search for webconnectors in the directory of the plugin CSFiles = CSParser.GetCSFilesForDirectory(Path.GetFullPath(AOutputPath + "/../Server"), SearchOption.AllDirectories); } else if (Directory.Exists(CSParser.ICTPath + "/Petra/Server/lib/M" + tn.Name)) { // any class in the module can contain a webconnector CSFiles = CSParser.GetCSFilesForDirectory(CSParser.ICTPath + "/Petra/Server/lib/M" + tn.Name, SearchOption.AllDirectories); } else { CSFiles = new List <CSParser>(); } SortedList InterfaceNames = GetInterfaceNamesFromImplementation(CSFiles); Template.SetCodelet("INTERFACES", string.Empty); WriteNamespaces(Template, tn, InterfaceNames, CSFiles); if (Template.FCodelets["INTERFACES"].Length == 0) { Template.InsertSnippet("INTERFACES", Template.GetSnippet("DUMMYINTERFACE")); } Template.FinishWriting(OutputFile, ".cs", true); }
/// <summary> /// generate code for reading and writing typed data tables from and to the database /// </summary> /// <param name="AStore"></param> /// <param name="strGroup"></param> /// <param name="AFilePath"></param> /// <param name="ANamespaceName"></param> /// <param name="AFilename"></param> /// <returns></returns> public static Boolean WriteTypedDataAccess(TDataDefinitionStore AStore, string strGroup, string AFilePath, string ANamespaceName, string AFilename) { Console.WriteLine("processing namespace PetraTypedDataAccess." + strGroup.Substring(0, 1).ToUpper() + strGroup.Substring(1)); string templateDir = TAppSettingsManager.GetValue("TemplateDir", true); ProcessTemplate Template = new ProcessTemplate(templateDir + Path.DirectorySeparatorChar + "ORM" + Path.DirectorySeparatorChar + "DataAccess.cs"); Template.SetCodelet("NAMESPACE", ANamespaceName); // load default header with license and copyright Template.SetCodelet("GPLFILEHEADER", ProcessTemplate.LoadEmptyFileComment(templateDir)); Template.AddToCodelet("USINGNAMESPACES", GetNamespace(strGroup), false); bool hasTables = false; foreach (TTable currentTable in AStore.GetTables()) { if (currentTable.strGroup == strGroup) { DirectReferences = new ArrayList(); ProcessTemplate snippet = Template.GetSnippet("TABLEACCESS"); InsertMainProcedures(AStore, currentTable, Template, snippet); InsertViaOtherTable(AStore, currentTable, Template, snippet); InsertViaLinkTable(AStore, currentTable, Template, snippet); Template.InsertSnippet("TABLEACCESSLOOP", snippet); hasTables = true; } } if (hasTables) { Template.FinishWriting(AFilePath + AFilename + "-generated.cs", ".cs", true); } return(true); }
/// <summary> /// insert the buttons for the form, eg. submit button, cancel button, etc /// </summary> /// <param name="ACtrl"></param> /// <param name="ATemplate"></param> /// <param name="AItemsPlaceholder"></param> /// <param name="AWriter"></param> public static void InsertButtons(TControlDef ACtrl, ProcessTemplate ATemplate, string AItemsPlaceholder, TFormWriter AWriter) { StringCollection children = TYml2Xml.GetElements(ACtrl.xmlNode, "Buttons"); foreach (string child in children) { TControlDef childCtrl = AWriter.FCodeStorage.FindOrCreateControl(child, ACtrl.controlName); IControlGenerator ctrlGen = AWriter.FindControlGenerator(childCtrl); ProcessTemplate ctrlSnippet = ctrlGen.SetControlProperties(AWriter, childCtrl); ProcessTemplate snippetCellDefinition = AWriter.FTemplate.GetSnippet("CELLDEFINITION"); LayoutCellInForm(childCtrl, -1, ctrlSnippet, snippetCellDefinition); ATemplate.InsertSnippet(AItemsPlaceholder, ctrlSnippet, ","); } }
private static void ImplementWebConnector( SortedList <string, TypeDeclaration> connectors, ProcessTemplate ATemplate, string AFullNamespace) { string ConnectorNamespace = AFullNamespace. Replace("Instantiator.", string.Empty); List <TypeDeclaration> ConnectorClasses = TCollectConnectorInterfaces.FindTypesInNamespace(connectors, ConnectorNamespace); ConnectorNamespace = ConnectorNamespace. Replace(".Shared.", ".Server."); foreach (TypeDeclaration connectorClass in ConnectorClasses) { List <string> MethodNames = new List <string>(); foreach (MethodDeclaration m in CSParser.GetMethods(connectorClass)) { if (TCollectConnectorInterfaces.IgnoreMethod(m.Attributes, m.Modifier)) { continue; } ProcessTemplate snippet; if (FCompileForStandalone) { if (!FUsingNamespaces.ContainsKey(ConnectorNamespace)) { FUsingNamespaces.Add(ConnectorNamespace, ConnectorNamespace); } snippet = ATemplate.GetSnippet("WEBCONNECTORMETHODSTANDALONE"); } else { snippet = ATemplate.GetSnippet("WEBCONNECTORMETHODREMOTE"); } InsertMethodCall(snippet, connectorClass, m, ref MethodNames); ATemplate.InsertSnippet("CONNECTORMETHODS", snippet); } } }
/// <summary>write the code for the designer file where the properties of the control are written</summary> public override ProcessTemplate SetControlProperties(TFormWriter writer, TControlDef ctrl) { ProcessTemplate snippetRowDefinition = writer.FTemplate.GetSnippet(FControlDefinitionSnippetName); ((TExtJsFormsWriter)writer).AddResourceString(snippetRowDefinition, "LABEL", ctrl, ctrl.Label); StringCollection Controls = FindContainedControls(writer, ctrl.xmlNode); snippetRowDefinition.AddToCodelet("ITEMS", ""); if (Controls.Count > 0) { // used for radiogroupbox foreach (string ChildControlName in Controls) { TControlDef childCtrl = FCodeStorage.FindOrCreateControl(ChildControlName, ctrl.controlName); IControlGenerator ctrlGen = writer.FindControlGenerator(childCtrl); ProcessTemplate ctrlSnippet = ctrlGen.SetControlProperties(writer, childCtrl); ctrlSnippet.SetCodelet("COLUMNWIDTH", ""); ctrlSnippet.SetCodelet("ITEMNAME", ctrl.controlName); ctrlSnippet.SetCodelet("ITEMID", childCtrl.controlName); if (ctrl.GetAttribute("hideLabel") == "true") { ctrlSnippet.SetCodelet("HIDELABEL", "true"); } else if (ChildControlName == Controls[0]) { ((TExtJsFormsWriter)writer).AddResourceString(ctrlSnippet, "LABEL", ctrl, ctrl.Label); } snippetRowDefinition.InsertSnippet("ITEMS", ctrlSnippet, ","); } } else { // used for GroupBox, and Composite TExtJsFormsWriter.InsertControl(ctrl, snippetRowDefinition, "ITEMS", "HiddenValues", writer); TExtJsFormsWriter.InsertControl(ctrl, snippetRowDefinition, "ITEMS", "Controls", writer); } return(snippetRowDefinition); }
private ProcessTemplate WriteConnectorClass(ProcessTemplate ATemplate, String FullNamespace, String Classname, String Namespace, SortedList <string, TNamespace> children, SortedList <string, TypeDeclaration> connectors) { if (children.Count > 0) { foreach (TNamespace sn in children.Values) { WriteConnectorClass( ATemplate, FullNamespace + "." + sn.Name, sn.Name, sn.Name, sn.Children, connectors); } return(ATemplate); } ProcessTemplate connectorClassSnippet = ATemplate.GetSnippet("CONNECTORCLASS"); string NamespaceInModule = FullNamespace.Substring( FullNamespace.IndexOf('.', "Ict.Petra.Shared.M".Length) + 1).Replace(".", string.Empty); connectorClassSnippet.SetCodelet("NAMESPACE", NamespaceInModule); connectorClassSnippet.SetCodelet("REMOTEDMETHODS", string.Empty); if (Namespace.EndsWith("WebConnectors")) { ImplementWebConnector(connectors, connectorClassSnippet, FullNamespace); } else { ImplementUIConnector(connectors, connectorClassSnippet, FullNamespace); } ATemplate.InsertSnippet("CONNECTORCLASSES", connectorClassSnippet); return(ATemplate); }
private static void InsertSubnamespaces(ProcessTemplate template, string AFullNamespace, SortedList <string, TNamespace> ASubNamespaces) { foreach (TNamespace t in ASubNamespaces.Values) { ProcessTemplate propertySnippet = ClientRemotingClassTemplate.GetSnippet("PROPERTY"); propertySnippet.SetCodelet("NAME", t.Name); string NamespaceInModule = AFullNamespace.Substring( AFullNamespace.IndexOf('.', "Ict.Petra.Shared.M".Length) + 1).Replace(".", string.Empty); propertySnippet.SetCodelet("TYPE", "I" + NamespaceInModule + t.Name + "Namespace"); propertySnippet.SetCodelet("GETTER", "yes"); template.InsertSnippet("METHODSANDPROPERTIES", propertySnippet); } }
//other interfaces, e.g. IPartnerUIConnectorsPartnerEdit // we don't know the interfaces that are implemented, so need to look for the base classes // we need to know all the source files that are part of the UIConnector dll private void WriteNamespaces(ProcessTemplate AMainTemplate, TNamespace tn, SortedList AInterfaceNames, List <CSParser> ACSFiles) { AMainTemplate.SetCodelet("MODULE", tn.Name); foreach (TNamespace sn in tn.Children.Values) { ProcessTemplate snippet = AMainTemplate.GetSnippet("SUBNAMESPACE"); snippet.SetCodelet("SUBNAMESPACENAME", sn.Name); snippet.SetCodelet("SUBNAMESPACEOBJECT", sn.Name); AMainTemplate.InsertSnippet("SUBNAMESPACES", snippet); } // parse Instantiator source code foreach (TNamespace sn in tn.Children.Values) { WriteNamespace(AMainTemplate, "Ict.Petra.Shared.Interfaces.M" + tn.Name + "." + sn.Name, sn.Name, tn, sn, sn.Children, AInterfaceNames, ACSFiles); } }
void WriteInterface( ProcessTemplate AMainTemplate, String ParentNamespace, String ParentInterfaceName, string AInterfaceName, TNamespace tn, TNamespace sn, SortedList <string, TNamespace> children, SortedList InterfaceNames, List <CSParser> ACSFiles) { ProcessTemplate snippet = AMainTemplate.GetSnippet("INTERFACE"); snippet.SetCodelet("INTERFACENAME", AInterfaceName); snippet.SetCodelet("CONTENT", string.Empty); //this should return the Connector classes; the instantiator classes are in a different namespace string ServerConnectorNamespace = ParentNamespace.Replace("Ict.Petra.Shared.Interfaces", "Ict.Petra.Server"); // don't write methods twice, once from Connector, and then again from Instantiator StringCollection MethodsAlreadyWritten = new StringCollection(); List <TypeDeclaration> ConnectorClasses2 = GetClassesThatImplementInterface( ACSFiles, AInterfaceName, ServerConnectorNamespace); WriteConnectorMethods( snippet, ref MethodsAlreadyWritten, ConnectorClasses2, AInterfaceName, ParentNamespace, ServerConnectorNamespace); AMainTemplate.InsertSnippet("INTERFACES", snippet); }
/// <summary> /// main function for creating a control /// </summary> /// <param name="ACtrl"></param> /// <param name="ATemplate"></param> /// <param name="AItemsPlaceholder"></param> /// <param name="ANodeName"></param> /// <param name="AWriter"></param> public static void InsertControl(TControlDef ACtrl, ProcessTemplate ATemplate, string AItemsPlaceholder, string ANodeName, TFormWriter AWriter) { XmlNode controlsNode = TXMLParser.GetChild(ACtrl.xmlNode, ANodeName); List <XmlNode> childNodes = TYml2Xml.GetChildren(controlsNode, true); if ((childNodes.Count > 0) && childNodes[0].Name.StartsWith("Row")) { foreach (XmlNode row in TYml2Xml.GetChildren(controlsNode, true)) { ProcessTemplate snippetRowDefinition = AWriter.FTemplate.GetSnippet("ROWDEFINITION"); StringCollection children = TYml2Xml.GetElements(controlsNode, row.Name); foreach (string child in children) { TControlDef childCtrl = AWriter.FCodeStorage.FindOrCreateControl(child, ACtrl.controlName); IControlGenerator ctrlGen = AWriter.FindControlGenerator(childCtrl); ProcessTemplate ctrlSnippet = ctrlGen.SetControlProperties(AWriter, childCtrl); ProcessTemplate snippetCellDefinition = AWriter.FTemplate.GetSnippet("CELLDEFINITION"); LayoutCellInForm(childCtrl, children.Count, ctrlSnippet, snippetCellDefinition); if ((children.Count == 1) && ctrlGen is RadioGroupSimpleGenerator) { // do not use the ROWDEFINITION, but insert control directly // this helps with aligning the label for the group radio buttons snippetRowDefinition.InsertSnippet("ITEMS", ctrlSnippet, ","); } else { snippetCellDefinition.InsertSnippet("ITEM", ctrlSnippet); snippetRowDefinition.InsertSnippet("ITEMS", snippetCellDefinition, ","); } } ATemplate.InsertSnippet(AItemsPlaceholder, snippetRowDefinition, ","); } } else { foreach (XmlNode childNode in childNodes) { string child = TYml2Xml.GetElementName(childNode); TControlDef childCtrl = AWriter.FCodeStorage.FindOrCreateControl(child, ACtrl.controlName); if ((ANodeName != "HiddenValues") && (childCtrl.controlTypePrefix == "hid")) { // somehow, hidden values get into the controls list as well. we don't want them there continue; } IControlGenerator ctrlGen = AWriter.FindControlGenerator(childCtrl); if (ctrlGen is FieldSetGenerator) { InsertControl(AWriter.FCodeStorage.FindOrCreateControl(child, ACtrl.controlName), ATemplate, AItemsPlaceholder, ANodeName, AWriter); } else { ProcessTemplate ctrlSnippet = ctrlGen.SetControlProperties(AWriter, childCtrl); ProcessTemplate snippetCellDefinition = AWriter.FTemplate.GetSnippet("CELLDEFINITION"); LayoutCellInForm(childCtrl, -1, ctrlSnippet, snippetCellDefinition); ATemplate.InsertSnippet(AItemsPlaceholder, ctrlSnippet, ","); } } } }
static private void CreateServerGlue(TNamespace tn, SortedList <string, TypeDeclaration> connectors, string AOutputPath) { String OutputFile = AOutputPath + Path.DirectorySeparatorChar + "ServerGlue.M" + tn.Name + "-generated.cs"; Console.WriteLine("working on " + OutputFile); ProcessTemplate Template = new ProcessTemplate(FTemplateDir + Path.DirectorySeparatorChar + "ClientServerGlue" + Path.DirectorySeparatorChar + "ServerGlue.cs"); // load default header with license and copyright Template.SetCodelet("GPLFILEHEADER", ProcessTemplate.LoadEmptyFileComment(FTemplateDir)); Template.SetCodelet("TOPLEVELMODULE", tn.Name); Template.SetCodelet("WEBCONNECTORS", string.Empty); Template.SetCodelet("UICONNECTORS", string.Empty); string InterfacePath = Path.GetFullPath(AOutputPath).Replace(Path.DirectorySeparatorChar, '/'); InterfacePath = InterfacePath.Substring(0, InterfacePath.IndexOf("csharp/ICT/Petra")) + "csharp/ICT/Petra/Shared/lib/Interfaces"; Template.AddToCodelet("USINGNAMESPACES", CreateInterfaces.AddNamespacesFromYmlFile(InterfacePath, tn.Name)); if (AOutputPath.Contains("ICT/Petra/Plugins/")) { Template.AddToCodelet("USINGNAMESPACES", "using Ict.Petra.Server.App.WebService;" + Environment.NewLine); // add namespaces that are required by the plugin InterfacePath = Path.GetFullPath(AOutputPath + "/../").Replace(Path.DirectorySeparatorChar, '/'); Template.AddToCodelet("USINGNAMESPACES", CreateInterfaces.AddNamespacesFromYmlFile(InterfacePath, "Plugin")); } FUsingNamespaces = new SortedList <string, string>(); FContainsAsynchronousExecutionProgress = false; foreach (string connector in connectors.Keys) { if (connector.EndsWith("UIConnector")) { WriteUIConnector(connector, connectors[connector], Template); } else { WriteWebConnector(connector, connectors[connector], Template); } } if (FContainsAsynchronousExecutionProgress) { Template.InsertSnippet("UICONNECTORS", Template.GetSnippet("ASYNCEXECPROCESSCONNECTOR")); if (!FUsingNamespaces.ContainsKey("Ict.Petra.Server.MCommon")) { FUsingNamespaces.Add("Ict.Petra.Server.MCommon", "Ict.Petra.Server.MCommon"); } } foreach (string usingNamespace in FUsingNamespaces.Keys) { Template.AddToCodelet("USINGNAMESPACES", "using " + usingNamespace + ";" + Environment.NewLine); } if (OutputFile.Replace("\\", "/").Contains("ICT/Petra/Plugins")) { string pluginWithNamespace = TAppSettingsManager.GetValue("plugin"); Template.SetCodelet("WEBSERVICENAMESPACE", pluginWithNamespace + ".WebService"); } else { Template.SetCodelet("WEBSERVICENAMESPACE", "Ict.Petra.Server.App.WebService"); } Template.FinishWriting(OutputFile, ".cs", true); }
static private void WriteUIConnector(string connectorname, TypeDeclaration connectorClass, ProcessTemplate Template) { List <string> MethodNames = new List <string>(); foreach (ConstructorDeclaration m in CSParser.GetConstructors(connectorClass)) { if (TCollectConnectorInterfaces.IgnoreMethod(m.Attributes, m.Modifier)) { continue; } string connectorNamespaceName = ((NamespaceDeclaration)connectorClass.Parent).Name; if (!FUsingNamespaces.ContainsKey(connectorNamespaceName)) { FUsingNamespaces.Add(connectorNamespaceName, connectorNamespaceName); } ProcessTemplate snippet = Template.GetSnippet("UICONNECTORCONSTRUCTOR"); snippet.SetCodelet("UICONNECTORCLASS", connectorClass.Name); snippet.SetCodelet("CHECKUSERMODULEPERMISSIONS", "// TODO CHECKUSERMODULEPERMISSIONS"); PrepareParametersForMethod(snippet, null, m.Parameters, m.Name, ref MethodNames); Template.InsertSnippet("UICONNECTORS", snippet); } // foreach public method create a method foreach (MethodDeclaration m in CSParser.GetMethods(connectorClass)) { if (TCollectConnectorInterfaces.IgnoreMethod(m.Attributes, m.Modifier)) { continue; } ProcessTemplate snippet = Template.GetSnippet("UICONNECTORMETHOD"); snippet.SetCodelet("METHODNAME", m.Name); snippet.SetCodelet("UICONNECTORCLASS", connectorClass.Name); snippet.SetCodelet("CHECKUSERMODULEPERMISSIONS", "// TODO CHECKUSERMODULEPERMISSIONS"); PrepareParametersForMethod(snippet, m.TypeReference, m.Parameters, m.Name, ref MethodNames); if (snippet.FCodelets["PARAMETERDEFINITION"].Length > 0) { snippet.AddToCodeletPrepend("PARAMETERDEFINITION", ", "); } Template.InsertSnippet("UICONNECTORS", snippet); } // foreach public property create a method foreach (PropertyDeclaration p in CSParser.GetProperties(connectorClass)) { if (TCollectConnectorInterfaces.IgnoreMethod(p.Attributes, p.Modifier)) { continue; } string propertytype = p.TypeReference.ToString(); // check if the parametertype is not a generic type, eg. dictionary or list if (!propertytype.Contains("<")) { propertytype = propertytype == "string" || propertytype == "String" ? "System.String" : propertytype; propertytype = propertytype == "bool" || propertytype == "Boolean" ? "System.Boolean" : propertytype; if (propertytype.Contains("UINT") || propertytype.Contains("unsigned")) { propertytype = propertytype.Contains("UInt32") || propertytype == "unsigned int" ? "System.UInt32" : propertytype; propertytype = propertytype.Contains("UInt16") || propertytype == "unsigned short" ? "System.UInt16" : propertytype; propertytype = propertytype.Contains("UInt64") || propertytype == "unsigned long" ? "System.UInt64" : propertytype; } else { propertytype = propertytype.Contains("Int32") || propertytype == "int" ? "System.Int32" : propertytype; propertytype = propertytype.Contains("Int16") || propertytype == "short" ? "System.Int16" : propertytype; propertytype = propertytype.Contains("Int64") || propertytype == "long" ? "System.Int64" : propertytype; } propertytype = propertytype.Contains("Decimal") || propertytype == "decimal" ? "System.Decimal" : propertytype; } bool BinaryReturn = !((propertytype == "System.Int64") || (propertytype == "System.Int32") || (propertytype == "System.Int16") || (propertytype == "System.String") || (propertytype == "System.Boolean")); string EncodedType = propertytype; string EncodeReturnType = string.Empty; string ActualValue = "AValue"; if (BinaryReturn) { EncodedType = "System.String"; EncodeReturnType = "THttpBinarySerializer.SerializeObject"; ActualValue = "(" + propertytype + ")THttpBinarySerializer.DeserializeObject(AValue)"; } ProcessTemplate propertySnippet = Template.GetSnippet("UICONNECTORPROPERTY"); propertySnippet.SetCodelet("UICONNECTORCLASS", connectorClass.Name); propertySnippet.SetCodelet("ENCODEDTYPE", EncodedType); propertySnippet.SetCodelet("PROPERTYNAME", p.Name); if (p.HasGetRegion) { if (p.TypeReference.ToString().StartsWith("I")) { if (p.TypeReference.ToString() == "IAsynchronousExecutionProgress") { FContainsAsynchronousExecutionProgress = true; } // return the ObjectID of the Sub-UIConnector propertySnippet.InsertSnippet("GETTER", Template.GetSnippet("GETSUBUICONNECTOR")); propertySnippet.SetCodelet("ENCODEDTYPE", "System.String"); } else { propertySnippet.SetCodelet("GETTER", "return {#ENCODERETURNTYPE}((({#UICONNECTORCLASS})FUIConnectors[ObjectID]).{#PROPERTYNAME});"); propertySnippet.SetCodelet("ENCODERETURNTYPE", EncodeReturnType); } } if (p.HasSetRegion) { propertySnippet.SetCodelet("SETTER", "true"); propertySnippet.SetCodelet("ACTUALPARAMETERS", ActualValue); } Template.InsertSnippet("UICONNECTORS", propertySnippet); } }
/// <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); }
void WriteInterface( ProcessTemplate AMainTemplate, String ParentNamespace, String ParentInterfaceName, string AInterfaceName, TNamespace tn, TNamespace sn, SortedList <string, TNamespace> children, SortedList InterfaceNames, List <CSParser> ACSFiles) { ProcessTemplate snippet = AMainTemplate.GetSnippet("INTERFACE"); snippet.SetCodelet("INTERFACENAME", AInterfaceName); snippet.SetCodelet("CONTENT", string.Empty); snippet.SetCodelet("SUBNAMESPACES", string.Empty); foreach (TNamespace child in children.Values) { ProcessTemplate snippetSubNamespace = AMainTemplate.GetSnippet("SUBNAMESPACE"); snippetSubNamespace.SetCodelet("SUBNAMESPACENAME", ParentInterfaceName + child.Name); snippetSubNamespace.SetCodelet("SUBNAMESPACEOBJECT", child.Name); snippet.InsertSnippet("SUBNAMESPACES", snippetSubNamespace); } //this should return the Connector classes; the instantiator classes are in a different namespace string ServerConnectorNamespace = ParentNamespace.Replace("Ict.Petra.Shared.Interfaces", "Ict.Petra.Server"); // don't write methods twice, once from Connector, and then again from Instantiator StringCollection MethodsAlreadyWritten = new StringCollection(); StringCollection InterfacesInNamespace = GetInterfacesInNamespace(ParentNamespace, InterfaceNames); foreach (string ChildInterface in InterfacesInNamespace) { List <TypeDeclaration> ConnectorClasses = GetClassesThatImplementInterface( ACSFiles, ChildInterface, ServerConnectorNamespace); if (AInterfaceName.EndsWith("Namespace")) { WriteConnectorConstructors( snippet, ref MethodsAlreadyWritten, ConnectorClasses, ChildInterface, ParentNamespace, ServerConnectorNamespace); } } List <TypeDeclaration> ConnectorClasses2 = GetClassesThatImplementInterface( ACSFiles, AInterfaceName, ServerConnectorNamespace); WriteConnectorMethods( snippet, ref MethodsAlreadyWritten, ConnectorClasses2, AInterfaceName, ParentNamespace, ServerConnectorNamespace); if (!ParentNamespace.Contains("WebConnector")) { // this is for the instantiator classes StringCollection NamespaceSplit = StringHelper.StrSplit(ParentNamespace, "."); // eg convert Ict.Petra.Shared.Interfaces.MPartner.Extracts.UIConnectors to Ict.Petra.Server.MPartner.Instantiator.Extracts.UIConnectors NamespaceSplit[2] = "Server"; NamespaceSplit[3] = NamespaceSplit[4]; NamespaceSplit[4] = "Instantiator"; string ServerInstantiatorNamespace = StringHelper.StrMerge(NamespaceSplit, '.'); List <TypeDeclaration> InstantiatorClasses = GetClassesThatImplementInterface( ACSFiles, AInterfaceName, ServerInstantiatorNamespace); WriteInstantiatorMethods( snippet, MethodsAlreadyWritten, InstantiatorClasses, AInterfaceName, ParentNamespace, ServerInstantiatorNamespace); } AMainTemplate.InsertSnippet("INTERFACES", snippet); }
/// <summary> /// write the interfaces for the methods that need to be reflected /// check connector files /// </summary> /// <param name="ATemplate"></param> /// <param name="AMethodsAlreadyWritten">write methods only once</param> /// <param name="AConnectorClasses">the classes that are implementing the methods</param> /// <param name="AInterfaceName">the interface that is written at the moment</param> /// <param name="AInterfaceNamespace">only needed to shorten the type names to improve readability</param> /// <param name="AServerNamespace">for the comment in the autogenerated code</param> /// <returns></returns> private bool WriteConnectorMethods( ProcessTemplate ATemplate, ref StringCollection AMethodsAlreadyWritten, List <TypeDeclaration> AConnectorClasses, String AInterfaceName, String AInterfaceNamespace, String AServerNamespace) { foreach (TypeDeclaration t in AConnectorClasses) { string ConnectorClassName = t.Name; foreach (PropertyDeclaration p in CSParser.GetProperties(t)) { if (TCollectConnectorInterfaces.IgnoreMethod(p.Attributes, p.Modifier)) { continue; } if (!p.GetRegion.Block.ToString().Contains("TCreateRemotableObject")) { TLogging.Log("Warning: properties in UIConnectors must use the class TCreateRemotableObject: " + AServerNamespace + "." + t.Name + "." + p.Name); } // don't write namespace hierarchy here if (p.TypeReference.Type.IndexOf("Namespace") == -1) { String returnType = AutoGenerationTools.TypeToString(p.TypeReference, AInterfaceNamespace); // this interface got implemented somewhere on the server ProcessTemplate snippet = ATemplate.GetSnippet("CONNECTORPROPERTY"); snippet.SetCodelet("CONNECTORCLASSNAME", ConnectorClassName); snippet.SetCodelet("SERVERNAMESPACE", AServerNamespace); snippet.SetCodelet("TYPE", returnType); snippet.SetCodelet("NAME", p.Name); if (p.HasGetRegion) { snippet.SetCodelet("GETTER", "true"); } if (p.HasSetRegion) { snippet.SetCodelet("SETTER", "true"); } ATemplate.InsertSnippet("CONTENT", snippet); } } foreach (MethodDeclaration m in CSParser.GetMethods(t)) { string MethodName = m.Name; if (TCollectConnectorInterfaces.IgnoreMethod(m.Attributes, m.Modifier)) { continue; } String formattedMethod = ""; String returnType = AutoGenerationTools.TypeToString(m.TypeReference, AInterfaceNamespace); int align = (returnType + " " + m.Name).Length + 1; // this interface got implemented somewhere on the server formattedMethod = "/// <summary> auto generated from Connector method(" + AServerNamespace + "." + ConnectorClassName + ")</summary>" + Environment.NewLine; formattedMethod += returnType + " " + m.Name + "("; bool firstParameter = true; foreach (ParameterDeclarationExpression p in m.Parameters) { if (!firstParameter) { ATemplate.AddToCodelet("CONTENT", formattedMethod + "," + Environment.NewLine); formattedMethod = new String(' ', align); } firstParameter = false; String parameterType = AutoGenerationTools.TypeToString(p.TypeReference, ""); if ((p.ParamModifier & ParameterModifiers.Ref) != 0) { formattedMethod += "ref "; } else if ((p.ParamModifier & ParameterModifiers.Out) != 0) { formattedMethod += "out "; } formattedMethod += parameterType + " " + p.ParameterName; } formattedMethod += ");"; AMethodsAlreadyWritten.Add(MethodName); ATemplate.AddToCodelet("CONTENT", formattedMethod + Environment.NewLine); } } return(true); }
private static void InsertMethodsAndProperties(ProcessTemplate template, TypeDeclaration t) { List <string> MethodNames = new List <string>(); // foreach public method create a method foreach (MethodDeclaration m in CSParser.GetMethods(t)) { if (TCollectConnectorInterfaces.IgnoreMethod(m.Attributes, m.Modifier)) { continue; } ProcessTemplate methodSnippet = template.GetSnippet("UICONNECTORMETHOD"); InsertMethodCall(methodSnippet, t, m, ref MethodNames); template.InsertSnippet("METHODSANDPROPERTIES", methodSnippet); } // foreach public property create a method foreach (PropertyDeclaration p in CSParser.GetProperties(t)) { if (TCollectConnectorInterfaces.IgnoreMethod(p.Attributes, p.Modifier)) { continue; } ProcessTemplate propertySnippet = template.GetSnippet("UICONNECTORPROPERTY"); string type = AutoGenerationTools.TypeToString(p.TypeReference, string.Empty); propertySnippet.SetCodelet("NAME", p.Name); propertySnippet.SetCodelet("TYPE", type); string expectedreturntype = GetExpectedReturnType(0, AutoGenerationTools.TypeToString(p.TypeReference, string.Empty)); propertySnippet.SetCodelet("EXPECTEDRETURNTYPE", expectedreturntype); if (p.HasGetRegion) { if (type.StartsWith("I")) { propertySnippet.SetCodelet( "GETTER", "return new T" + type.Substring( 1) + "(\"M{#TOPLEVELMODULE}\", THttpConnector.ReadUIConnectorProperty(FObjectID, \"M{#TOPLEVELMODULE}\", \"{#UICONNECTORCLASSNAME}\", \"{#NAME}\", \"System.String\").ToString());"); } else { propertySnippet.SetCodelet( "GETTER", "return ({#TYPE}) THttpConnector.ReadUIConnectorProperty(FObjectID, \"M{#TOPLEVELMODULE}\", \"{#UICONNECTORCLASSNAME}\", \"{#NAME}\", \"{#EXPECTEDRETURNTYPE}\");"); } } if (p.HasSetRegion) { propertySnippet.SetCodelet("SETTER", "yes"); } template.InsertSnippet("METHODSANDPROPERTIES", propertySnippet); } }
/// <summary> /// situation 2: bridging tables /// for example p_location and p_partner are connected through p_partner_location /// it would be helpful, to be able to do: /// location.LoadViaPartner(partnerkey) to get all locations of the partner /// partner.loadvialocation(locationkey) to get all partners living at that location /// general solution: pick up all foreign keys from other tables (B) to the primary key of the current table (A), /// where the other table has a foreign key to another table (C), using other fields in the primary key of (B) than the link to (A). /// get all tables that reference the current table /// </summary> /// <param name="AStore"></param> /// <param name="ACurrentTable"></param> /// <param name="ATemplate"></param> /// <param name="ASnippet"></param> private static void InsertViaLinkTable(TDataDefinitionStore AStore, TTable ACurrentTable, ProcessTemplate ATemplate, ProcessTemplate ASnippet) { // step 1: collect all the valid constraints of such link tables ArrayList OtherLinkConstraints = new ArrayList(); ArrayList References = new ArrayList(); foreach (TConstraint Reference in ACurrentTable.GetReferences()) { TTable LinkTable = AStore.GetTable(Reference.strThisTable); try { TConstraint LinkPrimaryKey = LinkTable.GetPrimaryKey(); if (StringHelper.Contains(LinkPrimaryKey.strThisFields, Reference.strThisFields)) { // check how many constraints from the link table are from fields in the primary key // a link table only should have 2 // so find the other one TConstraint OtherLinkConstraint = null; bool IsLinkTable = false; foreach (TConstraint LinkConstraint in LinkTable.grpConstraint) { // check if there is another constraint for the primary key of the link table. if (ValidForeignKeyConstraintForLoadVia(LinkConstraint) && (LinkConstraint != Reference) && (StringHelper.Contains(LinkPrimaryKey.strThisFields, LinkConstraint.strThisFields))) { if (OtherLinkConstraint == null) { OtherLinkConstraint = LinkConstraint; IsLinkTable = true; } else { IsLinkTable = false; } } else if (ValidForeignKeyConstraintForLoadVia(LinkConstraint) && (LinkConstraint != Reference) && (!StringHelper.Contains(LinkPrimaryKey.strThisFields, LinkConstraint.strThisFields)) && StringHelper.ContainsSome(LinkPrimaryKey.strThisFields, LinkConstraint.strThisFields)) { // if there is a key that partly is in the primary key, then this is not a link table. OtherLinkConstraint = LinkConstraint; IsLinkTable = false; } } if ((IsLinkTable) && (OtherLinkConstraint.strOtherTable != Reference.strOtherTable)) { // collect the links. then we are able to name them correctly, once we need them OtherLinkConstraints.Add(OtherLinkConstraint); References.Add(Reference); } } } catch (Exception) { // Console.WriteLine(e.Message); } } // step2: implement the link tables, using correct names for the procedures int Count = 0; foreach (TConstraint OtherLinkConstraint in OtherLinkConstraints) { TTable OtherTable = AStore.GetTable(OtherLinkConstraint.strOtherTable); string ProcedureName = "Via" + TTable.NiceTableName(OtherTable.strName); // check if other foreign key exists that references the same table, e.g. // PPartnerAccess.LoadViaSUserPRecentPartners // PPartnerAccess.LoadViaSUserPCustomisedGreeting // also PFoundationProposalAccess.LoadViaPFoundationPFoundationProposalDetail and // TODO AlreadyExistsProcedureSameName necessary for PPersonAccess.LoadViaPUnit (p_field_key_n) and PPersonAccess.LoadViaPUnitPmGeneralApplication // Question: does PPersonAccess.LoadViaPUnitPmGeneralApplication make sense? if (FindOtherConstraintSameOtherTable2(OtherLinkConstraints, OtherLinkConstraint) || LoadViaHasAlreadyBeenImplemented(OtherLinkConstraint) // TODO || AlreadyExistsProcedureSameName(ProcedureName) || ((ProcedureName == "ViaPUnit") && (OtherLinkConstraint.strThisTable == "pm_general_application")) ) { ProcedureName += TTable.NiceTableName(OtherLinkConstraint.strThisTable); } ATemplate.AddToCodelet("USINGNAMESPACES", GetNamespace(OtherTable.strGroup), false); ProcessTemplate snippetLinkTable = ATemplate.GetSnippet("VIALINKTABLE"); snippetLinkTable.SetCodelet("VIAPROCEDURENAME", ProcedureName); snippetLinkTable.SetCodelet("OTHERTABLENAME", TTable.NiceTableName(OtherTable.strName)); snippetLinkTable.SetCodelet("SQLOTHERTABLENAME", OtherTable.strName); snippetLinkTable.SetCodelet("SQLLINKTABLENAME", OtherLinkConstraint.strThisTable); string notUsed; int notUsedInt; string formalParametersOtherPrimaryKey; string actualParametersOtherPrimaryKey; PrepareCodeletsPrimaryKey(OtherTable, out formalParametersOtherPrimaryKey, out actualParametersOtherPrimaryKey, out notUsed, out notUsedInt); PrepareCodeletsPrimaryKey(ACurrentTable, out notUsed, out notUsed, out notUsed, out notUsedInt); string whereClauseForeignKey; string whereClauseViaOtherTable; string odbcParametersForeignKey; PrepareCodeletsForeignKey( OtherTable, OtherLinkConstraint, out whereClauseForeignKey, out whereClauseViaOtherTable, out odbcParametersForeignKey, out notUsedInt, out notUsed); string whereClauseViaLinkTable; string whereClauseAllViaTables; PrepareCodeletsViaLinkTable( (TConstraint)References[Count], OtherLinkConstraint, out whereClauseViaLinkTable, out whereClauseAllViaTables); snippetLinkTable.SetCodelet("FORMALPARAMETERSOTHERPRIMARYKEY", formalParametersOtherPrimaryKey); snippetLinkTable.SetCodelet("ACTUALPARAMETERSOTHERPRIMARYKEY", actualParametersOtherPrimaryKey); snippetLinkTable.SetCodelet("ODBCPARAMETERSFOREIGNKEY", odbcParametersForeignKey); snippetLinkTable.SetCodelet("WHERECLAUSEVIALINKTABLE", whereClauseViaLinkTable); snippetLinkTable.SetCodelet("WHERECLAUSEALLVIATABLES", whereClauseAllViaTables); ASnippet.InsertSnippet("VIALINKTABLE", snippetLinkTable); Count = Count + 1; } }
private static void ImplementUIConnector( SortedList <string, TypeDeclaration> connectors, ProcessTemplate ATemplate, string AFullNamespace) { string ConnectorNamespace = AFullNamespace. Replace("Instantiator.", string.Empty); List <TypeDeclaration> ConnectorClasses = TCollectConnectorInterfaces.FindTypesInNamespace(connectors, ConnectorNamespace); ConnectorNamespace = ConnectorNamespace. Replace(".Shared.", ".Server."); foreach (TypeDeclaration connectorClass in ConnectorClasses) { foreach (ConstructorDeclaration m in CSParser.GetConstructors(connectorClass)) { if (TCollectConnectorInterfaces.IgnoreMethod(m.Attributes, m.Modifier)) { continue; } ProcessTemplate snippet; FModuleHasUIConnector = true; if (FCompileForStandalone) { if (!FUsingNamespaces.ContainsKey(ConnectorNamespace)) { FUsingNamespaces.Add(ConnectorNamespace, ConnectorNamespace); } snippet = ATemplate.GetSnippet("UICONNECTORMETHODSTANDALONE"); } else { snippet = ATemplate.GetSnippet("UICONNECTORMETHODREMOTE"); } string ParameterDefinition = string.Empty; string ActualParameters = string.Empty; AutoGenerationTools.FormatParameters(m.Parameters, out ActualParameters, out ParameterDefinition); string methodname = m.Name.Substring(1); if (methodname.EndsWith("UIConnector")) { methodname = methodname.Substring(0, methodname.LastIndexOf("UIConnector")); } string interfacename = CSParser.GetImplementedInterface(connectorClass); snippet.SetCodelet("METHODNAME", methodname); snippet.SetCodelet("PARAMETERDEFINITION", ParameterDefinition); snippet.SetCodelet("ACTUALPARAMETERS", ActualParameters); snippet.SetCodelet("UICONNECTORINTERFACE", interfacename); snippet.SetCodelet("UICONNECTORCLASSNAME", connectorClass.Name); snippet.SetCodelet("UICONNECTORCLASS", string.Empty); if (!FCompileForStandalone) { if (!FUIConnectorsAdded.Contains(connectorClass.Name)) { FUIConnectorsAdded.Add(connectorClass.Name); snippet.InsertSnippet("UICONNECTORCLASS", GenerateUIConnector(ATemplate, connectorClass, interfacename)); } } ATemplate.InsertSnippet("CONNECTORMETHODS", snippet); } } }
/// creates a file with enums in Shared and one file per submodule in Server for cached tables public static void WriteCachedTables(TDataDefinitionStore AStore, string ACacheYamlFilename, string ASharedPath, string ATemplateDir) { // Load yaml file with list of tables that should be cached TYml2Xml ymlParser = new TYml2Xml(ACacheYamlFilename); XmlDocument xmlDoc = ymlParser.ParseYML2XML(); XmlNode module = xmlDoc.DocumentElement.FirstChild.FirstChild; while (module != null) { XmlNode subModule = module.FirstChild; bool severalSubModules = (subModule != null && subModule.NextSibling != null); // write the shared file with the enum definitions ProcessTemplate SharedTemplate = new ProcessTemplate(ATemplateDir + Path.DirectorySeparatorChar + "ORM" + Path.DirectorySeparatorChar + "Cacheable.Shared.cs"); SharedTemplate.SetCodelet("GPLFILEHEADER", ProcessTemplate.LoadEmptyFileComment(ATemplateDir)); // SharedTemplate.SetCodelet("NAMESPACE", "Ict.Petra.Shared.M" + module.Name); SharedTemplate.SetCodelet("NAMESPACE", "Ict.Petra.Shared"); while (subModule != null) { List <string> UsingNamespaces = new List <string>(); // write the server file for each submodule ProcessTemplate ServerTemplate = new ProcessTemplate(ATemplateDir + Path.DirectorySeparatorChar + "ORM" + Path.DirectorySeparatorChar + "Cacheable.Server.cs"); ServerTemplate.SetCodelet("GPLFILEHEADER", ProcessTemplate.LoadEmptyFileComment(ATemplateDir)); ServerTemplate.SetCodelet("NAMESPACE", "Ict.Petra.Server.M" + module.Name + "." + subModule.Name + ".Cacheable"); ServerTemplate.SetCodelet("SUBNAMESPACE", "M" + module.Name + "." + subModule.Name); ServerTemplate.SetCodelet("CACHEABLECLASS", "T" + module.Name + "Cacheable"); ServerTemplate.SetCodelet("SUBMODULE", subModule.Name); ServerTemplate.SetCodelet("GETCALCULATEDLISTFROMDB", ""); ServerTemplate.SetCodelet("LEDGERGETCACHEABLE", ""); ServerTemplate.SetCodelet("LEDGERSAVECACHEABLE", ""); if (!severalSubModules) { // for MCommon ServerTemplate.SetCodelet("NAMESPACE", "Ict.Petra.Server.M" + module.Name + ".Cacheable"); ServerTemplate.SetCodelet("SUBNAMESPACE", "M" + module.Name); ServerTemplate.SetCodelet("CACHEABLECLASS", "TCacheable"); } ProcessTemplate snippetSubmodule = SharedTemplate.GetSnippet("SUBMODULEENUM"); snippetSubmodule.SetCodelet("SUBMODULE", subModule.Name); snippetSubmodule.SetCodelet("MODULE", module.Name); ProcessTemplate snippetLedgerGetTable = null; ProcessTemplate snippetLedgerSaveTable = null; XmlNode TableOrListElement = subModule.FirstChild; while (TableOrListElement != null) { XmlNode enumElement = TableOrListElement.FirstChild; while (enumElement != null) { bool DependsOnLedger = false; if (TYml2Xml.GetAttributeRecursive(enumElement, "DependsOnLedger") == "true") { if (snippetLedgerGetTable == null) { snippetLedgerGetTable = ServerTemplate.GetSnippet("LEDGERGETCACHEABLE"); snippetLedgerGetTable.SetCodelet("SUBMODULE", subModule.Name); } if ((snippetLedgerSaveTable == null) && (TableOrListElement.Name == "DatabaseTables")) { snippetLedgerSaveTable = ServerTemplate.GetSnippet("LEDGERSAVECACHEABLE"); snippetLedgerSaveTable.SetCodelet("SUBMODULE", subModule.Name); } DependsOnLedger = true; ServerTemplate.SetCodelet("WITHLEDGER", "true"); } ProcessTemplate snippetElement = SharedTemplate.GetSnippet("ENUMELEMENT"); if ((enumElement.NextSibling == null) && ((TableOrListElement.NextSibling == null) || (TableOrListElement.NextSibling.FirstChild == null))) { snippetElement = SharedTemplate.GetSnippet("ENUMELEMENTLAST"); } string Comment = TXMLParser.GetAttribute(enumElement, "Comment"); if (TableOrListElement.Name == "DatabaseTables") { TTable Table = AStore.GetTable(enumElement.Name); string Namespace = "Ict.Petra.Shared." + TTable.GetNamespace(Table.strGroup) + ".Data"; if (!UsingNamespaces.Contains(Namespace)) { UsingNamespaces.Add(Namespace); } Namespace = "Ict.Petra.Server." + TTable.GetNamespace(Table.strGroup) + ".Validation"; if (!UsingNamespaces.Contains(Namespace)) { UsingNamespaces.Add(Namespace); } Namespace = "Ict.Petra.Server." + TTable.GetNamespace(Table.strGroup) + ".Data.Access"; if (!UsingNamespaces.Contains(Namespace)) { UsingNamespaces.Add(Namespace); } if (Table == null) { throw new Exception("Error: cannot find table " + enumElement.Name + " for caching in module " + module.Name); } if (Comment.Length == 0) { Comment = Table.strDescription; } } if (Comment.Length == 0) { Comment = "todoComment"; } snippetElement.SetCodelet("ENUMCOMMENT", Comment); string enumName = enumElement.Name; if (TXMLParser.HasAttribute(enumElement, "Enum")) { enumName = TXMLParser.GetAttribute(enumElement, "Enum"); } else if (TableOrListElement.Name == "DatabaseTables") { string character2 = enumElement.Name.Substring(1, 1); if (character2.ToLower() == character2) { // this is a table name that has a 2 digit prefix enumName = enumElement.Name.Substring(2) + "List"; } else { enumName = enumElement.Name.Substring(1) + "List"; } } snippetElement.SetCodelet("ENUMNAME", enumName); snippetElement.SetCodelet("DATATABLENAME", enumElement.Name); snippetSubmodule.InsertSnippet("ENUMELEMENTS", snippetElement); if (TableOrListElement.Name == "DatabaseTables") { ProcessTemplate snippetLoadTable = ServerTemplate.GetSnippet("LOADTABLE"); if (DependsOnLedger) { snippetLoadTable = ServerTemplate.GetSnippet("LOADTABLEVIALEDGER"); } snippetLoadTable.SetCodelet("ENUMNAME", enumName); snippetLoadTable.SetCodelet("DATATABLENAME", enumElement.Name); if (DependsOnLedger) { snippetLedgerGetTable.InsertSnippet("LOADTABLESANDLISTS", snippetLoadTable); } else { ServerTemplate.InsertSnippet("LOADTABLESANDLISTS", snippetLoadTable); } ProcessTemplate snippetSaveTable = ServerTemplate.GetSnippet("SAVETABLE"); snippetSaveTable.SetCodelet("ENUMNAME", enumName); snippetSaveTable.SetCodelet("SUBMODULE", subModule.Name); snippetSaveTable.SetCodelet("DATATABLENAME", enumElement.Name); if (DependsOnLedger) { snippetLedgerSaveTable.InsertSnippet("SAVETABLE", snippetSaveTable); } else { ServerTemplate.InsertSnippet("SAVETABLE", snippetSaveTable); } ProcessTemplate snippetDataValidation = ServerTemplate.GetSnippet("DATAVALIDATION"); snippetDataValidation.SetCodelet("ENUMNAME", enumName); snippetDataValidation.SetCodelet("DATATABLENAME", enumElement.Name); if (DependsOnLedger) { snippetLedgerSaveTable.InsertSnippet("DATAVALIDATION", snippetDataValidation); } else { ServerTemplate.InsertSnippet("DATAVALIDATION", snippetDataValidation); } } else { ProcessTemplate snippetLoadList = ServerTemplate.GetSnippet("LOADCALCULATEDLIST"); if (DependsOnLedger) { snippetLoadList = ServerTemplate.GetSnippet("LOADCALCULATEDLISTFORLEDGER"); } snippetLoadList.SetCodelet("ENUMNAME", enumName); snippetLoadList.SetCodelet("CALCULATEDLISTNAME", enumName); if (DependsOnLedger) { snippetLedgerGetTable.InsertSnippet("LOADTABLESANDLISTS", snippetLoadList); } else { ServerTemplate.InsertSnippet("LOADTABLESANDLISTS", snippetLoadList); } if (TYml2Xml.GetAttributeRecursive(enumElement, "IsStorableToDBTable") != String.Empty) { ProcessTemplate snippetSaveTable = ServerTemplate.GetSnippet("SAVETABLE"); snippetSaveTable.SetCodelet("ENUMNAME", enumName); snippetSaveTable.SetCodelet("SUBMODULE", subModule.Name); snippetSaveTable.SetCodelet("DATATABLENAME", TYml2Xml.GetAttributeRecursive(enumElement, "IsStorableToDBTable")); if (DependsOnLedger) { snippetLedgerSaveTable.InsertSnippet("SAVETABLE", snippetSaveTable); } else { ServerTemplate.InsertSnippet("SAVETABLE", snippetSaveTable); } ProcessTemplate snippetDataValidation = ServerTemplate.GetSnippet("DATAVALIDATION"); snippetDataValidation.SetCodelet("ENUMNAME", enumName); snippetDataValidation.SetCodelet("DATATABLENAME", TYml2Xml.GetAttributeRecursive(enumElement, "IsStorableToDBTable")); if (DependsOnLedger) { snippetLedgerSaveTable.InsertSnippet("DATAVALIDATION", snippetDataValidation); } else { ServerTemplate.InsertSnippet("DATAVALIDATION", snippetDataValidation); } } } enumElement = enumElement.NextSibling; if (enumElement != null) { snippetSubmodule.AddToCodelet("ENUMELEMENTS", Environment.NewLine); } } TableOrListElement = TableOrListElement.NextSibling; } SharedTemplate.InsertSnippet("ENUMS", snippetSubmodule); if (snippetLedgerGetTable != null) { ServerTemplate.InsertSnippet("LEDGERGETCACHEABLE", snippetLedgerGetTable); } if (snippetLedgerSaveTable != null) { ServerTemplate.InsertSnippet("LEDGERSAVECACHEABLE", snippetLedgerSaveTable); } ServerTemplate.SetCodelet("USINGNAMESPACES", string.Empty); foreach (string UsingNamespace in UsingNamespaces) { ServerTemplate.AddToCodelet("USINGNAMESPACES", "using " + UsingNamespace + ";" + Environment.NewLine); } string path = ASharedPath + Path.DirectorySeparatorChar + ".." + Path.DirectorySeparatorChar + "Server" + Path.DirectorySeparatorChar + "lib" + Path.DirectorySeparatorChar + "M" + module.Name + Path.DirectorySeparatorChar; if (File.Exists(path + "Cacheable.ManualCode.cs")) { path += "Cacheable-generated.cs"; } else { if (File.Exists(path + "data" + Path.DirectorySeparatorChar + subModule.Name + "." + "Cacheable.ManualCode.cs")) { path += "data" + Path.DirectorySeparatorChar + subModule.Name + "." + "Cacheable-generated.cs"; } else if (File.Exists(path + "data" + Path.DirectorySeparatorChar + "Cacheable.ManualCode.cs")) { path += "data" + Path.DirectorySeparatorChar + "Cacheable-generated.cs"; } else { path += subModule.Name + "." + "Cacheable-generated.cs"; } } ServerTemplate.FinishWriting(path, ".cs", true); subModule = subModule.NextSibling; } SharedTemplate.FinishWriting(ASharedPath + Path.DirectorySeparatorChar + "M" + module.Name + ".Cacheable-generated.cs", ".cs", true); module = module.NextSibling; } }
/// <summary> /// insert the viaothertable functions for one specific constraint /// </summary> /// <param name="AStore"></param> /// <param name="AConstraint"></param> /// <param name="ACurrentTable"></param> /// <param name="AOtherTable"></param> /// <param name="ATemplate"></param> /// <param name="ASnippet"></param> private static void InsertViaOtherTableConstraint(TDataDefinitionStore AStore, TConstraint AConstraint, TTable ACurrentTable, TTable AOtherTable, ProcessTemplate ATemplate, ProcessTemplate ASnippet) { ATemplate.AddToCodelet("USINGNAMESPACES", GetNamespace(AOtherTable.strGroup), false); ProcessTemplate snippetViaTable = ATemplate.GetSnippet("VIAOTHERTABLE"); snippetViaTable.SetCodelet("OTHERTABLENAME", TTable.NiceTableName(AOtherTable.strName)); snippetViaTable.SetCodelet("SQLOTHERTABLENAME", AOtherTable.strName); string ProcedureName = "Via" + TTable.NiceTableName(AOtherTable.strName); // check if other foreign key exists that references the same table, e.g. // PBankAccess.CountViaPPartnerPartnerKey // PBankAccess.CountViaPPartnerContactPartnerKey string DifferentField = FindOtherConstraintSameOtherTable(ACurrentTable.grpConstraint, AConstraint); if (DifferentField.Length != 0) { ProcedureName += TTable.NiceFieldName(DifferentField); } int notUsedInt; string formalParametersOtherPrimaryKey; string actualParametersOtherPrimaryKey; string dummy; PrepareCodeletsPrimaryKey(AOtherTable, out formalParametersOtherPrimaryKey, out actualParametersOtherPrimaryKey, out dummy, out notUsedInt); int numberFields; string namesOfThisTableFields; string notUsed; PrepareCodeletsForeignKey( AOtherTable, AConstraint, out notUsed, out notUsed, out notUsed, out numberFields, out namesOfThisTableFields); snippetViaTable.SetCodelet("VIAPROCEDURENAME", ProcedureName); snippetViaTable.SetCodelet("FORMALPARAMETERSOTHERPRIMARYKEY", formalParametersOtherPrimaryKey); snippetViaTable.SetCodelet("ACTUALPARAMETERSOTHERPRIMARYKEY", actualParametersOtherPrimaryKey); snippetViaTable.SetCodelet("NUMBERFIELDS", numberFields.ToString()); snippetViaTable.SetCodelet("NUMBERFIELDSOTHER", (actualParametersOtherPrimaryKey.Split(',').Length).ToString()); snippetViaTable.SetCodelet("THISTABLEFIELDS", namesOfThisTableFields); AddDirectReference(AConstraint); ASnippet.InsertSnippet("VIAOTHERTABLE", snippetViaTable); }