Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
        /// <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));
        }
Ejemplo n.º 3
0
        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);
            }
        }
Ejemplo n.º 4
0
        /// <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, ",");
            }
        }
Ejemplo n.º 5
0
    private void CreateAutoHierarchy(TNamespace tn, String AOutputPath)
    {
        String OutputFile = AOutputPath + Path.DirectorySeparatorChar + "M" + tn.Name +
                            Path.DirectorySeparatorChar + "Instantiator.AutoHierarchy-generated.cs";

        if (Directory.Exists(AOutputPath + Path.DirectorySeparatorChar + "M" + tn.Name +
                Path.DirectorySeparatorChar + "connect"))
        {
            OutputFile = AOutputPath + Path.DirectorySeparatorChar + "M" + tn.Name +
                         Path.DirectorySeparatorChar + "connect" +
                         Path.DirectorySeparatorChar + "Instantiator.AutoHierarchy-generated.cs";
        }

        Console.WriteLine("working on " + OutputFile);

        SortedList <string, TypeDeclaration>connectors = TCollectConnectorInterfaces.GetConnectors(tn.Name);

        ProcessTemplate Template = new ProcessTemplate(FTemplateDir + Path.DirectorySeparatorChar +
            "ClientServerGlue" + Path.DirectorySeparatorChar +
            "Instantiator.cs");

        // load default header with license and copyright
        Template.SetCodelet("GPLFILEHEADER", ProcessTemplate.LoadEmptyFileComment(FTemplateDir));

        Template.SetCodelet("TOPLEVELMODULE", tn.Name);

        Template.AddToCodelet("USINGNAMESPACES", "using Ict.Petra.Shared.Interfaces.M" + tn.Name + ";" + Environment.NewLine);

        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));

        ProcessTemplate topLevelNamespaceSnippet = Template.GetSnippet("TOPLEVELNAMESPACE");
        topLevelNamespaceSnippet.SetCodelet("SUBNAMESPACEREMOTABLECLASSES", "");
        topLevelNamespaceSnippet.SetCodelet("TOPLEVELMODULE", tn.Name);
        topLevelNamespaceSnippet.InsertSnippet("LOADERCLASS", WriteLoaderClass(Template, tn.Name));
        topLevelNamespaceSnippet.InsertSnippet("MAINREMOTABLECLASS",
            WriteRemotableClass(
                topLevelNamespaceSnippet,
                "Ict.Petra.Shared.M" + tn.Name,
                "TM" + tn.Name,
                "M" + tn.Name,
                true,
                tn.Children,
                connectors));

        foreach (TNamespace sn in tn.Children.Values)
        {
            topLevelNamespaceSnippet.InsertSnippet("SUBNAMESPACEREMOTABLECLASSES",
                WriteRemotableClass(
                    topLevelNamespaceSnippet,
                    "Ict.Petra.Shared.M" + tn.Name + "." + sn.Name,
                    sn.Name,
                    sn.Name,
                    false,
                    sn.Children,
                    connectors));
        }

        Template.InsertSnippet("CONTENT", topLevelNamespaceSnippet);

        Template.FinishWriting(OutputFile, ".cs", true);
    }
Ejemplo n.º 6
0
        /// <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;
            }
        }
