/// <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 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> /// This method kicks off the processing for writing the DIDL-Lite /// responses to Search and Browse actions. /// </summary> /// <param name="baseUrls"> /// A listing of local base URIs to use. /// The http scheme, IP address, port number, and virtual directory that make /// up the baseUrl for all http URIs. /// </param> /// <param name="properties"> /// ArrayList where each item is a metadata property name, provided /// by the UPNP control point. /// </param> /// <param name="entries"> /// The flat listing of media objects that need to be included in the response. /// </param> /// <returns></returns> private static string BuildXmlRepresentation(string[] baseUrls, ArrayList properties, ICollection entries) { ToXmlDataDv _d = new ToXmlDataDv(); _d.BaseUris = new ArrayList((ICollection) baseUrls); _d.DesiredProperties = properties; _d.IsRecursive = false; //string didl = MediaBuilder.BuildDidl(MediaObject.ToXmlFormatter_Default, _d, entries); string didl = MediaBuilder.BuildDidl(ToXmlFormatter.DefaultFormatter, _d, entries); return didl; }
/// <summary> /// Helper function for SinkCd_CreateObject(). Kicks off the process for /// obtaining the result xml and the string/CSV of new IDs for created items and containers. /// </summary> /// <param name="newBranches">list of media item and container objects that represent subtrees that are being created</param> /// <param name="newIds">comma separated value list of object IDs found in all of newBranches and its descendents</param> /// <param name="resultXml">DIDL-Lite XML for newBranches and its descendents</param> private void RecurseNewBranches(IList newBranches, StringBuilder newIds, XmlTextWriter resultXml) { //TODO: get all interfaces string baseUri = this.GetBaseUrlByInterface(); foreach (IUPnPMedia mo in newBranches) { //obtains the ids found in this subtree ObtainBranchIDs(mo, newIds); //prints this branch into xml ToXmlDataDv _d = new ToXmlDataDv(); //TODO: Add multiple uris _d.BaseUri = baseUri; _d.DesiredProperties = new ArrayList(0); _d.IsRecursive = true; //mo.ToXml(MediaObject.ToXmlFormatter_Default, _d, resultXml); mo.ToXml(ToXmlFormatter.DefaultFormatter, _d, resultXml); } }
/// <summary> /// This method kicks off the processing for writing the DIDL-Lite /// responses to Search and Browse actions. /// </summary> /// <param name="baseUrls"> /// A list, where each element is a string with the /// http scheme, IP address, port number, and virtual directory that make /// up the baseUrl for all http URIs. /// </param> /// <param name="properties"> /// ArrayList where each item is a metadata property name, provided /// by the UPNP control point. /// </param> /// <param name="entries"> /// The flat listing of media objects that need to be included in the response. /// </param> /// <exception cref="InvalidCastException"> /// Thrown if 'baseUrls' contains a non-string element. /// </exception> /// <exception cref="ArgumentException"> /// Thrown if 'baseUrls' is empty. /// </exception> /// <returns></returns> private static string BuildXmlRepresentation(ArrayList baseUrls, ArrayList properties, ICollection entries) { ToXmlDataDv _d = new ToXmlDataDv(); if (baseUrls.Count == 0) { throw new ArgumentException("MediaServerDevice.BuildXmlRepresentation() requires that 'baseUrls' be non-empty."); } // causes invalid cast exception if elements are bad foreach (string str in baseUrls); _d.BaseUri = null; _d.BaseUris = baseUrls; _d.DesiredProperties = properties; _d.IsRecursive = false; //string didl = MediaBuilder.BuildDidl(MediaObject.ToXmlFormatter_Default, _d, entries); string didl = MediaBuilder.BuildDidl(ToXmlFormatter.DefaultFormatter, _d, entries); return didl; }