private ITemplateDeleter GetPageTemplateDeleter(EntityToken entityToken) { if (entityToken is DataEntityToken) { return(new XmlPageTemplateDeleter(entityToken as DataEntityToken)); } if (entityToken is PageTemplateEntityToken) { Guid pageTemplateId = (entityToken as PageTemplateEntityToken).TemplateId; var pageTemplateDescriptor = PageTemplateFacade.GetPageTemplate(pageTemplateId); if (pageTemplateDescriptor is RazorPageTemplateDescriptor) { return(new RazorPageTemplateDeleter(pageTemplateDescriptor as RazorPageTemplateDescriptor)); } if (pageTemplateDescriptor is MasterPagePageTemplateDescriptor) { return(new MasterPagePageTemplateDeleter(pageTemplateDescriptor as MasterPagePageTemplateDescriptor)); } throw new NotSupportedException("Not supported page template descriptor type '{0}'" .FormatWith(pageTemplateDescriptor.GetType().FullName)); } throw new NotSupportedException("Not supported entity token type '{0}'".FormatWith(entityToken.GetType().FullName)); }
public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection) { var path = httpContext.Request.Path; var pageUrlData = PageUrls.ParseUrl(path); if (pageUrlData == null) { return(false); } using (new DataScope(pageUrlData.PublicationScope, pageUrlData.LocalizationScope)) { var page = PageManager.GetPageById(pageUrlData.PageId); if (!_templateIds.Contains(page.TemplateId)) { return(false); } var template = PageTemplateFacade.GetPageTemplate(page.TemplateId) as MvcPageTemplateDescriptor; return(template != null); } }
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); }
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); } } }
private void editPreviewCodeActivity_ExecuteCode(object sender, EventArgs e) { try { XhtmlDocument templateDocument = GetTemplateDocumentFromBindings(); IVisualFunction function = this.GetBinding <IVisualFunction>("Function"); Type interfaceType = TypeManager.GetType(function.TypeManagerName); DataTypeDescriptor typeDescriptor = DynamicTypeManager.GetDataTypeDescriptor(interfaceType); this.LogMessage(Composite.Core.Logging.LogLevel.Info, DataScopeManager.CurrentDataScope.Name); FunctionContextContainer fcc = PageRenderer.GetPageRenderFunctionContextContainer(); XhtmlDocument result = RenderingHelper.RenderCompleteDataList(function, templateDocument, typeDescriptor, fcc); IPage previewPage = DataFacade.BuildNew <IPage>(); previewPage.Id = GetRootPageId(); previewPage.Title = function.Name; previewPage.DataSourceId.DataScopeIdentifier = DataScopeIdentifier.Administrated; previewPage.DataSourceId.LocaleScope = LocalizationScopeManager.CurrentLocalizationScope; previewPage.TemplateId = this.GetBinding <Guid>("PreviewTemplateId"); var pageTemplate = PageTemplateFacade.GetPageTemplate(previewPage.TemplateId); IPagePlaceholderContent placeHolderContent = DataFacade.BuildNew <IPagePlaceholderContent>(); placeHolderContent.Content = string.Concat((result.Body.Elements().Select(b => b.ToString())).ToArray()); placeHolderContent.PlaceHolderId = pageTemplate.DefaultPlaceholderId; string output = PagePreviewBuilder.RenderPreview(previewPage, new List <IPagePlaceholderContent> { placeHolderContent }); var serviceContainer = WorkflowFacade.GetFlowControllerServicesContainer(WorkflowEnvironment.WorkflowInstanceId); var webRenderService = serviceContainer.GetService <IFormFlowWebRenderingService>(); webRenderService.SetNewPageOutput(new LiteralControl(output)); } catch (Exception ex) { FlowControllerServicesContainer serviceContainer = WorkflowFacade.GetFlowControllerServicesContainer(WorkflowEnvironment.WorkflowInstanceId); Control errOutput = new LiteralControl("<pre>" + ex + "</pre>"); var webRenderService = serviceContainer.GetService <IFormFlowWebRenderingService>(); webRenderService.SetNewPageOutput(errOutput); } }
protected override void OnActionExecuting(ActionExecutingContext filterContext) { var pageUrlData = PageUrls.ParseUrl(HttpContext.Request.Path); if (pageUrlData == null) { return; } C1PageRoute.PageUrlData = pageUrlData; _mvcContext = new MvcRenderingContext(ControllerContext); var page = PageRenderer.CurrentPage; ViewData.Add("C1PreviewContent", HttpContext.Items["C1PreviewContent"]); _template = PageTemplateFacade.GetPageTemplate(page.TemplateId) as MvcPageTemplateDescriptor; if (_template == null) { throw new InvalidOperationException(String.Format("The pagetemplate '{0}' is not a valid mvc template", page.TemplateId)); } var templateModel = Activator.CreateInstance(_template.TypeInfo.Item1); if (_template.PlaceholderDescriptions != null && _template.PlaceholderDescriptions.Any()) { foreach (var placeholder in _template.PlaceholderDescriptions) { var name = placeholder.Id; var prop = _template.TypeInfo.Item2[name]; var content = GetPlaceholderContent(name); BindPlaceholder(templateModel, prop, content); } } ViewData.Add("TemplateModel", templateModel); base.OnActionExecuting(filterContext); }
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); }
static void app_PostMapRequestHandler(object sender, EventArgs e) { var ctx = ((HttpApplication)sender).Context; var handler = ctx.CurrentHandler as Page; if (handler == null) { return; } handler.Load += (o, args) => { var c1Page = PageRenderer.CurrentPage; if (c1Page != null) { var template = PageTemplateFacade.GetPageTemplate(c1Page.TemplateId); var title = template.Title; NewRelicAgent.SetTransactionName("C1 Page", title); } else { var adminPath = UrlUtils.AdminRootPath; var requestPath = ctx.Request.Url.LocalPath; if (!requestPath.StartsWith(adminPath, StringComparison.OrdinalIgnoreCase)) { return; } var newRelic = handler.Request.QueryString["newrelic"]; if (newRelic == null || !newRelic.Equals("true")) { NewRelicAgent.DisableBrowserMonitoring(true); } } }; }
public override RouteData GetRouteData(HttpContextBase httpContext) { var path = httpContext.Request.Path; var pageUrlData = PageUrls.ParseUrl(path); if (pageUrlData == null) { return(null); } using (new DataScope(pageUrlData.PublicationScope, pageUrlData.LocalizationScope)) { var page = PageManager.GetPageById(pageUrlData.PageId); var templateIds = PageTemplateFacade.GetPageTemplates().OfType <MvcPageTemplateDescriptor>().Select(t => t.Id); if (!templateIds.Contains(page.TemplateId)) { return(null); } var template = PageTemplateFacade.GetPageTemplate(page.TemplateId) as MvcPageTemplateDescriptor; if (template == null) { return(null); } } return(new RouteData(this, new MvcRouteHandler()) { Values = { { "controller", _controller.ControllerName }, { "action", "Get" } } }); }