Ejemplo n.º 7
0
        /// based on the code model, create the code;
        /// using the code generators that have been loaded
        public override void CreateCode(TCodeStorage ACodeStorage, string AXAMLFilename, string ATemplateFile)
        {
            ResetAllValues();
            FCodeStorage = ACodeStorage;
            TControlGenerator.FCodeStorage = ACodeStorage;
            FTemplate = new ProcessTemplate(ATemplateFile);

            // load default header with license and copyright
            string templateDir = TAppSettingsManager.GetValue("TemplateDir", true);
            FTemplate.AddToCodelet("GPLFILEHEADER",
                ProcessTemplate.LoadEmptyFileComment(templateDir + Path.DirectorySeparatorChar + ".." +
                    Path.DirectorySeparatorChar));

            // init some template variables that can be empty
            FTemplate.AddToCodelet("INITUSERCONTROLS", "");
            FTemplate.AddToCodelet("INITMANUALCODE", "");
            FTemplate.AddToCodelet("GRIDMULTISELECTION", "");
            FTemplate.AddToCodelet("GRIDHEADERTOOLTIP", "");
            FTemplate.AddToCodelet("RUNONCEONACTIVATIONMANUAL", "");
            FTemplate.AddToCodelet("RUNONCEONPARENTACTIVATIONMANUAL", "");
            FTemplate.AddToCodelet("USERCONTROLSRUNONCEONACTIVATION", "");
            FTemplate.AddToCodelet("SETINITIALFOCUS", "");
            FTemplate.AddToCodelet("EXITMANUALCODE", "");
            FTemplate.AddToCodelet("CANCLOSEMANUAL", "");
            FTemplate.AddToCodelet("INITNEWROWMANUAL", "");
            FTemplate.AddToCodelet("DELETERECORD", "");
            FTemplate.AddToCodelet("DELETEREFERENCECOUNT", "");
            FTemplate.AddToCodelet("MULTIDELETEREFERENCECOUNT", "");
            FTemplate.AddToCodelet("ENABLEDELETEBUTTON", "");
            FTemplate.AddToCodelet("CANDELETESELECTION", "");
            FTemplate.AddToCodelet("CANDELETEROW", "");
            FTemplate.AddToCodelet("SELECTTABMANUAL", "");
            FTemplate.AddToCodelet("STOREMANUALCODE", "");
            FTemplate.AddToCodelet("FINDANDFILTERHOOKUPEVENTS", "");
            FTemplate.AddToCodelet("ACTIONENABLINGDISABLEMISSINGFUNCS", "");
            FTemplate.AddToCodelet("PRIMARYKEYCONTROLSREADONLY", "");
            FTemplate.AddToCodelet("SHOWDETAILSMANUAL", "");
            FTemplate.AddToCodelet("PREPROCESSCMDKEY", "");
            FTemplate.AddToCodelet("PROCESSCMDKEY", "");
            FTemplate.AddToCodelet("PROCESSCMDKEYCTRLF", "");
            FTemplate.AddToCodelet("PROCESSCMDKEYCTRLR", "");
            FTemplate.AddToCodelet("PROCESSCMDKEYMANUAL", "");
            FTemplate.AddToCodelet("FOCUSFIRSTEDITABLEDETAILSPANELCONTROL", "");
            FTemplate.AddToCodelet("CLEARDETAILS", "");
            FTemplate.AddToCodelet("CATALOGI18N", "");
            FTemplate.AddToCodelet("DYNAMICTABPAGEUSERCONTROLENUM", "");
            FTemplate.AddToCodelet("DYNAMICTABPAGEUSERCONTROLINITIALISATION", "");
            FTemplate.AddToCodelet("DYNAMICTABPAGEUSERCONTROLLOADING", "");
            FTemplate.AddToCodelet("ASSIGNFONTATTRIBUTES", "");
            FTemplate.AddToCodelet("CUSTOMDISPOSING", "");
            FTemplate.AddToCodelet("DYNAMICTABPAGEUSERCONTROLDECLARATION", "");
            FTemplate.AddToCodelet("DYNAMICTABPAGEBASICS", "");
            FTemplate.AddToCodelet("IGNOREFIRSTTABPAGESELECTIONCHANGEDEVENT", "");
            FTemplate.AddToCodelet("DYNAMICTABPAGEUSERCONTROLSETUPMETHODS", "");
            FTemplate.AddToCodelet("ELSESTATEMENT", "");
//          FTemplate.AddToCodelet("VALIDATEDETAILS", "");


            FTemplate.AddToCodelet("INITACTIONSTATE", "FPetraUtilsObject.InitActionState();" + Environment.NewLine);

            CallHandlerIfProvided("void BeforeShowDetailsManual", "SHOWDETAILS", "BeforeShowDetailsManual(ARow);");
            CallHandlerIfProvided("InitializeManualCode", "INITMANUALCODE", "InitializeManualCode();");
            CallHandlerIfProvided("RunOnceOnActivationManual", "RUNONCEONACTIVATIONMANUAL", "RunOnceOnActivationManual();");
            CallHandlerIfProvided("RunOnceOnParentActivationManual", "RUNONCEONPARENTACTIVATIONMANUAL", "RunOnceOnParentActivationManual();");
            CallHandlerIfProvided("ExitManualCode", "EXITMANUALCODE", "ExitManualCode();");
            CallHandlerIfProvided("CanCloseManual", "CANCLOSEMANUAL", " && CanCloseManual()");
            CallHandlerIfProvided("NewRowManual", "INITNEWROWMANUAL", "NewRowManual(ref NewRow);");
            CallHandlerIfProvided("StoreManualCode", "STOREMANUALCODE", "SubmissionResult = StoreManualCode(ref SubmitDS, out VerificationResult);");
            CallHandlerIfProvided("FindAndFilterHookUpEvents", "FINDANDFILTERHOOKUPEVENTS", "FindAndFilterHookUpEvents();");
            CallHandlerIfProvided("PreProcessCommandKey", "PREPROCESSCMDKEY", "PreProcessCommandKey();");

            if (FCodeStorage.ManualFileExistsAndContains("SelectTabManual"))
            {
                FTemplate.AddToCodelet("SELECTTABMANUAL",
                    "//Call code to execute on selection of new tab" + Environment.NewLine);
            }

            if (FCodeStorage.ManualFileExistsAndContains("PreDeleteManual"))
            {
                FTemplate.AddToCodelet("HASPREDELETEMANUAL", "true");
            }

            if (FCodeStorage.ManualFileExistsAndContains("DeleteRowManual"))
            {
                FTemplate.AddToCodelet("HASDELETEROWMANUAL", "true");
            }

            if (FCodeStorage.ManualFileExistsAndContains("PostDeleteManual"))
            {
                FTemplate.AddToCodelet("HASPOSTDELETEMANUAL", "true");
            }

            if (FCodeStorage.ManualFileExistsAndContains("GetChangedRecordCountManual"))
            {
                FTemplate.AddToCodelet("GETCHANGEDRECORDCOUNT", "return GetChangedRecordCountManual(out AMessage);");
            }
            else
            {
                FTemplate.AddToCodelet("GETCHANGEDRECORDCOUNT", "return FPetraUtilsObject.GetChangedRecordCount(FMainDS, out AMessage);");
            }

            if (FTemplate.FSnippets.ContainsKey("PROCESSCMDKEYCTRLL"))
            {
                if (FCodeStorage.FControlList.ContainsKey("grdDetails") && !FCodeStorage.FControlList["grdDetails"].HasAttribute("IgnoreEditMove]"))
                {
                    ProcessTemplate snipCtrlL = FTemplate.GetSnippet("PROCESSCMDKEYCTRLL");
                    FTemplate.InsertSnippet("PROCESSCMDKEY", snipCtrlL);

                    if (FCodeStorage.FControlList.ContainsKey("pnlDetails"))
                    {
                        ProcessTemplate snipCtrlE = FTemplate.GetSnippet("PROCESSCMDKEYCTRLE");
                        FTemplate.InsertSnippet("PROCESSCMDKEY", snipCtrlE);

                        ProcessTemplate snipSelectRow = FTemplate.GetSnippet("PROCESSCMDKEYSELECTROW");
                        FTemplate.InsertSnippet("PROCESSCMDKEY", snipSelectRow);

                        if (FCodeStorage.ManualFileExistsAndContains("void FocusFirstEditableControlManual()"))
                        {
                            FTemplate.SetCodelet("FOCUSFIRSTEDITABLEDETAILSPANELCONTROL", "FocusFirstEditableControlManual();" + Environment.NewLine);
                        }
                        else
                        {
                            ProcessTemplate snipFocusFirstControl = FTemplate.GetSnippet("FOCUSFIRSTDETAILSPANELCONTROL");
                            FTemplate.InsertSnippet("FOCUSFIRSTEDITABLEDETAILSPANELCONTROL", snipFocusFirstControl);
                        }
                    }
                }

                if (FCodeStorage.ManualFileExistsAndContains("ProcessCmdKeyManual(ref"))
                {
                    ProcessTemplate snipCmdKeyManual = FTemplate.GetSnippet("PROCESSCMDKEYMANUAL");
                    FTemplate.InsertSnippet("PROCESSCMDKEYMANUAL", snipCmdKeyManual);
                }
            }

            if ((FTemplate.FSnippets.ContainsKey("PROCESSCMDKEYCTRLF")) && (FCodeStorage.FControlList.ContainsKey("pnlFilterAndFind")))
            {
                ProcessTemplate snipCtrlF = FTemplate.GetSnippet("PROCESSCMDKEYCTRLF");

                if (FCodeStorage.FActionList.ContainsKey("actEditFind"))
                {
                    snipCtrlF.SetCodelet("ACTIONCLICK", FCodeStorage.FActionList["actEditFind"].actionClick);
                }
                else
                {
                    snipCtrlF.SetCodelet("ACTIONCLICK", "MniFilterFind_Click");
                }

                FTemplate.InsertSnippet("PROCESSCMDKEY", snipCtrlF);
            }

            if ((FTemplate.FSnippets.ContainsKey("PROCESSCMDKEYCTRLR")) && (FCodeStorage.FControlList.ContainsKey("pnlFilterAndFind")))
            {
                ProcessTemplate snipCtrlR = FTemplate.GetSnippet("PROCESSCMDKEYCTRLR");

                if (FCodeStorage.FActionList.ContainsKey("actEditFilter"))
                {
                    snipCtrlR.SetCodelet("ACTIONCLICK", FCodeStorage.FActionList["actEditFilter"].actionClick);
                }
                else
                {
                    snipCtrlR.SetCodelet("ACTIONCLICK", "MniFilterFind_Click");
                }

                FTemplate.InsertSnippet("PROCESSCMDKEY", snipCtrlR);
            }

            if (FCodeStorage.HasAttribute("DatasetType"))
            {
                FTemplate.SetCodelet("DATASETTYPE", FCodeStorage.GetAttribute("DatasetType"));
                FTemplate.SetCodelet("SHORTDATASETTYPE",
                    FCodeStorage.GetAttribute("DatasetType").Substring(FCodeStorage.GetAttribute("DatasetType").LastIndexOf(".") + 1));
                FTemplate.SetCodelet("MANAGEDDATASETORTYPE", "true");
            }
            else
            {
                FTemplate.SetCodelet("DATASETTYPE", String.Empty);
            }

//    FTemplate.SetCodelet("MANAGEDDATASETORTYPE", "true");

            XmlNode UsingNamespacesNode = TYml2Xml.GetChild(FCodeStorage.FRootNode, "UsingNamespaces");

            if (UsingNamespacesNode != null)
            {
                foreach (string s in TYml2Xml.GetElements(FCodeStorage.FRootNode, "UsingNamespaces"))
                {
                    FTemplate.AddToCodelet("USINGNAMESPACES", "using " + s + ";" + Environment.NewLine);
                }
            }
            else
            {
                FTemplate.AddToCodelet("USINGNAMESPACES", "");
            }

            SortedList <string, TTable>DataSetTables = null;

            // load the dataset if there is a dataset defined for this screen. this allows us to reference customtables and custom fields
            if (FCodeStorage.HasAttribute("DatasetType"))
            {
                DataSetTables = TDataBinding.LoadDatasetTables(CSParser.ICTPath, FCodeStorage.GetAttribute("DatasetType"), FCodeStorage);
            }
            else
            {
                TDataBinding.FCodeStorage = FCodeStorage;
                TDataBinding.ResetCurrentDataset();
            }

            if (FCodeStorage.HasAttribute("MasterTable"))
            {
                if ((DataSetTables != null) && DataSetTables.ContainsKey(FCodeStorage.GetAttribute("MasterTable")))
                {
                    TTable table = DataSetTables[FCodeStorage.GetAttribute("MasterTable")];
                    FTemplate.AddToCodelet("MASTERTABLE", table.strVariableNameInDataset);
                    FTemplate.AddToCodelet("MASTERTABLETYPE", table.strDotNetName);
                    FTemplate.SetCodelet("SHAREDVALIDATIONNAMESPACEMODULE",
                        String.Format("Ict.Petra.Shared.{0}.Validation",
                            TTable.GetNamespace(table.strGroup)));
                }
                else
                {
                    FTemplate.AddToCodelet("MASTERTABLE", FCodeStorage.GetAttribute("MasterTable"));

                    TTable table = TDataBinding.FPetraXMLStore.GetTable(FCodeStorage.GetAttribute("MasterTable"));
                    FTemplate.SetCodelet("SHAREDVALIDATIONNAMESPACEMODULE",
                        String.Format("Ict.Petra.Shared.{0}.Validation",
                            TTable.GetNamespace(table.strGroup)));

                    if (FCodeStorage.HasAttribute("MasterTableType"))
                    {
                        FTemplate.AddToCodelet("MASTERTABLETYPE", FCodeStorage.GetAttribute("MasterTableType"));
                    }
                    else
                    {
                        FTemplate.AddToCodelet("MASTERTABLETYPE", FCodeStorage.GetAttribute("MasterTable"));
                    }
                }
            }
            else
            {
                FTemplate.AddToCodelet("MASTERTABLE", "");
                FTemplate.AddToCodelet("MASTERTABLETYPE", "");
            }

            if (FCodeStorage.HasAttribute("DetailTable"))
            {
                string detailTable;

                if ((DataSetTables != null) && DataSetTables.ContainsKey(FCodeStorage.GetAttribute("DetailTable")))
                {
                    TTable table = DataSetTables[FCodeStorage.GetAttribute("DetailTable")];

                    if (table == null)
                    {
                        throw new Exception("invalid DetailTable, does not exist: " + FCodeStorage.GetAttribute("DetailTable"));
                    }

                    FTemplate.SetCodelet("SHAREDVALIDATIONNAMESPACEMODULE",
                        String.Format("Ict.Petra.Shared.{0}.Validation",
                            TTable.GetNamespace(table.strGroup)));

                    detailTable = table.strVariableNameInDataset;
                    FTemplate.AddToCodelet("DETAILTABLE", detailTable);
                    FTemplate.AddToCodelet("DETAILTABLETYPE", table.strDotNetName);
                }
                else
                {
                    detailTable = FCodeStorage.GetAttribute("DetailTable");
                    FTemplate.AddToCodelet("DETAILTABLE", detailTable);
                    FTemplate.AddToCodelet("DETAILTABLETYPE", detailTable);

                    TTable table = TDataBinding.FPetraXMLStore.GetTable(detailTable);
                    FTemplate.SetCodelet("SHAREDVALIDATIONNAMESPACEMODULE",
                        String.Format("Ict.Petra.Shared.{0}.Validation",
                            TTable.GetNamespace(table.strGroup)));
                }

                if ((FTemplate.FSnippets.Keys.Contains("INLINETYPEDDATASET"))
                    && (!FCodeStorage.HasAttribute("DatasetType")))
                {
                    ProcessTemplate inlineTypedDataSetSnippet = FTemplate.GetSnippet("INLINETYPEDDATASET");
                    inlineTypedDataSetSnippet.SetCodelet("DETAILTABLE", detailTable);

                    FTemplate.InsertSnippet("INLINETYPEDDATASET", inlineTypedDataSetSnippet);
                }
            }
            else
            {
                FTemplate.AddToCodelet("DETAILTABLE", "");
                FTemplate.AddToCodelet("DETAILTABLETYPE", "");
            }

            if (FCodeStorage.HasAttribute("TempTableName"))
            {
                FTemplate.AddToCodelet("TEMPTABLENAME", FCodeStorage.GetAttribute("TempTableName"));
            }

            if (FCodeStorage.HasAttribute("CacheableTable"))
            {
                FTemplate.AddToCodelet("CACHEABLETABLE", "\"" + FCodeStorage.GetAttribute("CacheableTable") + "\"");

                if (FCodeStorage.HasAttribute("CacheableTableSpecificFilter"))
                {
                    FTemplate.AddToCodelet("FILTERVAR", "object FFilter;");

                    string CacheableTableSpecificFilter = FCodeStorage.GetAttribute("CacheableTableSpecificFilter");

                    if (CacheableTableSpecificFilter.StartsWith("\""))
                    {
                        FTemplate.AddToCodelet("LOADDATAONCONSTRUCTORRUN", "LoadDataAndFinishScreenSetup();");
                        FTemplate.AddToCodelet("CACHEABLETABLERETRIEVEMETHOD", "GetCacheableDataTableFromCache");
                        FTemplate.AddToCodelet("DISPLAYFILTERINFORMTITLE", "this.Text = this.Text + \"   [Filtered]\";");
                        FTemplate.AddToCodelet("CACHEABLETABLESPECIFICFILTERLOAD", "" + CacheableTableSpecificFilter + ", FFilter");
                        FTemplate.AddToCodelet("CACHEABLETABLESPECIFICFILTERSAVE", ", " + CacheableTableSpecificFilter + ", FFilter");
                    }
                    else
                    {
                        FTemplate.AddToCodelet("LOADDATAONCONSTRUCTORRUN",
                            "// LoadDataAndFinishScreenSetup() needs to be called manually after setting FFilter!");
                        FTemplate.AddToCodelet("CACHEABLETABLERETRIEVEMETHOD", "GetSpecificallyFilteredCacheableDataTableFromCache");
                        FTemplate.AddToCodelet("DISPLAYFILTERINFORMTITLE",
                            "this.Text = this.Text + \"   [" + CacheableTableSpecificFilter + " = \" + FFilter.ToString() + \"]\";");
                        FTemplate.AddToCodelet("CACHEABLETABLESPECIFICFILTERLOAD", "\"" + CacheableTableSpecificFilter + "\", FFilter");
                        FTemplate.AddToCodelet("CACHEABLETABLESPECIFICFILTERSAVE", ", FFilter");
                    }

                    FTemplate.AddToCodelet("CACHEABLETABLESAVEMETHOD", "SaveSpecificallyFilteredCacheableDataTableToPetraServer");
                    //FTemplate.AddToCodelet("CACHEABLETABLESPECIFICFILTERSAVE", "FFilter, out VerificationResult");
                }
                else
                {
                    FTemplate.AddToCodelet("FILTERVAR", "");
                    FTemplate.AddToCodelet("DISPLAYFILTERINFORMTITLE", "");
                    FTemplate.AddToCodelet("LOADDATAONCONSTRUCTORRUN", "LoadDataAndFinishScreenSetup();");
                    FTemplate.AddToCodelet("CACHEABLETABLERETRIEVEMETHOD", "GetCacheableDataTableFromCache");
                    FTemplate.AddToCodelet("CACHEABLETABLESPECIFICFILTERLOAD", "String.Empty, null");
                    FTemplate.AddToCodelet("CACHEABLETABLESPECIFICFILTERSAVE", "");
                    FTemplate.AddToCodelet("CACHEABLETABLESAVEMETHOD", "SaveChangedCacheableDataTableToPetraServer");
                    //FTemplate.AddToCodelet("CACHEABLETABLESPECIFICFILTERSAVE", "out VerificationResult");
                }
            }

            if (FCodeStorage.HasAttribute("GenerateGetSelectedDetailRow")
                && (FCodeStorage.GetAttribute("GenerateGetSelectedDetailRow") == "true"))
            {
                FTemplate.AddToCodelet("GENERATEGETSELECTEDDETAILROW", "true");
            }

            if (FCodeStorage.HasAttribute("MultipleMasterRows")
                && (FCodeStorage.GetAttribute("MultipleMasterRows") == "true"))
            {
                FTemplate.AddToCodelet("MULTIPLEMASTERROWS", "true");
            }

            // Note - this IF clause needs to be the same as the one in generateReferenceCountConnectors.cs which is generating the server side code
            // Do Ctrl+F to find: this IF clause needs to be the same
            // in that file
            if ((FCodeStorage.GetAttribute("DetailTable") != String.Empty)
                && (FCodeStorage.FControlList.ContainsKey("btnDelete")
                    || FCodeStorage.FControlList.ContainsKey("btnDeleteType")
                    || FCodeStorage.FControlList.ContainsKey("btnDeleteExtract")
                    || FCodeStorage.FControlList.ContainsKey("btnDeleteDetail")
                    || (FCodeStorage.FControlList.ContainsKey("btnRemoveDetail") && (FCodeStorage.GetAttribute("FormType") != "report"))))
            {
                // We always auto-generate code to calculate the record reference count when a delete button exists unless specified in YAML
                if (TYml2Xml.GetAttribute((XmlNode)FCodeStorage.FXmlNodes["actDelete"], "SkipReferenceCheck").ToLower() != "true")
                {
                    AddDeleteReferenceCountImplementation();
                }

                // The generated code only writes the delete button event handler if there is a delete button and there is no manual code to handle the event
                if ((FCodeStorage.FActionList.ContainsKey("actDelete") && (FCodeStorage.FActionList["actDelete"].actionClick != "DeleteRecord"))
                    || FCodeStorage.ManualFileExistsAndContains("btnDelete.Click +=")
                    || FCodeStorage.ManualFileExistsAndContains("void DeleteRecord(")
                    || FCodeStorage.ManualFileExistsAndContains("void DeleteDetail(")
                    || FCodeStorage.ManualFileExistsAndContains("void DeleteRow(")
                    || FCodeStorage.ManualFileExistsAndContains("void RemoveDetail("))
                {
                    // Handled by manual code
                    Console.WriteLine("Skipping DeleteRecord() handler because it is handled by " +
                        Path.GetFileNameWithoutExtension(FCodeStorage.FManualCodeFilename));
                }
                else
                {
                    // Write the event handler to call the DeleteTableName() method
                    string deleteRecord = String.Format(
                        "{1}{0}private void DeleteRecord(Object sender, EventArgs e){1}{0}{{{1}{0}{0}Delete{2}();{1}{0}}}{1}{1}",
                        "    ",
                        Environment.NewLine,
                        FCodeStorage.GetAttribute("DetailTable"));
                    FTemplate.AddToCodelet("DELETERECORD", deleteRecord);

                    ProcessTemplate snippetCanDelete = FTemplate.GetSnippet("SNIPCANDELETESELECTION");
                    ProcessTemplate snippetCanDeleteRow = FTemplate.GetSnippet("SNIPCANDELETEROW");
                    bool bRequiresCanDeleteSelection = false;

                    // Write the one-line codelet that handles enable/disable of the delete button
                    string enableDelete = "btnDelete.Enabled = pnlDetails.Enabled";
                    string enableDeleteExtra = " && CanDeleteSelection()";

                    if (FCodeStorage.FControlList.ContainsKey("chkDetailDeletable")
                        || FCodeStorage.FControlList.ContainsKey("chkDeletable"))
                    {
                        enableDelete += enableDeleteExtra;
                        snippetCanDelete.SetCodelet("DELETEABLEFLAG", "Deletable");
                        snippetCanDeleteRow.SetCodelet("DELETEABLEFLAG", "Deletable");
                        bRequiresCanDeleteSelection = true;
                    }
                    else if (FCodeStorage.FControlList.ContainsKey("chkDetailDeletableFlag")
                             || FCodeStorage.FControlList.ContainsKey("chkDeletableFlag"))
                    {
                        enableDelete += enableDeleteExtra;
                        snippetCanDelete.SetCodelet("DELETEABLEFLAG", "DeletableFlag");
                        snippetCanDeleteRow.SetCodelet("DELETEABLEFLAG", "DeletableFlag");
                        bRequiresCanDeleteSelection = true;
                    }
                    else if (FCodeStorage.FControlList.ContainsKey("chkDetailTypeDeletable"))
                    {
                        enableDelete += enableDeleteExtra;
                        snippetCanDelete.SetCodelet("DELETEABLEFLAG", "TypeDeletable");
                        snippetCanDeleteRow.SetCodelet("DELETEABLEFLAG", "TypeDeletable");
                        bRequiresCanDeleteSelection = true;
                    }

                    enableDelete += ";" + Environment.NewLine;
                    FTemplate.AddToCodelet("ENABLEDELETEBUTTON", enableDelete);

                    if (bRequiresCanDeleteSelection)
                    {
                        snippetCanDelete.SetCodelet("DETAILTABLE", FCodeStorage.GetAttribute("DetailTable"));
                        FTemplate.InsertSnippet("CANDELETESELECTION", snippetCanDelete);
                        snippetCanDeleteRow.SetCodelet("DETAILTABLE", FCodeStorage.GetAttribute("DetailTable"));
                        FTemplate.InsertSnippet("CANDELETEROW", snippetCanDeleteRow);
                    }
                }
            }

            if (FTemplate.FCodelets["CANDELETEROW"].ToString() == String.Empty)
            {
                FTemplate.SetCodelet("CANDELETEROW", "return true;");
            }

            // find the first control that is a panel or groupbox or tab control
            if (FCodeStorage.HasRootControl("content"))
            {
                AddRootControl("content");
            }

            // Toolbar
            if (FCodeStorage.HasRootControl("tbr"))
            {
                AddRootControl("tbr");
            }

            // Main Menu
            if (FCodeStorage.HasRootControl("mnu"))
            {
                AddRootControl("mnu");
            }

            // Statusbar
            if (FCodeStorage.HasRootControl("stb"))
            {
                AddRootControl("stb");
            }

            // check for controls that have no parent
            List <TControlDef>orphans = FCodeStorage.GetOrphanedControls();

            if (orphans.Count > 0)
            {
                string msg = String.Empty;

                foreach (TControlDef o in orphans)
                {
                    msg += o.controlName + " ";
                }

                TLogging.Log("Warning !!! There are some controls that will not be part of the screen (missing parent control?): " + msg);
            }

            // add form events
            foreach (TEventHandler handler in FCodeStorage.FEventList.Values)
            {
                SetEventHandlerForForm(handler);
            }

            foreach (TReportParameter ReportPara in FCodeStorage.FReportParameterList.Values)
            {
                AddReportParameterImplementaion(ReportPara);
            }

            XmlNode rootNode = (XmlNode)FCodeStorage.FXmlNodes[TParseYAMLFormsDefinition.ROOTNODEYML];

            if (TYml2Xml.HasAttribute(rootNode, "UIConnectorType") && TYml2Xml.HasAttribute(rootNode, "UIConnectorCreate"))
            {
                FTemplate.AddToCodelet("UICONNECTORTYPE", TYml2Xml.GetAttribute(rootNode, "UIConnectorType"));
                FTemplate.AddToCodelet("UICONNECTORCREATE", TYml2Xml.GetAttribute(rootNode, "UIConnectorCreate"));
            }

            HandleWebConnectors(TYml2Xml.GetAttribute(rootNode, "Namespace"));

            if (TYml2Xml.HasAttribute(rootNode, "Icon"))
            {
                string iconFileName = TYml2Xml.GetAttribute(rootNode, "Icon");
                FTemplate.AddToCodelet("ADDMAINCONTROLS",
                    "this.Icon = (System.Drawing.Icon)resources.GetObject(\"$this.Icon\");" + Environment.NewLine);
                AddImageToResource("$this.Icon", iconFileName, "Icon");
            }

            if (FCodeStorage.FEventHandler.Contains("KeyEventHandler(this.Form_KeyDown)"))
            {
                // forms that have a KeyDown handler will need KeyPreview
                FTemplate.AddToCodelet("ADDMAINCONTROLS", "this.KeyPreview = true;" + Environment.NewLine);
            }

            string initialFocusControl = String.Empty;

            if (FCodeStorage.FControlList.ContainsKey("grdDetails"))
            {
                initialFocusControl = "grdDetails";
            }

            if (TYml2Xml.HasAttribute(rootNode, "InitialFocus"))
            {
                string tryFocus = TYml2Xml.GetAttribute(rootNode, "InitialFocus");

                if (FCodeStorage.FControlList.ContainsKey(tryFocus))
                {
                    initialFocusControl = tryFocus;
                }
                else
                {
                    TLogging.Log("Warning !!! Cannot set initial focus.  The specified control was not found: " + tryFocus);
                }
            }

            if (initialFocusControl != String.Empty)
            {
                FTemplate.SetCodelet("SETINITIALFOCUS", initialFocusControl + ".Focus();");
            }

            // add title
            if (ProperI18NCatalogGetString(FCodeStorage.FFormTitle))
            {
                FTemplate.AddToCodelet("CATALOGI18N",
                    "this.Text = Catalog.GetString(\"" + FCodeStorage.FFormTitle + "\");" + Environment.NewLine);
            }

            // add actions
            foreach (TActionHandler handler in FCodeStorage.FActionList.Values)
            {
                if (!handler.actionName.StartsWith("cnd"))
                {
                    AddActionHandlerImplementation(handler);
                }

                if (TYml2Xml.HasAttribute(handler.actionNode, "InitialValue"))
                {
                    string actionEnabling =
                        "if (e.ActionName == \"" + handler.actionName + "\")" + Environment.NewLine +
                        "{" + Environment.NewLine +
                        "    {#ENABLEDEPENDINGACTIONS_" + handler.actionName + "}" + Environment.NewLine +
                        "}" + Environment.NewLine + Environment.NewLine;
                    Template.AddToCodelet("ACTIONENABLING", actionEnabling);
                    Template.AddToCodelet(
                        "INITACTIONSTATE",
                        "ActionEnabledEvent(null, new ActionEventArgs(" +
                        "\"" + handler.actionName + "\", " + TYml2Xml.GetAttribute(handler.actionNode,
                            "InitialValue") + "));" + Environment.NewLine);
                }

                if (TYml2Xml.HasAttribute(handler.actionNode, "Enabled"))
                {
                    Template.AddToCodelet(
                        "ENABLEDEPENDINGACTIONS_" + TYml2Xml.GetAttribute(handler.actionNode, "Enabled"),
                        "FPetraUtilsObject.EnableAction(\"" + handler.actionName + "\", e.Enabled);" + Environment.NewLine);
                }
            }

            WriteAllControls();

            FinishUpInitialisingControls();

            if (FCodeStorage.ManualFileExistsAndContains("void ShowDataManual()"))
            {
                FTemplate.AddToCodelet("SHOWDATA", "ShowDataManual();" + Environment.NewLine);
            }
            else if (FCodeStorage.ManualFileExistsAndContains("void ShowDataManual("))
            {
                FTemplate.AddToCodelet("SHOWDATA", "ShowDataManual(ARow);" + Environment.NewLine);
            }

            if (FCodeStorage.FControlList.ContainsKey("pnlDetails"))
            {
                FTemplate.AddToCodelet("CLEARDETAILS", "FPetraUtilsObject.ClearControls(pnlDetails);" + Environment.NewLine);
            }

            if (FCodeStorage.ManualFileExistsAndContains("void ShowDetailsManual"))
            {
                FTemplate.AddToCodelet("SHOWDETAILS", "ShowDetailsManual(ARow);" + Environment.NewLine);
                FTemplate.AddToCodelet("CLEARDETAILS", "ShowDetailsManual(ARow);" + Environment.NewLine);
            }

            if (FCodeStorage.ManualFileExistsAndContains("GetDataFromControlsManual()"))
            {
                FTemplate.AddToCodelet("SAVEDATA", "GetDataFromControlsManual();" + Environment.NewLine);
            }
            else if (FCodeStorage.ManualFileExistsAndContains("GetDataFromControlsManual("))
            {
                FTemplate.AddToCodelet("SAVEDATA", "GetDataFromControlsManual(ARow);" + Environment.NewLine);
            }

            if (FCodeStorage.ManualFileExistsAndContains("GetDataFromControlsExtra()"))
            {
                FTemplate.AddToCodelet("SAVEDATAEXTRA", "GetDataFromControlsExtra();" + Environment.NewLine);
            }
            else if (FCodeStorage.ManualFileExistsAndContains("GetDataFromControlsExtra("))
            {
                FTemplate.AddToCodelet("SAVEDATAEXTRA", "GetDataFromControlsExtra(ARow);" + Environment.NewLine);
            }
            else
            {
                FTemplate.AddToCodelet("SAVEDATAEXTRA", "");
            }

//            if (FCodeStorage.ManualFileExistsAndContains("ValidateDetailsManual"))
//            {
//                ProcessTemplate validateSnippet = FTemplate.GetSnippet("VALIDATEDETAILS");
//                FTemplate.InsertSnippet("VALIDATEDETAILS", validateSnippet);
//            }
//
            if (FCodeStorage.ManualFileExistsAndContains("GetDetailDataFromControlsManual"))
            {
                FTemplate.AddToCodelet("SAVEDETAILS", "GetDetailDataFromControlsManual(ARow);" + Environment.NewLine);
            }

            if (FCodeStorage.ManualFileExistsAndContains("GetDetailDataFromControlsExtra"))
            {
                FTemplate.AddToCodelet("SAVEDETAILSEXTRA", "GetDetailDataFromControlsExtra(ARow);" + Environment.NewLine);
            }
            else
            {
                FTemplate.AddToCodelet("SAVEDETAILSEXTRA", "");
            }

            if (FCodeStorage.ManualFileExistsAndContains("void ReadControlsManual"))
            {
                FTemplate.AddToCodelet("READCONTROLS", "ReadControlsManual(ACalc, AReportAction);" + Environment.NewLine);
            }

            if (FCodeStorage.ManualFileExistsAndContains("void SetControlsManual"))
            {
                FTemplate.AddToCodelet("SETCONTROLS", "SetControlsManual(AParameters);" + Environment.NewLine);
            }

            if (FCodeStorage.ManualFileExistsAndContains("ValidateDataManual"))
            {
                FTemplate.SetCodelet("VALIDATEDATAMANUAL", "true");
            }

            if (FCodeStorage.ManualFileExistsAndContains("GetDetailsFromControlsManual"))
            {
                FTemplate.SetCodelet("GETDETAILSMANUAL", "true");
            }

            if (FCodeStorage.ManualFileExistsAndContains("ValidateDataDetailsManual"))
            {
                FTemplate.SetCodelet("VALIDATEDATADETAILSMANUAL", "true");
            }

            if (FCodeStorage.ManualFileExistsAndContains("GetSelectedDetailRowManual"))
            {
                FTemplate.AddToCodelet("GETSELECTEDDETAILROW", "return GetSelectedDetailRowManual();" + Environment.NewLine);
            }
            else
            {
                string getSelectedDetailRow =
                    "DataRowView[] SelectedGridRow = grdDetails.SelectedDataRowsAsDataRowView;" + Environment.NewLine + Environment.NewLine +
                    "if (SelectedGridRow.Length >= 1)" + Environment.NewLine +
                    "{" + Environment.NewLine +
                    "    return ({#DETAILTABLETYPE}Row)SelectedGridRow[0].Row;" + Environment.NewLine +
                    "}" + Environment.NewLine + Environment.NewLine +
                    "return null;" + Environment.NewLine + Environment.NewLine;

                FTemplate.SetCodelet("GETSELECTEDDETAILROW", getSelectedDetailRow);
            }

            InsertCodeIntoTemplate(AXAMLFilename);
        }
