예제 #1
0
    private ProcessTemplate WriteLoaderClass(ProcessTemplate ATemplate, String module)
    {
        ProcessTemplate loaderClassSnippet = ATemplate.GetSnippet("LOADERCLASS");

        loaderClassSnippet.SetCodelet("MODULE", module);
        return loaderClassSnippet;
    }
    /// <summary>
    /// generate the objects that can be serialized to the client
    /// </summary>
    public static ProcessTemplate AddClientRemotingClass(
        string ATemplateDir,
        string AClientObjectClass,
        string AInterfaceName,
        List <TypeDeclaration>ATypeImplemented,
        string AFullNamespace = "",
        SortedList <string, TNamespace>AChildrenNamespaces = null)
    {
        if (ClientRemotingClassTemplate == null)
        {
            ClientRemotingClassTemplate = new ProcessTemplate(ATemplateDir + Path.DirectorySeparatorChar +
                "ClientServerGlue" + Path.DirectorySeparatorChar +
                "ClientRemotingClass.cs");
        }

        ProcessTemplate snippet = ClientRemotingClassTemplate.GetSnippet("CLASS");

        snippet.SetCodelet("CLASSNAME", AClientObjectClass);
        snippet.SetCodelet("INTERFACE", AInterfaceName);

        // try to implement the properties and methods defined in the interface
        snippet.SetCodelet("METHODSANDPROPERTIES", string.Empty);

        // problem mit Partner.Extracts.UIConnectors; MCommon.UIConnectors tut

        if (AChildrenNamespaces != null)
        {
            // accessors for subnamespaces
            InsertSubnamespaces(snippet, AFullNamespace, AChildrenNamespaces);
        }
        else
        {
            foreach (TypeDeclaration t in ATypeImplemented)
            {
                if (t.UserData.ToString().EndsWith("UIConnectors"))
                {
                    if (AInterfaceName.EndsWith("Namespace"))
                    {
                        InsertConstructors(snippet, t);
                    }
                    else
                    {
                        // never gets here???
                        InsertMethodsAndProperties(snippet, t);
                    }
                }

                if (t.UserData.ToString().EndsWith("WebConnectors"))
                {
                    InsertMethodsAndProperties(snippet, t);
                }
            }
        }

        return snippet;
    }
예제 #3
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);
        }
예제 #4
0
        /// <summary>
        /// write an ordered list of tables, ordered by foreign key dependancies
        /// </summary>
        /// <param name="AStore"></param>
        /// <param name="AFilename"></param>
        public static void WriteTableList(TDataDefinitionStore AStore, string AFilename)
        {
            string templateDir = TAppSettingsManager.GetValue("TemplateDir", true);
            ProcessTemplate Template = new ProcessTemplate(templateDir + Path.DirectorySeparatorChar +
                "ORM" + Path.DirectorySeparatorChar +
                "TableList.cs");

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

            List <TTable>tables = AStore.GetTables();

            tables = TTableSort.TopologicalSort(AStore, tables);

            string namesCodelet = string.Empty;

            foreach (TTable t in tables)
            {
                namesCodelet += "list.Add(\"" + t.strName + "\");" + Environment.NewLine;
            }

            Template.AddToCodelet("DBTableNames", namesCodelet);

            List <TSequence>Sequences = AStore.GetSequences();

            namesCodelet = string.Empty;

            foreach (TSequence s in Sequences)
            {
                namesCodelet += "list.Add(\"" + s.strName + "\");" + Environment.NewLine;
            }

            Template.AddToCodelet("DBSequenceNames", namesCodelet);

            Template.FinishWriting(AFilename, ".cs", true);
        }
예제 #5
0
        /// <summary>
        /// insert the snippet into the current template, into the given codelet.
        /// add new text in front of the text that has already been added to the codelet
        /// </summary>
        /// <param name="ACodeletName"></param>
        /// <param name="ASnippet"></param>
        public void InsertSnippetPrepend(string ACodeletName, ProcessTemplate ASnippet)
        {
            ASnippet.ReplaceCodelets();

            if (FCodelets.ContainsKey(ACodeletName))
            {
                AddToCodeletPrepend(ACodeletName, ASnippet.FTemplateCode.ToString() + Environment.NewLine);
            }
            else
            {
                AddToCodeletPrepend(ACodeletName, ASnippet.FTemplateCode.ToString());
            }
        }
예제 #6
0
        /// <summary>
        /// insert the snippet into the current template, into the given codelet
        /// </summary>
        /// <param name="ACodeletName"></param>
        /// <param name="ASnippet"></param>
        public void InsertSnippet(string ACodeletName, ProcessTemplate ASnippet)
        {
            ASnippet.ReplaceCodelets();
            ASnippet.ProcessIFDEFs(ref ASnippet.FTemplateCode);
            ASnippet.ProcessIFNDEFs(ref ASnippet.FTemplateCode);

            if (FCodelets.ContainsKey(ACodeletName)
                && !FCodelets[ACodeletName].ToString().EndsWith(Environment.NewLine)
                && (FCodelets[ACodeletName].Length > 0))
            {
                AddToCodelet(ACodeletName, Environment.NewLine);
            }

            AddToCodelet(ACodeletName, ASnippet.FTemplateCode.ToString());
        }
