Exemple #1
0
        /// <summary>write the code for the designer file where the properties of the control are written</summary>
        public override ProcessTemplate SetControlProperties(TFormWriter writer, TControlDef ACtrl)
        {
            ProcessTemplate ctrlSnippet = base.SetControlProperties(writer, ACtrl);

            ((TExtJsFormsWriter)writer).AddResourceString(ctrlSnippet,
                                                          "URL",
                                                          ACtrl,
                                                          TYml2Xml.GetAttribute(ACtrl.xmlNode, "url"));
            ((TExtJsFormsWriter)writer).AddResourceString(ctrlSnippet,
                                                          "BROWSERMISSINGIFRAMESUPPORT",
                                                          null,
                                                          "Your browser is not able to display embedded documents. Please click on the following link to read the text: ");
            ((TExtJsFormsWriter)writer).AddResourceString(ctrlSnippet,
                                                          "IFRAMEINBIGGERWINDOW",
                                                          null,
                                                          "Open this document in a bigger window");

            ctrlSnippet.SetCodelet("HEIGHT", "250");

            if (ACtrl.HasAttribute("Height"))
            {
                ctrlSnippet.SetCodelet("HEIGHT", ACtrl.GetAttribute("Height"));
            }

            return(ctrlSnippet);
        }
Exemple #2
0
        /// <summary>
        /// generate the connector code for the client
        /// </summary>
        static public void GenerateConnectorCode(String AOutputPath, String ATemplateDir)
        {
            String OutputFile = AOutputPath + Path.DirectorySeparatorChar + "ClientGlue.Connector-generated.cs";

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

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

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

            if (FCompileForStandalone)
            {
                Template.AddToCodelet("USINGNAMESPACES", "using Ict.Common.DB;" + Environment.NewLine);
                Template.AddToCodelet("USINGNAMESPACES", "using Ict.Common.Remoting.Server;" + Environment.NewLine);
                Template.AddToCodelet("USINGNAMESPACES", "using Ict.Petra.Server.App.Core;" + Environment.NewLine);
                Template.AddToCodelet("USINGNAMESPACES", "using Ict.Petra.Server.App.Delegates;" + Environment.NewLine);
                Template.AddToCodelet("USINGNAMESPACES", "using Ict.Petra.Shared;" + Environment.NewLine);
                Template.AddToCodelet("USINGNAMESPACES", "using System.Security.Principal;" + Environment.NewLine);
                Template.InsertSnippet("CONNECTOR", Template.GetSnippet("CONNECTORSTANDALONE"));
                Template.InsertSnippet("STANDALONECLIENTMANAGER", Template.GetSnippet("STANDALONECLIENTMANAGER"));
            }
            else
            {
                Template.InsertSnippet("CONNECTOR", Template.GetSnippet("CONNECTORCLIENTSERVER"));
                Template.SetCodelet("STANDALONECLIENTMANAGER", string.Empty);
                Template.SetCodelet("HTTPREMOTING", "true");
            }

            Template.FinishWriting(OutputFile, ".cs", true);
        }
        private static void InsertConstructors(ProcessTemplate template, TypeDeclaration t)
        {
            // foreach constructor create a method
            List <ConstructorDeclaration> constructors = CSParser.GetConstructors(t);

            if (constructors.Count == 0)
            {
                // will cause compile error if the constructor is missing, because it is not implementing the interface completely
                throw new Exception("missing a connector constructor in " + t.Name + "; details: " + t.ToString());
            }

            // find constructor and copy the parameters
            foreach (ConstructorDeclaration m in constructors)
            {
                ProcessTemplate methodSnippet = ClientRemotingClassTemplate.GetSnippet("METHOD");

                methodSnippet.SetCodelet("METHODNAME", t.Name.Substring(1, t.Name.Length - 1 - "UIConnector".Length));
                methodSnippet.SetCodelet("RETURNTYPE", CSParser.GetImplementedInterface(t));

                string ParameterDefinition = string.Empty;
                string ActualParameters    = string.Empty;

                AutoGenerationTools.FormatParameters(m.Parameters, out ActualParameters, out ParameterDefinition);

                methodSnippet.SetCodelet("PARAMETERDEFINITION", ParameterDefinition);
                methodSnippet.SetCodelet("ACTUALPARAMETERS", ActualParameters);
                methodSnippet.SetCodelet("RETURN", "return ");

                template.InsertSnippet("METHODSANDPROPERTIES", methodSnippet);
            }
        }