Ejemplo n.º 8
0
    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("Ict.Petra.Shared.", "Ict.Petra.Server.");

        ATemplate.SetCodelet("CLIENTOBJECTFOREACHUICONNECTOR", string.Empty);

        foreach (TypeDeclaration connectorClass in ConnectorClasses)
        {
            foreach (ConstructorDeclaration m in CSParser.GetConstructors(connectorClass))
            {
                if (TCollectConnectorInterfaces.IgnoreMethod(m.Attributes, m.Modifier))
                {
                    continue;
                }

                ProcessTemplate snippet = ATemplate.GetSnippet("UICONNECTORMETHOD");

                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"));
                }

                snippet.SetCodelet("METHODNAME", methodname);
                snippet.SetCodelet("PARAMETERDEFINITION", ParameterDefinition);
                snippet.SetCodelet("ACTUALPARAMETERS", ActualParameters);
                snippet.SetCodelet("UICONNECTORINTERFACE", CSParser.GetImplementedInterface(connectorClass));
                snippet.SetCodelet("UICONNECTORCLIENTREMOTINGCLASS", connectorClass.Name + "Remote");
                snippet.SetCodelet("UICONNECTORCLASS", connectorClass.Name);

                if (!UsingConnectorNamespaces.Contains(ConnectorNamespace))
                {
                    UsingConnectorNamespaces.Add(ConnectorNamespace);
                }

                ATemplate.InsertSnippet("REMOTEDMETHODS", snippet);
            }

            List <TypeDeclaration>tempList = new List <TypeDeclaration>();
            tempList.Add(connectorClass);

            ATemplate.InsertSnippet("CLIENTOBJECTFOREACHUICONNECTOR",
                TCreateClientRemotingClass.AddClientRemotingClass(
                    FTemplateDir,
                    connectorClass.Name + "Remote",
                    CSParser.GetImplementedInterface(connectorClass),
                    tempList
                    ));
        }
    }
