private void AssertAllViewsInAssemblyCanBeCompiled(Assembly assembly) { var config = new TemplateServiceConfiguration(); config.BaseTemplateType = typeof(MvcTemplateBase <>); var processor = new TemplateService(config); var resourceNames = assembly.GetManifestResourceNames(); foreach (var resource in resourceNames) { if (resource.EndsWith(".cshtml", StringComparison.OrdinalIgnoreCase)) { var content = this.GetEmbeddedViewContent(resource, assembly); // The namespace for ChildActionExtensions processor.AddNamespace("System.Web.Mvc"); processor.AddNamespace("System.Web.Mvc.Html"); processor.AddNamespace("System.Web"); this.AssertViewCanBeCompiled(content, resource, processor); } } processor.Dispose(); }
/// <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; }
private static void AddDefaultNamespacesFromWebConfig(TemplateService templateService) { var webConfigPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Web.config"); if (!File.Exists(webConfigPath)) { return; } var fileMap = new ExeConfigurationFileMap() { ExeConfigFilename = webConfigPath }; var configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None); var razorConfig = configuration.GetSection("system.web.webPages.razor/pages") as RazorPagesSection; if (razorConfig == null) { return; } foreach (NamespaceInfo namespaceInfo in razorConfig.Namespaces) { templateService.AddNamespace(namespaceInfo.Namespace); } }
private static ITemplateService GetTemplateService(ViewEngineElement conf) { var ts = new TemplateService(); foreach (NamespaceElement ns in conf.Namespaces) { ts.AddNamespace(ns.Namespace); } return(ts); }
/// <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); }
public RoomMiddleware(AppFunc next, string path) { _next = next; _pathString = new PathString(path); _templateService.AddNamespace("ImageChat"); _room = (new Room(Program.Host, "http://deliver.commons.nicovideo.jp/thumbnail/nc19665?size=l")); _notifyAll.Subscribe(data => { var chatText = JsonConvert.DeserializeObject <ChatText>(data.Text); _room.Texts.Enqueue(chatText); while (_room.Texts.Count > 100) { _room.Texts.Dequeue(); } }); }
static void Main() { string dirsrc = Directory.GetCurrentDirectory(); Directory.SetCurrentDirectory(Path.Combine(dirsrc, @"..\BBQ")); using (var service = new TemplateService()) { service.AddNamespace("test_RazorHandy"); service.GetTemplate(File.ReadAllText(@".\Views\Shared\_L.cshtml"), null, "~/Views/Shared/_L.cshtml"); var result = service.Parse(File.ReadAllText(@".\Views\bbq\Index.cshtml"), new { }, null, "page"); Directory.SetCurrentDirectory(dirsrc); File.WriteAllText(@".\BBQ_static\index.html", result); } }
private string GenerateHtml(IEnumerable <ContentType> contentTypes, IEnumerable <Module> modules) { var contentTypeFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Views", "ContentType.cshtml"); var moduleFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Views", "Module.cshtml"); var finalDocumentFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Views", "FinalDocument.cshtml"); var templateService = new TemplateService(); templateService.AddNamespace("uSyncScrapper.Models"); var contentTypeBody = new StringBuilder(); var modulesBody = new StringBuilder(); foreach (var contentType in contentTypes) { contentTypeBody.Append(templateService.Parse(File.ReadAllText(contentTypeFilePath), contentType, null, "ContentType")); } foreach (var module in modules) { modulesBody.Append(templateService.Parse(File.ReadAllText(moduleFilePath), module, null, "Module")); } var finalDocType = new FinalDocument { DocTypesBody = contentTypeBody.ToString(), DocTypes = contentTypes, ModulesBody = modulesBody.ToString(), Modules = modules }; var finalDocument = templateService.Parse(File.ReadAllText(finalDocumentFilePath), finalDocType, null, "FinalDocument"); return(WebUtility.HtmlDecode(finalDocument)); }
static RazorService() { var templateService = new TemplateService(); List <string> nameSpaces = "Panasia.Core|Panasia.Core.Contents|Panasia.Core.App|Panasia.Core.Commands|Panasia.Core.Sys|Panasia.Core.Web" .Split('|').ToList(); var imports = ApplicationConfig.GetAppSettingValue("RazorImports", ""); if (!string.IsNullOrEmpty(imports)) { imports.Split('|').ForEach((ns) => { var item = ns.Trim().TrimEnd(';'); if (!nameSpaces.Contains(item)) { nameSpaces.Add(item); } }); } //ApplicationConfig.GetAppSettingValue("RazorImports","") // .Split('|').ForEach((ns) => // { // var item = ns.Trim().TrimEnd(';'); // if(!nameSpaces.Contains(item)) // { // nameSpaces.Add(item); // } // }); nameSpaces.ForEach((ns) => { templateService.AddNamespace(ns.Trim().TrimEnd(';')); }); RazorEngine.Razor.SetTemplateService(templateService); }
/// <summary> /// Add the namespaces found in the ASP.NET MVC configuration section of the Web.config file to the provided TemplateService instance. /// </summary> private static void AddDefaultNamespacesFromWebConfig(TemplateService templateService) { var webConfigPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Web.config"); if (!File.Exists(webConfigPath)) return; var fileMap = new ExeConfigurationFileMap() { ExeConfigFilename = webConfigPath }; var configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None); var razorConfig = configuration.GetSection("system.web.webPages.razor/pages") as RazorPagesSection; if (razorConfig == null) return; foreach (NamespaceInfo namespaceInfo in razorConfig.Namespaces) { templateService.AddNamespace(namespaceInfo.Namespace); } }
private void AssertAllViewsInAssemblyCanBeCompiled(Assembly assembly) { var config = new TemplateServiceConfiguration(); config.BaseTemplateType = typeof(MvcTemplateBase<>); var processor = new TemplateService(config); var resourceNames = assembly.GetManifestResourceNames(); foreach (var resource in resourceNames) { if (resource.EndsWith(".cshtml", StringComparison.OrdinalIgnoreCase)) { var content = this.GetEmbeddedViewContent(resource, assembly); // The namespace for ChildActionExtensions processor.AddNamespace("System.Web.Mvc.Html"); processor.AddNamespace("System.Web"); this.AssertViewCanBeCompiled(content, resource, processor); } } processor.Dispose(); }