コード例 #1
0
        /// <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);
        }
コード例 #2
0
        protected override void OnLoaded(PDFLoadContext context)
        {
            bool performload = false;

            this.EnsureContentsParsed(context, performload);
            base.OnLoaded(context);
        }
コード例 #3
0
 protected virtual void DoLoad(PDFLoadContext context, bool includeChildren)
 {
     if (includeChildren)
     {
         this.Styles.Load(context);
     }
 }
コード例 #4
0
 /// <summary>
 /// Invokes the load on each of the components in this list
 /// </summary>
 /// <param name="context"></param>
 public void Load(PDFLoadContext context)
 {
     foreach (IPDFComponent comp in this)
     {
         comp.Load(context);
     }
 }
コード例 #5
0
 protected virtual void OnLoaded(PDFLoadContext context)
 {
     if (null != this.Loaded)
     {
         this.Loaded(this, new PDFLoadEventArgs(context));
     }
 }
コード例 #6
0
 public void Load(PDFLoadContext context)
 {
     if (null != this.Loaded)
     {
         this.Loaded(this, new PDFLoadEventArgs(context));
     }
 }
コード例 #7
0
 private PDFLoadContext GetLoadContext(PDFDataContext dataContext)
 {
     if (null == _loadContext)
     {
         _loadContext = new PDFLoadContext(dataContext.Items, dataContext.TraceLog, dataContext.PerformanceMonitor, this.Document);
     }
     return(_loadContext);
 }
コード例 #8
0
 public void Load(PDFLoadContext context)
 {
     foreach (PDFObject item in this)
     {
         if (item is IPDFComponent)
         {
             (item as IPDFComponent).Load(context);
         }
     }
 }
コード例 #9
0
 protected virtual void DoLoadChildren(PDFLoadContext context)
 {
     if (this.HasContent)
     {
         for (int i = 0; i < this.InnerContent.Count; i++)
         {
             Component comp = this.InnerContent[i];
             comp.Load(context);
         }
     }
 }
コード例 #10
0
 /// <summary>
 /// Raises the loaded event.
 /// </summary>
 /// <param name="context"></param>
 protected virtual void OnLoaded(PDFLoadContext context)
 {
     if (this.HasRegisteredEvents)
     {
         PDFLoadedEventHandler handler = (PDFLoadedEventHandler)this.Events[LoadedEventKey];
         if (null != handler)
         {
             handler(this, new PDFLoadEventArgs(context));
         }
     }
 }
コード例 #11
0
        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);
        }
コード例 #12
0
        /// <summary>
        /// Load operation
        /// </summary>
        public void Load(PDFLoadContext context)
        {
            if (context.ShouldLogDebug)
            {
                context.TraceLog.Begin(TraceLevel.Debug, "Component", "Load Component '" + this.UniqueID + "'");
            }

            this.DoLoad(context);
            this.OnLoaded(context);

            if (context.ShouldLogDebug)
            {
                context.TraceLog.End(TraceLevel.Debug, "Component", "Load Component '" + this.UniqueID + "'");
            }
        }
コード例 #13
0
        /// <summary>
        /// Returns a style that would be applied to the document, based on the passed css and any class
        /// </summary>
        /// <param name="css">The css styles to use</param>
        /// <param name="docClass">The css class to set on the document if any</param>
        /// <returns>The applied style</returns>
        private Document BuildDocumentWithStyles(string css)
        {
            var doc       = new Document();
            var context   = new PDFLoadContext(doc.Params, doc.TraceLog, doc.PerformanceMonitor, doc);
            var cssparser = new CSSStyleParser(css, context);

            //Add the parsed styles
            foreach (var style in cssparser)
            {
                doc.Styles.Add(style);
            }

            //do the load and bind
            doc.InitializeAndLoad();
            doc.DataBind();

            return(doc);
        }
コード例 #14
0
        /// <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);
            }
        }
コード例 #15
0
        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++;
        }
コード例 #16
0
        protected override void OnLoaded(PDFLoadContext context)
        {
            base.OnLoaded(context);

            DoLoadReference(context);
        }
コード例 #17
0
 protected override void DoLoad(PDFLoadContext context)
 {
     base.DoLoad(context);
     this.DoLoadChildren(context);
 }
コード例 #18
0
 public void Load(PDFLoadContext context)
 {
     this.DoLoad(context, true);
     this.OnLoaded(context);
 }
コード例 #19
0
 protected override void OnLoaded(PDFLoadContext context)
 {
     AssertInnerStyles(context);
     base.OnLoaded(context);
 }
コード例 #20
0
        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
            }
        }
コード例 #21
0
        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;
        }
コード例 #22
0
 /// <summary>
 /// Inheritors should override this method to perform their own loading operations
 /// </summary>
 protected virtual void DoLoad(PDFLoadContext context)
 {
 }
コード例 #23
0
        protected override void DoLoad(PDFLoadContext context)
        {
            base.DoLoad(context);

            //this.EnsureContentsParsed(this.ParsableContents, context);
        }
コード例 #24
0
        /// <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);
        }