Ejemplo n.º 9
0
    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;
    }
Ejemplo n.º 10
0
    //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);
        }
    }
Ejemplo n.º 11
0
    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);
            }
        }
    }
Ejemplo n.º 12
0
    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);
    }
Ejemplo n.º 13
0
        /// <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");
                                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");
                            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);
        }
Ejemplo n.º 14
0
        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);
        }
        private Boolean CreateConnectors(String AOutputPath, String AModulePath, String ATemplateDir)
        {
            // Work out the module name from the module path
            string[] items = AModulePath.Split(new char[] { Path.DirectorySeparatorChar });

            if (items.Length == 0)
            {
                // the -inputclient command line parameter must be wrong
                return false;
            }

            // Module name is e.g. MCommon, MPartner etc
            string moduleName = items[items.Length - 1];

            // Work out the actual folder/file for the output file
            String OutputFolder = AOutputPath + Path.DirectorySeparatorChar + "lib" +
                                  Path.DirectorySeparatorChar + moduleName +
                                  Path.DirectorySeparatorChar + "web";

            String OutputFile = OutputFolder + Path.DirectorySeparatorChar + "ReferenceCount-generated.cs";
            Console.WriteLine("working on " + OutputFile);

            // Where is the template?
            String templateFilename = ATemplateDir +
                                      Path.DirectorySeparatorChar + "ORM" +
                                      Path.DirectorySeparatorChar + "ReferenceCountWebConnector.cs";

            if (!File.Exists(templateFilename))
            {
                // The -templatedir command line parameter must have been wrong
                return false;
            }

            // Open the template
            ProcessTemplate Template = new ProcessTemplate(templateFilename);

            // now we need to remove the leading 'M' from the module name
            moduleName = moduleName.Substring(1);
            string className = "T" + moduleName + "ReferenceCountWebConnector";

            Console.WriteLine("Starting connector for " + className + Environment.NewLine);

            int cacheableCount = 0;
            int nonCacheableCount = 0;

            // load default header with license and copyright
            Template.SetCodelet("GPLFILEHEADER", ProcessTemplate.LoadEmptyFileComment(ATemplateDir));
            Template.SetCodelet("TOPLEVELMODULE", moduleName);

            Template.SetCodelet("CLASSNAME", className);
            Template.SetCodelet("CACHEABLETABLECASES", string.Empty);
            Template.SetCodelet("CACHEABLETABLENAME", string.Empty);
            Template.SetCodelet("CACHEABLETABLECASE", string.Empty);
            Template.SetCodelet("CACHEABLETABLELISTNAME", string.Empty);
            Template.SetCodelet("CACHEABLETRANSACTION", string.Empty);
            Template.SetCodelet("CACHEABLEFINALLY", string.Empty);
            Template.SetCodelet("TABLESIF", string.Empty);
            Template.SetCodelet("TABLESELSEIF", string.Empty);
            Template.SetCodelet("TABLESELSE", string.Empty);
            Template.SetCodelet("TABLENAME", string.Empty);
            Template.SetCodelet("NONCACHEABLETRANSACTION", string.Empty);
            Template.SetCodelet("NONCACHEABLEFINALLY", string.Empty);

            // Find all the YAML files in the client module folder
            string[] clientFiles = Directory.GetFiles(AModulePath, "*.yaml", SearchOption.AllDirectories);

            foreach (String fn in clientFiles)
            {
                // only look for main files, not language specific files (*.xy-XY.yaml or *.xy.yaml)
                if (TProcessYAMLForms.IgnoreLanguageSpecificYamlFile(fn))
                {
                    continue;
                }

                XmlDocument doc = TYml2Xml.CreateXmlDocument();
                SortedList sortedNodes = null;
                TCodeStorage codeStorage = new TCodeStorage(doc, sortedNodes);
                TParseYAMLFormsDefinition yamlParser = new TParseYAMLFormsDefinition(ref codeStorage);
                yamlParser.LoadRecursively(fn, null);

                string attDetailTableName = codeStorage.GetAttribute("DetailTable");
                string attCacheableListName = codeStorage.GetAttribute("CacheableTable");

                // Note - this IF clause needs to be the same as the one in FormWriter.cs which is generating the client side code
                // Do Ctrl+F to find: this IF clause needs to be the same
                // in that file
                if ((attDetailTableName != String.Empty)
                    && (codeStorage.FControlList.ContainsKey("btnDelete")
                        || codeStorage.FControlList.ContainsKey("btnDeleteType")
                        || codeStorage.FControlList.ContainsKey("btnDeleteExtract")
                        || codeStorage.FControlList.ContainsKey("btnDeleteDetail")
                        || (codeStorage.FControlList.ContainsKey("btnRemoveDetail") && (codeStorage.GetAttribute("FormType") != "report"))))
                {
                    if (attCacheableListName != String.Empty)
                    {
                        ProcessTemplate snippet = Template.GetSnippet("CACHEABLETABLECASE");
                        snippet.SetCodelet("CACHEABLETABLENAME", attDetailTableName);
                        snippet.SetCodelet("CACHEABLETABLELISTNAME", attCacheableListName);
                        Template.InsertSnippet("CACHEABLETABLECASES", snippet);

                        if (cacheableCount == 0)
                        {
                            // Add these on the first time through
                            snippet = Template.GetSnippet("CACHEABLETRANSACTIONSNIP");
                            Template.InsertSnippet("CACHEABLETRANSACTION", snippet);
                            snippet = Template.GetSnippet("CACHEABLEFINALLYSNIP");
                            Template.InsertSnippet("CACHEABLEFINALLY", snippet);
                        }

                        Console.WriteLine("Creating cacheable reference count connector for " + attCacheableListName);
                        cacheableCount++;
                    }
                    else
                    {
                        ProcessTemplate snippet = null;

                        if (nonCacheableCount == 0)
                        {
                            snippet = Template.GetSnippet("TABLEIF");
                            snippet.SetCodelet("TABLENAME", attDetailTableName);
                            Template.InsertSnippet("TABLESIF", snippet);

                            snippet = Template.GetSnippet("NONCACHEABLETRANSACTIONSNIP");
                            Template.InsertSnippet("NONCACHEABLETRANSACTION", snippet);
                            snippet = Template.GetSnippet("NONCACHEABLEFINALLYSNIP");
                            Template.InsertSnippet("NONCACHEABLEFINALLY", snippet);
                        }
                        else
                        {
                            snippet = Template.GetSnippet("TABLEELSEIF");
                            snippet.SetCodelet("TABLENAME", attDetailTableName);
                            Template.InsertSnippet("TABLESELSEIF", snippet);
                        }

                        Console.WriteLine("Creating non-cacheable reference count connector for " + attDetailTableName);
                        nonCacheableCount++;
                    }
                }
            }

            // Now we finish off the template content depending on how many entries we made
            if ((nonCacheableCount == 0) && (cacheableCount > 0))
            {
                ProcessTemplate snippet = Template.GetSnippet("TABLENONE");
                Template.InsertSnippet("TABLESELSE", snippet);
            }

            if (nonCacheableCount > 0)
            {
                ProcessTemplate snippet = Template.GetSnippet("TABLEELSE");
                Template.InsertSnippet("TABLESELSE", snippet);
            }

            if ((cacheableCount > 0) || (nonCacheableCount > 0))
            {
                if (!Directory.Exists(OutputFolder))
                {
                    // The -outputserver command line parameter must be wrong, or the directory does not exist yet
                    // Directories must be manually created and added to source code control
                    Console.WriteLine("Error: directory does not exist: " + OutputFolder);
                    return false;
                }

                Console.WriteLine("Finishing connector for " + className + Environment.NewLine + Environment.NewLine);
                Template.FinishWriting(OutputFile, ".cs", true);

                FTotalCacheable += cacheableCount;
                FTotalNonCacheable += nonCacheableCount;
                FTotalConnectors++;
            }

            return true;
        }
