/// <summary> /// Instructs the "xmlWriter" argument to start the "res" element. /// Override properly allows mapping of local paths to relative URIs /// using the <see cref="MediaResource.AUTOMAPFILE"/> convention. /// </summary> /// <param name="formatter"> /// A <see cref="ToXmlFormatter"/> object that /// specifies method implementations for printing /// media objects and metadata. /// </param> /// <param name="data"> /// This object should be a <see cref="ToXmlData"/> /// object that contains additional instructions used /// by the "formatter" argument. /// </param> /// <param name="xmlWriter"> /// The <see cref="XmlTextWriter"/> object that /// will format the representation in an XML /// valid way. /// </param> /// <exception cref="InvalidCastException"> /// Thrown if the "data" argument is not a <see cref="ToXmlData"/> object. /// </exception> /// <exception cref="ApplicationException"> /// Thrown if the resource's importUri attribute has been explicitly set for /// a resource that uses the <see cref="MediaResource.AUTOMAPFILE"/> convention. /// </exception> public override void StartElement(ToXmlFormatter formatter, object data, XmlTextWriter xmlWriter) { ToXmlData _d = (ToXmlData)data; this.StartResourceXml(_d.DesiredProperties, xmlWriter); this.WriteAttributesXml(data, _d.DesiredProperties, xmlWriter); this.WriteImportUriXml(_d.BaseUri, _d.DesiredProperties, xmlWriter); }
/// <summary> /// This method provides a custom implementation for printing resources. /// This custom implementation makes it so that the importUri attribute /// is not printed and also makes it so that the contentUri field /// is a relative /// </summary> /// <param name="resource"></param> /// <param name="formatter"></param> /// <param name="data"></param> /// <param name="xmlWriter"></param> private void WriteResource(IMediaResource resource, ToXmlFormatter formatter, object data, XmlTextWriter xmlWriter) { ToXmlData_Custom _d = (ToXmlData_Custom)data; Tags T = Tags.GetInstance(); xmlWriter.WriteStartElement(T[_DIDL.Res]); // write everything but importUri foreach (string attribName in resource.ValidAttributes) { if (attribName != T[_RESATTRIB.importUri]) { StringBuilder sb = new StringBuilder(20); sb.AppendFormat("{0}@{1}", T[_DIDL.Res], attribName); string filterName = sb.ToString(); if (_d.DesiredProperties == null) { } else if ((_d.DesiredProperties.Count == 0) || _d.DesiredProperties.Contains(filterName)) { xmlWriter.WriteAttributeString(attribName, resource[attribName].ToString()); } } } // write content uri as the value of the 'res' element // and note the mapping /* * StringBuilder uri = new StringBuilder(); * uri.AppendFormat("{0}{1}", _d.BaseUri, _d.i); * string str = uri.ToString(); * xmlWriter.WriteString(str); * _d.Mappings[str] = resource; * _d.i++; */ if ((bool)_d.Mappings[resource] == false) { xmlWriter.WriteString(this.ConvertLocalFileToHTTPResource(resource)); _d.Mappings[resource] = true; } xmlWriter.WriteEndElement(); }
/// <summary> /// Override - Implementation will call <see cref="DvMediaContainer.UpdateMediaMetadata"/> /// if the delegate is non-null. The delegate is executed before the base class /// the XML is written. The implementation is also responsible for printing /// the XML in such a way that each automapped resource is printed once for each /// network interface. /// </summary> /// <param name="formatter"> /// A <see cref="ToXmlFormatter"/> object that /// specifies method implementations for printing /// media objects and metadata. /// </param> /// <param name="data"> /// This object should be a <see cref="ToXmlDataDv"/> /// object that contains additional instructions used /// by this implementation. /// </param> /// <param name="xmlWriter"> /// The <see cref="XmlTextWriter"/> object that /// will format the representation in an XML /// valid way. /// </param> /// <exception cref="InvalidCastException"> /// Thrown if the "data" argument is not a <see cref="ToXmlDataDv"/> object. /// </exception> /// <exception cref="InvalidCastException"> /// Thrown if the one of the UpdateStoragexxx delegates needs to get executed /// whilst the provided value for the metadata is not a PropertyULong instance. /// </exception> public override void WriteInnerXml(ToXmlFormatter formatter, object data, XmlTextWriter xmlWriter) { if (this.Callback_UpdateMetadata != null) { this.Callback_UpdateMetadata(this); } InnerXmlWriter.WriteInnerXml ( this, new InnerXmlWriter.DelegateWriteProperties(InnerXmlWriter.WriteInnerXmlProperties), new InnerXmlWriter.DelegateShouldPrintResources(this.PrintResources), // Write resources can throw InvalidCastException new InnerXmlWriter.DelegateWriteResources(InnerXmlWriterDv.WriteInnerXmlResources), new InnerXmlWriter.DelegateWriteDescNodes(InnerXmlWriter.WriteInnerXmlDescNodes), formatter, (ToXmlData)data, xmlWriter ); }
/// <summary> /// Override - Implementation will call <see cref="DvMediaItem.UpdateMediaMetadata"/> /// if the delegate is non-null. The delegate is executed before the base class /// the XML is written. The implementation is also responsible for printing /// the XML in such a way that each automapped resource is printed once for each /// network interface. /// </summary> /// <param name="formatter"> /// A <see cref="ToXmlFormatter"/> object that /// specifies method implementations for printing /// media objects and metadata. /// </param> /// <param name="data"> /// This object should be a <see cref="ToXmlDataDv"/> /// object that contains additional instructions used /// by this implementation. /// </param> /// <param name="xmlWriter"> /// The <see cref="XmlTextWriter"/> object that /// will format the representation in an XML /// valid way. /// </param> /// <exception cref="InvalidCastException"> /// Thrown if the "data" argument is not a <see cref="ToXmlDataDv"/> object. /// </exception> /// <exception cref="InvalidCastException"> /// Thrown if the one of the UpdateStoragexxx delegates needs to get executed /// whilst the provided value for the metadata is not a PropertyULong instance. /// </exception> public override void WriteInnerXml(ToXmlFormatter formatter, object data, XmlTextWriter xmlWriter) { // To prevent constant updating of metadata for a media object, // we don't have a callback for updating item metadata, unlike // DvMediaContainer. DvMediaItem relies on the parent container // to update the metadata of the item. ToXmlDataDv txdv = (ToXmlDataDv)data; InnerXmlWriter.WriteInnerXml ( this, new InnerXmlWriter.DelegateWriteProperties(InnerXmlWriter.WriteInnerXmlProperties), new InnerXmlWriter.DelegateShouldPrintResources(this.PrintResources), new InnerXmlWriter.DelegateWriteResources(InnerXmlWriterDv.WriteInnerXmlResources), new InnerXmlWriter.DelegateWriteDescNodes(InnerXmlWriter.WriteInnerXmlDescNodes), formatter, txdv, xmlWriter ); }
public void SetTxtBox() { if (this.MediaObj != null) { StringBuilder sbXml = null; sbXml = new StringBuilder(MediaObject.XML_BUFFER_SIZE); StringWriter sw = new StringWriter(sbXml); XmlTextWriter xmlWriter = new XmlTextWriter(sw); xmlWriter.Formatting = System.Xml.Formatting.Indented; xmlWriter.Namespaces = true; ToXmlFormatter _f = new ToXmlFormatter(); ToXmlData _d = new ToXmlData(); _d.DesiredProperties = new ArrayList(0); _d.IsRecursive = false; this.MediaObj.ToXml(_f, _d, xmlWriter); //this.MediaObj.ToXml(false, new ArrayList(0), xmlWriter); this.txtbox.Text = sbXml.ToString(); } }
public static void WriteInnerXmlResources(IUPnPMedia mo, InnerXmlWriter.DelegateShouldPrintResources shouldPrintResources, ToXmlFormatter formatter, ToXmlData data, XmlTextWriter xmlWriter) { IDvMedia dvm = (IDvMedia)mo; ToXmlDataDv txdv = (ToXmlDataDv)data; if (shouldPrintResources(txdv.DesiredProperties)) { if (txdv.BaseUris == null) { txdv.BaseUris = new ArrayList(); } if (txdv.BaseUris.Count == 0) { txdv.BaseUris.Add(txdv.BaseUri); } ToXmlFormatter resFormatter = formatter; resFormatter.StartElement = null; resFormatter.EndElement = null; resFormatter.WriteInnerXml = null; resFormatter.WriteValue = null; // Code is unfinished - intended to allow a media object to // print duplicate resource elements so that each resource // is printed once for every available network interface. foreach (string baseUri in txdv.BaseUris) { txdv.BaseUri = baseUri; foreach (IMediaResource res in dvm.MergedResources) { // Set up the resource formatter to use the // default StartElement, EndElement, WriteInnerXml, and WriteValue // implementations. This stuff has no effect // if the WriteResource field has been assigned. res.ToXml(resFormatter, txdv, xmlWriter); } } } }
/// <summary> /// Always prints the full representation as required by the CDS specification. /// No custom formatting options are honored, although desired properties /// are supported in the data param. /// </summary> /// <param name="formatter">only options related to CDS-normative formatting are honored</param> /// <param name="data">Must be <see cref="ToXmlData"/> instance.</param> /// <param name="xmlWriter"></param> public void ToXml(ToXmlFormatter formatter, object data, XmlTextWriter xmlWriter) { xmlWriter.WriteStartElement(T[_DIDL.Item]); xmlWriter.WriteAttributeString(T[_ATTRIB.id], this.ID); xmlWriter.WriteAttributeString(T[_ATTRIB.refID], this.m_Underlying.ID); xmlWriter.WriteAttributeString(T[_ATTRIB.parentID], this.m_Parent.ID); xmlWriter.WriteAttributeString(T[_ATTRIB.restricted], "1"); InnerXmlWriter.WriteInnerXml ( this, new InnerXmlWriter.DelegateWriteProperties(InnerXmlWriter.WriteInnerXmlProperties), new InnerXmlWriter.DelegateShouldPrintResources(MediaObject.ShouldPrintResources), new InnerXmlWriter.DelegateWriteResources(InnerXmlWriter.WriteInnerXmlResources), new InnerXmlWriter.DelegateWriteDescNodes(InnerXmlWriter.WriteInnerXmlDescNodes), formatter, (ToXmlData)data, xmlWriter ); xmlWriter.WriteEndElement(); }