/// <summary>
        /// Saves the current <see cref="YahooMediaRestriction"/> to the specified <see cref="XmlWriter"/>.
        /// </summary>
        /// <param name="writer">The <see cref="XmlWriter"/> to which you want to save.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="writer"/> is a null reference (Nothing in Visual Basic).</exception>
        public void WriteTo(XmlWriter writer)
        {
            Guard.ArgumentNotNull(writer, "writer");
            YahooMediaSyndicationExtension extension = new YahooMediaSyndicationExtension();

            writer.WriteStartElement("restriction", extension.XmlNamespace);

            if (this.Relationship != YahooMediaRestrictionRelationship.None)
            {
                writer.WriteAttributeString("relationship", YahooMediaRestriction.RelationshipAsString(this.Relationship));
            }

            if (this.EntityType != YahooMediaRestrictionType.None)
            {
                writer.WriteAttributeString("type", YahooMediaRestriction.RestrictionTypeAsString(this.EntityType));
            }

            if (this.Entities.Count > 0)
            {
                string[] entities = new string[this.Entities.Count];
                this.Entities.CopyTo(entities, 0);

                writer.WriteString(String.Join(" ", entities));
            }

            writer.WriteEndElement();
        }
예제 #2
0
        //============================================================
        //	ICOMPARABLE IMPLEMENTATION
        //============================================================
        #region CompareTo(object obj)
        /// <summary>
        /// Compares the current instance with another object of the same type.
        /// </summary>
        /// <param name="obj">An object to compare with this instance.</param>
        /// <returns>A 32-bit signed integer that indicates the relative order of the objects being compared.</returns>
        /// <exception cref="ArgumentException">The <paramref name="obj"/> is not the expected <see cref="Type"/>.</exception>
        public int CompareTo(object obj)
        {
            //------------------------------------------------------------
            //	If target is a null reference, instance is greater
            //------------------------------------------------------------
            if (obj == null)
            {
                return(1);
            }

            //------------------------------------------------------------
            //	Determine comparison result using property state of objects
            //------------------------------------------------------------
            YahooMediaRestriction value = obj as YahooMediaRestriction;

            if (value != null)
            {
                int result = ComparisonUtility.CompareSequence(this.Entities, value.Entities, StringComparison.Ordinal);
                result = result | this.EntityType.CompareTo(value.EntityType);
                result = result | this.Relationship.CompareTo(value.Relationship);

                return(result);
            }
            else
            {
                throw new ArgumentException(String.Format(null, "obj is not of type {0}, type was found to be '{1}'.", this.GetType().FullName, obj.GetType().FullName), "obj");
            }
        }
예제 #3
0
        /// <summary>
        /// Modifies the secondary collections of a <see cref="IYahooMediaCommonObjectEntities"/> to match the data source.
        /// </summary>
        /// <param name="target">The object that implements the <see cref="IYahooMediaCommonObjectEntities"/> interface to be filled.</param>
        /// <param name="source">The <see cref="XPathNavigator"/> to extract Yahoo media common entity information from.</param>
        /// <param name="manager">The <see cref="XmlNamespaceManager"/> object used to resolve prefixed Yahoo media elements and attributes.</param>
        /// <returns><b>true</b> if the <paramref name="target"/> was initialized using the supplied <paramref name="source"/>, otherwise <b>false</b>.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="target"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="manager"/> is a null reference (Nothing in Visual Basic).</exception>
        private static bool FillCommonObjectEntityCollectionsSecondary(IYahooMediaCommonObjectEntities target, XPathNavigator source, XmlNamespaceManager manager)
        {
            bool wasLoaded = false;

            Guard.ArgumentNotNull(target, "target");
            Guard.ArgumentNotNull(source, "source");
            Guard.ArgumentNotNull(manager, "manager");

            if (source.HasChildren)
            {
                XPathNodeIterator hashIterator        = source.Select("media:hash", manager);
                XPathNodeIterator restrictionIterator = source.Select("media:restriction", manager);
                XPathNodeIterator textIterator        = source.Select("media:text", manager);

                if (hashIterator != null && hashIterator.Count > 0)
                {
                    while (hashIterator.MoveNext())
                    {
                        YahooMediaHash hash = new YahooMediaHash();
                        if (hash.Load(hashIterator.Current))
                        {
                            target.Hashes.Add(hash);
                            wasLoaded = true;
                        }
                    }
                }

                if (restrictionIterator != null && restrictionIterator.Count > 0)
                {
                    while (restrictionIterator.MoveNext())
                    {
                        YahooMediaRestriction restriction = new YahooMediaRestriction();
                        if (restriction.Load(restrictionIterator.Current))
                        {
                            target.Restrictions.Add(restriction);
                            wasLoaded = true;
                        }
                    }
                }

                if (textIterator != null && textIterator.Count > 0)
                {
                    while (textIterator.MoveNext())
                    {
                        YahooMediaText text = new YahooMediaText();
                        if (text.Load(textIterator.Current))
                        {
                            target.TextSeries.Add(text);
                            wasLoaded = true;
                        }
                    }
                }
            }

            return(wasLoaded);
        }
        /// <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);
        }
        /// <summary>
        /// Compares the current instance with another object of the same type.
        /// </summary>
        /// <param name="obj">An object to compare with this instance.</param>
        /// <returns>A 32-bit signed integer that indicates the relative order of the objects being compared.</returns>
        /// <exception cref="ArgumentException">The <paramref name="obj"/> is not the expected <see cref="Type"/>.</exception>
        public int CompareTo(object obj)
        {
            if (obj == null)
            {
                return(1);
            }
            YahooMediaRestriction value = obj as YahooMediaRestriction;

            if (value != null)
            {
                int result = ComparisonUtility.CompareSequence(this.Entities, value.Entities, StringComparison.Ordinal);
                result = result | this.EntityType.CompareTo(value.EntityType);
                result = result | this.Relationship.CompareTo(value.Relationship);

                return(result);
            }
            else
            {
                throw new ArgumentException(String.Format(null, "obj is not of type {0}, type was found to be '{1}'.", this.GetType().FullName, obj.GetType().FullName), "obj");
            }
        }