Ejemplo n.º 16
0
        /// <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;
                    }

                    // 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;
        }
Ejemplo n.º 17
0
        /// <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);
        }
Ejemplo n.º 18
0
        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);
        }
Ejemplo n.º 19
0
        /// <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);

            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);
                }
            }

            Template.FinishWriting(AFilePath + AFilename + "-generated.cs", ".cs", true);

            return true;
        }
Ejemplo n.º 20
0
        /// <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);
        }
Ejemplo n.º 21
0
        /// <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, ",");
                    }
                }
            }
        }
Ejemplo n.º 22
0
        /// <summary>
        /// write the definition for the code of a typed row
        /// </summary>
        /// <param name="Template"></param>
        /// <param name="currentTable"></param>
        /// <param name="origTable"></param>
        /// <param name="WhereToInsert"></param>
        public static void InsertRowDefinition(ProcessTemplate Template, TTable currentTable, TTable origTable, string WhereToInsert)
        {
            ProcessTemplate snippet = Template.GetSnippet("TYPEDROW");

            if (origTable != null)
            {
                snippet.SetCodelet("BASECLASSROW", TTable.NiceTableName(currentTable.strName) + "Row");
                snippet.SetCodelet("OVERRIDE", "override ");
            }
            else
            {
                snippet.SetCodelet("BASECLASSROW", "System.Data.DataRow");
                snippet.SetCodelet("OVERRIDE", "virtual ");
            }

            snippet.SetCodeletComment("TABLE_DESCRIPTION", currentTable.strDescription);
            snippet.SetCodelet("TABLENAME", currentTable.strDotNetName);

            foreach (TTableField col in currentTable.grpTableField)
            {
                ProcessTemplate tempTemplate = null;
                string columnOverwrite = "";

                if ((origTable != null) && (origTable.GetField(col.strName, false) != null))
                {
                    columnOverwrite = "new ";
                }

                if (columnOverwrite.Length == 0)
                {
                    tempTemplate = Template.GetSnippet("ROWCOLUMNPROPERTY");
                    tempTemplate.SetCodelet("COLUMNDBNAME", col.strName);
                    tempTemplate.SetCodelet("COLUMNNAME", col.strNameDotNet);
                    tempTemplate.SetCodelet("COLUMNHELP", col.strDescription.Replace(Environment.NewLine, " "));
                    tempTemplate.SetCodelet("COLUMNLABEL", col.strLabel);
                    tempTemplate.SetCodelet("COLUMNLENGTH", col.iLength.ToString());
                    tempTemplate.SetCodelet("COLUMNDOTNETTYPE", col.GetDotNetType());

                    if (!col.bNotNull)
                    {
                        if (col.GetDotNetType().Contains("DateTime?"))
                        {
                            tempTemplate.SetCodelet("TESTFORNULL", "!value.HasValue");
                        }
                        else if (col.GetDotNetType().Contains("String"))
                        {
                            tempTemplate.SetCodelet("TESTFORNULL", "(value == null) || (value.Length == 0)");
                        }
                    }

                    if (col.GetDotNetType().Contains("DateTime?"))
                    {
                        tempTemplate.SetCodelet("ACTIONGETNULLVALUE", "return null;");
                    }
                    else if (col.GetDotNetType().Contains("DateTime"))
                    {
                        tempTemplate.SetCodelet("ACTIONGETNULLVALUE", "return DateTime.MinValue;");
                    }
                    else if (col.GetDotNetType().ToLower().Contains("string"))
                    {
                        tempTemplate.SetCodelet("ACTIONGETNULLVALUE", "return String.Empty;");
                    }
                    else
                    {
                        tempTemplate.SetCodelet("ACTIONGETNULLVALUE", "throw new System.Data.StrongTypingException(\"Error: DB null\", null);");
                    }

                    tempTemplate.SetCodeletComment("COLUMN_DESCRIPTION", col.strDescription);
                    snippet.InsertSnippet("ROWCOLUMNPROPERTIES", tempTemplate);

                    tempTemplate = Template.GetSnippet("FUNCTIONSFORNULLVALUES");
                    tempTemplate.SetCodelet("COLUMNNAME", TTable.NiceFieldName(col));
                    snippet.InsertSnippet("FUNCTIONSFORNULLVALUES", tempTemplate);
                }

                if ((col.strDefault.Length > 0) && (col.strDefault != "NULL"))
                {
                    string defaultValue = col.strDefault;

                    if (defaultValue == "SYSDATE")
                    {
                        defaultValue = "DateTime.Today";
                    }
                    else if ((col.strType == "bit") || ((col.strTypeDotNet != null) && col.strTypeDotNet.ToLower().Contains("bool")))
                    {
                        defaultValue = (defaultValue == "1" || defaultValue.ToLower() == "true").ToString().ToLower();
                    }
                    else if ((col.strType == "varchar") || ((col.strTypeDotNet != null) && col.strTypeDotNet.ToLower().Contains("string")))
                    {
                        defaultValue = '"' + defaultValue + '"';
                    }

                    snippet.AddToCodelet("ROWSETNULLORDEFAULT", "this[this.myTable.Column" + TTable.NiceFieldName(
                            col) + ".Ordinal] = " + defaultValue + ";" + Environment.NewLine);
                }
                else
                {
                    snippet.AddToCodelet("ROWSETNULLORDEFAULT", "this.SetNull(this.myTable.Column" + TTable.NiceFieldName(
                            col) + ");" + Environment.NewLine);
                }
            }

            Template.InsertSnippet(WhereToInsert, snippet);
        }
