コード例 #1
0
        public void HeaderBinding(object sender, PDFDataBindEventArgs args)
        {
            if (null == this.Title)
            {
                throw new NullReferenceException("Title heading was not set");
            }
            this.Title.Text = "Set from the controller";

            Results.Add("Controller Header Databound");
        }
コード例 #2
0
        //
        // methods
        //

        #region public void DataBind(PDFDataContext context)

        /// <summary>
        /// Supports the databinding capabilites of the parameter by raising the events
        /// </summary>
        /// <param name="context"></param>
        public virtual void DataBind(PDFDataContext context)
        {
            if (null != this.DataBinding || null != this.DataBound)
            {
                PDFDataBindEventArgs args = new PDFDataBindEventArgs(context);
                this.OnDataBinding(args);

                this.OnDataBound(args);
            }
        }
コード例 #3
0
        public void ForEachListItemBound(object sender, PDFDataBindEventArgs args)
        {
            var li = sender as ListItem;

            var str = (string)args.Context.DataStack.Current;

            str += " - Index " + args.Context.CurrentIndex;

            li.Contents.Add(new TextLiteral(str));

            Results.Add("Controller ForEach Label " + args.Context.CurrentIndex + " Databound");
        }
コード例 #4
0
        void footerlbl_DataBound(object sender, PDFDataBindEventArgs args)
        {
            this.DataBind(args.Context);
            Label lbl = (Label)sender;

            lbl.Text = this.FooterText;

            if (!string.IsNullOrEmpty(this.FooterText))
            {
                this.HasFooter = true;
            }
        }
コード例 #5
0
        void img_DataBinding(object sender, PDFDataBindEventArgs args)
        {
            this.DataBind(args.Context);
            Image img = (Image)sender;

            if (null != this._autobindItemPath)
            {
                this.ImageSource = AssertGetDataItemValue(this._autobindItemPath, args) as string;
            }

            img.Source             = this.ImageSource;
            img.AllowMissingImages = this.HideOnFail;
            img.Visible            = this.Visible;
        }
コード例 #6
0
        private static PDFDataBindEventArgs CreateDataBindArgs()
        {
            var config = Scryber.ServiceProvider.GetService <IScryberConfigurationService>();

            Assert.IsNotNull(config, "THere is no scryber config service");

            var log = config.TracingOptions.GetTraceLog();

            PDFItemCollection    items   = new PDFItemCollection(null);
            PDFDataContext       context = new PDFDataContext(items, log, new PDFPerformanceMonitor(true), null);
            PDFDataBindEventArgs args    = new PDFDataBindEventArgs(context);

            return(args);
        }
コード例 #7
0
        void cell_DataBound(object sender, PDFDataBindEventArgs e)
        {
            if (this.Visible)
            {
                this.AllInvisible = false;
            }

            int       rowindex = e.Context.CurrentIndex;
            TableCell cell     = (TableCell)sender;

            cell.StyleClass = this.CellClass;

            if (!string.IsNullOrEmpty(this.DataStyleIdentifier))
            {
                cell.DataStyleIdentifier = this.DataStyleIdentifier + "_itemcell";
            }

            if (rowindex % 2 == 1 && !string.IsNullOrEmpty(this.AlternatingCellClass))
            {
                if (!string.IsNullOrEmpty(cell.StyleClass))
                {
                    cell.StyleClass += " " + this.AlternatingCellClass;
                }
                else
                {
                    cell.StyleClass = this.AlternatingCellClass;
                }

                if (!string.IsNullOrEmpty(this.DataStyleIdentifier))
                {
                    cell.DataStyleIdentifier = this.DataStyleIdentifier + "_altitemcell";
                }
            }


            if (this.HasStyle && this.Style.HasValues)
            {
                this.Style.MergeInto(cell.Style, Style.DirectStylePriority);
            }


            if (rowindex % 2 == 1 && (null != this._altitemstyle && _altitemstyle.HasValues))
            {
                _altitemstyle.MergeInto(cell.Style, Style.DirectStylePriority);
            }
            else if (null != this._itemstyle && _itemstyle.HasValues)
            {
                _itemstyle.MergeInto(cell.Style, Style.DirectStylePriority);
            }
        }
