static RazorEngineExtension() { Razor.SetTemplateService(new TemplateService(new TemplateServiceConfiguration() { BaseTemplateType = typeof(CustomRazorTemplate <>) })); }
static RazorTemplateHtmlHelper() { var templateConfig = new TemplateServiceConfiguration { Resolver = new DelegateTemplateResolver(name => { var stream = EmbeddedResourceRegistry.ResolveResourceStream(name); using (var reader = new StreamReader(stream)) { var inherits = ""; var sb = new StringBuilder(); while (reader.Peek() > 0) { var readLine = reader.ReadLine(); if (readLine.StartsWith("@model ")) { inherits = ("@inherits FormFactory.RazorEngine.RazorTemplateFormFactoryTemplate<" + readLine.Substring(7) + ">\r\n"); continue; } if (readLine == "@using FormFactory.AspMvc") { sb.AppendLine("@using FormFactory.RazorEngine"); continue; } sb.AppendLine(readLine); } return(inherits + sb.ToString()); } }) }; templateConfig.BaseTemplateType = typeof(RazorTemplateFormFactoryTemplate <>); Razor.SetTemplateService(new TemplateService(templateConfig)); }
public string Render(string template, object data) { string result = null; var config = new TemplateServiceConfiguration() { Resolver = new TemplateResolver() }; config.Namespaces.Add("System.IO"); config.Namespaces.Add("RazorEngine.Text"); using (var service = new TemplateService(config)) { Razor.SetTemplateService(service); var cacheName = template.GetHashCode().ToString(); try { result = Razor.Parse(template, data, cacheName); } catch (TemplateCompilationException e) { foreach (var error in e.Errors) { Console.Error.WriteLine(error); } } } return(result); }
private WebAppServer CreateServer() { var resolver = new WindsorDependencyResolver(_container); var server = new WebAppServer(BaseAddress); server.HttpConfiguration.DependencyResolver = resolver; server.HttpConfiguration.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always; server.HttpConfiguration.Routes.MapHttpRoute( name: "DefaultAPI", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional }); server.HttpConfiguration.Routes.MapHttpRoute( name: "Default", routeTemplate: "{controller}/{action}", defaults: new { controller = "Home", action = "Index" }); //server.HttpConfiguration.MessageHandlers.Add(new FaviconHandler()); server.StaticFiles.Add("/Scripts", typeof(ScriptsLocator)); server.HttpConfiguration.MessageHandlers.Add(new StaticFileHandler("Scripts", "text/javascript")); var templateConfiguration = new TemplateServiceConfiguration(); templateConfiguration.Resolver = new EmbeddedTemplateResolver(typeof(ViewResourceLocator)); templateConfiguration.BaseTemplateType = typeof(CustomTemplateBase <>); Razor.SetTemplateService(new TemplateService(templateConfiguration)); return(server); }
public RazorViewEngine() { var config = new TemplateServiceConfiguration(); var templateService = new TemplateService(config); Razor.SetTemplateService(templateService); }
public static void Configure() { var service = new TemplateService(new TemplateServiceConfiguration { BaseTemplateType = typeof(RazorTemplateBase <>) }); Razor.SetTemplateService(service); }
public RazorViewEngine(Type rootLocatorType) { var config = new TemplateServiceConfiguration(); config.Resolver = new EmbeddedResolver(rootLocatorType); var templateService = new TemplateService(config); Razor.SetTemplateService(templateService); }
static void MWMS_Init() { Sql.connectionString = @"server=" + ConfigurationManager.AppSettings["ServerIP"] + ";uid=" + ConfigurationManager.AppSettings["Username"] + ";pwd=" + ConfigurationManager.AppSettings["Password"] + ";database=" + ConfigurationManager.AppSettings["DataBaseName"] + ";min pool size=10;max pool size=100;connect timeout = 20;pooling=true;"; Razor.SetTemplateService(MWMS.Template.BuildCode.TemplateService); RazorEngine.Razor.Compile("1", typeof(object[]), "_init_temp_code", true); // LoadMetadataReference(); }
public FluentMailer(IFluentMailerMessageBodyCreatorFactory fluentMailerMessageBodyCreatorFactory) { _fluentMailerMessageBodyCreatorFactory = fluentMailerMessageBodyCreatorFactory; var templateConfig = new TemplateServiceConfiguration { BaseTemplateType = typeof(MailerModuleTemplateBase <>), Resolver = new MailerModuleTemplateResolver() }; Razor.SetTemplateService(new TemplateService(templateConfig)); }
/// <summary> /// 删除提示信息: /// RazorEngine: We can't cleanup temp files if you use RazorEngine on the default Appdomain. /// </summary> public static void Init() { //参考地址 //https://github.com/Antaris/RazorEngine/issues/244 // var config = new TemplateServiceConfiguration(); config.DisableTempFileLocking = true; // loads the files in-memory (gives the templates full-trust permissions) config.CachingProvider = new DefaultCachingProvider(t => { }); //disables the warnings // Use the config Engine.Razor = RazorEngineService.Create(config); // new API Razor.SetTemplateService(new TemplateService(config)); // legacy API }
static RazorPageParser() { Singleton = new Lazy <IPageParser>( () => new RazorPageParser(), true); var rconf = new TemplateServiceConfiguration(); rconf.BaseTemplateType = typeof(HtmlTemplateBase <>); rconf.Namespaces.Add("WiGi"); rconf.Namespaces.Add("WiGi.Account"); rconf.Namespaces.Add("WiGi.Wiki"); Razor.SetTemplateService(new TemplateService(rconf)); }
public RazorMailer(string baseDir = null) { baseDir = baseDir ?? GetDefaultBaseDir(); var defaultResolver = new DefaultResolver(baseDir); this.templateResolver = defaultResolver; this.emailResolver = defaultResolver; this.templateService = new TemplateService(new EmailTemplateConfiguration(baseDir) { Resolver = defaultResolver }); Razor.SetTemplateService(templateService); }
public EmailService(NetworkCredential credentials) { Razor.SetTemplateService(new TemplateService(new TemplateServiceConfiguration { Resolver = new DelegateTemplateResolver(name => { using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(string.Format("App.EmailTemplates.{0}.cshtml", name))) using (var reader = new StreamReader(stream)) { return(reader.ReadToEnd()); } }) })); this.credentials = credentials; }
private void RegisterRazor(ILogger logger) { if (TemplateContentType == "html") { return; } if (!Templates.Any() && !GetAllTransforms().Any(t => t.Method == "template" || t.Method == "razor")) { return; } var config = new FluentTemplateServiceConfiguration(c => c.WithEncoding(Encoding.Raw)); var templateService = new TemplateService(config); logger.Debug("Switching RazorEngine content type to raw."); Razor.SetTemplateService(templateService); }
public RazorMailer(string templateDir) { if (string.IsNullOrEmpty(templateDir)) { throw new ApplicationException("No email template path specified in configuration"); } _templateDir = templateDir; if (!Directory.Exists(_templateDir)) { throw new ArgumentException("The templateDir supplied doesn't exist: " + _templateDir); } Razor.SetTemplateService(new TemplateService(new EmailTemplateConfiguration() { Resolver = new TemplateResolver(_templateDir) })); }
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 string Render(string siteKey, string template, dynamic data) { string result = null; var config = new TemplateServiceConfiguration { Resolver = new TemplateResolver(siteKey) }; config.Namespaces.Add("System.IO"); config.Namespaces.Add("RazorEngine.Text"); using (var service = new TemplateService(config)) { Razor.SetTemplateService(service); var cacheName = template.GetHashCode().ToString(CultureInfo.InvariantCulture); try { var pso = data as PSObject; if (pso != null) { data = pso.BaseObject; } result = Razor.Parse(template, data, cacheName); } catch (TemplateCompilationException e) { foreach (var error in e.Errors) { Console.Error.WriteLine(error); } } } return(result); }
public SampleService(bool throwOnStart, bool throwOnStop, bool throwUnhandled, Uri address) { _throwOnStart = throwOnStart; _throwOnStop = throwOnStop; _throwUnhandled = throwUnhandled; if (!EventLog.SourceExists(EventSource)) { EventLog.CreateEventSource(EventSource, "Application"); } EventLog.WriteEntry(EventSource, String.Format("Creating server at {0}", address.ToString())); _config = new HttpSelfHostConfiguration(address); _config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}", new { id = RouteParameter.Optional } ); _config.Routes.MapHttpRoute( "Default", "{controller}/{action}", new { controller = "Home", action = "Index", date = RouteParameter.Optional }); const string viewPathTemplate = "SampleTopshelfService.Views.{0}"; var templateConfig = new TemplateServiceConfiguration(); templateConfig.Resolver = new DelegateTemplateResolver(name => { string resourcePath = string.Format(viewPathTemplate, name); var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourcePath); using (var reader = new StreamReader(stream)) { return(reader.ReadToEnd()); } }); Razor.SetTemplateService(new TemplateService(templateConfig)); _server = new HttpSelfHostServer(_config); }
/// <summary> /// </summary> /// <returns></returns> internal static string ConnectionList() { var fileName = FilePath + "\\ConnectionList.htm"; String content; var stream = new StreamReader(fileName); content = stream.ReadToEnd(); var connectionList = String.Empty; foreach (var item in RuntimeMongoDBContext._mongoConnectionConfigList.Values) { if (item.ReplSetName == String.Empty) { connectionList += "<li><a href = 'Connection?" + item.ConnectionName + "'>" + item.ConnectionName + "@" + (item.Host == String.Empty ? "localhost" : item.Host) + (item.Port == 0 ? String.Empty : ":" + item.Port) + "</a></li>" + Environment.NewLine; } else { connectionList += "<li><a href = 'Connection?" + item.ConnectionName + "'>" + item.ConnectionName + "</a></li>" + Environment.NewLine; } } var config = new TemplateServiceConfiguration(); //config.ReferenceResolver = (IReferenceResolver)((new UseCurrentAssembliesReferenceResolver()).GetReferences(null)); config.Debug = true; var ser = new TemplateService(config); ser.AddNamespace("MongoUtility.Core"); ser.AddNamespace("SystemUtility"); Razor.SetTemplateService(ser); content = Razor.Parse(content, new { SystemConfig.config.ConnectionList }); return(content); }