コード例 #1
0
ファイル: GenerateYaml.cs プロジェクト: jsuen123/openpetragit
        /// <summary>
        /// write yaml files for localisation
        /// </summary>
        /// <param name="ALanguageCode"></param>
        /// <param name="AYamlFilePath"></param>
        /// <param name="APoFilePath"></param>
        public static void WriteYamlFiles(string ALanguageCode, string AYamlFilePath, string APoFilePath)
        {
            if (ALanguageCode == "en-EN")
            {
                return;
            }

            string[] yamlfiles = System.IO.Directory.GetFiles(AYamlFilePath, "*.yaml", SearchOption.AllDirectories);

            // load (compiled) po file, and use for the labels
            Catalog.SetLanguage(ALanguageCode);
            Catalog.Init();

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

                CreateLocalisedYamlFile(ALanguageCode, yamlfile);
            }

            TPoFileParser.WriteUpdatedPoFile(APoFilePath, NewTranslations);
        }
コード例 #2
0
        private static void ProcessFile(string filename, string ASelectedLocalisation)
        {
            TProcessYAMLForms processor = new TProcessYAMLForms(filename, ASelectedLocalisation);

            // report is at the moment the only real different type of screen,
            // because it uses different controls
            // otherwise, the Template attribute is also quite important, because it determines which code is written
            processor.AddWriter("navigation", typeof(TWinFormsWriter));
            processor.AddWriter("edit", typeof(TWinFormsWriter));
            processor.AddWriter("dialog", typeof(TWinFormsWriter));
            processor.AddWriter("report", typeof(TWinFormsWriter));
            processor.AddWriter("browse", typeof(TWinFormsWriter));

            processor.ProcessDocument();
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: wyerp/openpetra
        private static void ProcessFile(string filename, string ASelectedLocalisation)
        {
            if (ASelectedLocalisation == null)
            {
                // check for all existing localisations
                foreach (string file in System.IO.Directory.GetFiles(
                             Path.GetDirectoryName(filename),
                             "*.yaml"))
                {
                    if (!file.EndsWith(Path.GetFileName(filename)) &&
                        Path.GetFileName(file).StartsWith(Path.GetFileNameWithoutExtension(filename)))
                    {
                        ASelectedLocalisation = Path.GetExtension(Path.GetFileNameWithoutExtension(file)).Substring(1);

                        TProcessYAMLForms processorLocalized = new TProcessYAMLForms(file, null);

                        processorLocalized.AddWriter("SubmitForm", typeof(TExtJsFormsWriter));

                        processorLocalized.ProcessDocument();
                    }
                }

                if (ASelectedLocalisation != null)
                {
                    // do not generate the root yaml file
                    return;
                }
            }

            // by default, just generate the form for one (or default) localisation
            TProcessYAMLForms processor = new TProcessYAMLForms(filename, ASelectedLocalisation);

            processor.AddWriter("SubmitForm", typeof(TExtJsFormsWriter));

            processor.ProcessDocument();
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: jsuen123/openpetragit
        public static void Main(string[] args)
        {
            try
            {
                new TAppSettingsManager(false);

                if (Directory.Exists("log"))
                {
                    new TLogging("log/generatewinforms.log");
                }
                else
                {
                    new TLogging("generatewinforms.log");
                }

                TLogging.DebugLevel = TAppSettingsManager.GetInt16("Server.DebugLevel", 0);

                if (!TAppSettingsManager.HasValue("op"))
                {
                    Console.WriteLine("call: GenerateWinForms -op:generate -ymlfile:c:\\test.yaml -petraxml:petra.xml -localisation:en");
                    Console.WriteLine("  or: GenerateWinForms -op:generate -ymldir:c:\\myclient -petraxml:petra.xml -localisation:en");
                    Console.WriteLine("  or: GenerateWinForms -op:clean -ymldir:c:\\myclient");
                    Console.WriteLine("  or: GenerateWinForms -op:preview");
                    Console.Write("Press any key to continue . . . ");
                    Console.ReadLine();
                    Environment.Exit(-1);
                    return;
                }

                // calculate ICTPath from ymlfile path
                string fullYmlfilePath =
                    Path.GetFullPath(TAppSettingsManager.GetValue("ymlfile", TAppSettingsManager.GetValue("ymldir", false))).Replace(
                        "\\",
                        "/");

                if (!fullYmlfilePath.Contains("csharp/ICT"))
                {
                    Console.WriteLine("ymlfile must be below the csharp/ICT directory");
                }

                CSParser.ICTPath = fullYmlfilePath.Substring(0, fullYmlfilePath.IndexOf("csharp/ICT") + "csharp/ICT".Length);

                if (TAppSettingsManager.GetValue("op") == "clean")
                {
                    if (!Directory.Exists(fullYmlfilePath))
                    {
                        throw new Exception("invalid directory " + fullYmlfilePath);
                    }

                    // delete all generated files in the directory
                    foreach (string file in System.IO.Directory.GetFiles(fullYmlfilePath, "*.yaml", SearchOption.AllDirectories))
                    {
                        DeleteGeneratedFile(file, "-generated.cs");
                        DeleteGeneratedFile(file, "-generated.Designer.cs");
                        DeleteGeneratedFile(file, "-generated.resx");
                    }
                }
                else if (TAppSettingsManager.GetValue("op") == "preview")
                {
                    string SelectedLocalisation = null;         // none selected by default; winforms autosize works quite well

                    if (TAppSettingsManager.HasValue("localisation"))
                    {
                        SelectedLocalisation = TAppSettingsManager.GetValue("localisation");
                    }

                    TDataBinding.FPetraXMLStore = new TDataDefinitionStore();
                    Console.WriteLine("parsing " + TAppSettingsManager.GetValue("petraxml", true));
                    TDataDefinitionParser parser = new TDataDefinitionParser(TAppSettingsManager.GetValue("petraxml", true));
                    parser.ParseDocument(ref TDataBinding.FPetraXMLStore, true, true);

                    TFrmYamlPreview PreviewWindow = new TFrmYamlPreview(
                        TAppSettingsManager.GetValue("ymlfile"),
                        SelectedLocalisation);

                    AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledExceptionHandler);
                    Application.ThreadException += new ThreadExceptionEventHandler(UnhandledThreadExceptionHandler);

                    PreviewWindow.ShowDialog();

                    return;
                }
                else if (TAppSettingsManager.GetValue("op") == "generate")
                {
                    string SelectedLocalisation = null;         // none selected by default; winforms autosize works quite well

                    if (TAppSettingsManager.HasValue("localisation"))
                    {
                        SelectedLocalisation = TAppSettingsManager.GetValue("localisation");
                    }

                    TDataBinding.FPetraXMLStore = new TDataDefinitionStore();
                    Console.WriteLine("parsing " + TAppSettingsManager.GetValue("petraxml", true));
                    TDataDefinitionParser parser = new TDataDefinitionParser(TAppSettingsManager.GetValue("petraxml", true));
                    parser.ParseDocument(ref TDataBinding.FPetraXMLStore, true, true);

                    string ymlfileParam = TAppSettingsManager.GetValue("ymlfile", TAppSettingsManager.GetValue("ymldir", false));

                    if (ymlfileParam.Contains(","))
                    {
                        StringCollection collection = StringHelper.StrSplit(ymlfileParam, ",");

                        foreach (string file in collection)
                        {
                            ProcessFile(file, SelectedLocalisation);
                        }
                    }
                    else if (System.IO.Directory.Exists(ymlfileParam))
                    {
                        string[] yamlfiles = System.IO.Directory.GetFiles(ymlfileParam, "*.yaml", SearchOption.AllDirectories);
                        // sort the files so that the deepest files are first processed,
                        // since the files higher up are depending on them
                        // eg. FinanceMain.yaml needs to check for GLBatch-generated.cs

                        List <string> yamlFilesSorted = new List <string>(yamlfiles.Length);

                        foreach (string file in yamlfiles)
                        {
                            yamlFilesSorted.Add(file);
                        }

                        yamlFilesSorted.Sort(new YamlFileOrderComparer());

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

                            Console.WriteLine("working on " + file);
                            ProcessFile(file, SelectedLocalisation);
                        }
                    }
                    else
                    {
                        ProcessFile(ymlfileParam, SelectedLocalisation);
                    }
                }
            }
            catch (Exception e)
            {
                string commandline = "";

                foreach (string s in args)
                {
                    commandline += s + " ";
                }

                Console.WriteLine("Problem while processing " + commandline);
                Console.WriteLine(e.GetType().ToString() + ": " + e.Message);

                if (e.InnerException != null)
                {
                    Console.WriteLine(e.InnerException.GetType().ToString() + ": " + e.InnerException.Message);
                }

                // do not print a stacktrace for custom generated exception, eg. by the YML parser
                if ((e.GetType() != typeof(System.Exception)) || (TLogging.DebugLevel > 0))
                {
                    Console.WriteLine(e.StackTrace);
                }

                Environment.Exit(-1);
            }
        }
コード例 #5
0
        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);
        }