protected override IPDFTemplate GetTemplateForBinding(PDFDataContext context, int index, int count) { //If we are not visible then don't do anything and return null if (this.Visible == false) { return(null); } IPDFTemplate tempate = null; bool found = false; foreach (ChooseWhen where in this.Whens) { if (where.EvaluateTest(context)) { if (where.Template != null) { tempate = where.Template; } found = true; break; } } //If we have a template and should be binding on it if (!found && this.Otherwise != null && this.Otherwise.Template != null) { tempate = Otherwise.Template; } return(tempate); }
/// <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); }
protected virtual IEnumerable <IPDFComponent> DoParseContents(PDFContextBase context) { System.Xml.XmlNamespaceManager mgr = GetNamespaceManager(); IPDFTemplate gen = null; if (!string.IsNullOrEmpty(this.ParsableContents)) { gen = new Data.ParsableTemplateGenerator(this.ParsableContents, mgr); } else if (null != this.Template) { gen = this.Template; } if (null != gen) { IEnumerable <IPDFComponent> all = gen.Instantiate(0, this); return(all); } else { return new IPDFComponent[] { } }; }
/// <summary> /// Performs the layout of a single page, with header and footer generated and included as per the definition. /// Does not adjust the content size of the page /// </summary> protected void LayoutPageHeaderAndFooter() { IPDFTemplate headtemplate = this.GetCurrentHeaderTemplate(this.DocumentLayout.CurrentPageIndex); IPDFTemplate foottemplate = this.GetCurrentFooterTemplate(this.DocumentLayout.CurrentPageIndex); if (headtemplate != null) { PDFPageHeader header = new PDFPageHeader(); this.Page.AddGeneratedHeader(header, this.DocumentLayout.CurrentPageIndex); //Create the content inside the header component InstantiateTemplateForPage(header, headtemplate); Style head = header.GetAppliedStyle(); if (null != head) { this.Context.StyleStack.Push(head); } Style full = this.Context.StyleStack.GetFullStyle(header); this.DocumentLayout.CurrentPage.BeginHeader(header, full, this.Context); header.RegisterPreLayout(this.Context); this.DoLayoutAChild(header); header.RegisterLayoutComplete(this.Context); this.DocumentLayout.CurrentPage.EndHeader(); if (null != head) { this.Context.StyleStack.Pop(); } } if (foottemplate != null) { PDFPageFooter footer = new PDFPageFooter(); this.Page.AddGeneratedFooter(footer, this.DocumentLayout.CurrentPageIndex); InstantiateTemplateForPage(footer, foottemplate); Style foot = footer.GetAppliedStyle(); if (null != foot) { this.Context.StyleStack.Push(foot); } Style full = this.Context.StyleStack.GetFullStyle(footer); this.DocumentLayout.CurrentPage.BeginFooter(footer, full, this.Context); footer.RegisterPreLayout(this.Context); this.DoLayoutAChild(footer); footer.RegisterLayoutComplete(this.Context); this.DocumentLayout.CurrentPage.EndFooter(); } }
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); }
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++; }
/// <summary> /// Creates a concrete instance of the correct template into the PDFLayoutTemplate component /// </summary> /// <param name="container">A non null instance of the layout template component to contain the generated template components</param> protected virtual void InstantiateTemplateForPage(LayoutTemplateComponent container, IPDFTemplate template) { if (null == template) { throw new ArgumentNullException("template"); } if (null == container) { throw new ArgumentNullException("container"); } PDFRect avail = this.DocumentLayout.CurrentPage.LastOpenBlock().CurrentRegion.TotalBounds; int pg = this.DocumentLayout.CurrentPageIndex; container.InstantiateTemplate(template, this.Context, avail, pg); }
/// <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; }
public LinkContentHtml(IPDFTemplate gen, string path) : base(HTMLLinkType.Html, path) { this._gen = gen; this._index = 0; }
protected override void DoSetNativeValue(object value, IPDFComponent owner) { this.Template = (IPDFTemplate)value; }
protected override void DoSetNativeValueFromString(string value, IPDFComponent owner) { var namespaceManager = GetNamespaceManager(owner); this.Template = new Data.ParsableTemplateGenerator(value, namespaceManager); }