예제 #7
0
        /// <summary>
        /// add snippets from another template file
        /// (eg. for writing datasets, we want to reuse the table template for custom tables)
        /// </summary>
        /// <param name="AFilePath"></param>
        public void AddSnippetsFromOtherFile(string AFilePath)
        {
            ProcessTemplate temp = new ProcessTemplate(AFilePath);

            foreach (string key in temp.FSnippets.Keys)
            {
                // don't overwrite own snippets with same name
                if (!this.FSnippets.ContainsKey(key))
                {
                    this.FSnippets.Add(key, (string)temp.FSnippets[key]);
                }
            }
        }
예제 #8
0
        static private ProcessTemplate CreateModuleAccessPermissionCheck(ProcessTemplate ATemplate,
            string AConnectorClassWithNamespace,
            MethodDeclaration m)
        {
            if (m.Attributes != null)
            {
                foreach (AttributeSection attrSection in m.Attributes)
                {
                    foreach (ICSharpCode.NRefactory.Ast.Attribute attr in attrSection.Attributes)
                    {
                        if (attr.Name == "RequireModulePermission")
                        {
                            ProcessTemplate snippet = ATemplate.GetSnippet("CHECKUSERMODULEPERMISSIONS");
                            snippet.SetCodelet("METHODNAME", m.Name);
                            snippet.SetCodelet("CONNECTORWITHNAMESPACE", AConnectorClassWithNamespace);
                            snippet.SetCodelet("LEDGERNUMBER", "");

                            string ParameterTypes = ";";

                            foreach (ParameterDeclarationExpression p in m.Parameters)
                            {
                                if (p.ParameterName == "ALedgerNumber")
                                {
                                    snippet.SetCodelet("LEDGERNUMBER", ", ALedgerNumber");
                                }

                                string ParameterType = p.TypeReference.Type.Replace("&", "").Replace("System.", String.Empty);

                                if (ParameterType == "List")
                                {
                                    ParameterType = ParameterType.Replace("List", "List[" + p.TypeReference.GenericTypes[0].ToString() + "]");
                                    ParameterType = ParameterType.Replace("System.", String.Empty);
                                }

                                if (ParameterType == "Dictionary")
                                {
                                    ParameterType = ParameterType.Replace("Dictionary", "Dictionary[" +
                                        p.TypeReference.GenericTypes[0].ToString() + "," +
                                        p.TypeReference.GenericTypes[1].ToString() + "]");
                                    ParameterType = ParameterType.Replace("System.", String.Empty);
                                }

                                if (ParameterType.Contains("."))
                                {
                                    ParameterType = ParameterType.Substring(ParameterType.LastIndexOf(".") + 1);
                                }

                                if (p.TypeReference.Type == "System.Nullable")
                                {
                                    ParameterType = ParameterType.Replace("Nullable", "Nullable[" + p.TypeReference.GenericTypes[0].ToString() + "]");
                                }

                                if (p.TypeReference.IsArrayType)
                                {
                                    ParameterType += ".ARRAY";
                                }

//                            if (ParameterType == "SortedList")
//                            {
//Console.WriteLine(p.ParameterName + "'s ParameterType = SortedList");
//                                ParameterType = ParameterType.Replace("List", "List[" +
//                                    p.TypeReference.GenericTypes[0].ToString() + "," +
//                                    p.TypeReference.GenericTypes[1].ToString() + "]");
//                                ParameterType = ParameterType.Replace("System.", String.Empty);
//                            }

                                ParameterType = ParameterType.Replace("Boolean", "bool");
                                ParameterType = ParameterType.Replace("Int32", "int");
                                ParameterType = ParameterType.Replace("Int64", "long");

                                ParameterTypes += ParameterType + ";";
                            }

                            ParameterTypes = ParameterTypes.ToUpper();
                            snippet.SetCodelet("PARAMETERTYPES", ParameterTypes);
                            return snippet;
                        }
                        else if (attr.Name == "CheckServerAdminToken")
                        {
                            ProcessTemplate snippet = ATemplate.GetSnippet("CHECKSERVERADMINPERMISSION");
                            string paramdefinition = "string AServerAdminSecurityToken";

                            if (ATemplate.FCodelets["PARAMETERDEFINITION"].Length != 0)
                            {
                                paramdefinition += ", ";
                            }

                            ATemplate.AddToCodeletPrepend("PARAMETERDEFINITION", paramdefinition);
                            return snippet;
                        }
                    }
                }
            }

            TLogging.Log("Warning !!! Missing module access permissions for " + AConnectorClassWithNamespace + "::" + m.Name);

            return new ProcessTemplate();
        }