Exemple #4
0
        /// <summary>write the code for the designer file where the properties of the control are written</summary>
        public override ProcessTemplate SetControlProperties(TFormWriter writer, TControlDef ctrl)
        {
            ProcessTemplate ctrlSnippet = base.SetControlProperties(writer, ctrl);

            if (ctrlSnippet.FTemplateCode.Contains("{#REDIRECTONSUCCESS}"))
            {
                ProcessTemplate redirectSnippet = writer.FTemplate.GetSnippet("REDIRECTONSUCCESS");

                ctrlSnippet.SetCodelet("REDIRECTONSUCCESS", redirectSnippet.FTemplateCode.ToString());
            }

            if (ctrl.HasAttribute("AjaxRequestUrl"))
            {
                ((TExtJsFormsWriter)writer).AddResourceString(ctrlSnippet, "VALIDATIONERRORTITLE", ctrl, ctrl.GetAttribute("ValidationErrorTitle"));
                ((TExtJsFormsWriter)writer).AddResourceString(ctrlSnippet, "VALIDATIONERRORMESSAGE", ctrl, ctrl.GetAttribute("ValidationErrorMessage"));
                ((TExtJsFormsWriter)writer).AddResourceString(ctrlSnippet, "SENDINGDATATITLE", ctrl, ctrl.GetAttribute("SendingMessageTitle"));
                ((TExtJsFormsWriter)writer).AddResourceString(ctrlSnippet, "SENDINGDATAMESSAGE", ctrl, ctrl.GetAttribute("SendingMessage"));

                if (ctrl.HasAttribute("SuccessMessage"))
                {
                    ((TExtJsFormsWriter)writer).AddResourceString(ctrlSnippet, "REQUESTSUCCESSTITLE", ctrl, ctrl.GetAttribute("SuccessMessageTitle"));
                    ((TExtJsFormsWriter)writer).AddResourceString(ctrlSnippet, "REQUESTSUCCESSMESSAGE", ctrl, ctrl.GetAttribute("SuccessMessage"));
                }

                ((TExtJsFormsWriter)writer).AddResourceString(ctrlSnippet, "REQUESTFAILURETITLE", ctrl, ctrl.GetAttribute("FailureMessageTitle"));
                ((TExtJsFormsWriter)writer).AddResourceString(ctrlSnippet, "REQUESTFAILUREMESSAGE", ctrl, ctrl.GetAttribute("FailureMessage"));
            }

            ctrlSnippet.SetCodelet("REQUESTURL", ctrl.GetAttribute("AjaxRequestUrl"));
            ((TExtJsFormsWriter)writer).AddResourceString(ctrlSnippet, "REDIRECTURLONSUCCESS", ctrl, ctrl.GetAttribute("RedirectURLOnSuccess"));

            if (ctrl.GetAttribute("DownloadOnSuccess").StartsWith("jsonData"))
            {
                ctrlSnippet.SetCodelet("REDIRECTDOWNLOAD", ctrl.GetAttribute("DownloadOnSuccess"));
            }

            ((TExtJsFormsWriter)writer).AddResourceString(ctrlSnippet, "REDIRECTURLONCANCEL", ctrl, ctrl.GetAttribute("RedirectURLOnCancel"));
            ((TExtJsFormsWriter)writer).AddResourceString(ctrlSnippet, "CANCELQUESTIONTITLE", ctrl, ctrl.GetAttribute("CancelQuestionTitle"));
            ((TExtJsFormsWriter)writer).AddResourceString(ctrlSnippet, "CANCELQUESTIONMESSAGE", ctrl, ctrl.GetAttribute("CancelQuestionMessage"));

            XmlNode AjaxParametersNode = TYml2Xml.GetChild(ctrl.xmlNode, "AjaxRequestParameters");

            if (AjaxParametersNode != null)
            {
                string ParameterString = String.Empty;

                foreach (XmlAttribute attr in AjaxParametersNode.Attributes)
                {
                    if (!attr.Name.Equals("depth"))
                    {
                        ParameterString += attr.Name + ": '" + attr.Value + "', ";
                    }
                }

                ctrlSnippet.SetCodelet("REQUESTPARAMETERS", ParameterString);
                writer.FTemplate.SetCodelet("REQUESTPARAMETERS", "true");
            }

            return(ctrlSnippet);
        }
