/// <summary> /// Ritorna rappresentazione Xml del pager /// </summary> /// <returns></returns> public string ToXml() { using (XmlWrite xw = new XmlWrite()) { if (this.XmlFunction == null) { //Formattazione standard xw.WriteStartElement("Pager"); try { xw.WriteElementString("Position", this.Position.ToString()); xw.WriteElementString("Offset", this.Offset.ToString()); xw.WriteElementString("Page", this.Page.ToString()); xw.WriteElementString("TotRecords", this.TotRecords.ToString()); xw.WriteElementString("TotPages", this.TotPages.ToString()); } finally { xw.WriteEndElement(); } } else { this.XmlFunction(this, xw); } return(xw.ToString()); } }
/// <summary> /// Ritorna Xml con dati oggetti. E' possibile specificare un delegato per poter manipolare /// l'xml di ogni oggetto con altri dati. Utilizzando rewriteAll viene soppresso l'output Xml standard /// dell'oggetto /// </summary> /// <param name="function"> /// Delegato ad una funzione (e.s. AggiornaXmlUtente(Utente ut, Xmlwrite xw)) per la manipolazione dell'xml /// </param> /// <param name="rewriteAll"> /// Impostato a true disabilita l'output xml standard dell'oggetto /// </param> /// <param name="args"> /// Dati esterni da inviare alla funzione di scrittura xml /// </param> /// <returns></returns> public string ToXml(XmlFunction function, bool rewriteAll, params object[] args) { DataObjectBase o; using (XmlWrite xw = new XmlWrite()) { for (int i = 0; i < this.Count; i++) { o = this[i]; xw.WriteStartElement(o.mClassSchema.ClassName); try { if (!rewriteAll) { xw.WriteRaw(o.ToXml()); } //Se fornita funzione allora la richiama if (function != null) { function((T)o, xw, args); } } finally { xw.WriteEndElement(); } } return(xw.ToString()); } }
/// <summary> /// Ritorna la rappresentazione Xml. /// </summary> /// <param name="function"></param> /// <returns></returns> public string ToXml() { using (XmlWrite xw = new XmlWrite()) { if (XmlFunction == null) { //Crea Xml Standard xw.WriteStartElement("MESSAGELIST"); try { for (int i = 0; i < this.Count; i++) { xw.WriteRaw(this[i].ToXml()); } } finally { xw.WriteEndElement(); } } else { //Utilizza la funzione specificata XmlFunction(this, xw); } return(xw.ToString()); } }
/// <summary> /// Scrive valore per Xml /// </summary> /// <param name="xw"></param> /// <param name="obj"></param> /// <param name="depth"></param> public override void WriteXml(XmlWrite xw, DataObjectBase obj, int depth) { var oTemp = this.GetValue(obj); string sValue = string.Empty; string sFormat = null; //Scrive base 64 if (this.Type.IsArray) { sValue = Convert.ToBase64String(oTemp as byte[]); } else { if (TypeHelper.IsDecimalType(this.Type)) { sFormat = string.Intern(obj.GetSlot().Conf.XmlDefaultDecimalFormat); } else if (TypeHelper.IsDate(this.Type)) { sFormat = string.Intern(obj.GetSlot().Conf.XmlDefaultDateFormat); } if (string.IsNullOrEmpty(sFormat)) { sValue = oTemp.ToString(); } else { sValue = (oTemp as IFormattable).ToString(sFormat, System.Globalization.CultureInfo.CurrentCulture); } } xw.WriteElementString(this.Name, sValue); }
public void ChainedTyped() { var writer = XmlWrite.For <TheThing>().Tag("root").Many(x => x.TheInts, y => y.Tag("int").Content(x => x.ToString())); var expected = "<root><int>42</int><int>666</int></root>"; var actual = writer.Write(new TheThing()); Assert.Equal(expected, actual); }
public void ChainedDynamic() { var writer = XmlWrite.For <string>().Tag("root").Attribute("theName", x => x); var expected = "<root theName=\"yep\"/>"; var actual = writer.Write("yep"); Assert.Equal(expected, actual); }
public void MultipleAttributesBoth() { var writer = from root in XmlWrite.For <int>().Tag("root") from sub1 in root.Attribute("attr1", "yep").If(x => x == 42) from sub2 in root.Attribute("attr2", "again").If(x => x == 42) select root; Assert.Equal("<root attr1=\"yep\" attr2=\"again\"/>", writer.Write(42)); }
public void BetterInlineTyped() { var writer = XmlWrite.For <List <Dictionary <string, string> > >().Tag("root") .Many(list => list, dict => dict.Tag("dict") .Many(x => x.ToList(), kv => kv.Tag(x => x.Key).Content(x => x.Value))); Assert.Equal(expected, writer.Write(input)); }
public void WithDynamicRoot() { var writer = from root in XmlWrite.For <string>().Tag(x => x) select root; var expected = "<dynamic/>"; var actual = writer.Write("dynamic"); Assert.Equal(expected, actual); }
public void Up() { var writer = from root in XmlWrite.For <string>().Tag("root").Tag("1").Up().Tag("2") select root; var expected = "<root><1/><2/></root>"; var actual = writer.Write(""); Assert.Equal(expected, actual); }
public void JustTheRoot() { var writer = from root in XmlWrite.For <string>().Tag("root") select root; var expected = "<root/>"; var actual = writer.Write(""); Assert.Equal(expected, actual); }
public void TagAndContent() { var writer = from root in XmlWrite.For <string>().Tag("root").Content("content") select root; var expected = "<root>content</root>"; var actual = writer.Write(""); Assert.Equal(expected, actual); }
public void WithSomeContent() { var writer = from root in XmlWrite.For <string>().Tag("root") from content in root.Content("just some text") select root; var expected = "<root>just some text</root>"; var actual = writer.Write(""); Assert.Equal(expected, actual); }
public void WithDynamicContent() { var writer = from root in XmlWrite.For <string>().Tag("root") from content in root.Content(x => x) select root; var expected = "<root>dynamic</root>"; var actual = writer.Write("dynamic"); Assert.Equal(expected, actual); }
public void Inline() { var writer = from root in XmlWrite.For <int[]>().Tag("root") let intWriter = XmlWrite.For <int>().Tag("int").Content(x => x.ToString()) from sub in intWriter.Many() select root; var expected = "<root><int>42</int><int>666</int></root>"; var actual = writer.Write(new[] { 42, 666 }); Assert.Equal(expected, actual); }
public void Nested() { var writer = from root in XmlWrite.For <string>().Tag("root") from child in root.Tag("child") from content in child.Content("just some text") select root; var expected = "<root><child>just some text</child></root>"; var actual = writer.Write(""); Assert.Equal(expected, actual); }
public void Composed() { var intWriter = XmlWrite.For <string>().Tag("string").Content(x => x); var writer = from root in XmlWrite.For <string[]>().Tag("root") from sub in intWriter.Many() select root; var expected = "<root><string>42</string><string>666</string></root>"; var actual = writer.Write(new[] { "42", "666" }); Assert.Equal(expected, actual); }
public void Dynamic() { var writer = from root in XmlWrite.For <string>().Tag("root") from child in root.Tag("child") from content in child.Attribute("theName", x => x) select root; var expected = "<root><child theName=\"yep\"/></root>"; var actual = writer.Write("yep"); Assert.Equal(expected, actual); }
public void PassedOn() { var writer = from root in XmlWrite.For <string>().Tag("root") from odTitle in root.Tag("child").Tag("grandchild").Content("content") select root; var expected = "<root><child><grandchild>content</grandchild></child></root>"; var actual = writer.Write(""); Assert.Equal(expected, actual); }
public void HardCoded() { var writer = from input in XmlWrite.For <string>() from root in input.Tag("root") from child in root.Tag("child") from content in child.Attribute("theName", "TheValue") select root; var expected = "<root><child theName=\"TheValue\"/></root>"; var actual = writer.Write(""); Assert.Equal(expected, actual); }
public void Fluent() { var writer = XmlWrite.For <MyThing>() .Tag("root") .Sequence( x => x.Tag("fred"), x => x.Tag("jos")); var expected = "<root><fred/><jos/></root>"; var actual = writer.Write(new MyThing()); Assert.Equal(expected, actual); }
/// <summary> /// Crea rappresentazione Xml /// </summary> /// <param name="xw"></param> /// <param name="obj"></param> /// <param name="depth"></param> public override void WriteXml(XmlWrite xw, DataObjectBase obj, int depth) { var oTemp = (DataListBase)this.GetValue(obj); xw.WriteStartElement(this.Name); try { xw.WriteRaw((oTemp == null) ? string.Empty : oTemp.ToXml(depth)); } finally { xw.WriteEndElement(); } }
public void Inline() { var writer = from root in XmlWrite.For <List <Dictionary <string, string> > >().Tag("root") let keyValueWriter = XmlWrite.For <KeyValuePair <string, string> >().Tag(x => x.Key).Content(x => x.Value) let dictionaryWriter = from someThing in XmlWrite.For <Dictionary <string, string> >().Tag("dict") from sub in keyValueWriter.Many() select root from sub in dictionaryWriter.Many() select root; Assert.Equal(expected, writer.Write(input)); }
public void OneLevel() { var intWriter = XmlWrite.For <int>().Tag("int").Content(x => x.ToString()); var writer = from root in XmlWrite.For <int>().Tag("root") from sub in intWriter select root; var expected = "<root><int>42</int></root>"; var actual = writer.Write(42); Assert.Equal(expected, actual); }
public void HardCodedSubWriter() { var hcWriter = XmlWrite.ForAny().Tag("hard").Content("coded"); var writer = from root in XmlWrite.For <int>().Tag("root") from sub in hcWriter select root; var expected = "<root><hard>coded</hard></root>"; var actual = writer.Write(42); Assert.Equal(expected, actual); }
public void LessVerbose() { var writer = from root in XmlWrite.For <MyThing>().Tag("root") from myStringContent in root.Tag("string").Content(x => x.MyString) from myIntContent in root.Tag("int").Content(x => x.MyInt.ToString()) select root; var expected = "<root><string>some text</string><int>42</int></root>"; var thing = new MyThing { MyString = "some text", MyInt = 42 }; var actual = writer.Write(thing); Assert.Equal(expected, actual); }
public void Nested() { var writer = from root in XmlWrite.For <TheOtherThing>().Tag("root") from things in root.Many(x => x.Things, r => from i in r.Tag("thing") .Many(t => t.TheInts, i => i.Tag("int").Content(x => x.ToString())) select i ) select root; var expected = "<root><thing><int>42</int><int>666</int></thing><thing><int>42</int><int>666</int></thing></root>"; var actual = writer.Write(new TheOtherThing()); Assert.Equal(expected, actual); }
public void ByKeyValue() { var keyValueWriter = XmlWrite.For <KeyValuePair <string, string> >().Tag(x => x.Key).Content(x => x.Value); var writer = from root in XmlWrite.For <IDictionary <string, string> >().Tag("root") from sub in keyValueWriter.Many() select root; var expected = "<root><keyone>valueone</keyone><keytwo>valuetwo</keytwo></root>"; var actual = writer.Write(new Dictionary <string, string> { { "keyone", "valueone" }, { "keytwo", "valuetwo" } }); Assert.Equal(expected, actual); }
public void Explicit() { var writer = from root in XmlWrite.For <IDictionary <string, string> >().Tag("root") from k1 in root.Tag("keyone").Content(x => x["keyone"]) from k2 in root.Tag("keytwo").Content(x => x["keytwo"]) select root; var expected = "<root><keyone>valueone</keyone><keytwo>valuetwo</keytwo></root>"; var actual = writer.Write(new Dictionary <string, string> { { "keyone", "valueone" }, { "keytwo", "valuetwo" } }); Assert.Equal(expected, actual); }
/// <summary> /// Scrive Xml con possibilita' di integrazione dati attraverso la specifica di una funzione /// di manipolazione /// </summary> /// <param name="function"></param> /// <param name="rewriteAll"> /// Se true allora non emette l'Xml standard dell'oggetto /// </param> /// <param name="args"></param> /// <returns></returns> public string ToXml(XmlFunction function, bool rewriteAll, params object[] args) { using (XmlWrite xw = new XmlWrite()) { //Se deve riscrivere if (!rewriteAll) { xw.WriteRaw(this.ToXml(1)); } //Se fornita funzione allora la richiama if (function != null) { function((T)this, xw, args); } return(xw.ToString()); } }