private Boolean CreateConnectors(String AOutputPath, String AModulePath, String ATemplateDir)
        {
            // Work out the module name from the module path
            string[] items = AModulePath.Split(new char[] { Path.DirectorySeparatorChar });

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

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

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

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

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

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

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

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

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

            int cacheableCount = 0;
            int nonCacheableCount = 0;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            return true;
        }
Exemplo n.º 2
0
        void btnPreviewClick(object sender, EventArgs e)
        {
            TParseYAMLFormsDefinition.ClearCachedYamlFiles();
            bool bRequiresUCFilterFindDeclaration = false;

            // generate the code
            TFrmYamlPreview.ProcessFile(FFilename, FSelectedLocalisation);

            // load the designer code
            StreamReader  sr           = new StreamReader(FFilename.Replace(".yaml", "-generated.Designer.cs"));
            StringBuilder DesignerCode = new StringBuilder();

            string Namespace = string.Empty;
            string ClassName = "T" + Path.GetFileNameWithoutExtension(FFilename);

            while (!sr.EndOfStream)
            {
                string line = sr.ReadLine();

                if (line.StartsWith("namespace "))
                {
                    Namespace = line.Substring("namespace ".Length);
                }

                if (line.Contains("+= new "))
                {
                    // ignore event handlers
                }
                else if (line.Contains(".ListTable = "))
                {
                    // ignore TtxtAutoPopulatedButtonLabel.set_ListTable
                }
                else if (line.Contains("partial class"))
                {
                    ClassName = line.Substring("    partial class ".Length);

                    if (Path.GetFileNameWithoutExtension(FFilename).StartsWith("UC"))
                    {
                        line = line.Replace("partial", string.Empty) + ": UserControl {";
                    }
                    else
                    {
                        line = line.Replace("partial", string.Empty) + ": Form {";
                    }

                    DesignerCode.Append(line).Append(Environment.NewLine);
                    line = "public " + ClassName + "() : base()     { InitializeComponent(); }";
                    DesignerCode.Append(line).Append(Environment.NewLine);
                    // read opening curly bracket
                    line = sr.ReadLine();
                }
                else if (line.Contains("FucoFilterAndFind.Dispose()"))
                {
                    // FucoFilterAndFind is not decalred through the standard YAML file and so is not part of the Designer file
                    // This means we have to add it to our copy that will be compiled
                    bRequiresUCFilterFindDeclaration = true;
                }
                else if ((line.Contains("CheckBox chkToggleFilter;")) && bRequiresUCFilterFindDeclaration)
                {
                    // This is a good point to add our FucoFilterAndFind declaration
                    DesignerCode.Append(line).Append(Environment.NewLine);
                    DesignerCode.Append("        private Ict.Common.Controls.TUcoFilterAndFind FucoFilterAndFind;").Append(Environment.NewLine);
                }
                else
                {
                    DesignerCode.Append(line).Append(Environment.NewLine);
                }
            }

            sr.Close();

            if (TLogging.DebugLevel > 0)
            {
                StreamWriter sw = new StreamWriter("../../log/tempPreviewWinforms.cs");
                sw.WriteLine(DesignerCode.ToString());
                sw.Close();
            }

            // compile the designer code
            CompilerResults results = CompileForm(DesignerCode.ToString(), Namespace + "." + ClassName);

            if (results.Errors.HasErrors)
            {
                TLogging.Log(results.Errors.ToString());
                return;
            }

            // open the form
            ShowScreen(results.CompiledAssembly, Namespace + "." + ClassName);
        }
        private Boolean CreateConnectors(String AOutputPath, String AModulePath, String ATemplateDir)
        {
            // Work out the module name from the module path
            string[] items = AModulePath.Split(new char[] { Path.DirectorySeparatorChar });

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

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

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

            String OutputFile = OutputFolder + Path.DirectorySeparatorChar + "ReferenceCount-generated.cs";

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

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

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

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

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

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

            int cacheableCount    = 0;
            int nonCacheableCount = 0;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            return(true);
        }