コード例 #8
0
        void dimg_DataBinding(object sender, PDFDataBindEventArgs args)
        {
            this.DataBind(args.Context);
            DataImage dimg = (DataImage)sender;

            if (null != this._autobindItemPath)
            {
                object val = AssertGetDataItemValue(this._autobindItemPath, args);
                this.ImageData = ConvertValueToBase64Data(val);
                this.ImageKey  = GetImageKey(args.Context);
            }

            dimg.Data     = this.ImageData;
            dimg.ImageKey = this.ImageKey;
            dimg.Visible  = this.Visible;
        }
コード例 #9
0
        void footerCell_DataBound(object sender, PDFDataBindEventArgs args)
        {
            TableCell cell = (TableCell)sender;

            cell.StyleClass = this.HeaderCellClass;

            if (this.HasStyle && this.Style.HasValues)
            {
                this.Style.MergeInto(cell.Style, Style.DirectStylePriority);
            }

            if (null != this._footstyle && _footstyle.HasValues)
            {
                this._footstyle.MergeInto(cell.Style, Style.DirectStylePriority);
            }
        }
コード例 #10
0
        private void PDFWithTextField_DataBinding(object sender, PDFDataBindEventArgs e)
        {
            object val = AssertGetDataItemValue(this._autobindValue, e);

            if (null != val)
            {
                if (val is string)
                {
                    this.Value = DateTime.Parse("yyyy-MM-dd'T'hh:mm:ss");
                }
                else
                {
                    this.Value = (DateTime)val;
                }
            }
        }
コード例 #11
0
        public void TemplateItemCellBound(object sender, PDFDataBindEventArgs args)
        {
            //This is the wrapper component
            var row = sender as TableCell;

            var context = args.Context;

            var index = args.Context.CurrentIndex;

            //Add a class for every other item.

            if (index % 2 == 0)
            {
                row.Style.Background.Color = (Scryber.Drawing.PDFColor) "#DDD";// = (row.StyleClass == null) ? "alternate" : (row.StyleClass + " alternate");
            }
        }
コード例 #12
0
        public void BuildInnerInnerKeyedExpressionPath()
        {
            //Build the object graph
            string     expected   = "This is the test";
            FakeSource innerinner = new FakeSource();

            innerinner.Value = expected;

            FakeSource inner = new FakeSource();

            inner.Keys          = new Dictionary <string, FakeSource>();
            inner.Keys["First"] = innerinner;

            FakeSource root = new FakeSource();

            root.Items = new List <FakeSource>();
            root.Items.Add(null);
            root.Items.Add(inner);

            //expression and binding item
            string expr = "Root.Items[1].Keys['First'].Value";

            //Property to set
            System.Reflection.PropertyInfo prop = typeof(FakeRecipient).GetProperty("StringProperty");


            //Create the expression binding
            BindingItemExpression itembind = BindingItemExpression.Create(expr, prop);

            //Set the items value to be extracted as an inner property on the source
            PDFDataBindEventArgs args = CreateDataBindArgs();

            //Set the root entry to the top of the object braph
            args.Context.Items["Root"] = root;

            //bind the recipient - should have its property set to the item value
            FakeRecipient recip = new FakeRecipient();

            itembind.BindComponent(recip, args);

            //String Property should be set to the expected value
            string actual = recip.StringProperty;

            Assert.AreEqual(expected, actual);
        }
コード例 #13
0
        void link_DataBinding(object sender, PDFDataBindEventArgs args)
        {
            this.DataBind(args.Context);

            HtmlFragment fragment = (HtmlFragment)sender;

            if (null != this._autobindItemPath)
            {
                string html = AssertGetDataItemValue(_autobindItemPath, args) as string;
                if (!string.IsNullOrEmpty(html))
                {
                    this.Contents = html;
                }
            }

            fragment.Visible     = this.Visible;
            fragment.RawContents = this.Contents;
        }
