void SkinnedEndPoint_SkinPage(object sender, EndPointEventArgs e) { //Setup needed objects SkinnedEndPoint ep = (SkinnedEndPoint)sender; BASEApplication app = (BASEApplication)HttpContext.Current.ApplicationInstance; //Used to indicate if the default region for a page has been merged yet. bool defaultAdded = false; //Get template chunks for sites template. //Find the Region panel. //TODO: Add in more comprehensive checking for valid sites, default system site, etc. SiteVirtualInfoEntity site = BASE.Data.Helpers.SiteVirtualInfoDataHelper.SelectSingle(app.BASERequest.SiteUID); if (site == null) { throw new PageSkinningException("A Default site is required to skin a page with a template"); } //TODO: Add in checks for a valid TemplateGUid EntityCollection <TemplateChunksEntity> chunks = TemplateChunkDataHelper.Select(site.TemplateGUID.Value, true); List <HtmlChunk> htmlchunks = new HtmlParser().ParseToChunks(chunks, "bml"); Control[] controls = new HtmlParser().ParseToControls(ep, htmlchunks, "bml"); foreach (RegionPanel reg in ep.RegionPanels.Values) { ep.Form.Controls.Remove(reg); } foreach (Control c in controls) { if (c is RegionPlaceHolder) { RegionPlaceHolder plc = (RegionPlaceHolder)c; foreach (RegionPanel reg in ep.RegionPanels.Values) { //Make sure that we have a matching ID for proper merging of regions. if (reg.RegionID == plc.RegionID) { plc.AddRegionPanel(reg); } } //TODO We need to figure a way to Log any regions that are orphaned and never merge. } ep.Form.Controls.Add(c); } }
public Control[] CreateControls(Page page, List <HtmlChunk> chunks) { List <System.Web.UI.Control> controls = new List <System.Web.UI.Control>(); foreach (HtmlChunk chunk in chunks) { switch (chunk.ChunkType) { case HtmlChunkType.Tag: //This is a tag for a custom control controls.Add(TagParser.ParseTag(page, (HtmlTag)chunk)); //TODO: Change Tag System!!! break; case HtmlChunkType.Region: //make sure its a base:Region! //TODO: Make sure we pass the attributes somehow so that we can merge properly BmlRegion region = (BmlRegion)chunk; RegionPlaceHolder plc = new RegionPlaceHolder(); //Set the Region ID for any merging that may take place at a later stage plc.RegionID = region.Id; //optionally add innertext if any if (region.IsSelfClosing) { //TODO: Add content if any } //This is a tag for a custom control controls.Add(plc); break; case HtmlChunkType.Literal: System.Web.UI.WebControls.Literal lit = new System.Web.UI.WebControls.Literal(); lit.Text = chunk.Value; controls.Add(lit); break; default: throw new BASEGenericException("Invalid Chunk"); break; } } return(controls.ToArray()); }