Exemple #5
0
        private static ProcessTemplate GenerateUIConnector(ProcessTemplate ATemplate, TypeDeclaration connectorClass, string interfacename)
        {
            ProcessTemplate snippet = ATemplate.GetSnippet("UICONNECTORCLASS");

            snippet.SetCodelet("UICONNECTORINTERFACE", interfacename);
            snippet.SetCodelet("UICONNECTORCLASSNAME", connectorClass.Name);
            snippet.SetCodelet("CONSTRUCTORS", string.Empty);

            int constructorCounter = 0;

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

                constructorCounter++;

                ProcessTemplate snippetConstructor = ATemplate.GetSnippet("UICONNECTORCONSTRUCTOR");

                string ParameterDefinition = string.Empty;
                string ActualParameters    = string.Empty;

                AutoGenerationTools.FormatParameters(m.Parameters, out ActualParameters, out ParameterDefinition);

                snippetConstructor.SetCodelet("PARAMETERDEFINITION", ParameterDefinition);
                snippetConstructor.SetCodelet("UICONNECTORCLASSNAME", connectorClass.Name);
                snippetConstructor.SetCodelet("ACTUALPARAMETERS", ActualParameters);
                snippetConstructor.SetCodelet("ADDACTUALPARAMETERS", string.Empty);

                foreach (ParameterDeclarationExpression p in m.Parameters)
                {
                    if (((ParameterModifiers.Ref & p.ParamModifier) > 0) || ((ParameterModifiers.Out & p.ParamModifier) > 0))
                    {
                        throw new Exception("we do not support ref or out parameters in UIConnector constructor calls! " + connectorClass.Name);
                    }

                    snippetConstructor.AddToCodelet("ADDACTUALPARAMETERS",
                                                    "ActualParameters.Add(\"" + p.ParameterName + "\", " +
                                                    p.ParameterName + ");" + Environment.NewLine);
                }

                string methodname = m.Name;

                if (constructorCounter > 1)
                {
                    methodname += constructorCounter.ToString();
                }

                snippetConstructor.SetCodelet("METHODNAME", methodname);

                snippet.InsertSnippet("CONSTRUCTORS", snippetConstructor);
            }

            InsertMethodsAndProperties(snippet, connectorClass);

            return(snippet);
        }
Exemple #6
0
        /// <summary>write the code for the designer file where the properties of the control are written</summary>
        public override ProcessTemplate SetControlProperties(TFormWriter writer, TControlDef ctrl)
        {
            ProcessTemplate ctrlSnippet = base.SetControlProperties(writer, ctrl);

            ctrlSnippet.SetCodelet("BOXLABEL", ctrlSnippet.FCodelets["LABEL"].ToString());
            ctrlSnippet.SetCodelet("LABEL", "strEmpty");
            return(ctrlSnippet);
        }
        /// <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);
        }
Exemple #8
0
        private void CreateConnectors(TNamespace tn, String AOutputPath, String ATemplateDir)
        {
            String OutputFile = AOutputPath + Path.DirectorySeparatorChar + "M" + tn.Name +
                                Path.DirectorySeparatorChar + "Instantiator.Connectors-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.Connectors-generated.cs";
            }

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

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

            ProcessTemplate Template = new ProcessTemplate(ATemplateDir + Path.DirectorySeparatorChar +
                                                           "ClientServerGlue" + Path.DirectorySeparatorChar +
                                                           "Connector.cs");

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

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

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

            UsingConnectorNamespaces = new List <string>();

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

            Template.SetCodelet("CONNECTORCLASSES", string.Empty);

            foreach (TNamespace sn in tn.Children.Values)
            {
                WriteConnectorClass(
                    Template,
                    "Ict.Petra.Shared.M" + tn.Name + "." + sn.Name,
                    sn.Name,
                    sn.Name,
                    sn.Children,
                    connectors);
            }

            foreach (string n in UsingConnectorNamespaces)
            {
                Template.AddToCodelet("USINGNAMESPACES", "using " + n + ";" + Environment.NewLine);
            }

            Template.FinishWriting(OutputFile, ".cs", true);
        }
Exemple #9
0
        /// <summary>write the code for the designer file where the properties of the control are written</summary>
        public override ProcessTemplate SetControlProperties(TFormWriter writer, TControlDef ctrl)
        {
            ProcessTemplate ctrlSnippet = base.SetControlProperties(writer, ctrl);

            if (TXMLParser.HasAttribute(ctrl.xmlNode, "RadioChecked"))
            {
                ctrlSnippet.SetCodelet("CHECKED", "true");
            }

            ctrlSnippet.SetCodelet("BOXLABEL", ctrlSnippet.FCodelets["LABEL"].ToString());
            ctrlSnippet.SetCodelet("LABEL", "strEmpty");
            ctrlSnippet.SetCodelet("INPUTVALUE", ctrl.controlName.Substring(3));

            return(ctrlSnippet);
        }
Exemple #10
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));
        }