예제 #9
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);
            }
        }
예제 #10
0
        private static void PrepareParametersForMethod(
            ProcessTemplate snippet,
            TypeReference AReturnType,
            List <ParameterDeclarationExpression>AParameters,
            string AMethodName,
            ref List <string>AMethodNames)
        {
            string ParameterDefinition = string.Empty;
            string ActualParameters = string.Empty;

            snippet.SetCodelet("LOCALVARIABLES", string.Empty);
            string returnCodeFatClient = string.Empty;
            string returnCodeJSClient = string.Empty;
            int returnCounter = 0;

            foreach (ParameterDeclarationExpression p in AParameters)
            {
                string parametertype = p.TypeReference.ToString();
                bool ArrayParameter = false;

                // check if the parametertype is not a generic type, eg. dictionary or list
                if (!parametertype.Contains("<"))
                {
                    if (parametertype.EndsWith("[]"))
                    {
                        ArrayParameter = true;
//Console.WriteLine("ArrayParameter found: " + parametertype);
                    }

                    parametertype = parametertype == "string" || parametertype == "String" ? "System.String" : parametertype;
                    parametertype = parametertype == "bool" || parametertype == "Boolean" ? "System.Boolean" : parametertype;

                    if (parametertype.Contains("UINT") || parametertype.Contains("unsigned"))
                    {
                        parametertype = parametertype.Contains("UInt32") || parametertype == "unsigned int" ? "System.UInt32" : parametertype;
                        parametertype = parametertype.Contains("UInt16") || parametertype == "unsigned short" ? "System.UInt16" : parametertype;
                        parametertype = parametertype.Contains("UInt64") || parametertype == "unsigned long" ? "System.UInt64" : parametertype;
                    }
                    else
                    {
                        parametertype = parametertype.Contains("Int32") || parametertype == "int" ? "System.Int32" : parametertype;
                        parametertype = parametertype.Contains("Int16") || parametertype == "short" ? "System.Int16" : parametertype;
                        parametertype = parametertype.Contains("Int64") || parametertype == "long" ? "System.Int64" : parametertype;
                    }

                    parametertype = parametertype.Contains("Decimal") || parametertype == "decimal" ? "System.Decimal" : parametertype;

                    if (ArrayParameter
                        && !(parametertype.EndsWith("[]")))
                    {
                        // need to restore Array type!
                        parametertype += "[]";

//Console.WriteLine("ArrayParameter found - new parametertype = " + parametertype);
                    }
                }

                bool EnumParameter = parametertype.EndsWith("Enum");
                bool BinaryParameter =
                    !((parametertype.StartsWith("System.Int64")) || (parametertype.StartsWith("System.Int32"))
                      || (parametertype.StartsWith("System.Int16"))
                      || (parametertype.StartsWith("System.String")) || (parametertype.StartsWith("System.Boolean"))
                      || EnumParameter);

                if (ActualParameters.Length > 0)
                {
                    ActualParameters += ", ";
                }

                // ignore out parameters in the web service method definition
                if ((ParameterModifiers.Out & p.ParamModifier) == 0)
                {
                    if (ParameterDefinition.Length > 0)
                    {
                        ParameterDefinition += ", ";
                    }

                    if ((!BinaryParameter) && (!ArrayParameter) && (!EnumParameter))
                    {
                        ParameterDefinition += parametertype + " " + p.ParameterName;
                    }
                    else
                    {
                        ParameterDefinition += "string " + p.ParameterName;
                    }
                }

                // for string parameters, check if they have been encoded binary due to special characters in the string;
                // this obviously does not apply to out parameters
                if ((parametertype == "System.String") && ((ParameterModifiers.Out & p.ParamModifier) == 0))
                {
                    snippet.AddToCodelet(
                        "LOCALVARIABLES",
                        p.ParameterName + " = (string) THttpBinarySerializer.DeserializeObject(" + p.ParameterName + ",\"System.String\");" +
                        Environment.NewLine);
                }

                // EnumParameters are also binary encoded
                // this obviously does not apply to out parameters
                if (EnumParameter && ((ParameterModifiers.Out & p.ParamModifier) == 0))
                {
                    snippet.AddToCodelet(
                        "LOCALVARIABLES",
                        p.ParameterName + " = THttpBinarySerializer.DeserializeObject(" + p.ParameterName + ",\"System.String\").ToString();" +
                        Environment.NewLine);
                }

                if ((ParameterModifiers.Out & p.ParamModifier) != 0)
                {
                    snippet.AddToCodelet("LOCALVARIABLES", parametertype + " " + p.ParameterName + ";" + Environment.NewLine);
                    ActualParameters += "out " + p.ParameterName;
                }
                else if ((ParameterModifiers.Ref & p.ParamModifier) != 0)
                {
                    if (BinaryParameter)
                    {
                        snippet.AddToCodelet("LOCALVARIABLES", parametertype + " Local" + p.ParameterName + " = " +
                            " (" + parametertype + ")THttpBinarySerializer.DeserializeObject(" + p.ParameterName + ",\"binary\");" +
                            Environment.NewLine);
                        ActualParameters += "ref Local" + p.ParameterName;
                    }
                    else if (EnumParameter)
                    {
                        snippet.AddToCodelet("LOCALVARIABLES", parametertype + " Local" + p.ParameterName + " = " +
                            " (" + parametertype + ") Enum.Parse(typeof(" + parametertype + "), " + p.ParameterName + ");" +
                            Environment.NewLine);
                        ActualParameters += "ref Local" + p.ParameterName;
                    }
                    else
                    {
                        ActualParameters += "ref " + p.ParameterName;
                    }
                }
                else
                {
                    if (BinaryParameter
                        || ArrayParameter)
                    {
                        ActualParameters += "(" + parametertype + ")THttpBinarySerializer.DeserializeObject(" + p.ParameterName + ",\"binary\")";
                    }
                    else if (EnumParameter)
                    {
                        ActualParameters += " (" + parametertype + ") Enum.Parse(typeof(" + parametertype + "), " + p.ParameterName + ")";
                    }
                    else
                    {
                        ActualParameters += p.ParameterName;
                    }
                }

                if (((ParameterModifiers.Ref & p.ParamModifier) > 0) || ((ParameterModifiers.Out & p.ParamModifier) > 0))
                {
                    returnCodeFatClient +=
                        (returnCodeFatClient.Length > 0 ? "+\",\"+" : string.Empty) +
                        "THttpBinarySerializer.SerializeObjectWithType(" +
                        (((ParameterModifiers.Ref & p.ParamModifier) > 0 && BinaryParameter) ? "Local" : string.Empty) +
                        p.ParameterName + ")";

                    if (returnCounter == 1)
                    {
                        returnCodeJSClient = "\"{ \\\"0\\\": \" + " + returnCodeJSClient;
                    }

                    if (returnCounter > 0)
                    {
                        returnCodeJSClient += " + \", \\\"" + returnCounter.ToString() + "\\\": \" + ";
                    }

                    returnCodeJSClient +=
                        "THttpBinarySerializer.SerializeObjectWithType(" +
                        (((ParameterModifiers.Ref & p.ParamModifier) > 0 && BinaryParameter) ? "Local" : string.Empty) +
                        p.ParameterName + ")";

                    returnCounter++;
                }
            }

            if (AReturnType != null)
            {
                string returntype = AutoGenerationTools.TypeToString(AReturnType, "");

                if (!returntype.Contains("<"))
                {
                    returntype = returntype == "string" || returntype == "String" ? "System.String" : returntype;
                    returntype = returntype == "bool" || returntype == "Boolean" ? "System.Boolean" : returntype;

                    if (returntype.Contains("UINT") || returntype.Contains("unsigned"))
                    {
                        returntype = returntype.Contains("UInt32") || returntype == "unsigned int" ? "System.UInt32" : returntype;
                        returntype = returntype.Contains("UInt16") || returntype == "unsigned short" ? "System.UInt16" : returntype;
                        returntype = returntype.Contains("UInt64") || returntype == "unsigned long" ? "System.UInt64" : returntype;
                    }
                    else
                    {
                        returntype = returntype.Contains("Int32") || returntype == "int" ? "System.Int32" : returntype;
                        returntype = returntype.Contains("Int16") || returntype == "short" ? "System.Int16" : returntype;
                        returntype = returntype.Contains("Int64") || returntype == "long" ? "System.Int64" : returntype;
                    }

                    returntype = returntype.Contains("Decimal") || returntype == "decimal" ? "System.Decimal" : returntype;
                }

                if (returnCounter > 0)
                {
                    if (returntype != "void")
                    {
                        returnCodeFatClient +=
                            (returnCodeFatClient.Length > 0 ? "+\",\"+" : string.Empty) + "THttpBinarySerializer.SerializeObjectWithType(Result)";

                        if (returnCounter == 1)
                        {
                            returnCodeJSClient = "\"{ \\\"0\\\": \" + " + returnCodeJSClient;
                        }

                        returnCodeJSClient += "+\", \\\"" + returnCounter.ToString() + "\\\": \"+" +
                                              "THttpBinarySerializer.SerializeObjectWithType(Result)";

                        returnCounter++;
                    }

                    returntype = "string";
                }
                else if (returntype == "System.String")
                {
                    returntype = "string";
                    returnCodeFatClient = "THttpBinarySerializer.SerializeObjectWithType(Result)";
                    returnCodeJSClient = "Result";
                }
                else if (!((returntype == "System.Int64") || (returntype == "System.Int32") || (returntype == "System.Int16")
                           || (returntype == "System.UInt64") || (returntype == "System.UInt32") || (returntype == "System.UInt16")
                           || (returntype == "System.Decimal")
                           || (returntype == "System.Boolean")) && (returntype != "void"))
                {
                    returntype = "string";
                    returnCodeFatClient = returnCodeJSClient = "THttpBinarySerializer.SerializeObject(Result)";
                }

                string localreturn = AutoGenerationTools.TypeToString(AReturnType, "");

                if (localreturn == "void")
                {
                    localreturn = string.Empty;
                }
                else if ((returnCodeFatClient.Length > 0) || (returnCodeJSClient.Length > 0))
                {
                    localreturn += " Result = ";
                }
                else
                {
                    localreturn = "return ";
                }

                if (returnCounter > 1)
                {
                    returnCodeJSClient += "+ \"}\"";
                }

                snippet.SetCodelet("RETURN", string.Empty);

                if ((returnCodeFatClient.Length > 0) || (returnCodeJSClient.Length > 0))
                {
                    snippet.SetCodelet("RETURN",
                        returntype != "void" ? "return isJSClient()?" + returnCodeJSClient + ":" + returnCodeFatClient + ";" : string.Empty);
                }

                snippet.SetCodelet("RETURNTYPE", returntype);
                snippet.SetCodelet("LOCALRETURN", localreturn);
            }

//Console.WriteLine("Final ParameterDefinition = " + ParameterDefinition);
            snippet.SetCodelet("PARAMETERDEFINITION", ParameterDefinition);
            snippet.SetCodelet("ACTUALPARAMETERS", ActualParameters);

            // avoid duplicate names for webservice methods
            string methodname = AMethodName;
            int methodcounter = 1;

            while (AMethodNames.Contains(methodname))
            {
                methodcounter++;
                methodname = AMethodName + methodcounter.ToString();
            }

            AMethodNames.Add(methodname);

            snippet.SetCodelet("UNIQUEMETHODNAME", methodname);
        }
