/// <summary>
        ///
        /// </summary>
        /// <param name="mo"></param>
        /// <param name="writeProperties"></param>
        /// <param name="shouldPrintResources"></param>
        /// <param name="writeResources"></param>
        /// <param name="writeDescNodes"></param>
        /// <param name="formatter"></param>
        /// <param name="data"></param>
        /// <param name="xmlWriter"></param>
        public static void WriteInnerXml(
            IUPnPMedia mo,
            DelegateWriteProperties writeProperties,
            DelegateShouldPrintResources shouldPrintResources,
            DelegateWriteResources writeResources,
            DelegateWriteDescNodes writeDescNodes,
            ToXmlFormatter formatter,
            ToXmlData data,
            XmlTextWriter xmlWriter
            )
        {
            // When serializing the properties, resources, and desc nodes,
            // we must always write the inner xml, the value, and the element
            // declaration. Save the original values, print these portions
            // of the DIDL-Lite and then revert back.

            ToXmlData d2 = data;

            data.IncludeElementDeclaration = true;
            data.IncludeInnerXml           = true;
            data.IncludeValue = true;

            if (writeProperties != null)
            {
                writeProperties(mo, data, xmlWriter);
            }

            if (writeResources != null)
            {
                writeResources(mo, shouldPrintResources, formatter, data, xmlWriter);
            }

            if (writeDescNodes != null)
            {
                writeDescNodes(mo, data, xmlWriter);
            }

            data.IncludeElementDeclaration = d2.IncludeElementDeclaration;
            data.IncludeInnerXml           = d2.IncludeInnerXml;
            data.IncludeValue = d2.IncludeValue;

            IMediaContainer mc = mo as IMediaContainer;

            if (mc != null)
            {
                if (data.IsRecursive)
                {
                    foreach (IUPnPMedia child in mc.CompleteList)
                    {
                        ToXmlFormatter f2 = formatter;
                        f2.StartElement  = null;
                        f2.EndElement    = null;
                        f2.WriteInnerXml = null;
                        f2.WriteValue    = null;

                        child.ToXml(f2, data, xmlWriter);
                    }
                }
            }
        }
        /// <summary>
        /// Used primarily by <see cref="ICdsElement.ToXml"/> implementations.
        /// <para>
        /// Implementation will assign some default implementaitons
        /// to the unassigned <see cref="ToXmlFormatter.Method"/> fields
        /// of the "formatter" argument, unless information in
        /// the "data" argument specify otherwise.
        /// The assigned delegates are obtained from the "obj" argument's
        /// implementations of the <see cref="IToXmlData"/> methods.
        /// </para>
        /// <para>
        /// After assigning delegate implementations to the "formatter", the
        /// method calls <see cref="ToXmlFormatter.ToXml"/> to complete
        /// the standard implementation.
        /// </para>
        /// </summary>
        /// <param name="obj">This object provides the implementations assigned to the formatter argument.</param>
        /// <param name="formatter">
        /// A <see cref="ToXmlFormatter"/> object that
        /// specifies method implementations for printing
        /// media objects. Delegate fields may be reassigned here
        /// if they are null.
        /// </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>
        public static void ToXml(IToXmlData obj, ToXmlFormatter formatter, ToXmlData data, XmlTextWriter xmlWriter)
        {
            ToXmlData _d = (ToXmlData)data;

            if ((formatter.StartElement == null) && (_d.IncludeElementDeclaration == true))
            {
                formatter.StartElement = new ToXmlFormatter.Method(obj.StartElement);
            }

            if ((formatter.WriteInnerXml == null) && (_d.IncludeInnerXml == true))
            {
                formatter.WriteInnerXml = new ToXmlFormatter.Method(obj.WriteInnerXml);
            }

            if ((formatter.WriteValue == null) && (_d.IncludeValue == true))
            {
                formatter.WriteValue = new ToXmlFormatter.Method(obj.WriteValue);
            }

            if ((formatter.EndElement == null) && (_d.IncludeElementDeclaration == true))
            {
                formatter.EndElement = new ToXmlFormatter.Method(obj.EndElement);
            }

            // Now call those implementations.
            ToXmlFormatter.ToXml(formatter, data, xmlWriter);
        }
        /// <summary>
        /// Instructs the "xmlWriter" argument to start the "upnp:searchClass" element.
        /// </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 when the "data" argument is not a <see cref="ToXmlData"/> object.
        /// </exception>
        public override void StartElement(ToXmlFormatter formatter, object data, XmlTextWriter xmlWriter)
        {
            ToXmlData _d = (ToXmlData)data;

            xmlWriter.WriteStartElement(Tags.PropertyAttributes.upnp_searchClass);

            if (this.m_AttributeNames == null)
            {
                this.PrintFriendlyName(_d.DesiredProperties, xmlWriter);
                this.PrintIncludeDerived(_d.DesiredProperties, xmlWriter);
            }
            else
            {
                foreach (string attribName in this.m_AttributeNames)
                {
                    if (string.Compare(attribName, T[_ATTRIB.name]) == 0)
                    {
                        this.PrintFriendlyName(_d.DesiredProperties, xmlWriter);
                    }
                    else if (string.Compare(attribName, T[_ATTRIB.includeDerived]) == 0)
                    {
                        this.PrintIncludeDerived(_d.DesiredProperties, xmlWriter);
                    }
                }
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// The override is provided so that callers can specify their
 /// own implementations that will write the xml.
 /// This is achieved by setting the <see cref="ToXmlFormatter.WriteItem"/>
 /// field of the 'formatter'.
 /// </summary>
 /// <param name="formatter">
 /// Allows the caller to specify a custom implementation that writes
 /// the item's XML. Simply assign the <see cref="ToXmlFormatter.WriteItem"/>
 /// to have this method delegate the responsibility. Otherwise,
 /// the base class implementation of <see cref="MediaObject.ToXml"/>
 /// is called.
 /// </param>
 /// <param name="data">
 /// If the formatter's <see cref="ToXmlFormatter.WriteItem"/> field
 /// is non-null, then this object must be a type acceptable to that method's
 /// implementation. Otherwise, a <see cref="ToXmlData"/> object is required.
 /// </param>
 /// <param name="xmlWriter">
 /// This is where the xml gets printed.
 /// </param>
 public override void ToXml(ToXmlFormatter formatter, object data, XmlTextWriter xmlWriter)
 {
     if (formatter.WriteItem != null)
     {
         formatter.StartElement  = null;
         formatter.EndElement    = null;
         formatter.WriteInnerXml = null;
         formatter.WriteValue    = null;
         formatter.WriteItem(this, formatter, data, xmlWriter);
     }
     else
     {
         base.ToXml(formatter, data, xmlWriter);
     }
 }
        /// <summary>
        /// Instructs the "xmlWriter" argument to start the metadata element.
        /// </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>
        public void StartElement(ToXmlFormatter formatter, object data, XmlTextWriter xmlWriter)
        {
            ToXmlData _d = (ToXmlData)data;

            xmlWriter.WriteStartElement(this.ns_tag);
            if (_d.DesiredProperties != null)
            {
                if (_d.DesiredProperties.Contains(this.ns_tag + "@role"))
                {
                    if ((this.m_role != null) && (this.m_role != ""))
                    {
                        xmlWriter.WriteAttributeString("role", this.m_role);
                    }
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// <para>
        /// Programmers assign the <see cref="ToXmlFormatter.StartElement"/>
        /// field to this method, when attempting to print this media object.
        /// </para>
        /// <para>
        /// Algorithm:
        ///	1. declare the item element
        ///
        ///	2. If this object will be added as a direct child
        ///	of a container in a CreateObject request, then
        ///	do not print the object's ID.
        ///
        ///	3. Print the ID of the item that this object points
        ///	to if appropriate. If intending to request
        ///	a MediaServer to create a child object that points
        ///	to another object then a control point should
        ///	use the CreateReference, so in such a case
        ///	this method will throw an exception.
        ///
        ///	4. Print the parent object, taking into account
        ///	CreateObject instructions.
        ///
        ///	5. Print the restricted attribute.
        /// </para>
        /// </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.
        ///
        /// <para>
        /// For an explanation why this argument allows any object,
        /// please consult the documentation for the
        /// <see cref="ToXmlFormatter.Method"/> delegate type.
        /// </para>
        ///
        /// </param>
        /// <param name="xmlWriter">
        /// The <see cref="XmlTextWriter"/> object that
        /// will format the representation in an XML
        /// valid way.
        /// </param>
        /// <exception cref="InvalidCastException">
        /// Thrown when the "data" argument is not a
        /// <see cref="ToXmlData"/> object.
        public override void StartElement(ToXmlFormatter formatter, object data, XmlTextWriter xmlWriter)
        {
            ToXmlData _d = (ToXmlData)data;

            xmlWriter.WriteStartElement(T[_DIDL.Item]);

            if (_d.CreateObjectParentID != null)
            {
                xmlWriter.WriteAttributeString(T[_ATTRIB.id], "");
            }
            else
            {
                xmlWriter.WriteAttributeString(T[_ATTRIB.id], this.ID);
            }

            if (this.IsReference)
            {
                if (_d.CreateObjectParentID != null)
                {
                    throw new Error_BadMetadata("Cannot print this object's XML for use with CreateObject because it is a reference item. Use the CreateReference action instead. Error found on ID='" + this.m_ID + "'");
                }
                xmlWriter.WriteAttributeString(T[_ATTRIB.refID], this.RefID);
            }

            if (_d.CreateObjectParentID != null)
            {
                xmlWriter.WriteAttributeString(T[_ATTRIB.parentID], _d.CreateObjectParentID);
            }
            else if (this.m_Parent != null)
            {
                xmlWriter.WriteAttributeString(T[_ATTRIB.parentID], this.m_Parent.ID);
            }
            else if (this.m_ParentID != null)
            {
                xmlWriter.WriteAttributeString(T[_ATTRIB.parentID], this.m_ParentID);
            }
            else if (_d.IgnoreBlankParentError)
            {
                xmlWriter.WriteAttributeString(T[_ATTRIB.parentID], "-1");
            }
            else
            {
                throw new Error_BadMetadata("Object must have a parent in order to be printed as DIDL-Lite. Error found on ID='" + this.m_ID + "'");
            }

            xmlWriter.WriteAttributeString(T[_ATTRIB.restricted], GetBoolAsOneZero(this.IsRestricted).ToString());
        }
        /// <summary>
        /// Instructs the "xmlWriter" argument to start the "upnp:class" element.
        /// </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>
        public virtual void StartElement(ToXmlFormatter formatter, object data, XmlTextWriter xmlWriter)
        {
            xmlWriter.WriteStartElement(Tags.PropertyAttributes.upnp_class);
            ToXmlData _d = (ToXmlData)data;

            if (this.m_AttributeNames == null)
            {
                this.PrintFriendlyName(_d.DesiredProperties, xmlWriter);
            }
            else
            {
                foreach (string attribName in this.m_AttributeNames)
                {
                    if (string.Compare(attribName, T[_ATTRIB.name]) == 0)
                    {
                        this.PrintFriendlyName(_d.DesiredProperties, xmlWriter);
                    }
                }
            }
        }
        /// <summary>
        /// Default implementation to use when printing media object resources.
        /// </summary>
        /// <param name="mo"></param>
        /// <param name="shouldPrintResources"></param>
        /// <param name="formatter"></param>
        /// <param name="data"></param>
        /// <param name="xmlWriter"></param>
        public static void WriteInnerXmlResources(IUPnPMedia mo, DelegateShouldPrintResources shouldPrintResources, ToXmlFormatter formatter, ToXmlData data, XmlTextWriter xmlWriter)
        {
            if (shouldPrintResources(data.DesiredProperties))
            {
                // 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.
                ToXmlFormatter resFormatter = formatter;
                resFormatter.StartElement  = null;
                resFormatter.EndElement    = null;
                resFormatter.WriteInnerXml = null;
                resFormatter.WriteValue    = null;

                // print the resources
                foreach (IMediaResource res in mo.MergedResources)
                {
                    res.ToXml(resFormatter, data, xmlWriter);
                }
            }
        }
Exemplo n.º 9
0
		/// <summary>
		/// Default implementation to use when printing media object resources.
		/// </summary>
		/// <param name="mo"></param>
		/// <param name="shouldPrintResources"></param>
		/// <param name="formatter"></param>
		/// <param name="data"></param>
		/// <param name="xmlWriter"></param>
		public static void WriteInnerXmlResources(IUPnPMedia mo, DelegateShouldPrintResources shouldPrintResources, ToXmlFormatter formatter, ToXmlData data, XmlTextWriter xmlWriter)
		{
			if (shouldPrintResources(data.DesiredProperties))
			{
				// 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.
				ToXmlFormatter resFormatter = formatter;
				resFormatter.StartElement = null;
				resFormatter.EndElement = null;
				resFormatter.WriteInnerXml = null;
				resFormatter.WriteValue = null;

				// print the resources
				foreach (IMediaResource res in mo.MergedResources)
				{
					res.ToXml(resFormatter, data, xmlWriter);
				}
			}
		}
        /// <summary>
        /// A default implementation of the ToXml() method that
        /// simply calls each of the delegate-fields in the "formatter"
        /// argument.
        /// </summary>
        /// <param name="formatter">
        /// A <see cref="ToXmlFormatter"/> object that
        /// specifies method implementations for printing
        /// media objects and metadata.
        /// <para>
        /// If any of the <see cref="ToXmlFormatter.Method"/>
        /// fields are null, then the delegate is not
        /// executed. This feature can be used to print
        /// only the inner XML values.
        /// </para>
        /// </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>
        public static void ToXml(ToXmlFormatter formatter, object data, XmlTextWriter xmlWriter)
        {
            if (formatter.StartElement != null)
            {
                formatter.StartElement(formatter, data, xmlWriter);
            }

            if (formatter.WriteInnerXml != null)
            {
                formatter.WriteInnerXml(formatter, data, xmlWriter);
            }

            if (formatter.WriteValue != null)
            {
                formatter.WriteValue(formatter, data, xmlWriter);
            }

            if (formatter.EndElement != null)
            {
                formatter.EndElement(formatter, data, xmlWriter);
            }
        }
 /// <summary>
 /// Prints the XML representation of the metadata element.
 /// <para>
 /// Implementation calls the <see cref="ToXmlData.ToXml"/>
 /// method for its implementation.
 /// </para>
 /// </summary>
 /// <param name="formatter">
 /// A <see cref="ToXmlFormatter"/> object that
 /// specifies method implementations for printing
 /// media objects.
 /// </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>
 public void ToXml(ToXmlFormatter formatter, object data, XmlTextWriter xmlWriter)
 {
     ToXmlData.ToXml(this, formatter, (ToXmlData)data, xmlWriter);
 }
Exemplo n.º 12
0
        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();
            }
        }
Exemplo n.º 13
0
 /// <summary>
 /// Starts the xml element.
 /// </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>
 public abstract void StartElement(ToXmlFormatter formatter, object data, XmlTextWriter xmlWriter);
Exemplo n.º 14
0
        /// <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>
 /// Instructs the "xmlWriter" argument to close the metadata element.
 /// </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>
 public void EndElement(ToXmlFormatter formatter, object data, XmlTextWriter xmlWriter)
 {
     xmlWriter.WriteEndElement();
 }
Exemplo n.º 16
0
		/// <summary>
		/// Prints the XML representation of the resource.
		/// <para>
		/// If the formatter's <see cref="ToXmlFormatter.WriteResource"/>
		/// field is non-null, then that delegate is executed. Otherwise,
		/// the implementation calls the <see cref="ToXmlData.ToXml"/>
		/// method for its implementation.
		/// </para>
		/// </summary>
		/// 
		/// <param name="formatter">
		/// Allows the caller to specify a custom implementation that writes
		/// the resources's XML. Simply assign the <see cref="ToXmlFormatter.WriteResource"/>
		/// to have this method delegate the responsibility. Otherwise,
		/// the the implementation of <see cref="ToXmlData.ToXml"/>
		/// is called.
		/// </param>
		/// 
		/// <param name="data">
		/// If the formatter's <see cref="ToXmlFormatter.WriteResource"/> field
		/// is non-null, then this object must be a type acceptable to that method's
		/// implementation. Otherwise, a <see cref="ToXmlData"/> object is required.
		/// </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>
		public virtual void ToXml (ToXmlFormatter formatter, object data, XmlTextWriter xmlWriter)
		{
			if (formatter.WriteResource != null)
			{
				formatter.WriteResource(this, formatter, data, xmlWriter);
			}
			else
			{
				ToXmlData.ToXml(this, formatter, (ToXmlData) data, xmlWriter);
			}
		}
Exemplo n.º 17
0
		/// <summary>
		/// Empty - res elements have no child xml elements.
		/// </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>
		public virtual void WriteInnerXml(ToXmlFormatter formatter, object data, XmlTextWriter xmlWriter)
		{
			// This method intentionally left blank.
			;
		}
Exemplo n.º 18
0
		/// <summary>
		/// Instructs the "xmlWriter" argument to start the metadata element.
		/// </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>
		public void StartElement(ToXmlFormatter formatter, object data, XmlTextWriter xmlWriter)
		{
			xmlWriter.WriteStartElement(this.ns_tag);
		}
Exemplo n.º 19
0
		/// <summary>
		/// Instructs the "xmlWriter" argument to start the "upnp:searchClass" element.
		/// </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 when the "data" argument is not a <see cref="ToXmlData"/> object.
		/// </exception>
		public override void StartElement(ToXmlFormatter formatter, object data, XmlTextWriter xmlWriter)		
		{
			ToXmlData _d = (ToXmlData) data;

			xmlWriter.WriteStartElement(Tags.PropertyAttributes.upnp_searchClass);

			if (this.m_AttributeNames == null)
			{
				this.PrintFriendlyName(_d.DesiredProperties, xmlWriter);
				this.PrintIncludeDerived(_d.DesiredProperties, xmlWriter);
			}
			else
			{
				foreach (string attribName in this.m_AttributeNames)
				{
					if (string.Compare(attribName, T[_ATTRIB.name]) == 0)
					{
						this.PrintFriendlyName(_d.DesiredProperties, xmlWriter);
					}
					else if (string.Compare(attribName, T[_ATTRIB.includeDerived]) == 0)
					{
						this.PrintIncludeDerived(_d.DesiredProperties, xmlWriter);
					}
				}
			}
		}
Exemplo n.º 20
0
		/// <summary>
		/// Instructs the "xmlWriter" argument to write the value of
		/// the "res" element.
		/// </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>
		public virtual void WriteValue(ToXmlFormatter formatter, object data, XmlTextWriter xmlWriter)
		{
			ToXmlData _d = (ToXmlData) data;
			this.WriteContentUriXml(_d.BaseUri, xmlWriter);
		}
Exemplo n.º 21
0
		/// <summary>
		/// Instructs the "xmlWriter" argument to start the metadata element.
		/// </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>
		public void StartElement(ToXmlFormatter formatter, object data, XmlTextWriter xmlWriter)
		{
			ToXmlData _d = (ToXmlData) data;

			xmlWriter.WriteStartElement(this.ns_tag);
			if (_d.DesiredProperties != null)
			{
				if (_d.DesiredProperties.Contains(this.ns_tag+"@role"))
				{
					if ((this.m_role != null) && (this.m_role != ""))
					{
						xmlWriter.WriteAttributeString("role", this.m_role);
					}
				}
			}
		}
Exemplo n.º 22
0
 /// <summary>
 /// <para>
 /// Programmers assign the <see cref="ToXmlFormatter.WriteInnerXml"/>
 /// field to this method, when attempting to print this media object.
 /// </para>
 /// </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 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="ToXmlData"/> object.
 /// </exception>
 public virtual void WriteInnerXml(ToXmlFormatter formatter, object data, XmlTextWriter xmlWriter)
 {
     InnerXmlWriter.WriteInnerXml
         (
         this,
         new InnerXmlWriter.DelegateWriteProperties(InnerXmlWriter.WriteInnerXmlProperties),
         new InnerXmlWriter.DelegateShouldPrintResources(this.PrintResources),
         new InnerXmlWriter.DelegateWriteResources(InnerXmlWriter.WriteInnerXmlResources),
         new InnerXmlWriter.DelegateWriteDescNodes(InnerXmlWriter.WriteInnerXmlDescNodes),
         formatter,
         (ToXmlData) data,
         xmlWriter
         );
 }
Exemplo n.º 23
0
        /// <summary>
        /// Prints the XML representation of this media object.
        /// <para>
        /// Implementation will assign some default implementaitons
        /// to the unassigned <see cref="ToXmlFormatter.Method"/> fields 
        /// of the "formatter" argument, unless information in
        /// the "data" argument specify otherwise.
        /// </para>
        /// </summary>
        /// <param name="formatter">
        /// A <see cref="ToXmlFormatter"/> object that
        /// specifies method implementations for printing
        /// media objects.
        /// </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 when the "data" argument is not a <see cref="ToXmlData"/> object.
        /// </exception>
        public virtual void ToXml(ToXmlFormatter formatter, object data, XmlTextWriter xmlWriter)
        {
            formatter.StartElement = null;
            formatter.EndElement = null;
            formatter.WriteInnerXml = null;
            formatter.WriteValue  = null;

            ToXmlData _d = (ToXmlData) data;
            if (_d.IncludeElementDeclaration == true)
            {
                formatter.StartElement = new ToXmlFormatter.Method (this.StartElement);
            }

            if (_d.IncludeInnerXml == true)
            {
                formatter.WriteInnerXml = new ToXmlFormatter.Method (this.WriteInnerXml);
            }

            if (_d.IncludeElementDeclaration == true)
            {
                formatter.EndElement = new ToXmlFormatter.Method (this.EndElement);
            }

            // Now call those implementations.
            ToXmlFormatter.ToXml(formatter, data, xmlWriter);
        }
 /// <summary>
 /// Instructs the "xmlWriter" argument to start the metadata element.
 /// </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>
 public void StartElement(ToXmlFormatter formatter, object data, XmlTextWriter xmlWriter)
 {
     xmlWriter.WriteStartElement(this.ns_tag);
 }
Exemplo n.º 25
0
		/// <summary>
		/// Instructs the "xmlWriter" argument to start the "upnp:class" element.
		/// </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>
		public virtual void StartElement(ToXmlFormatter formatter, object data, XmlTextWriter xmlWriter)
		{
			xmlWriter.WriteStartElement(Tags.PropertyAttributes.upnp_class);
			ToXmlData _d = (ToXmlData) data;
			if (this.m_AttributeNames == null)
			{
				this.PrintFriendlyName(_d.DesiredProperties, xmlWriter);
			}
			else
			{
				foreach (string attribName in this.m_AttributeNames)
				{
					if (string.Compare(attribName, T[_ATTRIB.name]) == 0)
					{
						this.PrintFriendlyName(_d.DesiredProperties, xmlWriter);
					}
				}
			}
		}
 /// <summary>
 /// Instructs the "xmlWriter" argument to write the value of
 /// the metadata element.
 /// </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>
 public void WriteValue(ToXmlFormatter formatter, object data, XmlTextWriter xmlWriter)
 {
     xmlWriter.WriteString(this.StringValue);
 }
Exemplo n.º 27
0
		/// <summary>
		/// Instructs the "xmlWriter" argument to close the "upnp:class" element.
		/// </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>
		public virtual void EndElement(ToXmlFormatter formatter, object data, XmlTextWriter xmlWriter)
		{
			xmlWriter.WriteEndElement();
		}
 /// <summary>
 /// Empty - this element has no child xml elements.
 /// </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>
 public void WriteInnerXml(ToXmlFormatter formatter, object data, XmlTextWriter xmlWriter)
 {
 }
Exemplo n.º 29
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="mo"></param>
		/// <param name="writeProperties"></param>
		/// <param name="shouldPrintResources"></param>
		/// <param name="writeResources"></param>
		/// <param name="writeDescNodes"></param>
		/// <param name="formatter"></param>
		/// <param name="data"></param>
		/// <param name="xmlWriter"></param>
		public static void WriteInnerXml (
			IUPnPMedia mo, 
			DelegateWriteProperties writeProperties, 
			DelegateShouldPrintResources shouldPrintResources, 
			DelegateWriteResources writeResources, 
			DelegateWriteDescNodes writeDescNodes, 
			ToXmlFormatter formatter, 
			ToXmlData data, 
			XmlTextWriter xmlWriter
			)
		{
			// When serializing the properties, resources, and desc nodes,
			// we must always write the inner xml, the value, and the element
			// declaration. Save the original values, print these portions
			// of the DIDL-Lite and then revert back.

			ToXmlData d2 = data;
			
			data.IncludeElementDeclaration = true;
			data.IncludeInnerXml = true;
			data.IncludeValue = true;

			if (writeProperties != null)
			{
				writeProperties(mo, data, xmlWriter); 
			}
			
			if (writeResources != null) 
			{
				writeResources(mo, shouldPrintResources, formatter, data, xmlWriter); 
			}
			
			if (writeDescNodes != null) 
			{
				writeDescNodes(mo, data, xmlWriter); 
			}

			data.IncludeElementDeclaration = d2.IncludeElementDeclaration;
			data.IncludeInnerXml = d2.IncludeInnerXml;
			data.IncludeValue = d2.IncludeValue;

			IMediaContainer mc = mo as IMediaContainer;
			if (mc != null)
			{
				if (data.IsRecursive)
				{
					foreach (IUPnPMedia child in mc.CompleteList)
					{
						ToXmlFormatter f2 = formatter;
						f2.StartElement = null;
						f2.EndElement = null;
						f2.WriteInnerXml = null;
						f2.WriteValue = null;

						child.ToXml(f2, data, xmlWriter);
					}
				}
			}
		}
Exemplo n.º 30
0
		/// <summary>
		/// Instructs the "xmlWriter" argument to start the "res" element.
		/// </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>
		public virtual void StartElement(ToXmlFormatter formatter, object data, XmlTextWriter xmlWriter)
		{
			ToXmlData _d = (ToXmlData) data;
			this.StartResourceXml(_d.DesiredProperties, xmlWriter);
			this.WriteAttributesXml(data, _d.DesiredProperties, xmlWriter);
		}
Exemplo n.º 31
0
		/// <summary>
		/// <para>
		/// Programmers assign the <see cref="ToXmlFormatter.StartElement"/>
		/// field to this method, when attempting to print this media object.
		/// </para>
		/// <para>
		/// Algorithm:
		///	1. declare the item element
		///
		///	2. If this object will be added as a direct child
		///	of a container in a CreateObject request, then
		///	do not print the object's ID.
		///
		///	3. Print the ID of the item that this object points
		///	to if appropriate. If intending to request
		///	a MediaServer to create a child object that points 
		///	to another object then a control point should
		///	use the CreateReference, so in such a case
		///	this method will throw an exception.
		///
		///	4. Print the parent object, taking into account
		///	CreateObject instructions.
		///
		///	5. Print the restricted attribute.
		/// </para>
		/// </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.
		/// 
		/// <para>
		/// For an explanation why this argument allows any object,
		/// please consult the documentation for the
		/// <see cref="ToXmlFormatter.Method"/> delegate type.
		/// </para>
		/// 
		/// </param>
		/// <param name="xmlWriter">
		/// The <see cref="XmlTextWriter"/> object that
		/// will format the representation in an XML
		/// valid way.
		/// </param>
		/// <exception cref="InvalidCastException">
		/// Thrown when the "data" argument is not a
		/// <see cref="ToXmlData"/> object.
		public override void StartElement (ToXmlFormatter formatter, object data, XmlTextWriter xmlWriter)
		{
			ToXmlData _d = (ToXmlData) data;

			xmlWriter.WriteStartElement(T[_DIDL.Item]);

			if (_d.CreateObjectParentID != null)
			{
				xmlWriter.WriteAttributeString(T[_ATTRIB.id], "");
			}
			else
			{
				xmlWriter.WriteAttributeString(T[_ATTRIB.id], this.ID);
			}

			if (this.IsReference)
			{
				if (_d.CreateObjectParentID != null)
				{
					throw new Error_BadMetadata("Cannot print this object's XML for use with CreateObject because it is a reference item. Use the CreateReference action instead. Error found on ID='" +this.m_ID+"'");
				}
				xmlWriter.WriteAttributeString(T[_ATTRIB.refID], this.RefID);
			}

			if (_d.CreateObjectParentID != null)
			{
				xmlWriter.WriteAttributeString(T[_ATTRIB.parentID], _d.CreateObjectParentID);
			}
			else if (this.m_Parent != null)
			{
				xmlWriter.WriteAttributeString(T[_ATTRIB.parentID], this.m_Parent.ID);
			}
			else if (this.m_ParentID != null)
			{
				xmlWriter.WriteAttributeString(T[_ATTRIB.parentID], this.m_ParentID);
			}
			else if (_d.IgnoreBlankParentError)
			{
				xmlWriter.WriteAttributeString(T[_ATTRIB.parentID], "-1");
			}
			else
			{
				throw new Error_BadMetadata("Object must have a parent in order to be printed as DIDL-Lite. Error found on ID='" +this.m_ID+"'");
			}

			xmlWriter.WriteAttributeString(T[_ATTRIB.restricted], GetBoolAsOneZero(this.IsRestricted).ToString());
		}
Exemplo n.º 32
0
		/// <summary>
		/// Instructs the "xmlWriter" argument to close the "res" element.
		/// </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>
		public virtual void EndElement(ToXmlFormatter formatter, object data, XmlTextWriter xmlWriter)
		{
			this.EndResourceXml(xmlWriter);
		}
Exemplo n.º 33
0
		/// <summary>
		/// Used primarily by <see cref="ICdsElement.ToXml"/> implementations.
		/// <para>
		/// Implementation will assign some default implementaitons
		/// to the unassigned <see cref="ToXmlFormatter.Method"/> fields 
		/// of the "formatter" argument, unless information in
		/// the "data" argument specify otherwise.
		/// The assigned delegates are obtained from the "obj" argument's
		/// implementations of the <see cref="IToXmlData"/> methods.
		/// </para>
		/// <para>
		/// After assigning delegate implementations to the "formatter", the
		/// method calls <see cref="ToXmlFormatter.ToXml"/> to complete
		/// the standard implementation.
		/// </para>
		/// </summary>
		/// <param name="obj">This object provides the implementations assigned to the formatter argument.</param>
		/// <param name="formatter">
		/// A <see cref="ToXmlFormatter"/> object that
		/// specifies method implementations for printing
		/// media objects. Delegate fields may be reassigned here
		/// if they are null.
		/// </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>
		public static void ToXml(IToXmlData obj, ToXmlFormatter formatter, ToXmlData data, XmlTextWriter xmlWriter)
		{
			ToXmlData _d = (ToXmlData) data;
			if ((formatter.StartElement == null) && (_d.IncludeElementDeclaration == true))
			{
				formatter.StartElement = new ToXmlFormatter.Method (obj.StartElement);
			}
			
			if ((formatter.WriteInnerXml == null) && (_d.IncludeInnerXml == true))
			{
				formatter.WriteInnerXml = new ToXmlFormatter.Method (obj.WriteInnerXml);
			}

			if ((formatter.WriteValue == null) && (_d.IncludeValue == true))
			{
				formatter.WriteValue = new ToXmlFormatter.Method (obj.WriteValue);
			}

			if ((formatter.EndElement == null) && (_d.IncludeElementDeclaration == true))
			{
				formatter.EndElement = new ToXmlFormatter.Method (obj.EndElement);
			}

			// Now call those implementations.
			ToXmlFormatter.ToXml(formatter, data, xmlWriter);
		}
Exemplo n.º 34
0
		/// <summary>
		/// A default implementation of the ToXml() method that
		/// simply calls each of the delegate-fields in the "formatter"
		/// argument.
		/// </summary>
		/// <param name="formatter">
		/// A <see cref="ToXmlFormatter"/> object that
		/// specifies method implementations for printing
		/// media objects and metadata.
		/// <para>
		/// If any of the <see cref="ToXmlFormatter.Method"/>
		/// fields are null, then the delegate is not
		/// executed. This feature can be used to print
		/// only the inner XML values.
		/// </para>
		/// </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>
		public static void ToXml(ToXmlFormatter formatter, object data, XmlTextWriter xmlWriter)
		{
			if (formatter.StartElement != null)
			{
				formatter.StartElement(formatter, data, xmlWriter);
			}

			if (formatter.WriteInnerXml != null)
			{
				formatter.WriteInnerXml(formatter, data, xmlWriter);
			}

			if (formatter.WriteValue != null)
			{
				formatter.WriteValue(formatter, data, xmlWriter);
			}

			if (formatter.EndElement != null)
			{
				formatter.EndElement(formatter, data, xmlWriter);
			}
		}
Exemplo n.º 35
0
		public void ToXml(ToXmlFormatter formatter, object data, XmlTextWriter xmlWriter)
		{
		}
Exemplo n.º 36
0
		/// <summary>
		/// Prints the XML representation of the media class.
		/// <para>
		/// Implementation calls the <see cref="ToXmlData.ToXml"/>
		/// method for its implementation.
		/// </para>
		/// </summary>
		/// <param name="formatter">
		/// A <see cref="ToXmlFormatter"/> object that
		/// specifies method implementations for printing
		/// media objects.
		/// </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>
		public virtual void ToXml (ToXmlFormatter formatter, object data, XmlTextWriter xmlWriter)
		{
			ToXmlData.ToXml(this, formatter, (ToXmlData) data, xmlWriter);
		}
Exemplo n.º 37
0
		/// <summary>
		/// Method returns a DIDL-Lite representation of a set of media objects.
		/// </summary>
		/// <param name="formatter">
		/// <para>
		/// Formatter for printing the media objects. Standard formatter is to use
		/// <see cref="ToXmlFormatter.DefaultFormatter"/>.
		/// </para>
		/// 
		/// <para>
		/// Another alternative is to use a <see cref="ToXmlData"/> object,
		/// and assign the delegate-based fields to method implementations
		/// that will provide customized XML-writing of the objects. 
		/// The fields that should be assigned for a task are:
		/// <see cref="ToXmlFormatter.WriteContainet"/>,
		/// <see cref="ToXmlFormatter.WriteItem"/>, and
		/// <see cref="ToXmlFormatter.WriteResource"/>.
		/// </para>
		/// 
		/// <para>
		/// Programmers should never assign the 
		/// <see cref="ToXmlFormatter.StartElement"/>,
		/// <see cref="ToXmlFormatter.WriteInnerXml"/>,
		/// <see cref="ToXmlFormatter.WriteValue"/>, or
		/// <see cref="ToXmlFormatter.EndElement"/>.
		/// </para>
		/// 
		/// <param name="data">
		/// <para>
		/// Data object with instructions to give to the formatter. Standard ones
		/// usable by <see cref="MediaObject.ToXmlFormatter_Default"/> include
		/// <see cref="ToXmlData_Default"/> (used for flat lists), and
		/// <see cref="ToXmlData_AllRecurse"/> (used for representing a trees).
		/// You can use your own settings by instantiating a <see cref="ToXmlData"/>
		/// object and setting the fields yourself.
		/// </para>
		/// 
		/// <para>
		/// If the 
		/// <see cref="ToXmlFormatter.WriteContainet"/>,
		/// <see cref="ToXmlFormatter.WriteItem"/>, or
		/// <see cref="ToXmlFormatter.WriteResource"/>
		/// fields have been assigned, then the object that is sent
		/// must be compatible with the method implementations.
		/// One subtlety that must be noted is that if one of
		/// those fields is not assigned to a custom implementation,
		/// then it follows that the 'data' argument must be a
		/// <see cref="ToXmlData"/> instance. For maximum compatibility,
		/// programmers are encouraged to derive classes from
		/// <see cref="ToXmlData"/> instead of defining their own
		/// from scratch.
		/// </para>
		/// </param>
		/// <param name="entries"><see cref="ICollection"/> of IUPnPMedia objects</param>
		/// <returns></returns>
		public static string BuildDidl(ToXmlFormatter formatter, object data, ICollection entries)
		{
			StringBuilder sb = null;
			StringWriter sw = null;
			MemoryStream ms = null;
			XmlTextWriter xmlWriter = null;
			
			// set up the DIDL-Lite document for UTF8 or UTF16 encodings
			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);
			}

			// Set up the XML writer for proper formatting and the DIDL-Lite header

			xmlWriter.Formatting = System.Xml.Formatting.Indented;
			xmlWriter.Namespaces = true;
			xmlWriter.WriteStartDocument();
			
			MediaObject.WriteResponseHeader(xmlWriter);
		
			// Make a clone of 'data' if it's a ToXmlData object.
			// We'll need to clone it because we're may flip
			// some bits on it and the original ToXmlData object
			// is not supposed to be modified.
			ToXmlData _d = data as ToXmlData;
			ToXmlData _d2 = null;
			if (_d != null) { _d2 = _d.Clone() as ToXmlData; }

			if (_d2 != null)
			{
				if (_d2.VirtualOwner != null)
				{
					// Do a memberwise clone because we're going to
					// force this virtual container to not print its
					// child elements.
					formatter.StartElement = null;
					formatter.EndElement = null;
					formatter.WriteInnerXml = null;
					formatter.WriteValue  = null;

					_d2.IsRecursive = false;
					_d2.IgnoreBlankParentError = true;
					_d2.IncludeValue = false;
					_d2.IncludeInnerXml = true;

					_d2.VirtualOwner.StartElement(formatter, _d2, xmlWriter);
					_d2.VirtualOwner.WriteInnerXml(formatter, _d2, xmlWriter);
				}
			}

			// print each media object, indicating that we don't
			// want the recursive printing of child objects.
			// Also provide the base URL so that resource objects
			// are propertly printed

			formatter.StartElement = null;
			formatter.EndElement = null;
			formatter.WriteInnerXml = null;
			formatter.WriteValue  = null;
			foreach (IUPnPMedia obj in entries)
			{
				//obj.ToAlternateXml(false, baseUrl, properties, xmlWriter);
				obj.ToXml(formatter, data, xmlWriter);
			}
			
			// Close the virtual-owner container element
			if (_d2 != null)
			{
				if (_d2.VirtualOwner != null)
				{
					_d2.VirtualOwner.EndElement(formatter, _d2, xmlWriter);
				}
			}

			xmlWriter.WriteEndDocument();
			xmlWriter.Flush();
			
			// cast the string builder's data to a string

			string xmlResult;
			if (MediaObject.ENCODE_UTF8)
			{
				// UTF8 encoded stuff is a little different
				// because we need to drop the first 3 bytes
				// because they cause a magic characters to 
				// appear in the string.
				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();

			// Ensure that any preceding carriage returns 
			// are removed from the result string
			int crpos = xmlResult.IndexOf("\r\n");
			crpos = xmlResult.IndexOf('<', crpos);
			string trunc = xmlResult.Remove(0, crpos);

			return trunc;
		}
Exemplo n.º 38
0
		/// <summary>
		/// Instructs the "xmlWriter" argument to write the value of
		/// the "upnp:class" element.
		/// </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>
		public virtual void WriteValue(ToXmlFormatter formatter, object data, XmlTextWriter xmlWriter)
		{
			xmlWriter.WriteString(this.StringValue);
		}
Exemplo n.º 39
0
        /// <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
                );
        }
