public string Render(List <LogItem> logs, string title) { RazorModel model = new RazorModel { CaptureDate = DateTime.UtcNow, TotalDuration = logs.Count == 0 ? TimeSpan.MinValue : logs.Last().ServerTime - logs.First().ServerTime, Title = title, Logs = logs, RequestsCount = logs.Count(l => l is HttpRequestLog) }; #if NET452 RazorEngine <RazorTemplateBase> engine = new RazorEngine <RazorTemplateBase>(); engine.AddAssembly("System.Web.dll"); string html = engine.RenderTemplate(Resources.HtmlLogTemplate, model); return(html ?? engine.ErrorMessage); #else var engine = new RazorLight.RazorLightEngineBuilder() .UseMemoryCachingProvider() .Build(); return(engine.CompileRenderAsync("HtmlLog", Resources.HtmlLogTemplateNetStandard, model).Result); #endif }
public void SendEmailFromTemplate(NotificationTemplateTypes notificationTemplateTypeId, EmailEntity emailEntity) { string emailTo = string.Empty; var host = new RazorEngine <RazorTemplateBase>(); host.AddAssembly("System.Data.dll"); var template = GetTemplate(notificationTemplateTypeId, emailEntity.Culture); object razorContext = GetNotificationRazorContext(notificationTemplateTypeId, emailEntity, out emailTo); string compiledId = host.CompileTemplate(template.MessageTemplate); string message = host.RenderTemplateFromAssembly(compiledId, razorContext); Send(emailTo, template.Subject, message); }