Exemple #11
0
        /// <summary>
        /// use CSParser to parse the Server files
        /// </summary>
        /// <param name="tn"></param>
        /// <param name="AOutputPath"></param>
        private void WriteInterfaces(TNamespace tn, String AOutputPath)
        {
            String OutputFile = AOutputPath + Path.DirectorySeparatorChar + tn.Name + ".Interfaces-generated.cs";

            // open file
            Console.WriteLine("working on file " + OutputFile);

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

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

            Template.AddToCodelet("USINGNAMESPACES", AddNamespacesFromYmlFile(AOutputPath, tn.Name));

            // get all csharp files that might hold implementations of remotable classes
            List <CSParser> CSFiles = null;

            if (AOutputPath.Contains("ICT/Petra/Plugins"))
            {
                // search for webconnectors in the directory of the plugin
                CSFiles = CSParser.GetCSFilesForDirectory(Path.GetFullPath(AOutputPath + "/../Server"),
                                                          SearchOption.AllDirectories);
            }
            else if (Directory.Exists(CSParser.ICTPath + "/Petra/Server/lib/M" + tn.Name))
            {
                // any class in the module can contain a webconnector
                CSFiles = CSParser.GetCSFilesForDirectory(CSParser.ICTPath + "/Petra/Server/lib/M" + tn.Name,
                                                          SearchOption.AllDirectories);
            }
            else
            {
                CSFiles = new List <CSParser>();
            }

            SortedList InterfaceNames = GetInterfaceNamesFromImplementation(CSFiles);

            Template.SetCodelet("INTERFACES", string.Empty);
            WriteNamespaces(Template, tn, InterfaceNames, CSFiles);

            if (Template.FCodelets["INTERFACES"].Length == 0)
            {
                Template.InsertSnippet("INTERFACES", Template.GetSnippet("DUMMYINTERFACE"));
            }

            Template.FinishWriting(OutputFile, ".cs", true);
        }
        /// <summary>
        /// create the code for validation of a typed table
        /// </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 WriteValidation(TDataDefinitionStore AStore, string strGroup, string AFilePath, string ANamespaceName, string AFileName)
        {
            Console.WriteLine("processing validation of Typed Tables " + strGroup.Substring(0, 1).ToUpper() + strGroup.Substring(1));

            string          templateDir = TAppSettingsManager.GetValue("TemplateDir", true);
            ProcessTemplate Template    = new ProcessTemplate(templateDir + Path.DirectorySeparatorChar +
                                                              "ORM" + Path.DirectorySeparatorChar +
                                                              "DataTableValidation.cs");

            Template.AddToCodelet("NAMESPACE", ANamespaceName);
            Template.AddToCodelet("DATATABLENAMESPACE", ANamespaceName.Replace("Validation", "Data"));

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

            foreach (TTable currentTable in AStore.GetTables())
            {
                if (currentTable.strGroup == strGroup)
                {
                    InsertTableValidation(Template, currentTable, null, "TABLELOOP");
                }
            }

            if (!Directory.Exists(AFilePath))
            {
                Directory.CreateDirectory(AFilePath);
            }

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

            return(true);
        }
Exemple #13
0
        /// <summary>
        /// create the code for a typed table
        /// </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 WriteTypedTable(TDataDefinitionStore AStore, string strGroup, string AFilePath, string ANamespaceName, string AFileName)
        {
            Console.WriteLine("processing namespace Typed Tables " + strGroup.Substring(0, 1).ToUpper() + strGroup.Substring(1));

            string          templateDir = TAppSettingsManager.GetValue("TemplateDir", true);
            ProcessTemplate Template    = new ProcessTemplate(templateDir + Path.DirectorySeparatorChar +
                                                              "ORM" + Path.DirectorySeparatorChar +
                                                              "DataTable.cs");

            Template.AddToCodelet("NAMESPACE", ANamespaceName);

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

            foreach (TTable currentTable in AStore.GetTables())
            {
                if (currentTable.strGroup == strGroup)
                {
                    if (!currentTable.HasPrimaryKey())
                    {
                        TLogging.Log("Warning: there is no primary key for table " + currentTable.strName);
                    }

                    InsertTableDefinition(Template, currentTable, null, "TABLELOOP");
                    InsertRowDefinition(Template, currentTable, null, "TABLELOOP");
                }
            }

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

            return(true);
        }
        private ProcessTemplate WriteLoaderClass(ProcessTemplate ATemplate, String module)
        {
            ProcessTemplate loaderClassSnippet = ATemplate.GetSnippet("LOADERCLASS");

            loaderClassSnippet.SetCodelet("MODULE", module);
            return(loaderClassSnippet);
        }
        /// <summary>
        /// generate code for cascading deletions etc
        /// </summary>
        /// <param name="AStore"></param>
        /// <param name="AFilePath"></param>
        /// <param name="ANamespaceName"></param>
        /// <param name="AFileName"></param>
        /// <returns></returns>
        public static Boolean WriteTypedDataCascading(TDataDefinitionStore AStore, string AFilePath, string ANamespaceName, string AFileName)
        {
            Console.WriteLine("writing namespace " + ANamespaceName);

            string          templateDir = TAppSettingsManager.GetValue("TemplateDir", true);
            ProcessTemplate Template    = new ProcessTemplate(templateDir + Path.DirectorySeparatorChar +
                                                              "ORM" + Path.DirectorySeparatorChar +
                                                              "DataCascading.cs");

            Template.AddToCodelet("NAMESPACE", ANamespaceName);

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

            foreach (TTable currentTable in AStore.GetTables())
            {
                ProcessTemplate snippet = Template.GetSnippet("TABLECASCADING");

                if (InsertMainProcedures(AStore, currentTable, Template, snippet))
                {
                    Template.AddToCodelet("USINGNAMESPACES",
                                          CodeGenerationAccess.GetNamespace(currentTable.strGroup), false);
                    Template.AddToCodelet("USINGNAMESPACES",
                                          CodeGenerationAccess.GetNamespace(currentTable.strGroup).Replace(
                                              ".Data;", ".Data.Access;").
                                          Replace("Ict.Petra.Shared.", "Ict.Petra.Server."), false);

                    Template.InsertSnippet("TABLECASCADINGLOOP", snippet);
                }
            }

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

            return(true);
        }
