示例#1
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
            //------------------------------------------------------------
            YahooMediaThumbnail value = obj as YahooMediaThumbnail;

            if (value != null)
            {
                int result = this.Height.CompareTo(value.Height);
                result = result | this.Time.CompareTo(value.Time);
                result = result | Uri.Compare(this.Url, value.Url, UriComponents.AbsoluteUri, UriFormat.SafeUnescaped, StringComparison.OrdinalIgnoreCase);
                result = result | this.Width.CompareTo(value.Width);

                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");
            }
        }
        /// <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);
            }
            YahooMediaThumbnail value = obj as YahooMediaThumbnail;

            if (value != null)
            {
                int result = this.Height.CompareTo(value.Height);
                result = result | this.Time.CompareTo(value.Time);
                result = result | Uri.Compare(this.Url, value.Url, UriComponents.AbsoluteUri, UriFormat.SafeUnescaped, StringComparison.OrdinalIgnoreCase);
                result = result | this.Width.CompareTo(value.Width);

                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 primary 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 FillCommonObjectEntityCollectionsPrimary(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 categoryIterator      = source.Select("media:category", manager);
                XPathNodeIterator creditIterator        = source.Select("media:credit", manager);
                XPathNodeIterator ratingIterator        = source.Select("media:rating", manager);
                XPathNodeIterator thumbnailIterator     = source.Select("media:thumbnail", manager);

                if (categoryIterator != null && categoryIterator.Count > 0)
                {
                    while (categoryIterator.MoveNext())
                    {
                        YahooMediaCategory category = new YahooMediaCategory();
                        if (category.Load(categoryIterator.Current))
                        {
                            target.Categories.Add(category);
                            wasLoaded   = true;
                        }
                    }
                }

                if (creditIterator != null && creditIterator.Count > 0)
                {
                    while (creditIterator.MoveNext())
                    {
                        YahooMediaCredit credit = new YahooMediaCredit();
                        if (credit.Load(creditIterator.Current))
                        {
                            target.Credits.Add(credit);
                            wasLoaded   = true;
                        }
                    }
                }

                if (ratingIterator != null && ratingIterator.Count > 0)
                {
                    while (ratingIterator.MoveNext())
                    {
                        YahooMediaRating rating = new YahooMediaRating();
                        if (rating.Load(ratingIterator.Current))
                        {
                            target.Ratings.Add(rating);
                            wasLoaded   = true;
                        }
                    }
                }

                if (thumbnailIterator != null && thumbnailIterator.Count > 0)
                {
                    while (thumbnailIterator.MoveNext())
                    {
                        YahooMediaThumbnail thumbnail   = new YahooMediaThumbnail();
                        if (thumbnail.Load(thumbnailIterator.Current))
                        {
                            target.Thumbnails.Add(thumbnail);
                            wasLoaded   = true;
                        }
                    }
                }
            }

            return wasLoaded;
        }
示例#4
0
        /// <summary>
        /// Modifies the primary 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 FillCommonObjectEntityCollectionsPrimary(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 categoryIterator  = source.Select("media:category", manager);
                XPathNodeIterator creditIterator    = source.Select("media:credit", manager);
                XPathNodeIterator ratingIterator    = source.Select("media:rating", manager);
                XPathNodeIterator thumbnailIterator = source.Select("media:thumbnail", manager);

                if (categoryIterator != null && categoryIterator.Count > 0)
                {
                    while (categoryIterator.MoveNext())
                    {
                        YahooMediaCategory category = new YahooMediaCategory();
                        if (category.Load(categoryIterator.Current))
                        {
                            target.Categories.Add(category);
                            wasLoaded = true;
                        }
                    }
                }

                if (creditIterator != null && creditIterator.Count > 0)
                {
                    while (creditIterator.MoveNext())
                    {
                        YahooMediaCredit credit = new YahooMediaCredit();
                        if (credit.Load(creditIterator.Current))
                        {
                            target.Credits.Add(credit);
                            wasLoaded = true;
                        }
                    }
                }

                if (ratingIterator != null && ratingIterator.Count > 0)
                {
                    while (ratingIterator.MoveNext())
                    {
                        YahooMediaRating rating = new YahooMediaRating();
                        if (rating.Load(ratingIterator.Current))
                        {
                            target.Ratings.Add(rating);
                            wasLoaded = true;
                        }
                    }
                }

                if (thumbnailIterator != null && thumbnailIterator.Count > 0)
                {
                    while (thumbnailIterator.MoveNext())
                    {
                        YahooMediaThumbnail thumbnail = new YahooMediaThumbnail();
                        if (thumbnail.Load(thumbnailIterator.Current))
                        {
                            target.Thumbnails.Add(thumbnail);
                            wasLoaded = true;
                        }
                    }
                }
            }

            return(wasLoaded);
        }