Beispiel #1
0
        private void btnCompileSelect_Click(object sender, EventArgs e)
        {
            //编译选定的表
            Console.Clear();

            var startPath = Environment.CurrentDirectory;

            Console.WriteLine("当前目录:{0}", startPath);
            var compiler = new Compiler();

            int comileCount = 0;

            foreach (var filePath in fileList)
            {
                Console.WriteLine(filePath);
                var savePath = GenTmlPath + "\\" + SimpleExcelFile.GetOutFileName(filePath) + TmlExtensions;
                //编译表时,生成代码
                TableCompileResult compileResult = compiler.Compile(filePath, savePath);
                Console.WriteLine("编译结果:{0}---->{1}", filePath, savePath);
                Console.WriteLine();
                //生成代码
                BatchCompiler batchCompiler = new BatchCompiler();
                //NOTE 替换成相对路径(保证最后只有文件名)
                string repStr = Directory.GetParent(compileResult.TabFileRelativePath).FullName + "\\";
                compileResult.TabFileRelativePath = compileResult.TabFileRelativePath.Replace(repStr, "");
                batchCompiler.GenCodeFile(compileResult, DefaultTemplate.GenSingleClassCodeTemplate, GenCodePath, NameSpace, TmlExtensions, null, true);

                if (compileResult != null)
                {
                    comileCount += 1;
                }
            }

            ShowCompileResult(comileCount);
        }
        public override void CompileView(IEnumerable <IList <Chunk> > viewTemplates, IEnumerable <IList <Chunk> > allResources)
        {
            this.GenerateSourceCode(viewTemplates, allResources);
            Assembly assembly = new BatchCompiler().Compile(base.Debug, "csharp", new string[] { base.SourceCode });

            base.CompiledType = assembly.GetType(base.ViewClassFullName);
        }