Exemple #16
0
        /// <summary>write the code for the designer file where the properties of the control are written</summary>
        public override ProcessTemplate SetControlProperties(TFormWriter writer, TControlDef ctrl)
        {
            ProcessTemplate ctrlSnippet = base.SetControlProperties(writer, ctrl);

            ProcessTemplate uploadCheckAssistantSnippet = writer.FTemplate.GetSnippet("ASSISTANTPAGEWITHUPLOADVALID");

            ((TExtJsFormsWriter)writer).AddResourceString(uploadCheckAssistantSnippet, "MISSINGUPLOADTITLE", ctrl,
                                                          ctrl.GetAttribute("MissingUploadTitle"));
            ((TExtJsFormsWriter)writer).AddResourceString(uploadCheckAssistantSnippet, "MISSINGUPLOADMESSAGE", ctrl,
                                                          ctrl.GetAttribute("MissingUploadMessage"));

            writer.FTemplate.InsertSnippet("ISVALID", uploadCheckAssistantSnippet);
            writer.FTemplate.InsertSnippet("ONSHOW", writer.FTemplate.GetSnippet("ASSISTANTPAGEWITHUPLOADSHOW"));
            writer.FTemplate.InsertSnippet("ONHIDE", writer.FTemplate.GetSnippet("ASSISTANTPAGEWITHUPLOADHIDE"));

            ProcessTemplate uploadSnippet = writer.FTemplate.GetSnippet("UPLOADFORMDEFINITION");

            if (ctrl.HasAttribute("UploadButtonLabel"))
            {
                ((TExtJsFormsWriter)writer).AddResourceString(uploadCheckAssistantSnippet, "UPLOADBUTTONLABEL", ctrl,
                                                              ctrl.GetAttribute("UploadButtonLabel"));
                uploadSnippet.SetCodelet("UPLOADBUTTONLABEL", ctrl.controlName + "UPLOADBUTTONLABEL");
            }

            writer.FTemplate.InsertSnippet("UPLOADFORM", uploadSnippet);

            ProcessTemplate uploadCheckSnippet = writer.FTemplate.GetSnippet("VALIDUPLOADCHECK");

            writer.FTemplate.InsertSnippet("CHECKFORVALIDUPLOAD", uploadCheckSnippet);

            return(ctrlSnippet);
        }
        /// <summary>
        /// generate code for reading and writing typed data tables from and to the database
        /// </summary>
        /// <param name="AStore"></param>
        /// <param name="strGroup"></param>
        /// <param name="AFilePath"></param>
        /// <param name="ANamespaceName"></param>
        /// <param name="AFilename"></param>
        /// <returns></returns>
        public static Boolean WriteTypedDataAccess(TDataDefinitionStore AStore,
                                                   string strGroup,
                                                   string AFilePath,
                                                   string ANamespaceName,
                                                   string AFilename)
        {
            Console.WriteLine("processing namespace PetraTypedDataAccess." + strGroup.Substring(0, 1).ToUpper() + strGroup.Substring(1));

            string          templateDir = TAppSettingsManager.GetValue("TemplateDir", true);
            ProcessTemplate Template    = new ProcessTemplate(templateDir + Path.DirectorySeparatorChar +
                                                              "ORM" + Path.DirectorySeparatorChar +
                                                              "DataAccess.cs");

            Template.SetCodelet("NAMESPACE", ANamespaceName);

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

            Template.AddToCodelet("USINGNAMESPACES", GetNamespace(strGroup), false);

            bool hasTables = false;

            foreach (TTable currentTable in AStore.GetTables())
            {
                if (currentTable.strGroup == strGroup)
                {
                    DirectReferences = new ArrayList();

                    ProcessTemplate snippet = Template.GetSnippet("TABLEACCESS");

                    InsertMainProcedures(AStore, currentTable, Template, snippet);
                    InsertViaOtherTable(AStore, currentTable, Template, snippet);
                    InsertViaLinkTable(AStore, currentTable, Template, snippet);

                    Template.InsertSnippet("TABLEACCESSLOOP", snippet);

                    hasTables = true;
                }
            }

            if (hasTables)
            {
                Template.FinishWriting(AFilePath + AFilename + "-generated.cs", ".cs", true);
            }

            return(true);
        }
        /// <summary>write the code for the designer file where the properties of the control are written</summary>
        public override ProcessTemplate SetControlProperties(TFormWriter writer, TControlDef ctrl)
        {
            ProcessTemplate snippetRowDefinition = writer.FTemplate.GetSnippet(FControlDefinitionSnippetName);

            ((TExtJsFormsWriter)writer).AddResourceString(snippetRowDefinition, "LABEL", ctrl, ctrl.Label);

            StringCollection Controls = FindContainedControls(writer, ctrl.xmlNode);

            snippetRowDefinition.AddToCodelet("ITEMS", "");

            if (Controls.Count > 0)
            {
                // used for radiogroupbox
                foreach (string ChildControlName in Controls)
                {
                    TControlDef       childCtrl   = FCodeStorage.FindOrCreateControl(ChildControlName, ctrl.controlName);
                    IControlGenerator ctrlGen     = writer.FindControlGenerator(childCtrl);
                    ProcessTemplate   ctrlSnippet = ctrlGen.SetControlProperties(writer, childCtrl);

                    ctrlSnippet.SetCodelet("COLUMNWIDTH", "");

                    ctrlSnippet.SetCodelet("ITEMNAME", ctrl.controlName);
                    ctrlSnippet.SetCodelet("ITEMID", childCtrl.controlName);

                    if (ctrl.GetAttribute("hideLabel") == "true")
                    {
                        ctrlSnippet.SetCodelet("HIDELABEL", "true");
                    }
                    else if (ChildControlName == Controls[0])
                    {
                        ((TExtJsFormsWriter)writer).AddResourceString(ctrlSnippet, "LABEL", ctrl, ctrl.Label);
                    }

                    snippetRowDefinition.InsertSnippet("ITEMS", ctrlSnippet, ",");
                }
            }
            else
            {
                // used for GroupBox, and Composite
                TExtJsFormsWriter.InsertControl(ctrl, snippetRowDefinition, "ITEMS", "HiddenValues", writer);
                TExtJsFormsWriter.InsertControl(ctrl, snippetRowDefinition, "ITEMS", "Controls", writer);
            }

            return(snippetRowDefinition);
        }
