/// <summary> /// Initializes the object. /// </summary> protected virtual void Init() { this.m_bools = new BitArray(8, false); this.m_Desc = null; this.m_ID = ""; //this.m_LockDesc = new ReaderWriterLock(); if (MediaObject.UseStaticLock) { this.m_LockResources = MediaObject.StaticLock; } else { this.m_LockResources = new ReaderWriterLock(); } this.m_Parent = null; this.m_ParentID = null; this.ResetProperties(); this.ResetResources(); this._Tag = null; this.m_PropertiesStateNumber = int.MaxValue; }
/// <summary> /// Creates a /// <see cref="MediaContainer"/> /// object, given a metadata instantiation /// block. /// </summary> /// <param name="info"> /// The metadata to use when instantiating the media. /// </param> /// <returns>a new media container</returns> public static MediaContainer CreateContainer (container info) { MediaContainer newObj = new MediaContainer(); SetObjectProperties(newObj, info); return newObj; }
/// <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; }