예제 #1
0
        private string RenderContent() {

            if (Contents.Content.Equals(string.Empty)) {
                _process.Logger.Warn("Template {0} is empty.", Name);
                return string.Empty;
            }

            string renderedContent;
            if (Engine.Equals("velocity")) {
                var context = new VelocityContext();
                context.Put("Process", _process);
                foreach (var parameter in Parameters) {
                    context.Put(parameter.Value.Name, parameter.Value.Value);
                }
                using (var sw = new StringWriter()) {
                    Velocity.Evaluate(context, sw, string.Empty, Contents.Content);
                    renderedContent = sw.GetLifetimeService().ToString();
                }
            } else {
                var config = new FluentTemplateServiceConfiguration(c => c.WithEncoding(ContentType));
                var templateService = new TemplateService(config);
                Razor.SetTemplateService(templateService);

                renderedContent = Razor.Parse(Contents.Content, new {
                    Process = _process,
                    Parameters = Parameters.ToExpandoObject()
                });
            }

            _process.Logger.Debug("Rendered {0} template.", Name);
            return renderedContent;
        }
 public VelocityOperation(string outKey, string outType, string template, IEnumerable<KeyValuePair<string, Template>> templates, IParameters parameters)
     : base(outKey, outType, template, templates, parameters) {
     _context = new VelocityContext();
     Name = "Velocity (" + outKey + ")";
     }