Exemplo n.º 40
0
		/// <summary>
		/// Empty - "upnp:class" elements have no child XML elements.
		/// </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>
		public virtual void WriteInnerXml(ToXmlFormatter formatter, object data, XmlTextWriter xmlWriter)
		{
		}
Exemplo n.º 41
0
		/// <summary>
		/// The override is provided so that callers can specify their
		/// own implementations that will write the xml. 
		/// This is achieved by setting the <see cref="ToXmlFormatter.WriteContainer"/>
		/// field of the 'formatter'. 
		/// </summary>
		/// <param name="formatter">
		/// Allows the caller to specify a custom implementation that writes
		/// the container's XML. Simply assign the <see cref="ToXmlFormatter.WriteContainer"/>
		/// to have this method delegate the responsibility. Otherwise,
		/// the base class implementation of <see cref="MediaObject.ToXml"/>
		/// is called.
		/// </param>
		/// <param name="data">
		/// If the formatter's <see cref="ToXmlFormatter.WriteContainer"/> field
		/// is non-null, then this object must be a type acceptable to that method's
		/// implementation. Otherwise, a <see cref="ToXmlData"/> object is required.
		/// </param>
		/// <param name="xmlWriter">
		/// This is where the xml gets printed.
		/// </param>
		public override void ToXml(ToXmlFormatter formatter, object data, XmlTextWriter xmlWriter)
		{
			if (formatter.WriteContainer != null)
			{
				formatter.StartElement = null;
				formatter.EndElement = null;
				formatter.WriteInnerXml = null;
				formatter.WriteValue  = null;
				formatter.WriteContainer(this, formatter, data, xmlWriter);
			}
			else
			{
				base.ToXml(formatter, data, xmlWriter);
			}
		}
