public string Process(string template, string name, DisplayContext context = null, dynamic model = null)
        {
            try
            {
                var renderingContext = new TemplateRenderingContext
                {
                    TemplateType = TemplateType.TemplateContentItem,
                    TemplatePath = name
                };

                return _templateService.ExecuteTemplate(template, model, renderingContext);
            }
            catch (Exception ex)
            {
                if (ex.IsFatal()) throw;

                Logger.Error(ex, "An unexpected exception was caught during rendering the \"" + name + "\" Liquid template.");

                var reportActivityName = T("Liquid template errors: {0} shape", name).Text;

                var liquidReport = _reportsManager
                    .GetReports().FirstOrDefault(report => report.ActivityName == reportActivityName);

                var liquidReportId = liquidReport == null
                    ? _reportsManager
                        .CreateReport(
                            T("Errors caught in the Liquid template of the {0} shape.", name).Text,
                            reportActivityName)
                    : liquidReport.ReportId;

                _reportsManager.Add(liquidReportId, ReportEntryType.Error, ex.Message);

                return T("<strong style=\"color:red;font-weight:bold;\">An unexpected exception was caught during rendering \"{0}\" Liquid template. {1}</strong>", name, ex.Message).Text;
            }
        }
Esempio n. 2
0
        public void Render(ViewContext context, TextWriter writer)
        {
            var filename = context.HttpContext.Server.MapPath(ViewPath);

            var renderingContext = new TemplateRenderingContext
            {
                TemplateType = TemplateType.TemplateFile,
                TemplatePath = ViewPath
            };

            var output = _liquidTemplateService.ExecuteTemplate(File.ReadAllText(filename), context.ViewData.Model, renderingContext);
            writer.Write(output);
        }