Ejemplo n.º 23
0
    /// <summary>
    /// Creates a HTML file that contains central documentation of the Error Codes that are used throughout OpenPetra code
    /// </summary>
    public static bool Execute(string ACSharpPath, string ATemplateFilePath, string AOutFilePath)
    {
        Dictionary <string, ErrCodeInfo>ErrorCodes = new Dictionary <string, ErrCodeInfo>();
        CSParser parsedFile = new CSParser(ACSharpPath + "/ICT/Common/ErrorCodes.cs");
        string ErrCodeCategoryNice = String.Empty;

        TLogging.Log("Creating HTML documentation of OpenPetra Error Codes...");

        ProcessFile(parsedFile, ref ErrorCodes);
        parsedFile = new CSParser(ACSharpPath + "/ICT/Petra/Shared/ErrorCodes.cs");
        ProcessFile(parsedFile, ref ErrorCodes);
        parsedFile = new CSParser(ACSharpPath + "/ICT/Common/Verification/StringChecks.cs");
        ProcessFile(parsedFile, ref ErrorCodes);

        ProcessTemplate t = new ProcessTemplate(ATemplateFilePath);

        Dictionary <string, ProcessTemplate>snippets = new Dictionary <string, ProcessTemplate>();

        snippets.Add("GENC", t.GetSnippet("TABLE"));
        snippets["GENC"].SetCodelet("TABLEDESCRIPTION", "GENERAL (<i>Ict.Common* Libraries only</i>)");
        snippets.Add("GEN", t.GetSnippet("TABLE"));
        snippets["GEN"].SetCodelet("TABLEDESCRIPTION", "GENERAL (across the OpenPetra application)");
        snippets.Add("PARTN", t.GetSnippet("TABLE"));
        snippets["PARTN"].SetCodelet("TABLEDESCRIPTION", "PARTNER Module");
        snippets.Add("PERS", t.GetSnippet("TABLE"));
        snippets["PERS"].SetCodelet("TABLEDESCRIPTION", "PERSONNEL Module");
        snippets.Add("FIN", t.GetSnippet("TABLE"));
        snippets["FIN"].SetCodelet("TABLEDESCRIPTION", "FINANCE Module");
        snippets.Add("CONF", t.GetSnippet("TABLE"));
        snippets["CONF"].SetCodelet("TABLEDESCRIPTION", "CONFERENCE Module");
        snippets.Add("FINDEV", t.GetSnippet("TABLE"));
        snippets["FINDEV"].SetCodelet("TABLEDESCRIPTION", "FINANCIAL DEVELOPMENT Module");
        snippets.Add("SYSMAN", t.GetSnippet("TABLE"));
        snippets["SYSMAN"].SetCodelet("TABLEDESCRIPTION", "SYSTEM MANAGER Module");

        foreach (string snippetkey in snippets.Keys)
        {
            snippets[snippetkey].SetCodelet("ABBREVIATION", snippetkey);
            snippets[snippetkey].SetCodelet("ROWS", string.Empty);
        }

        foreach (string code in ErrorCodes.Keys)
        {
            foreach (string snippetkey in snippets.Keys)
            {
                if (code.StartsWith(snippetkey + "."))
                {
                    ProcessTemplate row = t.GetSnippet("ROW");
                    row.SetCodelet("CODE", code);

                    ErrCodeInfo ErrCode = ErrorCodes[code];

                    switch (ErrCode.Category)
                    {
                        case ErrCodeCategory.NonCriticalError:
                            ErrCodeCategoryNice = "Non-critical Error";
                            break;

                        default:
                            ErrCodeCategoryNice = ErrCode.Category.ToString("G");
                            break;
                    }

                    row.AddToCodelet("SHORTDESCRIPTION", (ErrCode.ShortDescription));
                    row.AddToCodelet("FULLDESCRIPTION", (ErrCode.FullDescription));
                    row.AddToCodelet("ERRORCODECATEGORY", (ErrCodeCategoryNice));
                    row.AddToCodelet("DECLARINGCLASS", (ErrCode.ErrorCodeConstantClass));

                    snippets[snippetkey].InsertSnippet("ROWS", row);
                }
            }
        }

        foreach (string snippetkey in snippets.Keys)
        {
            t.InsertSnippet("TABLES", snippets[snippetkey]);
        }

        return t.FinishWriting(AOutFilePath, ".html", true);
    }