예제 #11
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;
        }
예제 #12
0
        private static void InsertMainProcedures(TDataDefinitionStore AStore,
            TTable ACurrentTable,
            ProcessTemplate ATemplate,
            ProcessTemplate ASnippet)
        {
            ASnippet.SetCodelet("TABLENAME", TTable.NiceTableName(ACurrentTable.strName));
            ASnippet.SetCodeletComment("TABLE_DESCRIPTION", ACurrentTable.strDescription);
            ASnippet.SetCodelet("SQLTABLENAME", ACurrentTable.strName);
            ASnippet.SetCodelet("VIAOTHERTABLE", "");
            ASnippet.SetCodelet("VIALINKTABLE", "");

            string formalParametersPrimaryKey;
            string actualParametersPrimaryKey;
            string actualParametersPrimaryKeyToString;
            int numberPrimaryKeyColumns;

            PrepareCodeletsPrimaryKey(ACurrentTable,
                out formalParametersPrimaryKey,
                out actualParametersPrimaryKey,
                out actualParametersPrimaryKeyToString,
                out numberPrimaryKeyColumns);

            ASnippet.SetCodelet("FORMALPARAMETERSPRIMARYKEY", formalParametersPrimaryKey);
            ASnippet.SetCodelet("ACTUALPARAMETERSPRIMARYKEY", actualParametersPrimaryKey);
            ASnippet.SetCodelet("ACTUALPARAMETERSPRIMARYKEYTOSTRING", actualParametersPrimaryKeyToString);
            ASnippet.SetCodelet("PRIMARYKEYNUMBERCOLUMNS", numberPrimaryKeyColumns.ToString());

            string formalParametersUniqueKey;
            string actualParametersUniqueKey;
            int numberUniqueKeyColumns;

            PrepareCodeletsUniqueKey(ACurrentTable,
                out formalParametersUniqueKey,
                out actualParametersUniqueKey,
                out numberUniqueKeyColumns);

            ASnippet.SetCodelet("FORMALPARAMETERSUNIQUEKEY", formalParametersUniqueKey);
            ASnippet.SetCodelet("ACTUALPARAMETERSUNIQUEKEY", actualParametersUniqueKey);
            ASnippet.SetCodelet("UNIQUEKEYNUMBERCOLUMNS", numberUniqueKeyColumns.ToString());


            ASnippet.SetCodelet("SEQUENCENAMEANDFIELD", "");

            foreach (TTableField tablefield in ACurrentTable.grpTableField)
            {
                // is there a field filled by a sequence?
                // yes: get the next value of that sequence and assign to row
                if (tablefield.strSequence.Length > 0)
                {
                    ASnippet.SetCodelet("SEQUENCENAMEANDFIELD", ", \"" + tablefield.strSequence + "\", \"" + tablefield.strName + "\"");

                    // assume only one sequence per table
                    break;
                }
            }
        }