Beispiel #3
0
        public static void Main_(string[] args)
        {
            var options = new Option();

            if (CommandLine.Parser.Default.ParseArguments(args, options))
            {
                // Values are available here
                if (options.Verbose)
                {
                    Console.WriteLine("Filename: {0}", options.Directory);
                }

                var batchCompiler = new BatchCompiler();

                string templateString = DefaultTemplate.GenCodeTemplate;
                if (!string.IsNullOrEmpty(options.TemplateFilePath))
                {
                    Console.WriteLine(options.TemplateFilePath);
                    templateString = System.IO.File.ReadAllText(options.TemplateFilePath);
                }

                //var results =
                batchCompiler.CompileTableMLAll(options.Directory, options.OutputDirectory, options.CodeFilePath,
                                                templateString, "AppSettings", ".tml", null, !string.IsNullOrEmpty(options.CodeFilePath));

                Console.WriteLine("Done!");

                //				var compiler = new Compiler();
                //				var result = compiler.Compile(options.Directory);
                //				Console.WriteLine(string.Format("Compile excel file: {0} , to {1}", options.Directory, result.TabFileRelativePath));
            }
        }
        public Assembly BatchCompilation(string outputAssembly, IList <SparkViewDescriptor> descriptors)
        {
            List <CompiledViewEntry> list  = new List <CompiledViewEntry>();
            List <string>            list2 = new List <string>();

            foreach (SparkViewDescriptor descriptor in descriptors)
            {
                CompiledViewEntry item = new CompiledViewEntry {
                    Descriptor = descriptor,
                    Loader     = this.CreateViewLoader(),
                    Compiler   = this.LanguageFactory.CreateViewCompiler(this, descriptor)
                };
                List <IList <Chunk> > chunksLoaded    = new List <IList <Chunk> >();
                List <string>         templatesLoaded = new List <string>();
                this.LoadTemplates(item.Loader, descriptor.Templates, chunksLoaded, templatesLoaded);
                item.Compiler.GenerateSourceCode(chunksLoaded, item.Loader.GetEverythingLoaded());
                list2.Add(item.Compiler.SourceCode);
                list.Add(item);
            }
            BatchCompiler compiler2 = new BatchCompiler {
                OutputAssembly = outputAssembly
            };
            Assembly assembly = compiler2.Compile(this.Settings.Debug, "csharp", list2.ToArray());

            foreach (CompiledViewEntry entry3 in list)
            {
                entry3.Compiler.CompiledType = assembly.GetType(entry3.Compiler.ViewClassFullName);
                entry3.Activator             = this.ViewActivatorFactory.Register(entry3.Compiler.CompiledType);
                this.CompiledViewHolder.Store(entry3);
            }
            return(assembly);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="force">Whether or not,check diff.  false will be faster!</param>
        /// <param name="genCode">Generate static code?</param>
        public static void DoCompileSettings(bool force = true, string forceTemplate = null)
        {
            var sourcePath = SettingSourcePath;//AppEngine.GetConfig("SettingSourcePath");

            if (string.IsNullOrEmpty(sourcePath))
            {
                Log.Error("Need to KEngineConfig: SettingSourcePath");
                return;
            }
            var compilePath = AppEngine.GetConfig("KEngine.Setting", "SettingCompiledPath");

            if (string.IsNullOrEmpty(compilePath))
            {
                Log.Error("Need to KEngineConfig: SettingCompiledPath");
                return;
            }

            var bc = new BatchCompiler();

            var settingCodeIgnorePattern = AppEngine.GetConfig("KEngine.Setting", "SettingCodeIgnorePattern", false);
            var results = bc.CompileTableMLAll(sourcePath, compilePath, SettingCodePath, forceTemplate ?? DefaultTemplate.GenCodeTemplate, "AppSettings", SettingExtension, settingCodeIgnorePattern, force);

            //            CompileTabConfigs(sourcePath, compilePath, SettingCodePath, SettingExtension, force);
            var sb = new StringBuilder();

            foreach (var r in results)
            {
                sb.AppendLine(string.Format("Excel {0} -> {1}", r.ExcelFile, r.TabFileRelativePath));
            }
            Log.Info("TableML all Compile ok!\n{0}", sb.ToString());
            // make unity compile
            AssetDatabase.Refresh();
        }
Beispiel #6
0
        public override void CompileView(IEnumerable<IList<Chunk>> viewTemplates, IEnumerable<IList<Chunk>> allResources)
        {
            GenerateSourceCode(viewTemplates, allResources);

            var batchCompiler = new BatchCompiler();
            var assembly = batchCompiler.Compile(Debug, "csharp", SourceCode);
            CompiledType = assembly.GetType(ViewClassFullName);
        }
Beispiel #7
0
        public void TestBatchCompile()
        {
            var bc      = new BatchCompiler();
            var results = bc.CompileTableMLAll("TestSettings", "TestSettingsResult", "TestSettings.cs.gen", DefaultTemplate.GenCodeTemplate, "AppSettings", ".tml", null, true);

            Assert.AreEqual(4, results.Count);
            Assert.True(File.Exists("TestSettings.cs.gen"));
        }
Beispiel #8
0
        /// <summary>
        /// do compile settings
        /// </summary>
        /// <param name="force">Whether or not,check diff.  false will be faster!</param>
        /// <param name="genCode">Generate static code?</param>
        public static void DoCompileSettings(bool force = true, string forceTemplate = null, bool canCustom = true)
        {
            if (canCustom && CustomCompileSettings != null)
            {
                CustomCompileSettings();
                return;
            }

            List <TableCompileResult> results = null;

            if (AppConfig.IsUseLuaConfig)
            {
                Log.Info("Start Compile to lua");
                var genParam = new GenParam()
                {
                    settingCodeIgnorePattern = AppConfig.SettingCodeIgnorePattern,
                    genCSharpClass           = false, genCodeFilePath = null, forceAll = true, ExportLuaPath = AppConfig.ExportLuaPath
                };
                var compilerParam = new CompilerParam()
                {
                    CanExportTsv = false, ExportTsvPath = AppConfig.ExportTsvPath, ExportLuaPath = AppConfig.ExportLuaPath
                };
                results = new BatchCompiler().CompileAll(AppConfig.SettingResourcesPath, AppConfig.ExportLuaPath, genParam, compilerParam);
            }
            else
            {
                if (string.IsNullOrEmpty(AppConfig.ExportTsvPath))
                {
                    Log.Error("Need to KEngineConfig: ExportTsvPath");
                    return;
                }
                Log.Info("Start Compile to c#+tsv");

                var template = force ? (forceTemplate ?? DefaultTemplate.GenCodeTemplateOneFile) : null;
                var genParam = new GenParam()
                {
                    forceAll = force, genCSharpClass = true, genCodeFilePath = AppConfig.ExportCSharpPath,
                    genCodeTemplateString    = template, changeExtension = AppConfig.SettingExt,
                    settingCodeIgnorePattern = AppConfig.SettingCodeIgnorePattern, nameSpace = "AppSettings"
                };
                var compilerParam = new CompilerParam()
                {
                    CanExportTsv = true, ExportTsvPath = AppConfig.ExportTsvPath, ExportLuaPath = null
                };
                results = new BatchCompiler().CompileAll(AppConfig.SettingSourcePath, AppConfig.ExportTsvPath, genParam, compilerParam);
            }

            var sb = new StringBuilder();

            foreach (var r in results)
            {
                sb.AppendLine(string.Format("Excel {0} -> {1}", r.ExcelFile, r.TabFileRelativePath));
            }
            Log.Info("TableML all Compile ok!\n{0}", sb.ToString());
            // make unity compile
            AssetDatabase.Refresh();
        }
        public override void CompileView(IEnumerable <IList <Chunk> > viewTemplates, IEnumerable <IList <Chunk> > allResources)
        {
            GenerateSourceCode(viewTemplates, allResources);

            var batchCompiler = new BatchCompiler();
            var assembly      = batchCompiler.Compile(Debug, "visualbasic", SourceCode);

            CompiledType = assembly.GetType(ViewClassFullName);
        }
Beispiel #10
0
        public void BatchCompiler_Generates_AutoInput()
        {
            BatchCompiler batchCompiler = new BatchCompiler();

            batchCompiler.CreateFieldInput("@Column1", "Column 1", "Description for Column 1");
            batchCompiler.CreateFieldInput("@Column2", "Column 1", "Description for Column 1");

            batchCompiler.Input("@Column1", "COL 1");
            batchCompiler.Input("@Column2", "COL 2");

            Generator generator = new Generator();
            string    output    = generator.Generate(batchCompiler, "@{Column1} is the first column, @{Column2} is the second column.");

            Assert.AreEqual("COL 1 is the first column, COL 2 is the second column.", output);

            Assert.AreEqual("Column 1", batchCompiler.GetSymbolInfo("@Column1").Title);
            Assert.AreEqual("Description for Column 1", batchCompiler.GetSymbolInfo("@Column1").Description);
        }
Beispiel #11
0
        private void btnCompileAll_Click(object sender, EventArgs e)
        {
            //编译整个目录
            var startPath = Environment.CurrentDirectory;

            Console.WriteLine("当前目录:{0}", startPath);

            var srcDirectory = tbFileDir.Text;


            var batchCompiler = new BatchCompiler();

            string templateString = DefaultTemplate.GenSingleClassCodeTemplate;

            var results = batchCompiler.CompileTableMLAllInSingleFile(srcDirectory, GenTmlPath, GenCodePath,
                                                                      templateString, "AppSettings", ".k", null, !string.IsNullOrEmpty(GenCodePath));

            ShowCompileResult(results.Count);
        }
Beispiel #12
0
        public void ScriptExamples_BatchCompileFields_GeneratesBatchOutput()
        {
            IBatchCompiler batchCompiler = new BatchCompiler();

            batchCompiler.Compile(TxtFile.ReadText("Batch.tpl"));

            // this must take place afterwards, otherwise it will be cleared by the compile.
            batchCompiler.CreateFieldInput("@Column1", "Title", "Description");
            batchCompiler.CreateFieldInput("@Column2", "Title", "Description");
            batchCompiler.Input("@Column1", "COL 1");
            batchCompiler.Input("@Column2", "COL 2");

            ISymbolInfo[] symbolInfo = batchCompiler.GetSymbolInfoSet(new string[] { "@Column1", "@Column2" });

            Generator generator = new Generator();
            string    output    = generator.Generate(batchCompiler, "@{combination}");

            Assert.AreEqual("COL 1 - COL 2", output);

            Assert.AreEqual(2, symbolInfo.Length);
        }
Beispiel #13
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="force">Whether or not,check diff.  false will be faster!</param>
        /// <param name="genCode">Generate static code?</param>
        public static void DoCompileSettings(bool force = true, string forceTemplate = null, bool canCustom = true)
        {
            if (canCustom && CustomCompileSettings != null)
            {
                CustomCompileSettings();
                return;
            }

            var sourcePath = SettingSourcePath;//AppEngine.GetConfig("SettingSourcePath");

            if (string.IsNullOrEmpty(sourcePath))
            {
                Debug.LogError("Need to KEngineConfig: SettingSourcePath");
                return;
            }
            var compilePath = "Assets/Main/BundleEditor/DataTable";

            if (string.IsNullOrEmpty(compilePath))
            {
                Debug.LogError("Need to KEngineConfig: SettingCompiledPath");
                return;
            }

            var bc = new BatchCompiler();

            //var settingCodeIgnorePattern = null;
            var template = force ? (forceTemplate ?? DefaultTemplate.GenCodeTemplate) : null; //
            var results  = bc.CompileTableMLAll(sourcePath, compilePath, SettingCodePath, template, "AppSettings", SettingExtension, null, force);

            //            CompileTabConfigs(sourcePath, compilePath, SettingCodePath, SettingExtension, force);
            var sb = new StringBuilder();

            foreach (var r in results)
            {
                sb.AppendLine(string.Format("Excel {0} -> {1}", r.ExcelFile, r.TabFileRelativePath));
            }
            Debug.LogFormat("TableML all Compile ok!\n{0}", sb.ToString());
            // make unity compile
            AssetDatabase.Refresh();
        }
Beispiel #14
0
        /// <summary>
        /// 编译整个目录的excel,每个表生成一个cs文件
        /// </summary>
        public static void CompileAll()
        {
            var startPath = Environment.CurrentDirectory;

            Console.WriteLine("当前目录:{0}", startPath);
            //源excel文件路径
            //var srcDirectory = "settingsrc";
            var srcDirectory = "settingsrc";
            //输出tml文件路径
            var OutputDirectory = "setting";
            //生成的代码路径
            var    CodeFilePath             = "GenCode\\";
            string settingCodeIgnorePattern = "(I18N/.*)|(StringsTable.*)|(tool/*)|(log/*)|(server/*)|(client/*)";
            var    batchCompiler            = new BatchCompiler();

            string templateString = DefaultTemplate.GenSingleClassCodeTemplate;

            var results = batchCompiler.CompileTableMLAllInSingleFile(srcDirectory, OutputDirectory, CodeFilePath,
                                                                      templateString, "AppSettings", ".tml", settingCodeIgnorePattern, true);

            Console.WriteLine("Done!");
        }
Beispiel #15
0
        public Assembly BatchCompilation(string outputAssembly, IList <SparkViewDescriptor> descriptors)
        {
            var batch      = new List <CompiledViewEntry>();
            var sourceCode = new List <string>();

            foreach (var descriptor in descriptors)
            {
                var entry = new CompiledViewEntry
                {
                    Descriptor = descriptor,
                    Loader     = CreateViewLoader(),
                    Compiler   = LanguageFactory.CreateViewCompiler(this, descriptor)
                };

                var chunksLoaded    = new List <IList <Chunk> >();
                var templatesLoaded = new List <string>();
                LoadTemplates(entry.Loader, descriptor.Templates, chunksLoaded, templatesLoaded);

                entry.Compiler.GenerateSourceCode(chunksLoaded, entry.Loader.GetEverythingLoaded());
                sourceCode.Add(entry.Compiler.SourceCode);

                batch.Add(entry);
            }

            var batchCompiler = new BatchCompiler {
                OutputAssembly = outputAssembly
            };

            var assembly = batchCompiler.Compile(Settings.Debug, "csharp", sourceCode.ToArray());

            foreach (var entry in batch)
            {
                entry.Compiler.CompiledType = assembly.GetType(entry.Compiler.ViewClassFullName);
                entry.Activator             = ViewActivatorFactory.Register(entry.Compiler.CompiledType);
                CompiledViewHolder.Store(entry);
            }
            return(assembly);
        }
Beispiel #16
0
        public static void DoCompileSettings(bool force = true)
        {
            var bc = new BatchCompiler();

            var sourcePath               = "Product/DT_MySQLSource";
            var compilePath              = "Product/DT_MySQL";
            var SettingCodePath          = "Assets/AutoGenerate/DT_MySQL.cs";
            var template                 = DTMySQLTemplate.GenCodeTemplate; //
            var SettingExtension         = ".bytes";
            var settingCodeIgnorePattern = "(I18N/.*)|(StringsTable.*)";
            //var force = true;
            var results = bc.CompileTableMLAll(sourcePath, compilePath, SettingCodePath, template, "Ash", SettingExtension, settingCodeIgnorePattern, force);

            //            CompileTabConfigs(sourcePath, compilePath, SettingCodePath, SettingExtension, force);
            var sb = new StringBuilder();

            foreach (var r in results)
            {
                sb.AppendLine(string.Format("Excel {0} -> {1}", r.ExcelFile, r.TabFileRelativePath));
            }
            UnityEngine.Debug.Log("TableML all Compile ok!\n" + sb.ToString());
            // make unity compile
            AssetDatabase.Refresh();
        }
Beispiel #17
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="force">Whether or not,check diff.  false will be faster!</param>
        /// <param name="genCode">Generate static code?</param>
        public static void DoCompileSettings(bool force = true, string forceTemplate = null, bool canCustom = true)
        {
            if (canCustom && CustomCompileSettings != null)
            {
                CustomCompileSettings();
                return;
            }

            var sourcePath = SettingSourcePath;//AppEngine.GetConfig("SettingSourcePath");
            if (string.IsNullOrEmpty(sourcePath))
            {
                Log.Error("Need to KEngineConfig: SettingSourcePath");
                return;
            }
            var compilePath = AppEngine.GetConfig("KEngine.Setting", "SettingCompiledPath");
            if (string.IsNullOrEmpty(compilePath))
            {
                Log.Error("Need to KEngineConfig: SettingCompiledPath");
                return;
            }

            var bc = new BatchCompiler();

            var settingCodeIgnorePattern = AppEngine.GetConfig("KEngine.Setting", "SettingCodeIgnorePattern", false);
            var template = force ? (forceTemplate ?? DefaultTemplate.GenCodeTemplate) : null; //
            var results = bc.CompileTableMLAll(sourcePath, compilePath, SettingCodePath, template, "AppSettings", SettingExtension, settingCodeIgnorePattern, force);

            //            CompileTabConfigs(sourcePath, compilePath, SettingCodePath, SettingExtension, force);
            var sb = new StringBuilder();
            foreach (var r in results)
            {
                sb.AppendLine(string.Format("Excel {0} -> {1}", r.ExcelFile, r.TabFileRelativePath));
            }
            Log.Info("TableML all Compile ok!\n{0}", sb.ToString());
            // make unity compile
            AssetDatabase.Refresh();
        }