Ejemplo n.º 24
0
        /// <summary>
        /// create the code for the definition of a typed table
        /// </summary>
        /// <param name="Template"></param>
        /// <param name="currentTable"></param>
        /// <param name="origTable"></param>
        /// <param name="WhereToInsert"></param>
        public static void InsertTableDefinition(ProcessTemplate Template, TTable currentTable, TTable origTable, string WhereToInsert)
        {
            ProcessTemplate snippet = Template.GetSnippet("TYPEDTABLE");
            string derivedTable = "";

            if (origTable != null)
            {
                snippet.SetCodelet("BASECLASSTABLE", TTable.NiceTableName(currentTable.strName) + "Table");
                derivedTable = "new ";
                snippet.SetCodelet("TABLEID", origTable.iOrder.ToString());
            }
            else
            {
                snippet.SetCodelet("BASECLASSTABLE", "TTypedDataTable");
                snippet.SetCodelet("TABLEID", currentTable.iOrder.ToString());
            }

            snippet.SetCodelet("NEW", derivedTable);
            snippet.SetCodeletComment("TABLE_DESCRIPTION", currentTable.strDescription);
            snippet.SetCodelet("TABLENAME", currentTable.strDotNetName);

            if (currentTable.strVariableNameInDataset != null)
            {
                snippet.SetCodelet("TABLEVARIABLENAME", currentTable.strVariableNameInDataset);
            }
            else
            {
                snippet.SetCodelet("TABLEVARIABLENAME", currentTable.strDotNetName);
            }

            snippet.SetCodelet("DBTABLENAME", currentTable.strName);

            snippet.SetCodelet("DBTABLELABEL", currentTable.strLabel);

            if (currentTable.HasPrimaryKey())
            {
                TConstraint primKey = currentTable.GetPrimaryKey();
                bool first = true;
                string primaryKeyColumns = "";
                int prevIndex = -1;

                // the fields in the primary key should be used in the same order as in the table.
                // otherwise this is causing confusion. eg. a_processed_fee
                foreach (TTableField column in currentTable.grpTableField)
                {
                    int newIndex = -1;

                    if (primKey.strThisFields.Contains(column.strName))
                    {
                        newIndex = primKey.strThisFields.IndexOf(column.strName);
                    }
                    else if (primKey.strThisFields.Contains(TTable.NiceFieldName(column)))
                    {
                        newIndex = primKey.strThisFields.IndexOf(TTable.NiceFieldName(column));
                    }

                    if (newIndex != -1)
                    {
                        if (newIndex < prevIndex)
                        {
                            throw new Exception("Please fix the order of the fields in the primary key of table " + currentTable.strName);
                        }

                        prevIndex = newIndex;
                    }
                }

                // the fields in the primary key should be used in the same order as in the table.
                // otherwise this is causing confusion. eg. a_processed_fee
                foreach (TTableField column in currentTable.grpTableField)
                {
                    if (primKey.strThisFields.Contains(column.strName) || primKey.strThisFields.Contains(TTable.NiceFieldName(column)))
                    {
                        string columnName = column.strName;

                        string toAdd = currentTable.grpTableField.IndexOf(currentTable.GetField(columnName)).ToString();

                        if (!first)
                        {
                            toAdd = ", " + toAdd;
                            primaryKeyColumns += ",";
                        }

                        first = false;

                        snippet.AddToCodelet("COLUMNPRIMARYKEYORDER", toAdd);
                        primaryKeyColumns += "Column" + TTable.NiceFieldName(currentTable.GetField(columnName));
                    }
                }

                if (primaryKeyColumns.Length > 0)
                {
                    snippet.SetCodelet("PRIMARYKEYCOLUMNS", primaryKeyColumns);
                    snippet.SetCodelet("PRIMARYKEYCOLUMNSCOUNT", primKey.strThisFields.Count.ToString());
                }
            }
            else
            {
                snippet.AddToCodelet("COLUMNPRIMARYKEYORDER", "");
            }

            if (currentTable.HasUniqueKey())
            {
                TConstraint primKey = currentTable.GetFirstUniqueKey();
                bool first = true;

                foreach (string columnName in primKey.strThisFields)
                {
                    string toAdd = currentTable.grpTableField.IndexOf(currentTable.GetField(columnName)).ToString();

                    if (!first)
                    {
                        toAdd = ", " + toAdd;
                    }

                    first = false;

                    snippet.AddToCodelet("COLUMNUNIQUEKEYORDER", toAdd);
                }
            }
            else
            {
                snippet.AddToCodelet("COLUMNUNIQUEKEYORDER", "");
            }

            int colOrder = 0;

            foreach (TTableField col in currentTable.grpTableField)
            {
                col.strTableName = currentTable.strName;
                ProcessTemplate tempTemplate = null;
                string columnOverwrite = "";
                bool writeColumnProperties = true;

                if ((origTable != null) && (origTable.GetField(col.strName, false) != null))
                {
                    columnOverwrite = "new ";

                    if (origTable.GetField(col.strName).iOrder == colOrder)
                    {
                        // same order number, save some lines of code by not writing them
                        writeColumnProperties = false;
                    }
                }

                if (writeColumnProperties && (columnOverwrite.Length == 0))
                {
                    tempTemplate = Template.GetSnippet("DATACOLUMN");
                    tempTemplate.SetCodeletComment("COLUMN_DESCRIPTION", col.strDescription);
                    tempTemplate.SetCodelet("COLUMNNAME", TTable.NiceFieldName(col));
                    snippet.InsertSnippet("DATACOLUMNS", tempTemplate);
                }

                if (writeColumnProperties)
                {
                    tempTemplate = Template.GetSnippet("COLUMNIDS");
                    tempTemplate.SetCodelet("COLUMNNAME", TTable.NiceFieldName(col));
                    tempTemplate.SetCodelet("COLUMNORDERNUMBER", colOrder.ToString());
                    tempTemplate.SetCodelet("NEW", columnOverwrite);
                    snippet.InsertSnippet("COLUMNIDS", tempTemplate);
                }

                if (origTable == null)
                {
                    tempTemplate = Template.GetSnippet("COLUMNINFO");
                    tempTemplate.SetCodelet("COLUMNORDERNUMBER", colOrder.ToString());
                    tempTemplate.SetCodelet("COLUMNNAME", TTable.NiceFieldName(col));
                    tempTemplate.SetCodelet("COLUMNDBNAME", col.strName);
                    tempTemplate.SetCodelet("COLUMNLABEL", col.strLabel);
                    tempTemplate.SetCodelet("COLUMNODBCTYPE", CodeGenerationPetra.ToOdbcTypeString(col));
                    tempTemplate.SetCodelet("COLUMNLENGTH", col.iLength.ToString());
                    tempTemplate.SetCodelet("COLUMNNOTNULL", col.bNotNull.ToString().ToLower());
                    tempTemplate.SetCodelet("COLUMNCOMMA", colOrder + 1 < currentTable.grpTableField.Count ? "," : "");
                    snippet.InsertSnippet("COLUMNINFO", tempTemplate);
                }

                tempTemplate = Template.GetSnippet("INITCLASSADDCOLUMN");
                tempTemplate.SetCodelet("COLUMNDBNAME", col.strName);
                tempTemplate.SetCodelet("COLUMNDOTNETTYPE", col.GetDotNetType());
                tempTemplate.SetCodelet("COLUMNDOTNETTYPENOTNULLABLE", col.GetDotNetType().Replace("?", ""));
                snippet.InsertSnippet("INITCLASSADDCOLUMN", tempTemplate);

                tempTemplate = Template.GetSnippet("INITVARSCOLUMN");
                tempTemplate.SetCodelet("COLUMNDBNAME", col.strName);
                tempTemplate.SetCodelet("COLUMNNAME", TTable.NiceFieldName(col));
                snippet.InsertSnippet("INITVARSCOLUMN", tempTemplate);

                if (writeColumnProperties)
                {
                    tempTemplate = Template.GetSnippet("STATICCOLUMNPROPERTIES");
                    tempTemplate.SetCodelet("COLUMNDBNAME", col.strName);
                    tempTemplate.SetCodelet("COLUMNNAME", TTable.NiceFieldName(col));
                    tempTemplate.SetCodelet("COLUMNHELP", col.strHelp.Replace("\"", "\\\""));
                    tempTemplate.SetCodelet("COLUMNLENGTH", col.iLength.ToString());
                    tempTemplate.SetCodelet("NEW", columnOverwrite);
                    snippet.InsertSnippet("STATICCOLUMNPROPERTIES", tempTemplate);
                }

                colOrder++;
            }

            Template.InsertSnippet(WhereToInsert, snippet);
        }
Ejemplo n.º 25
0
    private ProcessTemplate WriteRemotableClass(ProcessTemplate ATemplate,
        String FullNamespace,
        String Classname,
        String Namespace,
        Boolean HighestLevel,
        SortedList <string, TNamespace>children,
        SortedList <string, TypeDeclaration>connectors)
    {
        if ((children.Count == 0) && !HighestLevel)
        {
            return new ProcessTemplate();
        }

        ProcessTemplate remotableClassSnippet = ATemplate.GetSnippet("REMOTABLECLASS");

        remotableClassSnippet.SetCodelet("SUBNAMESPACEREMOTABLECLASSES", string.Empty);

        remotableClassSnippet.SetCodelet("NAMESPACE", Namespace);

        remotableClassSnippet.SetCodelet("CLIENTOBJECTFOREACHPROPERTY", string.Empty);
        remotableClassSnippet.SetCodelet("SUBNAMESPACEPROPERTIES", string.Empty);

        foreach (TNamespace sn in children.Values)
        {
            ProcessTemplate subNamespaceSnippet = ATemplate.GetSnippet("SUBNAMESPACEPROPERTY");

            string NamespaceName = Namespace + sn.Name;

            if (HighestLevel)
            {
                NamespaceName = sn.Name;
            }

            subNamespaceSnippet.SetCodelet("OBJECTNAME", sn.Name);
            subNamespaceSnippet.SetCodelet("NAMESPACENAME", NamespaceName);
            subNamespaceSnippet.SetCodelet("NAMESPACE", Namespace);

            remotableClassSnippet.InsertSnippet("SUBNAMESPACEPROPERTIES", subNamespaceSnippet);

            if (sn.Children.Count > 0)
            {
                // properties for each sub namespace
                foreach (TNamespace subnamespace in sn.Children.Values)
                {
                    ATemplate.InsertSnippet("SUBNAMESPACEREMOTABLECLASSES",
                        WriteRemotableClass(ATemplate,
                            FullNamespace + "." + sn.Name + "." + subnamespace.Name,
                            sn.Name + subnamespace.Name,
                            NamespaceName + subnamespace.Name,
                            false,
                            subnamespace.Children,
                            connectors));
                }

                remotableClassSnippet.InsertSnippet("CLIENTOBJECTFOREACHPROPERTY",
                    TCreateClientRemotingClass.AddClientRemotingClass(
                        FTemplateDir,
                        "T" + NamespaceName + "NamespaceRemote",
                        "I" + NamespaceName + "Namespace",
                        new List <TypeDeclaration>(),
                        FullNamespace + "." + sn.Name,
                        sn.Children
                        ));
            }
            else
            {
                remotableClassSnippet.InsertSnippet("CLIENTOBJECTFOREACHPROPERTY",
                    TCreateClientRemotingClass.AddClientRemotingClass(
                        FTemplateDir,
                        "T" + NamespaceName + "NamespaceRemote",
                        "I" + NamespaceName + "Namespace",
                        TCollectConnectorInterfaces.FindTypesInNamespace(connectors, FullNamespace + "." + sn.Name)
                        ));
            }
        }

        return remotableClassSnippet;
    }
