/// <summary>
        /// Returns true if the other MediaClass has the same value and attribute values.
        /// </summary>
        /// <param name="cdsElement">a MediaClass instance; derived classes don't count</param>
        /// <returns></returns>
        public override bool Equals(object cdsElement)
        {
            MediaClass other = (MediaClass)cdsElement;

            if (this.GetType() == other.GetType())
            {
                if (this.m_ClassName.Equals(other.m_ClassName))
                {
                    if (this.m_DerivedFrom.Equals(other.m_DerivedFrom))
                    {
                        if (this.m_FriendlyName.Equals(other.m_FriendlyName))
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
        /// <summary>
        /// Populates the MediaClasses arraylist.
        /// </summary>
        private static void GetMediaClasses()
        {
            lock (MediaClasses.SyncRoot)
            {
                if (MediaClasses.Count == 0)
                {
                    // Iterate through assemblies
                    Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
                    foreach (Assembly asm in assemblies)
                    {
                        // Iterate through class types of each assembly
                        Type[] types = asm.GetTypes();
                        foreach (Type type in types)
                        {
                            // Only classes derived from MediaBuilder.CoreMetadata
                            // are considered for defining a media classes.
                            if (type.IsSubclassOf(typeof(MediaBuilder.CoreMetadata)))
                            {
                                // Recurse up the class's base types and derive
                                // a string that reveals the full media class
                                // that this type represents.

                                Stack baseTypes = new Stack();
                                Type baseType = type;

                                while (baseType != typeof(MediaBuilder.CoreMetadata))
                                {
                                    baseTypes.Push(baseType);
                                    baseType = baseType.BaseType;
                                }

                                StringBuilder sb = new StringBuilder(baseTypes.Count * 8 + 1);
                                sb.Append("object.");

                                while (baseTypes.Count > 0)
                                {
                                    baseType = (Type)baseTypes.Pop();
                                    sb.Append(baseType.Name);
                                    if (baseTypes.Count > 0)
                                    {
                                        sb.Append(".");
                                    }
                                }

                                string mediaClassString = sb.ToString();

                                // Introspect the type for a friendly name.
                                FieldInfo fi = type.GetField("CdsFriendlyName", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);

                                string friendly = "";
                                if (fi != null)
                                {
                                    ConstructorInfo ci = type.GetConstructor(new Type[0]);
                                    if (ci != null)
                                    {
                                        object obj = ci.Invoke(new Object[0]);
                                        friendly = (string)fi.GetValue(obj);
                                    }
                                }

                                // Instantiate a media class and store it in the array
                                MediaClass newClass = new MediaClass(mediaClassString, friendly);

                                MediaClassInfo mci = new MediaClassInfo();
                                mci._Type = type;
                                mci._Class = newClass;
                                Sorter.Set(MediaClasses, mci, false); ;
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// The ability to modify objects directly to a container/item is not available
 /// for a public programmer. Each CpMediaItem object is responsible
 /// for maintaining its own state.
 /// </summary>
 /// <param name="propertyName"></param>
 /// <param name="val"></param>
 public override void SetPropertyValue_MediaClass(string propertyName, MediaClass val)
 {
     this.CheckRuntimeBindings(new StackTrace());
     base.SetPropertyValue_MediaClass(propertyName, val);
 }
 /// <summary>
 /// Must indicate the media class and whether derived media class
 /// types should also be included as matches.
 /// </summary>
 /// <param name="mediaClass"></param>
 /// <param name="includeDerived"></param>
 public MatchOnClass(MediaClass mediaClass, bool includeDerived)
 {
     this.m_Class          = mediaClass;
     this.m_IncludeDerived = includeDerived;
 }
 /// <summary>
 /// Returns true if the StringValue values of both media classes are equal.
 /// </summary>
 /// <param name="_class"></param>
 /// <returns></returns>
 public bool FullClassNameMatches(MediaClass _class)
 {
     return(string.Compare(this.ToString(), _class.ToString(), true) == 0);
 }
 /// <summary>
 /// Returns true, if the item is derived from
 /// or is of the specified class.
 /// </summary>
 /// <param name="derivedFrom">the media class to which to compare to</param>
 /// <returns>true indicates an IS-A relationship with the specified media class</returns>
 public bool IsA(MediaClass derivedFrom)
 {
     return(this.ToString().StartsWith(derivedFrom.ToString()));
 }
        /// <summary>
        /// Sets a value in the hashtable
        /// </summary>
        /// <param name="key">property name</param>
        private void SetVal(string key, ICdsElement[] objs)
        {
            //this.m_Table[key] = objs;
            if ((key == T[_DC.title]))
            {
                this.m_Title = (PropertyString)objs[0];
            }
            else if ((key == T[_DC.creator]))
            {
                this.m_Creator = (PropertyString)objs[0];
            }
            else if ((key == T[_UPNP.Class]))
            {
                this.m_Class = (MediaClass)objs[0];
            }
            else
            {
                Exception error = null;
                try
                {
                    this.m_LockTable.AcquireWriterLock(-1);
                    try
                    {
                        _Hashtable.Set(m_Table, key, objs);
                    }
                    catch (Exception e)
                    {
                        error = e;
                    }
                }
                finally
                {
                    this.m_LockTable.ReleaseWriterLock();
                }

                if (error != null)
                {
                    Exception ne = new Exception("MediaProperties.set_this[string]()", error);
                    throw ne;
                }
            }
            this.IncrementStateNumber();
        }
Exemplo n.º 8
0
 /// <summary>
 /// Metadata often benefits from having strongly typed values, and
 /// this method allows a programmer to easily set a CDS entry's property
 /// with strongly typed values very easily. A public programmer's ability to modify
 /// an object's metadata directly is available only from a device-side programming
 /// scenario.
 /// </summary>
 /// <param name="propertyName">
 /// Standard metadata properties can be obtained by using the OpenSource.UPnP.AV.CdsMetadata.CommonPropertyNames enumerator
 /// in conjunction with an instantiation of the OpenSource.UPnP.AV.CdsMetadata.Tags class, which returns string representations of common CDS tagnames and attributes.
 /// </param>
 /// <param name="values">array of MediaClass values that will overwrite all values associated with the specified metadata field</param>
 public virtual void SetPropertyValue_MediaClass(string propertyName, MediaClass[] values)
 {
     ArrayList al = new ArrayList(values.Length);
     al.AddRange(values);
     this.m_Properties[propertyName] = al;
 }
 /// <summary>
 /// Special ISerializable constructor.
 /// Do basic initialization and then serialize from the info object.
 /// </summary>
 /// <param name="info"></param>
 /// <param name="context"></param>
 private MediaProperties(SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
 {
     Init();
     this.m_Table = (ArrayList)info.GetValue("m_Table", typeof(ArrayList));
     this.m_Title = (PropertyString)info.GetValue("m_Title", typeof(PropertyString));
     this.m_Creator = (PropertyString)info.GetValue("m_Creator", typeof(PropertyString));
     this.m_Class = (MediaClass)info.GetValue("m_Class", typeof(MediaClass));
     this.IsEnabled_OnMetadataChanged = info.GetBoolean("IsEnabled_OnMetadataChanged");
 }
 /// <summary>
 /// <para>
 /// This method clears the hashtable values for all properties.
 /// </para>
 /// <para>
 /// Derived classes will have access to this and so will internal classes.
 /// Programmers deriving from this object are strongly encouraged to not use 
 /// this unless they ABSOLUTELY know what they're doing.
 /// </para>
 /// </summary>
 internal void ClearProperties()
 {
     try
     {
         this.m_LockTable.AcquireWriterLock(-1);
         this.m_Table = new ArrayList(2);
         this.m_Title = null;
         this.m_Creator = null;
         this.m_Class = null;
         this.IncrementStateNumber();
     }
     finally
     {
         this.m_LockTable.ReleaseWriterLock();
     }
 }
Exemplo n.º 11
0
        /// <summary>
        /// Updates m_CacheTitle, m_CacheCreator, and m_CacheClass.
        /// </summary>
        protected void UpdateCache()
        {
            if (this.m_PropertiesStateNumber != this.m_Properties.StateNumber)
            {
                // Some have made an argument that the extensive amount of
                // error checking is unnecessary given that I ensure that
                // the value is proper before setting.
                //
                // Unfortunately, simply returning list[0].Value has problems.
                // A number of applications have been written with the
                // expectation that this property will never return null
                // or throw an InvalidCast/NullReference exception.
                //
                // The whole purpose of UpdateCache is to minimize
                // the error-checking done for the Title, Creator, and
                // Class properties (which are all properties provided
                // as a courtesy so programmers don't have to do tedious
                // error checking).
                //
                // Given that the vast majority of
                // implementations won't change metadata regularly,
                // the caching is actually quite effective.

                string title = T[_DC.title];
                string creator = T[_DC.creator];
                string Class = T[_UPNP.Class];
                string[] properties = {title, creator, Class};
                Hashtable lists = this.m_Properties.GetValues(properties);
                IList list;

                this.m_CacheTitle = "";
                this.m_CacheCreator = "";
                this.m_CacheClass = null;

                if (lists != null)
                {
                    list = (IList) lists[title];
                    if ((list != null) && (list.Count > 0) && (list[0] is CdsMetadata.ICdsElement))
                    {
                        this.m_CacheTitle = (string) ((ICdsElement)list[0]).Value;
                    }

                    list = (IList) lists[creator];
                    if ((list != null) && (list.Count > 0) && (list[0] is CdsMetadata.ICdsElement))
                    {
                        this.m_CacheCreator = (string) ((ICdsElement)list[0]).Value;
                    }

                    list = (IList) lists[Class];
                    if ((list != null) && (list.Count > 0) && (list[0] is CdsMetadata.MediaClass))
                    {
                        this.m_CacheClass = (MediaClass) list[0];
                    }
                }

                this.m_PropertiesStateNumber = this.m_Properties.StateNumber;
            }
        }
Exemplo n.º 12
0
 /// <summary>
 /// Used to validate a media class. 
 /// </summary>
 /// <param name="mclass"></param>
 /// <exception cref="Error_BadMetadata">
 /// Thrown if the media class is null/invalid.
 /// </exception>
 protected void ThrowExceptionIfBadClass(MediaClass mclass)
 {
     if ((mclass == null))
     {
         throw new Error_BadMetadata("Must specify a media class. Error found on ID='" +this.m_ID+"'");
     }
 }
Exemplo n.º 13
0
 /// <summary>
 /// Metadata often benefits from having strongly typed values, and
 /// this method allows a programmer to easily set a CDS entry's property
 /// with strongly typed values very easily. A public programmer's ability to modify
 /// an object's metadata directly is available only from a device-side programming
 /// scenario.
 /// </summary>
 /// <param name="propertyName">
 /// Standard metadata properties can be obtained by using the OpenSource.UPnP.AV.CdsMetadata.CommonPropertyNames enumerator
 /// in conjunction with an instantiation of the OpenSource.UPnP.AV.CdsMetadata.Tags class, which returns string representations of common CDS tagnames and attributes.
 /// </param>
 /// <param name="val">a single MediaClass value that will overwrite all values associated with the specified metadata field</param>
 public virtual void SetPropertyValue_MediaClass(string propertyName, MediaClass val)
 {
     MediaClass[] values = new MediaClass[1];
     values[0] = val;
     SetPropertyValue_MediaClass(propertyName, values);
 }
Exemplo n.º 14
0
		/// <summary>
		/// Returns true, if the item is derived from
		/// or is of the specified class.
		/// </summary>
		/// <param name="derivedFrom">the media class to which to compare to</param>
		/// <returns>true indicates an IS-A relationship with the specified media class</returns>
		public bool IsA (MediaClass derivedFrom)
		{
			return (this.ToString().StartsWith(derivedFrom.ToString()));
		}
 /// <summary>
 /// Throws an exception. CpRootCollectionContainers
 /// are not like normal containers because they
 /// aggregate root containers. For this reason
 /// the ability to modify properties, resources,
 /// and metadata is NEVER allowed since 
 /// there is no actual metadata to retrieve or set.
 /// </summary>
 /// <param name="propertyName"></param>
 /// <param name="val"></param>
 public override void SetPropertyValue_MediaClass(string propertyName, MediaClass val)
 {
     CheckProtection();
 }
Exemplo n.º 16
0
		/// <summary>
		/// Returns true if the StringValue values of both media classes are equal.
		/// </summary>
		/// <param name="_class"></param>
		/// <returns></returns>
		public bool FullClassNameMatches (MediaClass _class)
		{
			return (string.Compare(this.ToString(), _class.ToString(), true) == 0);
		}
Exemplo n.º 17
0
		/// <summary>
		/// Must indicate the media class and whether derived media class
		/// types should also be included as matches.
		/// </summary>
		/// <param name="mediaClass"></param>
		/// <param name="includeDerived"></param>
		public MatchOnClass (MediaClass mediaClass, bool includeDerived)
		{
			this.m_Class = mediaClass;
			this.m_IncludeDerived = includeDerived;
		}