/// <summary> /// Performs the actual transformation logic of this <see cref="T:TcmTemplating.TemplateBase" />. /// </summary> /// <remarks> /// Transform is the main entry-point for template functionality. /// </remarks> protected override void Transform() { using (StringWriterEncoding sw = new StringWriterEncoding(Encoding.UTF8)) { using (XmlWriter xml = XmlTextWriter.Create(sw, TemplateXmlWriterSettings)) { // Ensure the XmlWriter is available in the current rendering context Engine.PublishingContext.RenderContext.ContextVariables.Add(NATIVE_XML_WRITER, xml); foreach (global::Tridion.ContentManager.CommunicationManagement.ComponentPresentation componentPresentation in Page.ComponentPresentations) { xml.WriteRaw(Engine.RenderComponentPresentation(componentPresentation.Component.Id, componentPresentation.ComponentTemplate.Id)); } xml.WriteProcessingTime(ProcessedTime); xml.Close(); // Remove the XmlWriter from the current rendering context Engine.PublishingContext.RenderContext.ContextVariables.Remove(NATIVE_XML_WRITER); } Package.AddXml(global::Tridion.ContentManager.Templating.Package.OutputName, sw.ToString()); } }
/// <summary> /// Performs the actual transformation logic of this <see cref="T:TcmTemplating.TemplateBase" />. /// </summary> /// <remarks> /// Transform is the main entry-point for template functionality. /// </remarks> protected override void Transform() { using (StringWriterEncoding sw = new StringWriterEncoding(Encoding.UTF8)) { using (XmlWriter xml = XmlTextWriter.Create(sw)) { xml.WriteStartDocument(); xml.WriteStartElement("binary"); xml.WriteAttribute("uri", Component.Id); xml.WriteAttribute("id", Component.Id.ItemId); xml.WriteAttribute("title", Component.Title); xml.WriteAttribute("url", PublishBinary(Component)); xml.WriteEndElement(); xml.WriteEndDocument(); } Package.AddString(Tridion.ContentManager.Templating.Package.OutputName, sw.ToString()); } }
public static int Main() { StringWriterEncoding test = new StringWriterEncoding(); TestLibrary.TestFramework.BeginTestCase("StringWriterEncoding"); if (test.RunTests()) { TestLibrary.TestFramework.EndTestCase(); TestLibrary.TestFramework.LogInformation("PASS"); return(100); } else { TestLibrary.TestFramework.EndTestCase(); TestLibrary.TestFramework.LogInformation("FAIL"); return(0); } }
public static int Main() { StringWriterEncoding test = new StringWriterEncoding(); TestLibrary.TestFramework.BeginTestCase("StringWriterEncoding"); if (test.RunTests()) { TestLibrary.TestFramework.EndTestCase(); TestLibrary.TestFramework.LogInformation("PASS"); return 100; } else { TestLibrary.TestFramework.EndTestCase(); TestLibrary.TestFramework.LogInformation("FAIL"); return 0; } }
//Cobvierte el objeto comprobante a xml private void Serializar(Comprobante comprobante) { XmlSerializerNamespaces xmlNameSpace = new XmlSerializerNamespaces(); xmlNameSpace.Add("cfdi", "http://www.sat.gob.mx/cfd/3"); xmlNameSpace.Add("tfd", "http://www.sat.gob.mx/TimbreFiscalDigital"); xmlNameSpace.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance"); XmlSerializer serializer = new XmlSerializer(typeof(Comprobante)); using (var stringWriter = new StringWriterEncoding(Encoding.UTF8)) { using (XmlWriter writter = XmlWriter.Create(stringWriter)) { serializer.Serialize(writter, comprobante, xmlNameSpace); xml = stringWriter.ToString(); } } //guardamos el string en un archivo File.WriteAllText(facturaActual, xml); }
/// <summary> /// Performs the actual transformation logic of this <see cref="T:TcmTemplatingTemplateBase" />. /// </summary> /// <remarks> /// Transform is the main entry-point for template functionality. /// </remarks> protected override void Transform() { using (StringWriterEncoding sw = new StringWriterEncoding(Encoding.UTF8)) { using (TemplateHtmlWriter hw = new TemplateHtmlWriter(sw)) { hw.RenderBeginTag(HtmlTextWriterTag.Html); hw.RenderBeginTag(HtmlTextWriterTag.Head); hw.AddAttribute(HtmlTextWriterAttribute.Name, "Robots"); hw.AddAttribute(HtmlTextWriterAttribute.Content, "NoIndex, NoFollow"); hw.RenderBeginTag(HtmlTextWriterTag.Meta); hw.RenderEndTag(); hw.RenderBeginTag(HtmlTextWriterTag.Title); hw.Write("Last Published"); hw.RenderEndTag(); hw.RenderBeginTag(HtmlTextWriterTag.Body); hw.RenderBeginTag(HtmlTextWriterTag.P); hw.Write("Last Published at {0}", DateTime.Now.ToString("dd-MMM-yyyy HH:mm:ss")); if (PublishingUser != null) { hw.Write(" by {0}", PublishingUser.Title); } hw.RenderEndTag(); hw.RenderEndTag(); hw.RenderEndTag(); hw.RenderEndTag(); } Package.AddString(Package.OutputName, sw.ToString()); } }
/// <summary> /// Write out any custom metadata for the Tridion deployer extension /// </summary> /// <remarks> /// Sample custom metadata XML: /// <!--<my_metadata> /// <keywords> /// <Category Name="my_publication_path"> /// <Keyword>\publication\english</Keyword> /// </Category> /// </keywords> /// <custom> /// <ValidityStart>2010-10-31T15:42:00</ValidityStart> /// <ValidityEnd type="dateTime">2020-01-01T23:59:00</ValidityEnd> /// <Subject>Dubai</Subject> /// <Location /> /// <ContentType>General</ContentType> /// </custom> /// </my_metadata>--> /// </remarks> protected void WriteCustomMetadata() { if (CustomMetaData.Count > 0 || CustomKeywords.Count > 0) { using (StringWriter sw = new StringWriterEncoding(Encoding.UTF8)) { using (XmlTextWriter xw = new XmlTextWriter(sw)) { xw.WriteStartElement(CUSTOM_META_INSTRUCTION); if (CustomKeywords.Count > 0) { xw.WriteStartElement("keywords"); foreach (IGrouping <String, Keyword> category in CustomKeywords.GroupBy(k => k.OrganizationalItem.Title, k => k)) { xw.WriteStartElement("Category"); xw.WriteAttributeString("Name", category.Key); foreach (Keyword keyword in category) { xw.WriteStartElement("Keyword"); xw.WriteValue(keyword.Title); xw.WriteEndElement(); } xw.WriteEndElement(); } xw.WriteEndElement(); // </keywords> } if (CustomMetaData.Count > 0) { xw.WriteStartElement("custom"); foreach (KeyValuePair <String, Object> entry in CustomMetaData) { switch (Type.GetTypeCode(entry.Value.GetType())) { case TypeCode.String: xw.WriteStartElement(entry.Key); xw.WriteValue(entry.Value as String); xw.WriteEndElement(); break; case TypeCode.DateTime: xw.WriteStartElement(entry.Key); xw.WriteAttributeString("type", "dateTime"); xw.WriteValue(((DateTime)entry.Value).ToString("yyyy-MM-ddTHH:mm:ss")); xw.WriteEndElement(); break; case TypeCode.Byte: case TypeCode.Decimal: case TypeCode.Double: case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Int64: case TypeCode.SByte: case TypeCode.Single: case TypeCode.UInt16: case TypeCode.UInt32: case TypeCode.UInt64: xw.WriteStartElement(entry.Key); xw.WriteAttributeString("type", "float"); xw.WriteValue(entry.Value.ToString()); xw.WriteEndElement(); break; } } xw.WriteEndElement(); // </custom> } xw.WriteEndElement(); // </my_metadata> } sw.Flush(); Xml.WriteComment(sw.ToString()); } } }