예제 #13
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;
            }
        }
예제 #14
0
        /// <summary>
        /// this is for foreign keys, eg load all countries with currency EUR
        /// </summary>
        /// <param name="AStore"></param>
        /// <param name="ACurrentTable"></param>
        /// <param name="ATemplate"></param>
        /// <param name="ASnippet"></param>
        private static void InsertViaOtherTable(TDataDefinitionStore AStore,
            TTable ACurrentTable,
            ProcessTemplate ATemplate,
            ProcessTemplate ASnippet)
        {
            foreach (TConstraint myConstraint in ACurrentTable.grpConstraint)
            {
                if (ValidForeignKeyConstraintForLoadVia(myConstraint))
                {
                    TTable OtherTable = AStore.GetTable(myConstraint.strOtherTable);

                    if (!LoadViaHasAlreadyBeenImplemented(myConstraint))
                    {
                        InsertViaOtherTableConstraint(AStore,
                            myConstraint,
                            ACurrentTable,
                            OtherTable,
                            ATemplate,
                            ASnippet);
                    }

                    // AccountHierarchy: there is no constraint that references Ledger directly, but constraint referencing the Account table with a key that contains the ledger reference
                    // but because the key in Ledger is already the primary key, a LoadViaLedger is required.
                    // other way round: p_foundation_proposal_detail has 2 constraints for foundation and foundationproposal
                    foreach (string field in myConstraint.strOtherFields)
                    {
                        // get a constraint that is only based on that field
                        TConstraint OtherLinkConstraint = OtherTable.GetConstraint(StringHelper.StrSplit(field, ","));

                        if ((OtherLinkConstraint != null) && ValidForeignKeyConstraintForLoadVia(OtherLinkConstraint))
                        {
                            TConstraint NewConstraint = new TConstraint();
                            NewConstraint.strName = OtherLinkConstraint.strName + "forLoadVia";
                            NewConstraint.strType = "foreignkey";
                            NewConstraint.strThisTable = myConstraint.strThisTable;
                            NewConstraint.strThisFields =
                                StringHelper.StrSplit(myConstraint.strThisFields[myConstraint.strOtherFields.IndexOf(
                                                                                     field)], ",");
                            NewConstraint.strOtherTable = OtherLinkConstraint.strOtherTable;
                            NewConstraint.strOtherFields = OtherLinkConstraint.strOtherFields;

                            if (!LoadViaHasAlreadyBeenImplemented(NewConstraint))
                            {
                                InsertViaOtherTableConstraint(AStore,
                                    NewConstraint,
                                    ACurrentTable,
                                    AStore.GetTable(OtherLinkConstraint.strOtherTable),
                                    ATemplate,
                                    ASnippet);
                            }
                        }
                    }
                }
            }
        }