Exemple #19
0
        private ProcessTemplate WriteConnectorClass(ProcessTemplate ATemplate,
                                                    String FullNamespace,
                                                    String Classname,
                                                    String Namespace,
                                                    SortedList <string, TNamespace> children,
                                                    SortedList <string, TypeDeclaration> connectors)
        {
            if (children.Count > 0)
            {
                foreach (TNamespace sn in children.Values)
                {
                    WriteConnectorClass(
                        ATemplate,
                        FullNamespace + "." + sn.Name,
                        sn.Name,
                        sn.Name,
                        sn.Children,
                        connectors);
                }

                return(ATemplate);
            }

            ProcessTemplate connectorClassSnippet = ATemplate.GetSnippet("CONNECTORCLASS");

            string NamespaceInModule = FullNamespace.Substring(
                FullNamespace.IndexOf('.', "Ict.Petra.Shared.M".Length) + 1).Replace(".", string.Empty);

            connectorClassSnippet.SetCodelet("NAMESPACE", NamespaceInModule);

            connectorClassSnippet.SetCodelet("REMOTEDMETHODS", string.Empty);

            if (Namespace.EndsWith("WebConnectors"))
            {
                ImplementWebConnector(connectors, connectorClassSnippet, FullNamespace);
            }
            else
            {
                ImplementUIConnector(connectors, connectorClassSnippet, FullNamespace);
            }

            ATemplate.InsertSnippet("CONNECTORCLASSES", connectorClassSnippet);
            return(ATemplate);
        }
        /// <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);
        }
