private const int APPEND = -1; //mark the index so it appends to the container protected int AddTemplateToContainer(IPDFContainerComponent container, int index, IPDFTemplate template) { int count = 0; IEnumerable <IPDFComponent> generated = template.Instantiate(index, container); foreach (IPDFComponent comp in generated) { Component actual = comp as Component; if (null != actual) { if (index >= 0 && index < container.Content.Count) { container.Content.Insert(index, actual); } else { container.Content.Add(actual); } count++; } if (comp is IPDFBindableComponent) { ((IPDFBindableComponent)comp).DataBinding += PDFDataGridTemplateColumn_DataBinding; } } return(count); }
protected override void DoDataBindToContainer(PDFDataContext context, IPDFContainerComponent container) { if (this.Test && this.Visible) { base.DoDataBindToContainer(context, container); } }
/// <summary> /// Lays out all the contents of the list item in the current itemblock and returns the used height of the /// components it has laid out. /// </summary> /// <param name="entry"></param> /// <returns></returns> private PDFUnit LayoutItemContent(ListNumberEntry entry) { ComponentList contents = null; IPDFContainerComponent container = entry.ListItem as IPDFContainerComponent; PDFUnit avail = _itemblock.CurrentRegion.AvailableHeight; if (container.HasContent) { //because we are mimicing being the container - set the full style to the item style Style last = this.FullStyle; this.FullStyle = entry.FullStyle; contents = container.Content; this.DoLayoutChildren(contents); //And restore the full style to the previous item after. this.FullStyle = last; } this._itemblock.CurrentRegion.CloseCurrentItem(); // Calculate the height used and return PDFUnit newAvail = _itemblock.CurrentRegion.AvailableHeight; PDFUnit used = avail - newAvail; return(used); }
/// <summary> /// Inserts a new Component in the container /// </summary> /// <param name="container"></param> /// <param name="index"></param> /// <param name="ele"></param> private void InsertComponentInContainer(IPDFContainerComponent container, int index, IPDFComponent ele, PDFInitContext init, PDFLoadContext load) { ele.Init(init); IPDFComponentList list = container.Content as IPDFComponentList; list.Insert(index, ele); _addedonbind.Add(ele); ele.Load(load); }
/// <summary> /// Removes any previously bound Components /// </summary> /// <param name="all"></param> /// <param name="container"></param> private void ClearPreviousBoundComponents(ICollection <IPDFComponent> all, IPDFContainerComponent container) { //dispose and clear foreach (Component ele in all) { container.Content.Remove(ele); ele.Dispose(); } all.Clear(); }
private bool ShowEmptyTemplate(IPDFContainerComponent container, int index, PDFDataContext context) { if (null == this.EmptyTemplate) { return(false); } else { this.InstantiateAndAddWithTemplate(this.EmptyTemplate, 0, index, container, context); return(true); } }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <param name="container"></param> protected virtual void DoDataBindToContainer(PDFDataContext context, IPDFContainerComponent container) { //If we have a template and should be binding on it int oldindex = context.CurrentIndex; int index = container.Content.IndexOf(this); DoBindDataIntoContainer(container, index, context); _toparent = container; context.CurrentIndex = oldindex; }
protected virtual void ParseHtmlContents(string source, string html, IPDFContainerComponent container, int insertIndex) { HTMLParserSettings settings = GetParserSettings(); if (this.Format == HtmlFormatType.Markdown) { Markdown md = new Markdown(); html = md.Transform(html); } HTMLParser parser = new HTMLParser(html, settings); Stack <IPDFComponent> route = new Stack <IPDFComponent>(); IPDFComponentList contents = container.Content; //int codeDepth = 0; foreach (Scryber.Html.Parsing.HTMLParserResult result in parser) { if (result.Valid && null != result.Parsed) { IPDFComponent parsed = result.Parsed; if (result.IsEnd) { route.Pop(); } else { if (route.Count == 0) { _added.Add(parsed); contents.Insert(insertIndex, parsed); insertIndex++; if (parsed is IPDFLoadableComponent) { ((IPDFLoadableComponent)parsed).LoadedSource = source; } } else { IPDFContainerComponent parent = (IPDFContainerComponent)route.Peek(); ((IPDFComponentList)parent.Content).Add(parsed); } route.Push(result.Parsed); } } } }
// // methods // /// <summary> /// Main override so that the data can be bound to the any templates /// </summary> /// <param name="context"></param> /// <param name="includeChildren"></param> protected override void DoDataBind(PDFDataContext context, bool includeChildren) { if (_addedonbind != null && _addedonbind.Count > 0) { this.ClearPreviousBoundComponents(_addedonbind, _toparent); } else if (null == _addedonbind) { _addedonbind = new List <IPDFComponent>(); } //call the base method first base.DoDataBind(context, includeChildren); if (includeChildren) { IPDFContainerComponent container = GetContainerParent(); DoDataBindToContainer(context, container); } }
/// <summary> /// /// </summary> /// <param name="container"></param> /// <param name="containerposition"></param> /// <param name="template"></param> /// <param name="context"></param> protected override void DoBindDataIntoContainer(IPDFContainerComponent container, int containerposition, PDFDataContext context) { int prevcount = context.CurrentIndex; PDFDataStack stack = context.DataStack; object origData = stack.HasData ? stack.Current : null; IPDFDataSource source = stack.HasData ? stack.Source : null; foreach (WithField fld in this.Fields) { this.BindingActions.Add(origData, source, fld); } if (this.AutoBindContent != DataAutoBindContent.None) { this.AddAutoBindFields(origData, source, context); } this.BindActionedComponents(this.BindingActions, context); }
public static void AddDataContent(this ContainerComponent container, string dataContent, PDFContextBase context) { var found = GetDataContent(container, dataContent, context); if (null == found) { return; } var content = found.Instantiate(0, container); if (null != content) { IPDFContainerComponent icontainer = container; foreach (var item in content) { if (item is Component) { icontainer.Content.Add((Component)item); } } } }
protected virtual void EnsureContentsParsed(PDFContextBase context, bool performload) { if (_parsed) { return; } IPDFContainerComponent container = this.GetContainerParent(); int index = container.Content.IndexOf(this); try { if (_added != null && _added.Count > 0) { foreach (IPDFComponent prev in _added) { container.Content.Remove(prev as Component); } _added.Clear(); } } catch (Exception ex) { throw new PDFParserException("The previousl parsed components could not be removed from the parent container. See the inner exception for more details.", ex); } string fullpath = string.Empty; try { if (!string.IsNullOrEmpty(this.Source)) { fullpath = this.MapPath(this.Source); if (Uri.IsWellFormedUriString(fullpath, UriKind.Absolute)) { using (System.Net.WebClient wc = new System.Net.WebClient()) { this._contentsAsString = wc.DownloadString(fullpath); } } else { this._contentsAsString = System.IO.File.ReadAllText(fullpath); if (this.UnEncode) { this._contentsAsString = System.Web.HttpUtility.HtmlDecode(this._contentsAsString); } } } else if (null != this.XHTMLContents) { fullpath = "HTMLFragment.Contents"; _contentsAsString = this.XHTMLContents.OuterXml; } else if (!string.IsNullOrEmpty(this.RawContents)) { _contentsAsString = this.RawContents; if (this.UnEncode) { this._contentsAsString = System.Web.HttpUtility.HtmlDecode(this._contentsAsString); } } } catch (Exception ex) { throw new PDFParserException("Could not download the required html contents from the specified source: " + fullpath, ex); } if (!string.IsNullOrEmpty(this._contentsAsString)) { if (null == this._added) { _added = new List <IPDFComponent>(); } try { this.ParseHtmlContents(fullpath, this._contentsAsString, container, index); } catch (Exception ex) { throw new PDFParserException("The Html reader could not parse the Html contents from the specified source: " + fullpath, ex); } if (_added.Count > 0) { //Need to do the initialization for each of the items. PDFInitContext initContext = new PDFInitContext(context.Items, context.TraceLog, context.PerformanceMonitor, this.Document); for (int i = 0; i < _added.Count; i++) { _added[i].Init(initContext); } //If the load even has already happened then we need to execute the load event //for each of the relevant items that were added. if (performload) { PDFLoadContext loadContext = new PDFLoadContext(context.Items, context.TraceLog, context.PerformanceMonitor, this.Document); for (int i = 0; i < _added.Count; i++) { IPDFComponent comp = _added[i]; if (comp is VisualComponent) { (comp as VisualComponent).Load(loadContext); } } } } } _parsed = true; }
/// <summary> /// /// </summary> /// <param name="container"></param> /// <param name="containerposition"></param> /// <param name="template"></param> /// <param name="context"></param> protected virtual void DoBindDataIntoContainer(IPDFContainerComponent container, int containerposition, PDFDataContext context) { int prevcount = context.CurrentIndex; PDFDataStack stack = context.DataStack; object data = stack.HasData ? context.DataStack.Current : null; IPDFDataSource source = stack.HasData ? context.DataStack.Source : null; int count = 0; int added = 0; IEnumerator enumerator = null; if (CanEnumerate(data)) { if (context.ShouldLogDebug) { context.TraceLog.Begin(TraceLevel.Verbose, "Binding Template", "Starting to bind enumerable data into container " + this.ID); } IEnumerable ienum = data as IEnumerable; enumerator = this.CreateEnumerator(ienum); while (enumerator.MoveNext()) { context.CurrentIndex = count; context.DataStack.Push(enumerator.Current, source); int number = 0; IPDFTemplate template = this.GetTemplateForBinding(context, count, added + containerposition); if (null != template) { number = InstantiateAndAddWithTemplate(template, count, added + containerposition, container, context); } context.DataStack.Pop(); if (context.ShouldLogDebug) { context.TraceLog.Add(TraceLevel.Debug, "Binding Template", "Bound data into template index : " + count + " and added " + number + " components"); } count++; added += number; } if (count == 0) { context.TraceLog.Add(TraceLevel.Message, "Binding Template", "ZERO items were data bound with the Binding Template Component as MoveNext returned false from the start"); } if (context.ShouldLogDebug) { context.TraceLog.End(TraceLevel.Verbose, "Binding Template", "Completed binding enumerable data into Binding Template Component, " + added + " components added, with " + count + " enumerable data items"); } else if (context.ShouldLogVerbose) { context.TraceLog.Add(TraceLevel.Verbose, "Binding Template", "Completed binding enumerable data into Binding Template Component, " + added + " components added, with " + count + " enumerable data items"); } } else if (data != null) { if (context.ShouldLogDebug) { context.TraceLog.Begin(TraceLevel.Verbose, "Binding Template", "Starting to bind single data into Binding Template Component"); } context.CurrentIndex = 1; context.DataStack.Push(data, source); IPDFTemplate template = this.GetTemplateForBinding(context, count, added + containerposition); if (null != template) { added += InstantiateAndAddWithTemplate(template, count, added + containerposition, container, context); } context.DataStack.Pop(); if (context.ShouldLogDebug) { context.TraceLog.End(TraceLevel.Verbose, "Binding Template", "Completed binding single data into the Binding Template Component, " + added + " components added."); } else if (context.ShouldLogVerbose) { context.TraceLog.Add(TraceLevel.Verbose, "Binding Template", "Completed binding single data into the Binding Template Component, " + added + " components added."); } } else { if (context.ShouldLogDebug) { context.TraceLog.Begin(TraceLevel.Verbose, "Binding Template", "Starting to bind into Binding Template Component with NO context data"); } context.CurrentIndex = 1; IPDFTemplate template = this.GetTemplateForBinding(context, count, added + containerposition); if (null != template) { added += InstantiateAndAddWithTemplate(template, count, added + containerposition, container, context); } if (context.ShouldLogDebug) { context.TraceLog.End(TraceLevel.Verbose, "Binding Template", "Completed binding the Binding Template Component with NO data, " + added + " components added."); } else if (context.ShouldLogVerbose) { context.TraceLog.Add(TraceLevel.Verbose, "Binding Template", "Completed binding the Binding Template Component with NO data, " + added + " components added."); } } context.CurrentIndex = prevcount; }
/// <summary> /// Creates a new instance of the template and adds it to this components content /// </summary> /// <param name="context"></param> /// <param name="count"></param> /// <param name="index"></param> /// <param name="container"></param> /// <param name="template"></param> /// <returns></returns> protected virtual int InstantiateAndAddWithTemplate(IPDFTemplate template, int count, int index, IPDFContainerComponent container, PDFDataContext context) { if (null == template) { return(0); } PDFInitContext init = GetInitContext(context); PDFLoadContext load = GetLoadContext(context); IEnumerable <IPDFComponent> created = template.Instantiate(count, this); int added = 0; if (created != null) { foreach (IPDFComponent ele in ((IEnumerable)created)) { InsertComponentInContainer(container, index, ele, init, load); if (ele is IPDFBindableComponent) { ((IPDFBindableComponent)ele).DataBind(context); } index++; added++; //raise the event this.OnItemDataBound(context, ele); } } return(added); }
/// <summary> /// /// </summary> /// <param name="container"></param> /// <param name="containerposition"></param> /// <param name="template"></param> /// <param name="context"></param> protected virtual void DoBindDataIntoContainer(IPDFContainerComponent container, int containerposition, PDFDataContext context) { }
public void InstantiateTemplate(IPDFTemplate template, PDFLayoutContext context, PDFRect available, int pageindex) { if (null == template) { throw new ArgumentNullException("template"); } if (null == context) { throw new ArgumentNullException("context"); } List <IPDFComponent> generated = new List <IPDFComponent>(template.Instantiate(GeneratedCount, this)); if (generated.Count == 0) { return; } PDFInitContext init = new PDFInitContext(context.Items, context.TraceLog, context.PerformanceMonitor, this.Document) { Compression = context.Compression, OutputFormat = context.OutputFormat, Conformance = context.Conformance }; PDFLoadContext load = new PDFLoadContext(context.Items, context.TraceLog, context.PerformanceMonitor, this.Document) { Compression = context.Compression, OutputFormat = context.OutputFormat, Conformance = context.Conformance }; PDFDataContext data = new PDFDataContext(context.Items, context.TraceLog, context.PerformanceMonitor, this.Document) { Compression = context.Compression, OutputFormat = context.OutputFormat, Conformance = context.Conformance }; IPDFContainerComponent container = this; IPDFComponentList components = container.Content as IPDFComponentList; for (int index = 0; index < generated.Count; index++) { IPDFComponent comp = generated[index]; components.Insert(index, comp); comp.Init(init); } foreach (IPDFComponent comp in generated) { comp.Load(load); } foreach (IPDFComponent comp in generated) { if (comp is IPDFBindableComponent) { (comp as IPDFBindableComponent).DataBind(data); } } this.GeneratedCount++; }
protected override void DoBindDataIntoContainer(IPDFContainerComponent container, int containerposition, PDFDataContext context) { IPDFDataSource origSource = context.DataStack.Source; object origData = context.DataStack.Pop(); object parentData = null; if (context.DataStack.HasData) { parentData = context.DataStack.Current; } Style applied = this.GetAppliedStyle(); applied = applied.Flatten(); IEnumerator enumerator = this.GetDataEnumerator(origData); if (this.AutoBindContent != DataAutoBindContent.None) { this.AddAutoBindColumns(context); } TableGrid grid = new TableGrid(); container.Content.Add(grid); if (this.HasStyle && this.Style.HasValues) { this.Style.MergeInto(grid.Style, Style.DirectStylePriority); } if (!string.IsNullOrEmpty(this.StyleClass)) { grid.StyleClass = this.StyleClass; } if (this.HasOutline) { grid.Outline = this.Outline; } this.ApplyCellStyles(); int colindex = 0; int rowindex = -1; this._bindingActions = new List <BindingActionList>(); if (this.ShouldBuildHeader()) { TableHeaderRow header = new TableHeaderRow(); grid.Rows.Add(header); BindingActionList headBind = new BindingActionList(); this.BindingActions.Add(headBind); //Add the columns foreach (DataGridColumn column in this.Columns) { if (column.Visible == false) { continue; } Component comp = column.DoBuildHeaderCell(grid, header, rowindex, colindex, context); if (null != comp && null != parentData) { headBind.Add(new BindingAction(parentData, origSource, comp)); } colindex++; } rowindex++; } while (enumerator.MoveNext()) { colindex = 0; TableRow row = new TableRow(); grid.Rows.Add(row); BindingActionList rowBind = new BindingActionList(); this.BindingActions.Add(rowBind); foreach (DataGridColumn column in this.Columns) { if (column.Visible == false) { continue; } Component comp = column.DoBuildItemCell(grid, row, rowindex, colindex, context); if (null != comp) { rowBind.Add(new BindingAction(enumerator.Current, origSource, comp)); } colindex++; } rowindex++; } colindex = 0; if (this.ShouldBuildFooter()) { TableFooterRow footer = new TableFooterRow(); grid.Rows.Add(footer); BindingActionList footBind = new BindingActionList(); this.BindingActions.Add(footBind); foreach (DataGridColumn column in this.Columns) { if (column.Visible == false) { continue; } Component comp = column.DoBuildFooterCell(grid, footer, rowindex, colindex, context); if (null != comp && null != parentData) { footBind.Add(new BindingAction(parentData, origSource, comp)); } colindex++; } } context.DataStack.Push(origData, origSource); this.InitAndLoadRoot(grid, context); this.BindActionedComponents(this.BindingActions, context); bool allhidden = RemoveHiddenColumns(context); if (allhidden || grid.Rows.Count == 0) { grid.Visible = false; this.ShowEmptyTemplate(container, containerposition, context); } this.RemoveHeadersAndFooters(grid, context); _built = grid; }