Exemplo n.º 42
0
		/// <summary>
		/// <para>
		/// Programmers assign the <see cref="ToXmlFormatter.StartElement"/>
		/// field to this method, when attempting to print this media object.
		/// </para>
		/// <para>
		/// Algorithm:
		///	1. declare the container element
		///
		///	2. If this object will be added as a direct child
		///	of a container in a CreateObject request, then
		///	do not print the object's ID.
		///
		///	3. Print the searchable attribute, which is required.
		///
		///	4. Print the ID of the item that this object points
		///	to if appropriate. If intending to request
		///	a MediaServer to create a child object that points 
		///	to another object then a control point should
		///	use the CreateReference, so in such a case
		///	this method will throw an exception.
		///
		///	5. Print the parent object, taking into account
		///	CreateObject instructions.
		///
		///	6. Print the restricted attribute.
		///
		///	7. Print the optional childcount attribute, if requested to do so.
		/// </para>
		/// </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 when the "data" argument is not a
		/// <see cref="ToXmlData"/> object.
		public override void StartElement (ToXmlFormatter formatter, object data, XmlTextWriter xmlWriter)
		{
			ToXmlData _d = (ToXmlData) data;
			ArrayList desiredProperties = _d.DesiredProperties;

			xmlWriter.WriteStartElement(T[_DIDL.Container]);

			if (_d.CreateObjectParentID != null)
			{
				xmlWriter.WriteAttributeString(T[_ATTRIB.id], "");
			}
			else
			{
				xmlWriter.WriteAttributeString(T[_ATTRIB.id], this.ID);
			}
		
			xmlWriter.WriteAttributeString(T[_ATTRIB.searchable], GetBoolAsOneZero(this.IsSearchable).ToString());

			if (_d.CreateObjectParentID != null)
			{
				xmlWriter.WriteAttributeString(T[_ATTRIB.parentID], _d.CreateObjectParentID);
			}
			else if (this.m_Parent != null)
			{
				xmlWriter.WriteAttributeString(T[_ATTRIB.parentID], this.m_Parent.ID);
			}
			else if (this.m_ParentID != null)
			{
				xmlWriter.WriteAttributeString(T[_ATTRIB.parentID], this.m_ParentID);
			}
			else
			{
				xmlWriter.WriteAttributeString(T[_ATTRIB.parentID], "-1");
			}

			xmlWriter.WriteAttributeString(T[_ATTRIB.restricted], GetBoolAsOneZero(this.IsRestricted).ToString());

			if (desiredProperties != null)
			{
				if (
					(desiredProperties.Count == 0) || 
					(desiredProperties.Contains(Tags.PropertyAttributes.container_childCount))
					)
				{
					xmlWriter.WriteAttributeString(T[_ATTRIB.childCount], this.ChildCount.ToString());
				}
			}
		}
        /// <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
                );
        }