private static int Run(Options options, ILogger logger) { // Initialize basic command options. //Parser.Default.ParseArguments<Options>(args) // .WithParsed(options => // { try { var(workingFolder, intermediateFolder, generatedCodeFolder, compilingFiles) = DeconstructPaths(options); var rebuildRequired = options.RebuildRequired; var cachedExcludesListFile = Path.Combine(intermediateFolder, "Excludes.txt"); // 如果可以差量编译,那么检测之前已经生成的文件,然后将其直接输出。 if (!rebuildRequired && File.Exists(cachedExcludesListFile)) { var cachedExcludeLines = File.ReadAllLines(cachedExcludesListFile, Encoding.UTF8); foreach (var exclude in cachedExcludeLines) { logger.Message(exclude); } return(0); } var assembly = new CompileAssembly(compilingFiles); // 分析 IPlainCodeTransformer。 var transformer = new CodeTransformer(workingFolder, generatedCodeFolder, assembly); var excludes = transformer.Transform(); // 分析 CompileTimeTemplate。 var templateTransformer = new TemplateTransformer(workingFolder, generatedCodeFolder, assembly); var templateExcludes = templateTransformer.Transform(); var toExcludes = excludes.Union(templateExcludes) .Select(x => PathEx.MakeRelativePath(workingFolder, x)).ToArray(); foreach (var exclude in toExcludes) { logger.Message(exclude); } File.WriteAllLines(cachedExcludesListFile, toExcludes, Encoding.UTF8); } catch (CompilingException ex) { foreach (var error in ex.Errors) { logger.Error($"error:{error}"); } } catch (Exception ex) { logger.Error($"error:{ex}"); } //}) //.WithNotParsed(errorList => { }); return(0); }
public async Task Transforms_Plain_Json_Template(string content) { var templateTransformer = new TemplateTransformer(Moq.Mock.Of <IScriptRunnerFactory>(), Moq.Mock.Of <ILogger <TemplateTransformer> >()); var rawTemplate = Moq.Mock.Of <IRawTemplate>(t => t.Content == content); var scriptContext = Moq.Mock.Of <IScriptContext>(); var transformedTemplate = await templateTransformer.Transform(rawTemplate, scriptContext); Assert(transformedTemplate); }
private void button2_Click(object sender, EventArgs e) { TemplateContainer container = new TemplateContainer(); container.AddAttribute("varprueba", "prueba"); container.AddAttribute("vartrans", "transformación"); container.AddAttribute("i", 7); string s = "El resultado es [%if(i > 7)%]cierto[%else%]falso"; s = TemplateTransformer.Transform(s); s = JavascriptEvaluator.ReplaceString(s, container); this.richTextBox2.Text = s; }
private void button1_Click(object sender, EventArgs e) { StructureParser parser = new StructureParser(this.richTextBox1.Text); StructureTree root = parser.Parse(); MetaModel metamodel = root.Build(); MetaTemplateConverter converter = new MetaTemplateConverter(); TemplateContainer container = converter.Convert(metamodel); string template = "Domains:\n========\n[%foreach(domain in Domains)%]\n Id: [%domain.Id%]\n Name: [%domain.Name%]\n IsIdentity: [%domain.IsIdentity%]\n DataType: [%domain.DataType%]\n Length: [%domain.DataTypeLength%]\n Decimals: [%domain.DataTypeDecimals%]\n[%end%]\n"; template += "Tables:\n=======\n[%foreach(table in Tables)%]\n Id: [%table.Id%]\n Name: [%table.Name%]\n LogicalName: [%table.LogicalName%]\n PhysicalName: [%table.PhysicalName%]\n [\n[%foreach(column in table.Columns)%] TableId: [%column.TableId%]\n Ix: [%column.Ix%]\n Name: [%column.Name%]\n LogicalName: [%column.LogicalName%]\n PhysicalName: [%column.PhysicalName%]\n IsPrimaryKey: [%column.IsPrimaryKey%]\n IsNullable: [%column.IsNullable%]\n IsIdentity: [%column.IsIdentity%]\n DataType: [%column.DataType%]\n Length: [%column.DataTypeLength%]\n Decimals: [%column.DataTypeDecimals%]\n IsForeignKey: [%column.IsForeignKey%]\n [%end%]\n][%end%]\n"; template = TemplateTransformer.Transform(template); template = JavascriptEvaluator.ReplaceString(template, container); this.richTextBox2.Text = template; }
public async Task Transforms_Scripted_Json_Template(string content) { var rawTemplate = Moq.Mock.Of <IRawTemplate>(t => t.Content == content); var scriptContext = Moq.Mock.Of <IScriptContext>(); var scriptRunnerFactory = Moq.Mock.Of <IScriptRunnerFactory>(f => f.Invoke <IScriptContext, object>(scriptContext, "Request.Route[\"parameter1\"] == \"firstParameter\"") == Task.FromResult((object)true) && f.Invoke <IScriptContext, object>(scriptContext, "Faker.Random.Number(1,7)") == Task.FromResult((object)5) && f.Invoke <IScriptContext, object>(scriptContext, "JsonConvert.SerializeObject(new DateTime(2012, 04, 23, 18, 25, 43, 511, DateTimeKind.Utc))") == Task.FromResult((object)"\"2012-04-23T18:25:43.511Z\"")); var templateTransformer = new TemplateTransformer(scriptRunnerFactory, Moq.Mock.Of <ILogger <TemplateTransformer> >()); var transformedTemplate = await templateTransformer.Transform(rawTemplate, scriptContext); Assert(transformedTemplate); }
private void RunCore() { var context = new ProjectCompilingContext(_options); var rebuildRequired = _options.RebuildRequired; var cachedExcludesListFile = Path.Combine(context.ToolsFolder, "Excludes.txt"); // 如果可以差量编译,那么检测之前已经生成的文件,然后将其直接输出。 if (!rebuildRequired && File.Exists(cachedExcludesListFile)) { var cachedExcludeLines = File.ReadAllLines(cachedExcludesListFile, Encoding.UTF8); foreach (var exclude in cachedExcludeLines) { _logger.Message(exclude); } return; } // 分析 IPlainCodeTransformer。 var transformer = new CodeTransformer(context); var excludes = transformer.Transform(); // 分析 CompileTimeTemplate。 var templateTransformer = new TemplateTransformer(context); var templateExcludes = templateTransformer.Transform(); var toExcludes = excludes.Union(templateExcludes) .Select(x => PathEx.MakeRelativePath(context.WorkingFolder, x)).ToArray(); foreach (var exclude in toExcludes) { _logger.Message(exclude); } File.WriteAllLines(cachedExcludesListFile, toExcludes, Encoding.UTF8); }