internal bool LoadRazorTemplate( string virtualPath, out WebPageBase webPage, out PageTemplateDescriptor parsedTemplate, out IDictionary <string, PropertyInfo> placeholderProperties, out Exception loadingException) { try { webPage = WebPageBase.CreateInstanceFromVirtualPath(virtualPath); } catch (Exception ex) { Log.LogError(LogTitle, "Failed to compile razor file '{0}'", virtualPath); Log.LogError(LogTitle, ex); loadingException = ex is TargetInvocationException ? ex.InnerException : ex; webPage = null; parsedTemplate = null; placeholderProperties = null; return(false); } if (webPage == null || !(webPage is RazorPageTemplate)) { parsedTemplate = null; placeholderProperties = null; loadingException = null; return(true); } RazorPageTemplate razorPageTemplate = webPage as RazorPageTemplate; razorPageTemplate.Configure(); try { ParseTemplate(virtualPath, razorPageTemplate, out parsedTemplate, out placeholderProperties); } catch (Exception ex) { Log.LogError(LogTitle, "Failed to load razor page template '{0}'", virtualPath); Log.LogError(LogTitle, ex); loadingException = ex; parsedTemplate = null; placeholderProperties = null; return(false); } finally { razorPageTemplate.Dispose(); } loadingException = null; return(true); }
private void ParseTemplate(string virtualPath, AspNet.Razor.RazorPageTemplate webPage, out PageTemplateDescriptor templateDescriptor, out IDictionary <string, PropertyInfo> placeholderProperties) { Func <PageTemplateDescriptor> constructor = () => new RazorPageTemplateDescriptor(virtualPath); templateDescriptor = TemplateDefinitionHelper.BuildPageTemplateDescriptor(webPage, constructor, out placeholderProperties); }
private void SetUpTextAreas(bool flush) { Guid selectedTemplateId = this.SelectedTemplateId; PageTemplateDescriptor pageTemplate = PageTemplateFacade.GetPageTemplate(selectedTemplateId); Verify.IsNotNull(pageTemplate, "Failed to get page template by id '{0}'", selectedTemplateId); if (!pageTemplate.IsValid) { throw new InvalidOperationException( "Page template '{0}' contains errors. You can edit the template in the 'Layout' section".FormatWith(selectedTemplateId), pageTemplate.LoadingException); } var handledIds = new List <string>(); ContentsPlaceHolder.Controls.Clear(); foreach (var placeholderDescription in pageTemplate.PlaceholderDescriptions) { string placeholderId = placeholderDescription.Id; if (handledIds.Contains(placeholderId) == false) { var pageTypeContainerClasses = ContainerClassManager.GetPageTypeContainerClasses(this.PageTypeId, placeholderDescription.Id); var allContainerClasses = ContainerClassManager.MergeContainerClasses(placeholderDescription.ContainerClasses, pageTypeContainerClasses); TextBox contentTextBox = new Composite.Core.WebClient.UiControlLib.TextBox(); contentTextBox.TextMode = TextBoxMode.MultiLine; contentTextBox.ID = placeholderId; contentTextBox.Attributes.Add("placeholderid", placeholderId); contentTextBox.Attributes.Add("placeholdername", placeholderDescription.Title); contentTextBox.Attributes.Add("containerclasses", string.Join(",", allContainerClasses)); if (placeholderId == pageTemplate.DefaultPlaceholderId) { contentTextBox.Attributes.Add("selected", "true"); } if (flush) { if (this.NamedXhtmlFragments.ContainsKey(placeholderId)) { contentTextBox.Text = this.NamedXhtmlFragments[placeholderId]; } else { contentTextBox.Text = ""; } } ContentsPlaceHolder.Controls.Add(contentTextBox); handledIds.Add(placeholderId); } } }