コード例 #14
0
        void link_DataBinding(object sender, PDFDataBindEventArgs args)
        {
            this.DataBind(args.Context);

            Link link = (Link)sender;

            if (null != this._autobindItemPath)
            {
                string href = AssertGetDataItemValue(_autobindItemPath, args) as string;
                if (!string.IsNullOrEmpty(href))
                {
                    this.Action = LinkAction.Uri;
                    this.File   = href;
                    this.Text   = href;
                }
            }
            link.Action         = this.Action;
            link.Destination    = this.Destination;
            link.DestinationFit = this.DestinationFit;
            link.File           = this.File;
            link.NewWindow      = this.NewWindow;
            link.Visible        = this.Visible;


            if (null != this.ImageData)
            {
                DataImage dimg = new DataImage();
                dimg.Data = this.ImageData;
                link.Contents.Add(dimg);
            }
            else if (!string.IsNullOrEmpty(this.ImageSource))
            {
                Image image = new Image();
                image.Source = this.ImageSource;
                link.Contents.Add(image);
            }
            else if (!string.IsNullOrEmpty(this.Text))
            {
                Label lbl = new Label();
                lbl.Text = this.Text;
                link.Contents.Add(lbl);
            }
        }
コード例 #15
0
        //
        // public interface
        //

        #region public void BindComponent(object sender, PDFDataBindEventArgs args)

        /// <summary>
        /// Main method that sets the value of the senders property to the result of this instances XPath expression.
        /// Using the current data context.
        ///  Signature can be attached to an IPDFBindableComponent DataBound or DataBinding events.
        /// </summary>
        /// <param name="sender">The instance that raised the event</param>
        /// <param name="args"></param>
        public void BindComponent(object sender, PDFDataBindEventArgs args)
        {
            if (null == sender)
            {
                throw new ArgumentNullException("sender");
            }
            if (null == args)
            {
                throw new ArgumentNullException("args");
            }
            if (null == args.Context)
            {
                throw new ArgumentNullException("args.Context");
            }

            PDFDataStack stack = args.Context.DataStack;

            IPDFDataSource src = stack.Source;

            //Pop the current one so we can get the next one up (for count and position operations)
            object data = stack.Pop();

            try
            {
                DoBindComponent(sender, data, args.Context);
            }
            catch (Exception ex)
            {
                if (args.Context.Conformance == ParserConformanceMode.Lax)
                {
                    args.Context.TraceLog.Add(TraceLevel.Error, "Item Binding", "Could not Set property '" + this.Property.Name + "': " + ex.Message, ex);
                }
                else
                {
                    throw;
                }
            }
            finally
            {
                //Put the data we popped back on
                args.Context.DataStack.Push(data, src);
            }
        }
コード例 #16
0
        /// <summary>
        /// Evaluates the XPath expression against the current data context - raising an exception if there is no current data on the stack
        /// </summary>
        /// <param name="path"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        protected object AssertGetDataItemValue(string path, PDFDataBindEventArgs args)
        {
            if (args.Context.DataStack.HasData == false)
            {
                throw new PDFDataException(Errors.CouldNotBindDataComponent);
            }

            object value = null;

            try
            {
                value = args.Context.DataStack.Source.Evaluate(path, args.Context.DataStack.Current, args.Context);
            }
            catch (Exception ex)
            {
                throw new PDFDataException(Errors.CouldNotBindDataComponent, ex);
            }

            return(value);
        }
コード例 #17
0
        public void BindComponent(object sender, PDFDataBindEventArgs args)
        {
            if (null == this.ItemValueProvider)
            {
                this.ItemValueProvider = args.Context.Items.ValueProvider(
                    args.Context.CurrentIndex,
                    args.Context.DataStack.HasData ? args.Context.DataStack.Current : null);
            }

            object value;

            if (this.TryEvaluate(this.ItemValueProvider, sender, args.Context, out value))
            {
                this.SetPropertyValue(sender, value, Expression.ToString(), BoundTo, args.Context);
            }
            else
            {
                args.Context.TraceLog.Add(TraceLevel.Warning, "Expression Binding", "The expression '" + this.OriginalExpression + "' for '" + sender.ToString() + "' on property '" + this.BoundTo.Name + "' could not be evaluated ");
            }
        }
コード例 #18
0
        void number_DataBinding(object sender, PDFDataBindEventArgs args)
        {
            this.DataBind(args.Context);
            Number num = ((Number)sender);

            if (null != _autobindItemPath)
            {
                object value = AssertGetDataItemValue(this._autobindItemPath, args);
                if (null != value)
                {
                    string numStr = value.ToString();
                    if (!string.IsNullOrEmpty(numStr))
                    {
                        this.Value = double.Parse(numStr);
                    }
                }
            }
            num.Value        = this.Value;
            num.NumberFormat = this.NumberFormat;
            num.Visible      = this.Visible;
        }
