private void ParseExistingTemplateForCopying(Guid templateId, out string codeTemplate, out string folderPath) { var razorTemplate = PageTemplateFacade.GetPageTemplate(templateId) as RazorPageTemplateDescriptor; Verify.IsNotNull(razorTemplate, "Failed to get razor template descriptor by id '{0}'", templateId); var provider = PageTemplateProviderRegistry.GetProviderByTemplateId(templateId) as RazorPageTemplateProvider; Verify.IsNotNull(provider, "Failed to get razor template provider by template id '{0}'", templateId); string fullPath = PathUtil.Resolve(razorTemplate.VirtualPath); string text = C1File.ReadAllText(fullPath); const string quote = @""""; Verify.That(text.IndexOf(templateId.ToString(), StringComparison.OrdinalIgnoreCase) > 0, "Failed to replace existing templateId '{0}'", templateId); text = text.Replace(templateId.ToString(), Marker_TemplateId, StringComparison.OrdinalIgnoreCase); // Replacing title text = text.Replace("@" + quote + razorTemplate.Title.Replace(quote, quote + quote) + quote, quote + Marker_TemplateTitle + quote) .Replace(quote + CSharpEncodeString(razorTemplate.Title) + quote, quote + Marker_TemplateTitle + quote); codeTemplate = text; folderPath = Path.GetDirectoryName(fullPath); }
/// <summary> /// Builds the page renderer. /// </summary> /// <param name="pageTemplateId">The page template id.</param> /// <returns></returns> public static IPageRenderer BuildPageRenderer(Guid pageTemplateId) { var provider = PageTemplateProviderRegistry.GetProviderByTemplateId(pageTemplateId); Verify.IsNotNull(provider, "Failed to get page template with id '{0}'. The template may contain errors preventing it to compile. Check the Orckestra CMS log for possible compilation errors.", pageTemplateId); return(provider.BuildPageRenderer(pageTemplateId)); }
/// <summary> /// Gets the page template. /// </summary> /// <param name="pageTemplateId">The page template id.</param> /// <returns></returns> public static PageTemplateDescriptor GetPageTemplate(Guid pageTemplateId) { var provider = PageTemplateProviderRegistry.GetProviderByTemplateId(pageTemplateId); if (provider == null) { return(null); } return(provider.GetPageTemplates().FirstOrDefault(t => t.Id == pageTemplateId)); }
private void ParseTemplateForCopying( Guid templateId, out string markupTemplate, out string codebehindTemplate, out string templateFolder) { var masterTemplate = PageTemplateFacade.GetPageTemplate(templateId) as MasterPagePageTemplateDescriptor; Verify.IsNotNull(masterTemplate, "Failed to get MasterPagePageTemplateDescriptor by template id '{0}'", templateId); var provider = PageTemplateProviderRegistry.GetProviderByTemplateId(templateId) as MasterPagePageTemplateProvider; Verify.IsNotNull(provider, "Failed to get MasterPagePageTemplateProvider by template id '{0}'", templateId); string markup = C1File.ReadAllText(masterTemplate.FilePath); string codebehind = C1File.ReadAllText(masterTemplate.CodeBehindFilePath); string codebehindFileName = Path.GetFileName(masterTemplate.CodeBehindFilePath); // Parsing markup markup = markup.Replace(codebehindFileName, Marker_Codebehind); // Parsing codebehind const string quote = @""""; Verify.That(codebehind.IndexOf(templateId.ToString(), StringComparison.OrdinalIgnoreCase) > 0, "Failed to replace existing templateId '{0}'", templateId); codebehind = codebehind.Replace(templateId.ToString(), Marker_TemplateId, StringComparison.OrdinalIgnoreCase); // Replacing title, considering 2 types of encoding codebehind = codebehind.Replace("@" + quote + masterTemplate.Title.Replace(quote, quote + quote) + quote, quote + Marker_TemplateTitle + quote); codebehind = codebehind.Replace(quote + CSharpEncodeString(masterTemplate.Title) + quote, quote + Marker_TemplateTitle + quote); markupTemplate = markup; codebehindTemplate = codebehind; templateFolder = Path.GetDirectoryName(masterTemplate.CodeBehindFilePath); }