コード例 #1
0
        //============================================================
        //	STATIC METHODS
        //============================================================
        #region RelationshipAsString(YahooMediaRestrictionRelationship type)
        /// <summary>
        /// Returns the relationship identifier for the supplied <see cref="YahooMediaRestrictionRelationship"/>.
        /// </summary>
        /// <param name="relationship">The <see cref="YahooMediaRestrictionRelationship"/> to get the relationship identifier for.</param>
        /// <returns>The relationship identifier for the supplied <paramref name="relationship"/>, otherwise returns an empty string.</returns>
        public static string RelationshipAsString(YahooMediaRestrictionRelationship relationship)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            string name = String.Empty;

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

                    if (restrictionRelationship == relationship)
                    {
                        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);
        }
コード例 #2
0
        /// <summary>
        /// Returns the <see cref="YahooMediaRestrictionRelationship"/> enumeration value that corresponds to the specified relationship name.
        /// </summary>
        /// <param name="name">The name of the relationship.</param>
        /// <returns>A <see cref="YahooMediaRestrictionRelationship"/> enumeration value that corresponds to the specified string, otherwise returns <b>YahooMediaRestrictionRelationship.None</b>.</returns>
        /// <remarks>This method disregards case of specified relationship 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 YahooMediaRestrictionRelationship RelationshipByName(string name)
        {
            YahooMediaRestrictionRelationship restrictionRelationship = YahooMediaRestrictionRelationship.None;

            Guard.ArgumentNotNullOrEmptyString(name, "name");
            foreach (System.Reflection.FieldInfo fieldInfo in typeof(YahooMediaRestrictionRelationship).GetFields())
            {
                if (fieldInfo.FieldType == typeof(YahooMediaRestrictionRelationship))
                {
                    YahooMediaRestrictionRelationship relationship = (YahooMediaRestrictionRelationship)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)
                        {
                            restrictionRelationship = relationship;
                            break;
                        }
                    }
                }
            }

            return(restrictionRelationship);
        }
コード例 #3
0
        /// <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>
        /// 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)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            bool wasLoaded              = false;

            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(source, "source");

            //------------------------------------------------------------
            //	Attempt to extract syndication information
            //------------------------------------------------------------
            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;
        }
コード例 #5
0
        /// <summary>
        /// Returns the <see cref="YahooMediaRestrictionRelationship"/> enumeration value that corresponds to the specified relationship name.
        /// </summary>
        /// <param name="name">The name of the relationship.</param>
        /// <returns>A <see cref="YahooMediaRestrictionRelationship"/> enumeration value that corresponds to the specified string, otherwise returns <b>YahooMediaRestrictionRelationship.None</b>.</returns>
        /// <remarks>This method disregards case of specified relationship 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 YahooMediaRestrictionRelationship RelationshipByName(string name)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            YahooMediaRestrictionRelationship restrictionRelationship   = YahooMediaRestrictionRelationship.None;

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

            //------------------------------------------------------------
            //	Determine syndication content format based on supplied name
            //------------------------------------------------------------
            foreach (System.Reflection.FieldInfo fieldInfo in typeof(YahooMediaRestrictionRelationship).GetFields())
            {
                if (fieldInfo.FieldType == typeof(YahooMediaRestrictionRelationship))
                {
                    YahooMediaRestrictionRelationship relationship  = (YahooMediaRestrictionRelationship)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)
                        {
                            restrictionRelationship = relationship;
                            break;
                        }
                    }
                }
            }

            return restrictionRelationship;
        }
コード例 #6
0
        /// <summary>
        /// Returns the relationship identifier for the supplied <see cref="YahooMediaRestrictionRelationship"/>.
        /// </summary>
        /// <param name="relationship">The <see cref="YahooMediaRestrictionRelationship"/> to get the relationship identifier for.</param>
        /// <returns>The relationship identifier for the supplied <paramref name="relationship"/>, otherwise returns an empty string.</returns>
        public static string RelationshipAsString(YahooMediaRestrictionRelationship relationship)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            string name = String.Empty;

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

                    if (restrictionRelationship == relationship)
                    {
                        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;
        }