Exemple #21
0
        /// <summary>write the code for the designer file where the properties of the control are written</summary>
        public override ProcessTemplate SetControlProperties(TFormWriter writer, TControlDef ctrl)
        {
            ProcessTemplate ctrlSnippet = base.SetControlProperties(writer, ctrl);

            string valuesArray = "[";

            List <XmlNode> optionalValues =
                TYml2Xml.GetChildren(TXMLParser.GetChild(ctrl.xmlNode, "OptionalValues"), true);

            // DefaultValue with = sign before control name
            for (int counter = 0; counter < optionalValues.Count; counter++)
            {
                string loopValue = TYml2Xml.GetElementName(optionalValues[counter]);

                if (loopValue.StartsWith("="))
                {
                    loopValue = loopValue.Substring(1).Trim();
                    ctrlSnippet.SetCodelet("VALUE", loopValue);
                }

                if (counter > 0)
                {
                    valuesArray += ", ";
                }

                ((TExtJsFormsWriter)writer).AddResourceString(ctrlSnippet, "OPTION" + counter.ToString(), ctrl, loopValue);

                string strName = "this." + ctrl.controlName + "OPTION" + counter.ToString();

                valuesArray += "['" + loopValue + "', " + strName + "]";
            }

            valuesArray += "]";

            ctrlSnippet.SetCodelet("OPTIONALVALUESARRAY", valuesArray);

            if (ctrl.HasAttribute("width"))
            {
                ctrlSnippet.SetCodelet("WIDTH", ctrl.GetAttribute("width"));
            }

            return(ctrlSnippet);
        }
Exemple #22
0
        /// <summary>write the code for the designer file where the properties of the control are written</summary>
        public override ProcessTemplate SetControlProperties(TFormWriter writer, TControlDef ACtrl)
        {
            ProcessTemplate ctrlSnippet = base.SetControlProperties(writer, ACtrl);

            string customAttributes = "boxMaxWidth: 175,";

            ctrlSnippet.SetCodelet("CUSTOMATTRIBUTES", customAttributes);

            return(ctrlSnippet);
        }
Exemple #23
0
        void ImplementWebConnector(
            SortedList <string, TypeDeclaration> connectors,
            ProcessTemplate ATemplate, string AFullNamespace)
        {
            string ConnectorNamespace = AFullNamespace.
                                        Replace("Instantiator.", string.Empty);

            List <TypeDeclaration> ConnectorClasses = TCollectConnectorInterfaces.FindTypesInNamespace(connectors, ConnectorNamespace);

            ConnectorNamespace = ConnectorNamespace.
                                 Replace("Ict.Petra.Shared.", "Ict.Petra.Server.");

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

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

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

                    string ParameterDefinition = string.Empty;
                    string ActualParameters    = string.Empty;

                    AutoGenerationTools.FormatParameters(m.Parameters, out ActualParameters, out ParameterDefinition);

                    snippet.InsertSnippet("CHECKUSERMODULEPERMISSIONS",
                                          CreateModuleAccessPermissionCheck(
                                              ATemplate,
                                              connectorClass.Name,
                                              m));

                    string returntype = AutoGenerationTools.TypeToString(m.TypeReference, "");

                    snippet.SetCodelet("RETURN", returntype != "void" ? "return " : string.Empty);

                    snippet.SetCodelet("METHODNAME", m.Name);
                    snippet.SetCodelet("ACTUALPARAMETERS", ActualParameters);
                    snippet.SetCodelet("PARAMETERDEFINITION", ParameterDefinition);
                    snippet.SetCodelet("RETURNTYPE", returntype);
                    snippet.SetCodelet("WEBCONNECTORCLASS", connectorClass.Name);

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

                    ATemplate.InsertSnippet("REMOTEDMETHODS", snippet);
                }
            }
        }
        private static void InsertSubnamespaces(ProcessTemplate template,
                                                string AFullNamespace,
                                                SortedList <string, TNamespace> ASubNamespaces)
        {
            foreach (TNamespace t in ASubNamespaces.Values)
            {
                ProcessTemplate propertySnippet = ClientRemotingClassTemplate.GetSnippet("PROPERTY");

                propertySnippet.SetCodelet("NAME", t.Name);

                string NamespaceInModule = AFullNamespace.Substring(
                    AFullNamespace.IndexOf('.', "Ict.Petra.Shared.M".Length) + 1).Replace(".", string.Empty);

                propertySnippet.SetCodelet("TYPE", "I" + NamespaceInModule + t.Name + "Namespace");

                propertySnippet.SetCodelet("GETTER", "yes");

                template.InsertSnippet("METHODSANDPROPERTIES", propertySnippet);
            }
        }
