public VelocityTransform(IContext context = null, IReader reader = null) : base(context, "object") { if (IsMissingContext()) { return; } Returns = Context.Field.Type; if (IsMissing(context.Operation.Template)) { return; } VelocityInitializer.Init(); var fileBasedTemplate = context.Process.Templates.FirstOrDefault(t => t.Name == context.Operation.Template); if (fileBasedTemplate != null) { var memoryLogger = new MemoryLogger(); context.Operation.Template = reader.Read(fileBasedTemplate.File, null, memoryLogger); if (memoryLogger.Errors().Any()) { foreach (var error in memoryLogger.Errors()) { context.Error(error); } } } _input = MultipleInput(); _templateName = Context.Field.Alias + " Template"; }
public ActionResponse Execute() { var logger = new MemoryLogger(); var code = 200; var message = "Ok"; foreach (var script in _context.Process.Scripts.Where(s => !s.Global)) { if (script.File != string.Empty) { script.Content = _reader.Read(script.File, new Dictionary <string, string>(), logger); if (logger.Errors().Any()) { code = 500; foreach (var error in logger.Errors()) { message += error + " "; } break; } foreach (var entity in _context.Process.Entities) { if (entity.Script == script.Name && entity.Query == string.Empty && script.Content != string.Empty) { entity.Query = script.Content; } } } } return(new ActionResponse(code, message) { Action = new Transformalize.Configuration.Action { Before = true, After = false, Type = "internal", ErrorMode = "abort", Description = "load script" } }); }
public VelocityTransform(IContext context, IReader reader) : base(context, context.Field.Type) { VelocityInitializer.Init(); var fileBasedTemplate = context.Process.Templates.FirstOrDefault(t => t.Name == context.Transform.Template); if (fileBasedTemplate != null) { var memoryLogger = new MemoryLogger(); context.Transform.Template = reader.Read(fileBasedTemplate.File, null, memoryLogger); if (memoryLogger.Errors().Any()) { foreach (var error in memoryLogger.Errors()) { context.Error(error); } } } _input = MultipleInput(); _templateName = Context.Field.Alias + " Template"; }
public void TestXml() { var xml = @" <cfg> <connections> <add provider='file' file='good.txt' /> <add provider='file' /><!-- bad, missing file --> <add provider='folder' folder='c:\good' /> <add provider='folder' file='bad.txt' /><!-- bad, missing folder --> </connections> </cfg> ".Replace("'", "\""); var anotherLogger = new MemoryLogger(); var cfg = new CustomProblemCfg(xml, anotherLogger); var problems = cfg.Errors(); Assert.AreEqual(3, problems.Length); Assert.IsTrue(problems[0] == "file provider needs file attribute."); Assert.IsTrue(problems[1] == "I don't like c:\\good."); Assert.IsTrue(problems[2] == "folder provider needs folder attribute."); Assert.AreEqual(3, anotherLogger.Errors().Length); }
public string[] Errors() { return(_logger.Errors()); }