/// <summary> /// Initializes each of the components in this list /// </summary> /// <param name="context"></param> public void Init(PDFInitContext context) { foreach (IPDFComponent comp in this) { comp.Init(context); } }
protected virtual void DoInit(PDFInitContext context, bool includeChildren) { if (includeChildren) { this.Styles.Init(context); } }
void IPDFComponent.Init(PDFInitContext context) { if (null != this.Initialized) { this.Initialized(this, new PDFInitEventArgs(context)); } }
protected virtual void OnInit(PDFInitContext context) { if (null != this.Initialized) { this.Initialized(this, new PDFInitEventArgs(context)); } }
/// <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); }
private PDFInitContext GetInitContext(PDFDataContext dataContext) { if (null == _initContext) { _initContext = new PDFInitContext(dataContext.Items, dataContext.TraceLog, dataContext.PerformanceMonitor, this.Document); } return(_initContext); }
protected override void DoInit(PDFInitContext context) { if (!this._hasExplicitCompress) { this._compress = this.Document != null && this.Document.RenderOptions != null ? this.Document.RenderOptions.ImageCompression == ImageCompressionType.WebOptimize : false; } base.DoInit(context); }
// // lifecycle methods // public void Init(PDFInitContext context) { foreach (PDFObject item in this) { if (item is IPDFComponent) { (item as IPDFComponent).Init(context); } } }
public IPDFComponent PartialView(Document doc, PDFInitContext context) { var str = ""; using (var reader = new System.IO.StringReader(str)) { var content = Document.Parse(reader, ParseSourceType.DynamicContent); return(content); } }
/// <summary> /// Raises the initialized event /// </summary> /// <param name="context"></param> protected virtual void OnInitialized(PDFInitContext context) { if (this.HasRegisteredEvents) { PDFInitializedEventHandler handler = (PDFInitializedEventHandler)this.Events[InitEventKey]; if (null != handler) { handler(this, new PDFInitEventArgs(context)); } } }
/// <summary> /// Initializes all children in the document /// </summary> protected virtual void DoInitChildren(PDFInitContext context) { if (this.HasContent) { for (int i = 0; i < this.InnerContent.Count; i++) { Component comp = this.InnerContent[i]; comp.Init(context); } } }
public void InitTest() { StylesDocument target = new StylesDocument(); // TODO: Initialize to an appropriate value PDFInitContext context = new PDFInitContext(new PDFItemCollection(null), new Logging.DoNothingTraceLog(TraceRecordLevel.Off), new PDFPerformanceMonitor(true), null); target.Initialized += target_Initialized; isInitialized = false; target.Init(context); //Set to true by the event handler Assert.IsTrue(isInitialized); }
private void InitAndLoadRoot(Component built, PDFContextBase context) { if (context.TraceLog.ShouldLog(TraceLevel.Debug)) { context.TraceLog.Add(TraceLevel.Debug, "DataGrid", "Initializing and loading root component before binding"); } PDFTraceLog log = context.TraceLog; PDFInitContext init = new PDFInitContext(context.Items, log, context.PerformanceMonitor, this.Document); PDFLoadContext load = new PDFLoadContext(context.Items, log, context.PerformanceMonitor, this.Document); built.Init(init); built.Load(load); }
// //public methods // #region public void Init() + protected virtual void DoInit() /// <summary> /// Initializes the instance /// </summary> public void Init(PDFInitContext context) { if (context.ShouldLogDebug) { context.TraceLog.Begin(TraceLevel.Debug, "Component", "Init Component '" + this.UniqueID + "'"); } this.DoInit(context); this.OnInitialized(context); if (context.ShouldLogDebug) { context.TraceLog.End(TraceLevel.Debug, "Component", "Init Component '" + this.UniqueID + "'"); } }
/// <summary> /// Makse sure that if we do have some data and it has not been parsed, them we should parse it. /// </summary> /// <param name="data"></param> /// <param name="context"></param> /// <returns>True if we did do the actual parsing when this method was called, otherwise false.</returns> protected virtual bool EnsureContentsParsed(PDFContextBase context) { if (!this._parsed) { IEnumerable <IPDFComponent> all = DoParseContents(context); foreach (IPDFComponent child in all) { this.InnerContent.Add((Component)child); } //Do the init and load for these components PDFInitContext init = new PDFInitContext(context.Items, context.TraceLog, context.PerformanceMonitor, this.Document); PDFLoadContext load = new PDFLoadContext(context.Items, context.TraceLog, context.PerformanceMonitor, this.Document); foreach (IPDFComponent child in all) { child.Init(init); } foreach (IPDFComponent child in all) { if (child is Component) { ((Component)child).Load(load); } } //We did do the parsing so let's return true. _parsed = true; return(_parsed); } else { return(false); } }
protected virtual void AddAutoBindFields(object data, IPDFDataSource source, PDFDataContext context) { if (string.IsNullOrEmpty(this.DataSourceID)) { throw new InvalidOperationException("Can only auto bind the schema when the With has an explicit DataSourceID and the referencing source supports Schema derriving"); } IPDFDataSource found = base.FindDocumentComponentById(this.DataSourceID) as IPDFDataSource; if (null == found || found.SupportsDataSchema == false) { throw new InvalidOperationException("Can only auto bind the schema when the With has an explicit DataSourceID and the referencing source supports Schema derriving"); } PDFDataSchema schema = found.GetDataSchema(this.SelectPath, context); if (null == schema || schema.Items == null || schema.Items.Count == 0) { context.TraceLog.Add(TraceLevel.Warning, "PDFWithFieldSet", string.Format("Cannot autobind the columns as no schema items were returned for the path '{0}'", this.SelectPath)); } else { if (context.TraceLog.ShouldLog(TraceLevel.Debug)) { context.TraceLog.Add(TraceLevel.Debug, "DataGrid", "Initializing and loading root component before binding"); } PDFTraceLog log = context.TraceLog; PDFInitContext init = new PDFInitContext(context.Items, log, context.PerformanceMonitor, this.Document); PDFLoadContext load = new PDFLoadContext(context.Items, log, context.PerformanceMonitor, this.Document); foreach (PDFDataItem item in schema.Items) { if (ShouldIncludeAutoBoundItem(item)) { WithBoundField field = GetFieldForType(item.DataType); if (null != field) { field.StyleClass = this.FieldClass; field.FieldLabel = string.IsNullOrEmpty(item.Title) ? item.Name : item.Title; field.LabelClass = this.LabelClass; field.ValueClass = this.ValueClass; field.LabelPostFix = this.LabelPostFix; field.LayoutType = this.AutoLayoutType; field.DataType = item.DataType; field.HideIfEmpty = this.HideEmptyFields; field.SetDataSourceBindingItem(item, context); if (context.TraceLog.ShouldLog(TraceLevel.Debug)) { context.TraceLog.Add(TraceLevel.Debug, "PDFWithFieldSet", string.Format("The data field was automatically created for the schdema item '{0}' in set '{1}'", item, this)); } this.Fields.Add(field); field.Init(init); field.Load(load); this.BindingActions.Add(new BindingAction(data, source, field)); } } } //added all the items } }
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; }
// // overrides + supporting methods // #region protected override void DoInit() + protected virtual void DoInitChildren() /// <summary> /// Performs the base initialization and then calls DoInitChildren to ensure that each of its children are initialized. /// </summary> protected override void DoInit(PDFInitContext context) { base.DoInit(context); this.DoInitChildren(context); }
/// <summary> /// Inheritors should override this method to perform their own initialization /// </summary> protected virtual void DoInit(PDFInitContext 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++; }
/// <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> ///// Creates a new style and returns all the merges styles ///// </summary> ///// <param name="classname"></param> ///// <returns></returns> //public override Scryber.Styles.PDFStyle MatchClass(string classname) //{ // return this.Styles.MatchClass(classname); //} public void Init(PDFInitContext context) { this.DoInit(context, true); this.OnInit(context); }