Exemple #25
0
        /// based on the code model, create the code;
        /// using the code generators that have been loaded
        public override void CreateCode(TCodeStorage ACodeStorage, string ATemplateFile)
        {
            FCodeStorage = ACodeStorage;
            TControlGenerator.FCodeStorage = ACodeStorage;
            FTemplate = new ProcessTemplate(ATemplateFile);
            FFormName = Path.GetFileNameWithoutExtension(YamlFilename).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(YamlFilename);

            string languagefilepath = Path.GetDirectoryName(YamlFilename) + Path.DirectorySeparatorChar +
                                      Path.GetFileNameWithoutExtension(YamlFilename) + "-lang-template.js";

            File.WriteAllText(languagefilepath, FLanguageFileTemplate.FinishWriting(true));
        }
        //other interfaces, e.g. IPartnerUIConnectorsPartnerEdit
        // we don't know the interfaces that are implemented, so need to look for the base classes
        // we need to know all the source files that are part of the UIConnector dll
        private void WriteNamespaces(ProcessTemplate AMainTemplate,
                                     TNamespace tn, SortedList AInterfaceNames, List <CSParser> ACSFiles)
        {
            AMainTemplate.SetCodelet("MODULE", tn.Name);

            foreach (TNamespace sn in tn.Children.Values)
            {
                ProcessTemplate snippet = AMainTemplate.GetSnippet("SUBNAMESPACE");
                snippet.SetCodelet("SUBNAMESPACENAME", sn.Name);
                snippet.SetCodelet("SUBNAMESPACEOBJECT", sn.Name);
                AMainTemplate.InsertSnippet("SUBNAMESPACES", snippet);
            }

            // parse Instantiator source code
            foreach (TNamespace sn in tn.Children.Values)
            {
                WriteNamespace(AMainTemplate,
                               "Ict.Petra.Shared.Interfaces.M" + tn.Name + "." + sn.Name,
                               sn.Name, tn, sn, sn.Children, AInterfaceNames, ACSFiles);
            }
        }
Exemple #27
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);
        }
Exemple #28
0
        /// <summary>write the code for the designer file where the properties of the control are written</summary>
        public override ProcessTemplate SetControlProperties(TFormWriter writer, TControlDef ctrl)
        {
            ProcessTemplate ctrlSnippet = base.SetControlProperties(writer, ctrl);

            ((TExtJsFormsWriter)writer).AddResourceString(ctrlSnippet,
                                                          "VALUE",
                                                          ctrl,
                                                          TYml2Xml.GetAttribute(ctrl.xmlNode, "value"));

            ctrlSnippet.SetCodelet("VALUE", "this." + ctrl.controlName + "VALUE");

            return(ctrlSnippet);
        }
Exemple #29
0
        //other interfaces, e.g. IPartnerUIConnectorsPartnerEdit
        // we don't know the interfaces that are implemented, so need to look for the base classes
        // we need to know all the source files that are part of the UIConnector dll
        private void WriteNamespaces(ProcessTemplate AMainTemplate,
                                     TNamespace tn, SortedList AInterfaceNames, List <CSParser> ACSFiles)
        {
            AMainTemplate.SetCodelet("MODULE", tn.Name);

            // parse Instantiator source code
            foreach (TNamespace sn in tn.Children.Values)
            {
                WriteNamespace(AMainTemplate,
                               "Ict.Petra.Shared.Interfaces.M" + tn.Name + "." + sn.Name,
                               sn.Name, tn, sn, sn.Children, AInterfaceNames, ACSFiles);
            }
        }
Exemple #30
0
        /// <summary>
        /// insert all variables into the template
        /// </summary>
        /// <param name="AXAMLFilename"></param>
        public virtual void InsertCodeIntoTemplate(string AXAMLFilename)
        {
            FTemplate.SetCodelet("FORMWIDTH", FCodeStorage.FWidth.ToString());
            FTemplate.SetCodelet("FORMHEIGHT", FCodeStorage.FHeight.ToString());

            if (FCodeStorage.HasAttribute("LabelWidth"))
            {
                FTemplate.SetCodelet("LABELWIDTH", FCodeStorage.GetAttribute("LabelWidth"));
            }
            else
            {
                FTemplate.SetCodelet("LABELWIDTH", "140");
            }

            FTemplate.SetCodelet("FORMNAME", FFormName);
            FTemplate.SetCodelet("FORMTYPE", "T" + FFormName);

            string FormHeader = "true";

            if (FCodeStorage.HasAttribute("FormHeader"))
            {
                FormHeader = FCodeStorage.GetAttribute("FormHeader");
            }

            FTemplate.SetCodelet("FORMHEADER", FormHeader);

            string FormFrame = "true";

            if (FCodeStorage.HasAttribute("FormFrame"))
            {
                FormFrame = FCodeStorage.GetAttribute("FormFrame");
            }

            FTemplate.SetCodelet("FORMFRAME", FormFrame);

            FLanguageFileTemplate.SetCodelet("FORMNAME", FFormName);
            FLanguageFileTemplate.SetCodelet("FORMTYPE", "T" + FFormName);
        }