Beispiel #1
0
        /// <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);
            }
            YahooMediaText value = obj as YahooMediaText;

            if (value != null)
            {
                int result = String.Compare(this.Content, value.Content, StringComparison.OrdinalIgnoreCase);
                result = result | this.End.CompareTo(value.End);

                string sourceLanguageName = this.Language != null ? this.Language.Name : String.Empty;
                string targetLanguageName = value.Language != null ? value.Language.Name : String.Empty;
                result = result | String.Compare(sourceLanguageName, targetLanguageName, StringComparison.OrdinalIgnoreCase);

                result = result | this.Start.CompareTo(value.Start);
                result = result | this.TextType.CompareTo(value.TextType);

                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");
            }
        }
Beispiel #2
0
        /// <summary>
        /// Saves the current <see cref="YahooMediaText"/> 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("text", extension.XmlNamespace);

            if (this.TextType != YahooMediaTextConstructType.None)
            {
                writer.WriteAttributeString("type", YahooMediaText.TextTypeAsString(this.TextType));
            }

            if (this.Language != null)
            {
                writer.WriteAttributeString("lang", this.Language.Name);
            }

            if (this.Start != TimeSpan.MinValue)
            {
                writer.WriteAttributeString("start", this.Start.ToString());
            }

            if (this.End != TimeSpan.MinValue)
            {
                writer.WriteAttributeString("end", this.End.ToString());
            }

            if (!String.IsNullOrEmpty(this.Content))
            {
                writer.WriteString(this.Content);
            }

            writer.WriteEndElement();
        }
        //============================================================
        //	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
            //------------------------------------------------------------
            YahooMediaText value = obj as YahooMediaText;

            if (value != null)
            {
                int result = String.Compare(this.Content, value.Content, StringComparison.OrdinalIgnoreCase);
                result = result | this.End.CompareTo(value.End);

                string sourceLanguageName = this.Language != null ? this.Language.Name : String.Empty;
                string targetLanguageName = value.Language != null ? value.Language.Name : String.Empty;
                result = result | String.Compare(sourceLanguageName, targetLanguageName, StringComparison.OrdinalIgnoreCase);

                result = result | this.Start.CompareTo(value.Start);
                result = result | this.TextType.CompareTo(value.TextType);

                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");
            }
        }
Beispiel #4
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>
        /// Saves the current <see cref="YahooMediaText"/> 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("text", extension.XmlNamespace);

            if (this.TextType != YahooMediaTextConstructType.None)
            {
                writer.WriteAttributeString("type", YahooMediaText.TextTypeAsString(this.TextType));
            }

            if (this.Language != null)
            {
                writer.WriteAttributeString("lang", this.Language.Name);
            }

            if (this.Start != TimeSpan.MinValue)
            {
                writer.WriteAttributeString("start", this.Start.ToString());
            }

            if (this.End != TimeSpan.MinValue)
            {
                writer.WriteAttributeString("end", this.End.ToString());
            }

            if (!String.IsNullOrEmpty(this.Content))
            {
                writer.WriteString(this.Content);
            }

            writer.WriteEndElement();
        }
Beispiel #6
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;
        }