/// <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>
        /// Returns string representation of item.
        /// </summary>
        /// <returns></returns>
        public string ToDidl()
        {
            ArrayList properties = new ArrayList();

            StringBuilder sb        = null;
            StringWriter  sw        = null;
            MemoryStream  ms        = null;
            XmlTextWriter xmlWriter = null;

            if (MediaObject.ENCODE_UTF8)
            {
                ms        = new MemoryStream(MediaObject.XML_BUFFER_SIZE);
                xmlWriter = new XmlTextWriter(ms, System.Text.Encoding.UTF8);
            }
            else
            {
                sb        = new StringBuilder(MediaObject.XML_BUFFER_SIZE);
                sw        = new StringWriter(sb);
                xmlWriter = new XmlTextWriter(sw);
            }

            xmlWriter.Formatting = System.Xml.Formatting.Indented;
            xmlWriter.Namespaces = true;
            xmlWriter.WriteStartDocument();

            MediaObject.WriteResponseHeader(xmlWriter);

            ToXmlData _d = (ToXmlData)MediaObject.ToXmlData_AllRecurse.Clone();

            _d.IsRecursive = false;
            this.ToXml(ToXmlFormatter.DefaultFormatter, _d, xmlWriter);

            xmlWriter.WriteEndDocument();
            xmlWriter.Flush();

            string xmlResult;

            if (MediaObject.ENCODE_UTF8)
            {
                int          len   = (int)ms.ToArray().Length - MediaObject.TruncateLength_UTF8;
                UTF8Encoding utf8e = new UTF8Encoding(false, true);
                xmlResult = utf8e.GetString(ms.ToArray(), MediaObject.TruncateLength_UTF8, len);
            }
            else
            {
                xmlResult = sb.ToString();
            }
            xmlWriter.Close();

            int crpos = xmlResult.IndexOf("\r\n");

            crpos = xmlResult.IndexOf('<', crpos);
            string trunc = xmlResult.Remove(0, crpos);

            return(trunc);
        }
        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();
            }
        }
예제 #4
0
        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);
                    }
                }
            }
        }