예제 #6
0
        /// <summary>
        /// Saves the current <see cref="YahooMediaRestriction"/> to the specified <see cref="XmlWriter"/>.
        /// </summary>
        /// <param name="writer">The <see cref="XmlWriter"/> to which you want to save.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="writer"/> is a null reference (Nothing in Visual Basic).</exception>
        public void WriteTo(XmlWriter writer)
        {
            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(writer, "writer");

            //------------------------------------------------------------
            //	Create extension instance to retrieve XML namespace
            //------------------------------------------------------------
            YahooMediaSyndicationExtension extension = new YahooMediaSyndicationExtension();

            //------------------------------------------------------------
            //	Write XML representation of the current instance
            //------------------------------------------------------------
            writer.WriteStartElement("restriction", extension.XmlNamespace);

            if (this.Relationship != YahooMediaRestrictionRelationship.None)
            {
                writer.WriteAttributeString("relationship", YahooMediaRestriction.RelationshipAsString(this.Relationship));
            }

            if (this.EntityType != YahooMediaRestrictionType.None)
            {
                writer.WriteAttributeString("type", YahooMediaRestriction.RestrictionTypeAsString(this.EntityType));
            }

            if (this.Entities.Count > 0)
            {
                string[] entities = new string[this.Entities.Count];
                this.Entities.CopyTo(entities, 0);

                writer.WriteString(String.Join(" ", entities));
            }

            writer.WriteEndElement();
        }
예제 #7
0
        /// <summary>
        /// Modifies the secondary collections of a <see cref="IYahooMediaCommonObjectEntities"/> to match the data source.
        /// </summary>
        /// <param name="target">The object that implements the <see cref="IYahooMediaCommonObjectEntities"/> interface to be filled.</param>
        /// <param name="source">The <see cref="XPathNavigator"/> to extract Yahoo media common entity information from.</param>
        /// <param name="manager">The <see cref="XmlNamespaceManager"/> object used to resolve prefixed Yahoo media elements and attributes.</param>
        /// <returns><b>true</b> if the <paramref name="target"/> was initialized using the supplied <paramref name="source"/>, otherwise <b>false</b>.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="target"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="manager"/> is a null reference (Nothing in Visual Basic).</exception>
        private static bool FillCommonObjectEntityCollectionsSecondary(IYahooMediaCommonObjectEntities target, XPathNavigator source, XmlNamespaceManager manager)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            bool wasLoaded  = false;

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

            //------------------------------------------------------------
            //	Attempt to extract common entity information
            //------------------------------------------------------------
            if(source.HasChildren)
            {
                XPathNodeIterator hashIterator          = source.Select("media:hash", manager);
                XPathNodeIterator restrictionIterator   = source.Select("media:restriction", manager);
                XPathNodeIterator textIterator          = source.Select("media:text", manager);

                if (hashIterator != null && hashIterator.Count > 0)
                {
                    while (hashIterator.MoveNext())
                    {
                        YahooMediaHash hash = new YahooMediaHash();
                        if (hash.Load(hashIterator.Current))
                        {
                            target.Hashes.Add(hash);
                            wasLoaded   = true;
                        }
                    }
                }

                if (restrictionIterator != null && restrictionIterator.Count > 0)
                {
                    while (restrictionIterator.MoveNext())
                    {
                        YahooMediaRestriction restriction   = new YahooMediaRestriction();
                        if (restriction.Load(restrictionIterator.Current))
                        {
                            target.Restrictions.Add(restriction);
                            wasLoaded   = true;
                        }
                    }
                }

                if (textIterator != null && textIterator.Count > 0)
                {
                    while (textIterator.MoveNext())
                    {
                        YahooMediaText text = new YahooMediaText();
                        if (text.Load(textIterator.Current))
                        {
                            target.TextSeries.Add(text);
                            wasLoaded   = true;
                        }
                    }
                }
            }

            return wasLoaded;
        }