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"); }
// // 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); } }
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"); }
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; } }
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; }
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); }
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); } }
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; }
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); } }
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; } } }
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"); } }
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); }
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; }
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); } }
// // 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); } }
/// <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); }
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 "); } }
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; }
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; }
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; }
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); } } } }
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); }
void Background_DataBound(object sender, PDFDataBindEventArgs e) { bg_bound = true; }
void PDFDataGridTemplateColumn_DataBinding(object sender, PDFDataBindEventArgs e) { ((Component)sender).Visible = this.Visible; }
public void DocumentDataBound(object sender, PDFDataBindEventArgs args) { Results.Add("Controller Document Databound"); }
void target_DataBound(object sender, PDFDataBindEventArgs e) { style_bound = true; }
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"); }
void headerCell_DataBound(object sender, PDFDataBindEventArgs e) { TableCell cell = (TableCell)sender; ApplyHeaderCellStyles(cell); }
void target_DataBinding(object sender, PDFDataBindEventArgs e) { style_binding = true; }