예제 #1
0
        /// <summary>
        /// Returns the restriction type identifier for the supplied <see cref="YahooMediaRestrictionType"/>.
        /// </summary>
        /// <param name="type">The <see cref="YahooMediaRestrictionType"/> to get the restriction type identifier for.</param>
        /// <returns>The restriction type identifier for the supplied <paramref name="type"/>, otherwise returns an empty string.</returns>
        public static string RestrictionTypeAsString(YahooMediaRestrictionType type)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            string name = String.Empty;

            //------------------------------------------------------------
            //	Return alternate value based on supplied protocol
            //------------------------------------------------------------
            foreach (System.Reflection.FieldInfo fieldInfo in typeof(YahooMediaRestrictionType).GetFields())
            {
                if (fieldInfo.FieldType == typeof(YahooMediaRestrictionType))
                {
                    YahooMediaRestrictionType restrictionType = (YahooMediaRestrictionType)Enum.Parse(fieldInfo.FieldType, fieldInfo.Name);

                    if (restrictionType == type)
                    {
                        object[] customAttributes = fieldInfo.GetCustomAttributes(typeof(EnumerationMetadataAttribute), false);

                        if (customAttributes != null && customAttributes.Length > 0)
                        {
                            EnumerationMetadataAttribute enumerationMetadata = customAttributes[0] as EnumerationMetadataAttribute;

                            name = enumerationMetadata.AlternateValue;
                            break;
                        }
                    }
                }
            }

            return(name);
        }
        /// <summary>
        /// Returns the <see cref="YahooMediaRestrictionType"/> enumeration value that corresponds to the specified restriction type name.
        /// </summary>
        /// <param name="name">The name of the restriction type.</param>
        /// <returns>A <see cref="YahooMediaRestrictionType"/> enumeration value that corresponds to the specified string, otherwise returns <b>YahooMediaRestrictionType.None</b>.</returns>
        /// <remarks>This method disregards case of specified restriction type name.</remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="name"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="name"/> is an empty string.</exception>
        public static YahooMediaRestrictionType RestrictionTypeByName(string name)
        {
            YahooMediaRestrictionType restrictionType = YahooMediaRestrictionType.None;

            Guard.ArgumentNotNullOrEmptyString(name, "name");
            foreach (System.Reflection.FieldInfo fieldInfo in typeof(YahooMediaRestrictionType).GetFields())
            {
                if (fieldInfo.FieldType == typeof(YahooMediaRestrictionType))
                {
                    YahooMediaRestrictionType type = (YahooMediaRestrictionType)Enum.Parse(fieldInfo.FieldType, fieldInfo.Name);
                    object[] customAttributes      = fieldInfo.GetCustomAttributes(typeof(EnumerationMetadataAttribute), false);

                    if (customAttributes != null && customAttributes.Length > 0)
                    {
                        EnumerationMetadataAttribute enumerationMetadata = customAttributes[0] as EnumerationMetadataAttribute;

                        if (String.Compare(name, enumerationMetadata.AlternateValue, StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            restrictionType = type;
                            break;
                        }
                    }
                }
            }

            return(restrictionType);
        }
        /// <summary>
        /// Loads this <see cref="YahooMediaRestriction"/> using the supplied <see cref="XPathNavigator"/>.
        /// </summary>
        /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param>
        /// <returns><b>true</b> if the <see cref="YahooMediaRestriction"/> was initialized using the supplied <paramref name="source"/>, otherwise <b>false</b>.</returns>
        /// <remarks>
        ///     This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="YahooMediaRestriction"/>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        public bool Load(XPathNavigator source)
        {
            bool wasLoaded = false;

            Guard.ArgumentNotNull(source, "source");
            if (source.HasAttributes)
            {
                string relationshipAttribute = source.GetAttribute("relationship", String.Empty);
                string typeAttribute         = source.GetAttribute("type", String.Empty);

                if (!String.IsNullOrEmpty(relationshipAttribute))
                {
                    YahooMediaRestrictionRelationship relationship = YahooMediaRestriction.RelationshipByName(relationshipAttribute);
                    if (relationship != YahooMediaRestrictionRelationship.None)
                    {
                        this.Relationship = relationship;
                        wasLoaded         = true;
                    }
                }

                if (!String.IsNullOrEmpty(typeAttribute))
                {
                    YahooMediaRestrictionType type = YahooMediaRestriction.RestrictionTypeByName(typeAttribute);
                    if (type != YahooMediaRestrictionType.None)
                    {
                        this.EntityType = type;
                        wasLoaded       = true;
                    }
                }
            }

            if (!String.IsNullOrEmpty(source.Value))
            {
                if (source.Value.Contains(" "))
                {
                    string[] entities = source.Value.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                    if (entities.Length > 0)
                    {
                        foreach (string entity in entities)
                        {
                            this.Entities.Add(entity);
                        }
                        wasLoaded = true;
                    }
                }
                else
                {
                    this.Entities.Add(source.Value);
                    wasLoaded = true;
                }
            }

            return(wasLoaded);
        }
예제 #4
0
        /// <summary>
        /// Returns the <see cref="YahooMediaRestrictionType"/> enumeration value that corresponds to the specified restriction type name.
        /// </summary>
        /// <param name="name">The name of the restriction type.</param>
        /// <returns>A <see cref="YahooMediaRestrictionType"/> enumeration value that corresponds to the specified string, otherwise returns <b>YahooMediaRestrictionType.None</b>.</returns>
        /// <remarks>This method disregards case of specified restriction type name.</remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="name"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="name"/> is an empty string.</exception>
        public static YahooMediaRestrictionType RestrictionTypeByName(string name)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            YahooMediaRestrictionType restrictionType   = YahooMediaRestrictionType.None;

            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNullOrEmptyString(name, "name");

            //------------------------------------------------------------
            //	Determine syndication content format based on supplied name
            //------------------------------------------------------------
            foreach (System.Reflection.FieldInfo fieldInfo in typeof(YahooMediaRestrictionType).GetFields())
            {
                if (fieldInfo.FieldType == typeof(YahooMediaRestrictionType))
                {
                    YahooMediaRestrictionType type  = (YahooMediaRestrictionType)Enum.Parse(fieldInfo.FieldType, fieldInfo.Name);
                    object[] customAttributes       = fieldInfo.GetCustomAttributes(typeof(EnumerationMetadataAttribute), false);

                    if (customAttributes != null && customAttributes.Length > 0)
                    {
                        EnumerationMetadataAttribute enumerationMetadata = customAttributes[0] as EnumerationMetadataAttribute;

                        if (String.Compare(name, enumerationMetadata.AlternateValue, StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            restrictionType = type;
                            break;
                        }
                    }
                }
            }

            return restrictionType;
        }
예제 #5
0
        /// <summary>
        /// Returns the restriction type identifier for the supplied <see cref="YahooMediaRestrictionType"/>.
        /// </summary>
        /// <param name="type">The <see cref="YahooMediaRestrictionType"/> to get the restriction type identifier for.</param>
        /// <returns>The restriction type identifier for the supplied <paramref name="type"/>, otherwise returns an empty string.</returns>
        public static string RestrictionTypeAsString(YahooMediaRestrictionType type)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            string name = String.Empty;

            //------------------------------------------------------------
            //	Return alternate value based on supplied protocol
            //------------------------------------------------------------
            foreach (System.Reflection.FieldInfo fieldInfo in typeof(YahooMediaRestrictionType).GetFields())
            {
                if (fieldInfo.FieldType == typeof(YahooMediaRestrictionType))
                {
                    YahooMediaRestrictionType restrictionType   = (YahooMediaRestrictionType)Enum.Parse(fieldInfo.FieldType, fieldInfo.Name);

                    if (restrictionType == type)
                    {
                        object[] customAttributes   = fieldInfo.GetCustomAttributes(typeof(EnumerationMetadataAttribute), false);

                        if (customAttributes != null && customAttributes.Length > 0)
                        {
                            EnumerationMetadataAttribute enumerationMetadata = customAttributes[0] as EnumerationMetadataAttribute;

                            name    = enumerationMetadata.AlternateValue;
                            break;
                        }
                    }
                }
            }

            return name;
        }