예제 #15
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);
        }
예제 #16
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);
    }
예제 #17
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);
        }
예제 #18
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;
    }
예제 #19
0
        /// <summary>
        /// add a string that is translatable
        /// </summary>
        /// <param name="ACtrlSnippet"></param>
        /// <param name="APlaceHolder"></param>
        /// <param name="ACtrl"></param>
        /// <param name="AText"></param>
        public void AddResourceString(ProcessTemplate ACtrlSnippet, string APlaceHolder, TControlDef ACtrl, string AText)
        {
            string strName;

            if (ACtrl == null)
            {
                strName = APlaceHolder;
            }
            else
            {
                strName = ACtrl.controlName + APlaceHolder;
            }

            ACtrlSnippet.SetCodelet(APlaceHolder, strName);
            FTemplate.AddToCodelet("RESOURCESTRINGS", strName + ":'" + AText + "'," + Environment.NewLine);

            // write to app-lang-en.js file
            FLanguageFileTemplate.AddToCodelet("RESOURCESTRINGS", strName + ":'" + AText + "'," + Environment.NewLine);
        }
예제 #20
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));
        }
예제 #21
0
        private static void LayoutCellInForm(TControlDef ACtrl,
            Int32 AChildrenCount,
            ProcessTemplate ACtrlSnippet,
            ProcessTemplate ASnippetCellDefinition)
        {
            if (ACtrl.HasAttribute("labelWidth"))
            {
                ASnippetCellDefinition.SetCodelet("LABELWIDTH", ACtrl.GetAttribute("labelWidth"));
            }

            if (ACtrl.HasAttribute("columnWidth"))
            {
                ASnippetCellDefinition.SetCodelet("COLUMNWIDTH", ACtrl.GetAttribute("columnWidth").Replace(",", "."));
            }
            else
            {
                ASnippetCellDefinition.SetCodelet("COLUMNWIDTH", (1.0 / AChildrenCount).ToString().Replace(",", "."));
            }

            string Anchor = ANCHOR_DEFAULT_COLUMN;

            if (AChildrenCount == 1)
            {
                Anchor = ANCHOR_SINGLE_COLUMN;
            }

            if (ACtrl.HasAttribute("columnWidth"))
            {
                Anchor = "94%";
            }

            if (ACtrl.GetAttribute("hideLabel") == "true")
            {
                ACtrlSnippet.SetCodelet("HIDELABEL", "true");
                Anchor = ANCHOR_HIDDEN_LABEL;
            }

            ACtrlSnippet.SetCodelet("ANCHOR", Anchor);
        }