Ejemplo n.º 26
0
        /// <summary>
        /// code for cascading functions
        /// </summary>
        /// <param name="AStore"></param>
        /// <param name="ACurrentTable"></param>
        /// <param name="ATemplate"></param>
        /// <param name="ASnippet"></param>
        /// <returns>false if no cascading available</returns>
        private static bool InsertMainProcedures(TDataDefinitionStore AStore,
            TTable ACurrentTable,
            ProcessTemplate ATemplate,
            ProcessTemplate ASnippet)
        {
            string csvListPrimaryKeyFields;
            string formalParametersPrimaryKey;
            string actualParametersPrimaryKey;

            Tuple <string, string, string>[] formalParametersPrimaryKeySeparate;
            string actualParametersPrimaryKeyFromPKArray = String.Empty;

            ASnippet.AddToCodelet("TABLENAME", TTable.NiceTableName(ACurrentTable.strName));
            ASnippet.AddToCodelet("THISTABLELABEL", ACurrentTable.strLabel);

            PrepareCodeletsPrimaryKey(ACurrentTable,
                out csvListPrimaryKeyFields,
                out formalParametersPrimaryKey,
                out actualParametersPrimaryKey,
                out formalParametersPrimaryKeySeparate);

            for (int Counter = 0; Counter < formalParametersPrimaryKeySeparate.Length; Counter++)
            {
                actualParametersPrimaryKeyFromPKArray +=
                    "(" + formalParametersPrimaryKeySeparate[Counter].Item1 + ")" +
                    "APrimaryKeyValues[" + Counter.ToString() + "], ";
            }

            // Strip off trailing ", "
            actualParametersPrimaryKeyFromPKArray = actualParametersPrimaryKeyFromPKArray.Substring(0,
                actualParametersPrimaryKeyFromPKArray.Length - 2);

            ASnippet.AddToCodelet("CSVLISTPRIMARYKEYFIELDS", csvListPrimaryKeyFields);
            ASnippet.AddToCodelet("FORMALPARAMETERSPRIMARYKEY", formalParametersPrimaryKey);
            ASnippet.AddToCodelet("ACTUALPARAMETERSPRIMARYKEY", actualParametersPrimaryKey);
            ASnippet.AddToCodelet("ACTUALPARAMETERSPRIMARYKEYFROMPKARRAY", actualParametersPrimaryKeyFromPKArray);

            for (int Counter = 0; Counter < ACurrentTable.GetPrimaryKey().strThisFields.Count; Counter++)
            {
                ProcessTemplate PKInfoDictBuilding = ASnippet.GetSnippet("PRIMARYKEYINFODICTBUILDING");
                PKInfoDictBuilding.SetCodelet("PKCOLUMNLABEL", formalParametersPrimaryKeySeparate[Counter].Item3);
                PKInfoDictBuilding.SetCodelet("PKCOLUMNCONTENT", formalParametersPrimaryKeySeparate[Counter].Item2);
                ASnippet.InsertSnippet("PRIMARYKEYINFODICTBUILDING", PKInfoDictBuilding);
            }

            ASnippet.AddToCodelet("PRIMARYKEYCOLUMNCOUNT", ACurrentTable.GetPrimaryKey().strThisFields.Count.ToString());

            foreach (TConstraint constraint in ACurrentTable.FReferenced)
            {
                if (AStore.GetTable(constraint.strThisTable).HasPrimaryKey())
                {
                    string csvListOtherPrimaryKeyFields;
                    string notUsed;
                    Tuple <string, string, string>[] formalParametersPrimaryKeySeparate2;

                    TTable OtherTable = AStore.GetTable(constraint.strThisTable);

                    PrepareCodeletsPrimaryKey(OtherTable,
                        out csvListOtherPrimaryKeyFields,
                        out notUsed,
                        out notUsed,
                        out formalParametersPrimaryKeySeparate2);

                    // check if other foreign key exists that references the same table, e.g.
                    // PBankAccess.LoadViaPPartnerPartnerKey
                    // PBankAccess.LoadViaPPartnerContactPartnerKey
                    string DifferentField = CodeGenerationAccess.FindOtherConstraintSameOtherTable(
                        OtherTable.grpConstraint,
                        constraint);
                    string LoadViaProcedureName = TTable.NiceTableName(ACurrentTable.strName);
                    string MyOtherTableName = "My" + TTable.NiceTableName(constraint.strThisTable);

                    if (DifferentField.Length != 0)
                    {
                        LoadViaProcedureName += TTable.NiceFieldName(DifferentField);
                        MyOtherTableName += TTable.NiceFieldName(DifferentField);
                    }

                    // for the moment, don't implement it for too big tables, e.g. s_user)
                    if ((ACurrentTable.HasPrimaryKey() || (ACurrentTable.FReferenced.Count <= CASCADING_DELETE_MAX_REFERENCES))
                        && ((constraint.strThisTable != "a_ledger")
                            && (!LoadViaProcedureName.StartsWith("SUser"))))
                    {
                        ProcessTemplate snippetDelete = ASnippet.GetSnippet("DELETEBYPRIMARYKEYCASCADING");
                        snippetDelete.SetCodelet("OTHERTABLENAME", TTable.NiceTableName(constraint.strThisTable));
                        snippetDelete.SetCodelet("MYOTHERTABLENAME", MyOtherTableName);
                        snippetDelete.SetCodelet("VIAPROCEDURENAME", "Via" + LoadViaProcedureName);
                        snippetDelete.SetCodelet("CSVLISTOTHERPRIMARYKEYFIELDS", csvListOtherPrimaryKeyFields);
                        snippetDelete.SetCodelet("OTHERTABLEALSOCASCADING", "true");


                        ASnippet.InsertSnippet("DELETEBYPRIMARYKEYCASCADING", snippetDelete);

                        snippetDelete = ASnippet.GetSnippet("DELETEBYTEMPLATECASCADING");
                        snippetDelete.SetCodelet("OTHERTABLENAME", TTable.NiceTableName(constraint.strThisTable));
                        snippetDelete.SetCodelet("MYOTHERTABLENAME", MyOtherTableName);
                        snippetDelete.SetCodelet("VIAPROCEDURENAME", "Via" + LoadViaProcedureName);
                        snippetDelete.SetCodelet("CSVLISTOTHERPRIMARYKEYFIELDS", csvListOtherPrimaryKeyFields);
                        snippetDelete.SetCodelet("OTHERTABLEALSOCASCADING", "true");


                        ASnippet.InsertSnippet("DELETEBYTEMPLATECASCADING", snippetDelete);
                    }

                    if ((constraint.strThisTable != "a_ledger")
                        && (!LoadViaProcedureName.StartsWith("SUser")))
                    {
                        ProcessTemplate snippetCount = ASnippet.GetSnippet("COUNTBYPRIMARYKEYCASCADING");
                        snippetCount.SetCodelet("OTHERTABLENAME", TTable.NiceTableName(constraint.strThisTable));
                        snippetCount.SetCodelet("MYOTHERTABLENAME", MyOtherTableName);
                        snippetCount.SetCodelet("VIAPROCEDURENAME", "Via" + LoadViaProcedureName);
                        snippetCount.SetCodelet("CSVLISTOTHERPRIMARYKEYFIELDS", csvListOtherPrimaryKeyFields);
                        snippetCount.SetCodelet("OTHERTABLEALSOCASCADING", "true");

                        for (int Counter = 0; Counter < OtherTable.GetPrimaryKey().strThisFields.Count; Counter++)
                        {
                            ProcessTemplate PKInfoDictBuilding2 = ASnippet.GetSnippet("PRIMARYKEYINFODICTBUILDING");
                            PKInfoDictBuilding2.SetCodelet("PKCOLUMNLABEL", formalParametersPrimaryKeySeparate2[Counter].Item3);
                            PKInfoDictBuilding2.SetCodelet("PKCOLUMNCONTENT", "\"\"");
                            snippetCount.InsertSnippet("PRIMARYKEYINFODICTBUILDING2", PKInfoDictBuilding2);
                        }

                        snippetCount.SetCodelet("PRIMARYKEYCOLUMNCOUNT2", OtherTable.GetPrimaryKey().strThisFields.Count.ToString());

                        ASnippet.InsertSnippet("COUNTBYPRIMARYKEYCASCADING", snippetCount);

                        snippetCount = ASnippet.GetSnippet("COUNTBYTEMPLATECASCADING");
                        snippetCount.SetCodelet("OTHERTABLENAME", TTable.NiceTableName(constraint.strThisTable));
                        snippetCount.SetCodelet("OTHERTABLELABEL", OtherTable.strLabel);
                        snippetCount.SetCodelet("MYOTHERTABLENAME", MyOtherTableName);
                        snippetCount.SetCodelet("VIAPROCEDURENAME", "Via" + LoadViaProcedureName);
                        snippetCount.SetCodelet("CSVLISTOTHERPRIMARYKEYFIELDS", csvListOtherPrimaryKeyFields);
                        snippetCount.SetCodelet("OTHERTABLEALSOCASCADING", "true");

                        for (int Counter = 0; Counter < OtherTable.GetPrimaryKey().strThisFields.Count; Counter++)
                        {
                            ProcessTemplate PKInfoDictBuilding2 = ASnippet.GetSnippet("PRIMARYKEYINFODICTBUILDING");
                            PKInfoDictBuilding2.SetCodelet("PKCOLUMNLABEL", formalParametersPrimaryKeySeparate2[Counter].Item3);
                            PKInfoDictBuilding2.SetCodelet("PKCOLUMNCONTENT", "\"\"");
                            snippetCount.InsertSnippet("PRIMARYKEYINFODICTBUILDING2", PKInfoDictBuilding2);
                        }

                        snippetCount.SetCodelet("PRIMARYKEYCOLUMNCOUNT2", OtherTable.GetPrimaryKey().strThisFields.Count.ToString());

                        ASnippet.InsertSnippet("COUNTBYTEMPLATECASCADING", snippetCount);
                    }
                }
            }

            return true;
        }
Ejemplo n.º 27
0
        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);
            }
        }
Ejemplo n.º 28
0
        /// <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;
        }
Ejemplo n.º 29
0
        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.Contains(":"))
                {
                    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);
        }
Ejemplo n.º 30
0
        /// 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.Shared." + 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;
            }
        }