public void SetupConnection(MediaItem[] items)
 {
     if (items == null || items.Length == 0) return;
     PendingConnection = DateTime.Now.Ticks;
     renderer.CreateConnection(items, PendingConnection);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Calls base class implementation of Init()
 /// and then initializes the fields for this class.
 /// </summary>
 protected override void Init()
 {
     base.Init();
     this.m_LockReferences = new object();
     this.m_ReferringItems = null;
     this.m_Deleting = false;
     this.m_RefItem = null;
 }
Ejemplo n.º 3
0
		/// <summary>
		/// Creates a 
		/// <see cref="MediaItem"/>
		/// object, given a metadata instantiation
		/// block.
		/// </summary>
		/// <param name="info">
		/// The metadata to use when instantiating the media.
		/// </param>
		/// <returns>a new media item</returns>
		public static MediaItem CreateItem (item info)
		{
			MediaItem newObj = new MediaItem();
			SetObjectProperties(newObj, info);
			return newObj;
		}
Ejemplo n.º 4
0
        /// <summary>
        /// <see cref="DvMediaContainer.RemoveObject"/>
        /// and <see cref="DvMediaContainer.RemoveObjects"/>
        /// call this method before removing it from its child list.
        /// This will automatically remove items that refer to this item
        /// from their respective parents.
        /// </summary>
        public void NotifyPendingDelete()
        {
            lock (this.m_LockReferences)
            {
                this.m_Deleting = true;

                ArrayList removeThese = new ArrayList();

                if (m_ReferringItems != null)
                {
                    //foreach (WeakReference wr in this.m_ReferringItems)
                    foreach (IDvItem referringItem in this.m_ReferringItems)
                    {
                        // force a strong reference of the target before checking it's alive

                        //IDvItem referringItem = (IDvItem) wr.Target;
                        //if (wr.IsAlive)
                        //{
                            IDvContainer parent = (IDvContainer) referringItem.Parent;

                            if (parent != null)
                            {
                                parent.RemoveObject(referringItem);
                            }
                            else
                            {
                                //removeThese.Add(wr);
                                removeThese.Add(referringItem);
                            }
                        //}
                        //else
                        //{
                        //	removeThese.Add(wr);
                        //}
                    }

                    //foreach (WeakReference wr in removeThese)
                    foreach (IDvItem referringItem in removeThese)
                    {
                        //this.m_ReferringItems.Remove(wr);
                        this.m_ReferringItems.Remove(referringItem);
                    }
                }

                this.m_ReferringItems = null;
                this.m_RefItem = null;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Returns a deep copy of the object's metadata in a new MediaObject.
        /// The class returned instance will be either
        /// <see cref="MediaItem"/> or <see cref="MediaContainer"/>.
        /// <para>
        /// The deep-copy object will not have the same ID,
        /// nor will the .Tag field be set.
        /// </para>
        /// </summary>
        /// <returns></returns>
        public IUPnPMedia MetadataCopy()
        {
            StringBuilder sbXml = null;
            sbXml = new StringBuilder(XML_BUFFER_SIZE);
            StringWriter sw = new StringWriter(sbXml);
            XmlTextWriter xmlWriter = new XmlTextWriter(sw);
            xmlWriter.Namespaces = true;

            MediaObject.WriteResponseHeader(xmlWriter);

            // set up the ToXml() method to write everything
            ToXmlData _d = (ToXmlData) MediaObject.ToXmlData_Default.Clone();
            _d.IgnoreBlankParentError = true;
            this.ToXml(ToXmlFormatter.DefaultFormatter, _d, xmlWriter);
            MediaObject.WriteResponseFooter(xmlWriter);
            xmlWriter.Flush();
            string xmlstr = sbXml.ToString();
            xmlWriter.Close();

            MediaContainer mc = this as MediaContainer;
            MediaItem mi = this as MediaItem;
            MediaObject newObj = null;

            XmlDocument xmldoc = new XmlDocument();
            xmldoc.LoadXml(xmlstr);
            XmlElement child = (XmlElement) xmldoc.ChildNodes[0].ChildNodes[0];

            if (mc != null)
            {
                newObj = new MediaContainer(child);
            }
            else if (mi != null)
            {
                newObj = new MediaItem(child);
            }
            else
            {
                throw new Exception("Bad evil. Should always have an item or container.");
            }
            newObj.m_ID = MediaBuilder.GetUniqueId();

            return newObj;
        }