예제 #22
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);
            }
        }
예제 #23
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, ",");
                    }
                }
            }
        }
예제 #24
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);
        }
예제 #25
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, ",");
            }
        }
예제 #26
0
        /// <summary>
        /// get the specified snippet, in a new Template
        /// </summary>
        /// <param name="ASnippetName"></param>
        /// <returns></returns>
        public ProcessTemplate GetSnippet(string ASnippetName)
        {
            ProcessTemplate snippetTemplate = new ProcessTemplate();

            if (FSnippets.ContainsKey(ASnippetName))
            {
                snippetTemplate.FTemplateCode = new StringBuilder(FSnippets[ASnippetName]);
            }
            else
            {
                snippetTemplate.FTemplateCode = null;
            }

            if (snippetTemplate.FTemplateCode == null)
            {
                throw new Exception("Cannot find snippet with name " + ASnippetName);
            }

            snippetTemplate.FSnippets = this.FSnippets;
            return snippetTemplate;
        }
예제 #27
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)
        {
            FCodeStorage = ACodeStorage;
            TControlGenerator.FCodeStorage = ACodeStorage;
            FTemplate = new ProcessTemplate(ATemplateFile);
            FFormName = Path.GetFileNameWithoutExtension(AXAMLFilename).Replace("-", "_");

            // drop language specific part of the name
            if (FFormName.Contains("."))
            {
                FFormName = FFormName.Substring(0, FFormName.IndexOf("."));
            }

            FFormName = FFormName.ToUpper()[0] + FFormName.Substring(1);
            FFormName += "Form";

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

            FTemplate.SetCodelet("UPLOADFORM", "");
            FTemplate.SetCodelet("CHECKFORVALIDUPLOAD", "");

            FLanguageFileTemplate = FTemplate.GetSnippet("LANGUAGEFILE");

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

            InsertCodeIntoTemplate(AXAMLFilename);

            string languagefilepath = Path.GetDirectoryName(AXAMLFilename) + Path.DirectorySeparatorChar +
                                      Path.GetFileNameWithoutExtension(AXAMLFilename) + "-lang-template.js";
            File.WriteAllText(languagefilepath, FLanguageFileTemplate.FinishWriting(true));
        }
예제 #28
0
        /// <summary>
        /// insert the snippet into the current template, into the given codelet.
        /// use separator to separate from previous items inserted into that codelet
        /// </summary>
        /// <param name="ACodeletName"></param>
        /// <param name="ASnippet"></param>
        /// <param name="ASeparator"></param>
        public void InsertSnippet(string ACodeletName, ProcessTemplate ASnippet, string ASeparator)
        {
            ASnippet.ReplaceCodelets();
            ASnippet.ProcessIFDEFs(ref ASnippet.FTemplateCode);
            ASnippet.ProcessIFNDEFs(ref ASnippet.FTemplateCode);

            if (FCodelets.ContainsKey(ACodeletName)
                && (FCodelets[ACodeletName].Length > 0))
            {
                AddSeparatorToCodelet(ACodeletName, ASeparator);
            }

            AddToCodelet(ACodeletName, ASnippet.FTemplateCode.ToString());
        }
