예제 #1
0
        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";
        }
예제 #2
0

        
        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"
                }
            });
        }
예제 #4
0
        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";
        }
예제 #5
0
        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);
        }
예제 #6
0
 public string[] Errors()
 {
     return(_logger.Errors());
 }