//---- //--- //20130603 :: mellorasinxelas /// <summary> /// Builds a page number element /// </summary> /// <param name="node"></param> /// <param name="fontAttrs"></param> /// <returns></returns> private PageNumber _buildPageNumber(XmlNode node, XmlAttributeCollection fontAttrs) { string text = XmlHelper.GetAttributeValue(TextBox.TextAttributeConstant, node.Attributes, ""); List <Variable> vars = new List <Variable>(); XmlNodeList varNodes = node.SelectNodes(VarElementConstant); foreach (XmlNode varNode in varNodes) { string name = XmlHelper.GetAttributeValue(Variable.NameAttributeConstant, varNode.Attributes, ""); if (name != string.Empty) { //load formatter DefaultFormat?formatter = null; string formatterParams = null; formatter = BasicVarFormatter.Parse(XmlHelper.GetAttributeValue(FormatableVariable.FormatterAttributeConstant, varNode.Attributes, null)); if (formatter != null) { formatterParams = XmlHelper.GetAttributeValue(FormatableVariable.FormatterParametersAttributeConstant, varNode.Attributes, null); } if (UseOptionalTags) { bool optional = XmlHelper.GetAttributeBoolean(Variable.OptionalAttributeConstant, varNode.Attributes, false); if (formatter == null) { vars.Add(new Variable(name, optional)); } else { vars.Add(new FormatableVariable(name, optional, formatter.Value, formatterParams)); } } else { if (formatter == null) { vars.Add(new Variable(name)); } else { vars.Add(new FormatableVariable(name, formatter.Value, formatterParams)); } } } } PageNumber _pageNumberBox = new PageNumber(text, fontAttrs, node.Attributes, vars); PageNumberBoxes.Add(_pageNumberBox); return(_pageNumberBox); }
//20130406 :: mellorasinxelas /// <summary> /// Build programmer custom element. /// </summary> /// <param name="node"></param> /// <param name="fontAttrs"></param> /// <returns></returns> public DrawElement BuildCustomElement(XmlNode node, XmlAttributeCollection fontAttrs) { //load object name string classname = XmlHelper.GetAttributeValue(DefaultCustomElement.ClassNameAttributeCustomElement, node.Attributes, null); if (classname == null) { throw new NullReferenceException("Custom elements needs Class Name!"); } //load VARS List <Variable> vars = new List <Variable>(); XmlNodeList varNodes = node.SelectNodes(VarElementConstant); foreach (XmlNode varNode in varNodes) { string name = XmlHelper.GetAttributeValue(Variable.NameAttributeConstant, varNode.Attributes, ""); if (name != string.Empty) { //load formatter DefaultFormat?formatter = null; string formatterParams = null; formatter = BasicVarFormatter.Parse(XmlHelper.GetAttributeValue(FormatableVariable.FormatterAttributeConstant, varNode.Attributes, null)); if (formatter != null) { formatterParams = XmlHelper.GetAttributeValue(FormatableVariable.FormatterParametersAttributeConstant, varNode.Attributes, null); } if (UseOptionalTags) { bool optional = XmlHelper.GetAttributeBoolean(Variable.OptionalAttributeConstant, varNode.Attributes, false); if (formatter == null) { vars.Add(new Variable(name, optional)); } else { vars.Add(new FormatableVariable(name, optional, formatter.Value, formatterParams)); } } else { if (formatter == null) { vars.Add(new Variable(name)); } else { vars.Add(new FormatableVariable(name, formatter.Value, formatterParams)); } } } } //load object Type tLoad = null; try { tLoad = AssembliesTypesLoader.GetType(classname); } catch (Exception ex1) { Console.WriteLine(ex1.ToString()); } if (tLoad == null) { throw new Exception("Custom element '" + classname + "' type don't found!"); } object objLoad = null; try { objLoad = Activator.CreateInstance(tLoad, new object[] { fontAttrs, node.Attributes, vars }); } catch (Exception ex2) { try { objLoad = Activator.CreateInstance(tLoad, new object[] { fontAttrs, node.Attributes }); } catch (Exception ex3) { Console.WriteLine("Custom element must have (fontAttr, textAttr) builder or (fontAttr, textAttr, List<Variables>)"); Console.WriteLine(ex2.ToString()); Console.WriteLine(ex3.ToString()); } } if (objLoad == null) { throw new NullReferenceException("Object '" + classname + "' don't loaded!"); } if (!(objLoad is DrawElement)) { throw new Exception("Object '" + classname + "' type doesn't match!. DrawElement is required!"); } return((DrawElement)objLoad); }