예제 #29
0
        /// <summary>
        /// constructor, open template from file
        /// </summary>
        /// <param name="AFullPath"></param>
        public ProcessTemplate(string AFullPath = null)
        {
            if ((AFullPath == null) || (AFullPath.Length == 0))
            {
                return;
            }

            if (!File.Exists(AFullPath))
            {
                throw new Exception("Cannot find template file " + AFullPath + "; please adjust the TemplateDir parameter");
            }

            StreamReader r;

            r             = File.OpenText(AFullPath);
            FTemplateCode = new StringBuilder();

            while (!r.EndOfStream)
            {
                string line = r.ReadLine().TrimEnd(new char[] { '\r', '\t', ' ', '\n' }).Replace("\t", "    ");
                FTemplateCode.Append(line).Append(Environment.NewLine);
            }

            r.Close();

            // add other files, {#INCLUDE <filename>}
            while (FTemplateCode.Contains("{#INCLUDE "))
            {
                Int32  pos             = FTemplateCode.IndexOf("{#INCLUDE ");
                Int32  newLinePos      = FTemplateCode.IndexOf(Environment.NewLine, pos);
                string line            = FTemplateCode.Substring(pos, newLinePos - pos);
                Int32  bracketClosePos = FTemplateCode.IndexOf("}", pos);
                string filename        = FTemplateCode.Substring(pos + "{#INCLUDE ".Length, bracketClosePos - pos - "{#INCLUDE ".Length).Trim();

                // do this recursively, to get snippets and code in the right place, even from the include files
                ProcessTemplate includedTemplate = new ProcessTemplate(Path.GetDirectoryName(AFullPath) + Path.DirectorySeparatorChar + filename);

                FTemplateCode = FTemplateCode.Replace(line, includedTemplate.FTemplateCode.ToString());

                foreach (string key in includedTemplate.FSnippets.Keys)
                {
                    FSnippets.Add(key, includedTemplate.FSnippets[key]);
                }
            }

            // split off snippets (identified by "{##")
            if (FTemplateCode.Contains("{##"))
            {
                StringCollection snippets = StringHelper.StrSplit(FTemplateCode.ToString(), "{##");

                // first part is the actual template code
                FTemplateCode = new StringBuilder(snippets[0]);

                for (int counter = 1; counter < snippets.Count; counter++)
                {
                    string snippetName = snippets[counter].Substring(0, snippets[counter].IndexOf("}"));

                    // exclude first newline
                    string snippetText = snippets[counter].Substring(snippets[counter].IndexOf(Environment.NewLine) + Environment.NewLine.Length);

                    // remove all whitespaces from the end, but keep one line ending for ENDIF etc
                    snippetText = snippetText.TrimEnd(new char[] { '\n', '\r', ' ', '\t' }) + Environment.NewLine;
                    FSnippets.Add(snippetName, snippetText);
                }
            }

            // just make sure that there is a newline at the end, for ENDIF etc
            FTemplateCode.Append(Environment.NewLine);
        }
예제 #30
0
        /// <summary>
        /// constructor, open template from file
        /// </summary>
        /// <param name="AFullPath"></param>
        public ProcessTemplate(string AFullPath = null)
        {
            if ((AFullPath == null) || (AFullPath.Length == 0))
            {
                return;
            }

            if (!File.Exists(AFullPath))
            {
                throw new Exception("Cannot find template file " + AFullPath + "; please adjust the TemplateDir parameter");
            }

            StreamReader r;
            r = File.OpenText(AFullPath);
            FTemplateCode = new StringBuilder();

            while (!r.EndOfStream)
            {
                string line = r.ReadLine().TrimEnd(new char[] { '\r', '\t', ' ', '\n' }).Replace("\t", "    ");
                FTemplateCode.Append(line).Append(Environment.NewLine);
            }

            r.Close();

            // add other files, {#INCLUDE <filename>}
            while (FTemplateCode.Contains("{#INCLUDE "))
            {
                Int32 pos = FTemplateCode.IndexOf("{#INCLUDE ");
                Int32 newLinePos = FTemplateCode.IndexOf(Environment.NewLine, pos);
                string line = FTemplateCode.Substring(pos, newLinePos - pos);
                Int32 bracketClosePos = FTemplateCode.IndexOf("}", pos);
                string filename = FTemplateCode.Substring(pos + "{#INCLUDE ".Length, bracketClosePos - pos - "{#INCLUDE ".Length).Trim();

                // do this recursively, to get snippets and code in the right place, even from the include files
                ProcessTemplate includedTemplate = new ProcessTemplate(Path.GetDirectoryName(AFullPath) + Path.DirectorySeparatorChar + filename);

                FTemplateCode = FTemplateCode.Replace(line, includedTemplate.FTemplateCode.ToString());

                foreach (string key in includedTemplate.FSnippets.Keys)
                {
                    FSnippets.Add(key, includedTemplate.FSnippets[key]);
                }
            }

            // split off snippets (identified by "{##")
            if (FTemplateCode.Contains("{##"))
            {
                StringCollection snippets = StringHelper.StrSplit(FTemplateCode.ToString(), "{##");

                // first part is the actual template code
                FTemplateCode = new StringBuilder(snippets[0]);

                for (int counter = 1; counter < snippets.Count; counter++)
                {
                    string snippetName = snippets[counter].Substring(0, snippets[counter].IndexOf("}"));

                    // exclude first newline
                    string snippetText = snippets[counter].Substring(snippets[counter].IndexOf(Environment.NewLine) + Environment.NewLine.Length);

                    // remove all whitespaces from the end, but keep one line ending for ENDIF etc
                    snippetText = snippetText.TrimEnd(new char[] { '\n', '\r', ' ', '\t' }) + Environment.NewLine;
                    FSnippets.Add(snippetName, snippetText);
                }
            }

            // just make sure that there is a newline at the end, for ENDIF etc
            FTemplateCode.Append(Environment.NewLine);
        }
예제 #31
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);
    }