Exemple #1
0
 void IPDFComponentList.Insert(int index, IPDFComponent component)
 {
     if (component is Component)
     {
         this.Insert(index, (Component)component);
         this.OnCollectionChanged();
     }
     else
     {
         RecordAndRaise.InvalidCast(Errors.CannotConvertObjectToType, component.GetType(), "PDFComponent");
     }
 }
        /// <summary>
        /// Sets an arrangement for this component
        /// </summary>
        /// <param name="arrange"></param>
        protected virtual void SetArrangement(PDFComponentArrangement arrange)
        {
            if (arrange is PDFComponentMultiArrangement)
            {
                if (_arrange == null)
                {
                    _arrange = arrange;
                    //this.EnsureAllChildrenAreOnThisPage(arrange);
                }

                else if (_arrange != null && _arrange is PDFComponentMultiArrangement)
                {
                    ((PDFComponentMultiArrangement)_arrange).AppendArrangement((PDFComponentMultiArrangement)arrange);
                }
                else
                {
                    throw RecordAndRaise.InvalidCast(Errors.CannotConvertObjectToType, typeof(PDFComponentArrangement), typeof(PDFComponentMultiArrangement));
                }
            }
            else
            {
                _arrange = arrange;
            }
        }
        //
        // IPDFTemplate Instantiate method.
        //

        public IEnumerable <IPDFComponent> Instantiate(int index, IPDFComponent owner)
        {
            if (!_initialised)
            {
                this.InitTemplate(this.XmlContent, this.NamespacePrefixMappings);
            }

            if (null == owner)
            {
                throw new ArgumentNullException("owner");
            }

            using (System.IO.StringReader sr = new System.IO.StringReader(this._toparse))
            {
                //Get the closest remote component
                IPDFRemoteComponent remote = this.GetRemoteComponent(owner);
                IPDFDocument        doc    = owner.Document;
                IPDFComponent       comp;
                if (doc is IPDFTemplateParser)
                {
                    comp = ((IPDFTemplateParser)doc).ParseTemplate(remote, sr);
                }
                else
                {
                    throw RecordAndRaise.NullReference(Errors.ParentDocumentMustBeTemplateParser);
                }

                if (this.IsBlock)
                {
                    if (!(comp is TemplateBlockInstance))
                    {
                        throw RecordAndRaise.InvalidCast(Errors.CannotConvertObjectToType, comp.GetType(), typeof(TemplateBlockInstance));
                    }

                    TemplateBlockInstance template = (TemplateBlockInstance)comp;

                    if (null != this.Style && (template is IPDFStyledComponent))
                    {
                        this.Style.MergeInto((template as IPDFStyledComponent).Style);
                    }

                    template.StyleClass  = this.StyleClass;
                    template.ElementName = this.ElementName;
                }
                else
                {
                    if (!(comp is TemplateInstance))
                    {
                        throw RecordAndRaise.InvalidCast(Errors.CannotConvertObjectToType, comp.GetType(), typeof(TemplateInstance));
                    }

                    TemplateInstance template = (TemplateInstance)comp;

                    if (null != this.Style && (template is IPDFStyledComponent))
                    {
                        this.Style.MergeInto((template as IPDFStyledComponent).Style);
                    }

                    template.StyleClass  = this.StyleClass;
                    template.ElementName = this.ElementName;
                }

                if (comp is Component && owner is Component && this.UseDataStyleIdentifier)
                {
                    var stem = this.DataStyleStem;
                    if (string.IsNullOrEmpty(stem))
                    {
                        stem = ((Component)owner).UniqueID;
                    }

                    DataStyleIdentifierVisitor visitor = new DataStyleIdentifierVisitor(stem, 1);
                    visitor.PushToComponents(comp as Component);
                }

                List <IPDFComponent> all = new List <IPDFComponent>(1);

                all.Add(comp);
                return(all);
            }
        }