コード例 #19
0
        void lbl_DataBinding(object sender, PDFDataBindEventArgs args)
        {
            this.DataBind(args.Context);

            if (null != _autobindItemPath)
            {
                object value = AssertGetDataItemValue(_autobindItemPath, args);
                if (null != value)
                {
                    this.Text = value.ToString();
                }
                else
                {
                    this.Text = "";
                }
            }

            Label lbl = (Label)sender;

            lbl.Text    = this.Text;
            lbl.Visible = this.Visible;
        }
コード例 #20
0
        void date_DataBinding(object sender, PDFDataBindEventArgs args)
        {
            this.DataBind(args.Context);
            Date num = ((Date)sender);

            //check for the autobind item path.
            if (null != this._autobindItemPath)
            {
                object   val = AssertGetDataItemValue(this._autobindItemPath, args);
                DateTime result;
                if (null != val && !string.IsNullOrEmpty(val.ToString()) && DateTime.TryParse(val.ToString(), out result))
                {
                    num.Value = result;
                }
            }
            else
            {
                num.Value = this.Value;
            }

            num.DateFormat = this.DateFormat;
        }
コード例 #21
0
        public void BindComponent(object sender, PDFDataBindEventArgs args)
        {
            if (null != this._path)
            {
                try
                {
                    object value = this._path.GetValue(args.Context.Items, args.Context);

                    this.SetPropertyValue(sender, value, this.Expression, this.Property, args.Context);
                }
                catch (PDFDataException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    string id;
                    if (sender is IPDFComponent component)
                    {
                        id = ((IPDFComponent)sender).ID;
                    }
                    else
                    {
                        id = "UNKNOWN";
                    }

                    string message = "Cannot bind the values for '" + sender.ToString() + "' with id " + id;

                    if (args.Context.Conformance == ParserConformanceMode.Lax)
                    {
                        args.Context.TraceLog.Add(TraceLevel.Error, "Data Binding", message, ex);
                    }
                    else
                    {
                        throw new Scryber.PDFBindException(message, ex);
                    }
                }
            }
        }
コード例 #22
0
        public void BuildNotSetExpressionPath()
        {
            //Property to set
            System.Reflection.PropertyInfo prop = typeof(FakeRecipient).GetProperty("StringProperty");


            //expression and binding item
            string expr = "Root";
            BindingItemExpression itembind = BindingItemExpression.Create(expr, prop);

            //DO NOT Set the items value to be extracted
            PDFDataBindEventArgs args = CreateDataBindArgs();
            //string expected = "This is the test";
            //args.Context.Items["Root"] = expected;

            //bind the recipient - should have its property set to the item value
            FakeRecipient recip = new FakeRecipient();

            itembind.BindComponent(recip, args);

            string actual = recip.StringProperty;

            Assert.IsNull(actual);
        }
コード例 #23
0
 void Background_DataBound(object sender, PDFDataBindEventArgs e)
 {
     bg_bound = true;
 }
コード例 #24
0
 void PDFDataGridTemplateColumn_DataBinding(object sender, PDFDataBindEventArgs e)
 {
     ((Component)sender).Visible = this.Visible;
 }
コード例 #25
0
 public void DocumentDataBound(object sender, PDFDataBindEventArgs args)
 {
     Results.Add("Controller Document Databound");
 }
コード例 #26
0
 void target_DataBound(object sender, PDFDataBindEventArgs e)
 {
     style_bound = true;
 }
コード例 #27
0
        public void ImageBound(object sender, PDFDataBindEventArgs args)
        {
            HTMLParagraph p = sender as HTMLParagraph;

            p.Contents.Add(new TextLiteral("This is my content"));
        }
 public void HandlePageBound(object sender, PDFDataBindEventArgs args)
 {
     Assert.IsNotNull(args.Context);
     Invoked.Add("bound");
 }
コード例 #29
0
        void headerCell_DataBound(object sender, PDFDataBindEventArgs e)
        {
            TableCell cell = (TableCell)sender;

            ApplyHeaderCellStyles(cell);
        }
コード例 #30
0
 void target_DataBinding(object sender, PDFDataBindEventArgs e)
 {
     style_binding = true;
 }