public void WhenDivisaThenGenerateFile() { var divisa = new DivisaViewModel { Nombre = "Dolar Oficial", Simbolo = "USD", ValorCompra = "5,02", ValorVenta = "5,08", Actualizacion = "18/03/2013", Variacion = "1,3%", }; var tileXmlGenerator = new TileXmlGenerator(); const string fileName = "dolaroficial.xml"; File.Delete(fileName); using (var destination = File.CreateText(fileName)) { var wSettings = new XmlWriterSettings { Indent = true, Encoding = Encoding.GetEncoding("ISO-8859-1") }; var xw = XmlWriter.Create(destination, wSettings); tileXmlGenerator.GenerateXmlFile(xw, divisa); destination.Flush(); } }
public void GenerateXmlFile(XmlWriter xw, DivisaViewModel divisa) { //<tile> // <visual> // <binding template="TileSquareText01"> // <text id="1">Text Field 1</text> // <text id="2">Text Field 2</text> // <text id="3">Text Field 3</text> // <text id="4">Text Field 4</text> // </binding> // </visual> //</tile> xw.WriteStartDocument(); xw.WriteStartElement("tile"); xw.WriteStartElement("visual"); xw.WriteStartElement("binding"); xw.WriteStartAttribute("template"); xw.WriteString("TileSquareText01"); xw.WriteEndAttribute(); xw.WriteStartElement("text"); xw.WriteStartAttribute("id"); xw.WriteString("1"); xw.WriteEndAttribute(); xw.WriteString(divisa.Nombre.Unaccent().Split(' ').Last()); xw.WriteEndElement(); xw.WriteStartElement("text"); xw.WriteStartAttribute("id"); xw.WriteString("2"); xw.WriteEndAttribute(); xw.WriteString(string.Format("Compra: $ {0}", divisa.ValorCompra)); xw.WriteEndElement(); xw.WriteStartElement("text"); xw.WriteStartAttribute("id"); xw.WriteString("3"); xw.WriteEndAttribute(); xw.WriteString(string.Format("Venta: $ {0}", divisa.ValorVenta)); xw.WriteEndElement(); xw.WriteStartElement("text"); xw.WriteStartAttribute("id"); xw.WriteString("4"); xw.WriteEndAttribute(); xw.WriteString(divisa.Actualizacion.Replace(" ", "")); xw.WriteEndElement(); xw.WriteEndElement(); // binding xw.WriteEndElement(); // visual xw.WriteEndElement(); // tile xw.WriteEndDocument(); xw.Flush(); }
public void GenerateAndSaveXmlFromDivisa(DivisaViewModel divisa) { string nombre = divisa.Nombre.ToUrl(); var fileName = string.Format("{0}.xml", nombre); var blobStorageType = GBellmann.Azure.Storage.AzureAccount.DefaultAccount().CreateCloudBlobClient(); var container = blobStorageType.GetContainerReference("dolarblue"); using (var destination = new MemoryStream()) { var wSettings = new XmlWriterSettings { Indent = true, Encoding = Encoding.GetEncoding("ISO-8859-1") }; var xw = XmlWriter.Create(destination, wSettings); GenerateXmlFile(xw, divisa); destination.Seek(0, SeekOrigin.Begin); var destBlobReference = container.GetBlobReference(fileName); destBlobReference.Properties.ContentType = "text/xml"; destBlobReference.Properties.ContentEncoding = "ISO-8859-1"; destBlobReference.UploadFromStream(destination); } }