//============================================================
        //	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
            //------------------------------------------------------------
            YahooMediaTextConstruct value = obj as YahooMediaTextConstruct;

            if (value != null)
            {
                int result = String.Compare(this.Content, value.Content, StringComparison.OrdinalIgnoreCase);
                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");
            }
        }
        /// <summary>
        /// Loads this <see cref="YahooMediaTextConstruct"/> 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="YahooMediaTextConstruct"/> 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="YahooMediaTextConstruct"/>.
        /// </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 typeAttribute = source.GetAttribute("type", String.Empty);
                if (!String.IsNullOrEmpty(typeAttribute))
                {
                    YahooMediaTextConstructType type = YahooMediaTextConstruct.TextTypeByName(typeAttribute);
                    if (type != YahooMediaTextConstructType.None)
                    {
                        this.TextType = type;
                        wasLoaded     = true;
                    }
                }
            }

            if (!String.IsNullOrEmpty(source.Value))
            {
                this.Content = source.Value;
                wasLoaded    = true;
            }

            return(wasLoaded);
        }
        /// <summary>
        /// Saves the current <see cref="YahooMediaTextConstruct"/> to the specified <see cref="XmlWriter"/>.
        /// </summary>
        /// <param name="writer">The <see cref="XmlWriter"/> to which you want to save.</param>
        /// <param name="elementName">The local name of the text construct being written.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="writer"/> is a null reference (Nothing in Visual Basic).</exception>
        public void WriteTo(XmlWriter writer, string elementName)
        {
            //------------------------------------------------------------
            //	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(elementName, extension.XmlNamespace);

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

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

            writer.WriteEndElement();
        }
        /// <summary>
        /// Saves the current <see cref="YahooMediaTextConstruct"/> to the specified <see cref="XmlWriter"/>.
        /// </summary>
        /// <param name="writer">The <see cref="XmlWriter"/> to which you want to save.</param>
        /// <param name="elementName">The local name of the text construct being written.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="writer"/> is a null reference (Nothing in Visual Basic).</exception>
        public void WriteTo(XmlWriter writer, string elementName)
        {
            Guard.ArgumentNotNull(writer, "writer");
            YahooMediaSyndicationExtension extension = new YahooMediaSyndicationExtension();

            writer.WriteStartElement(elementName, extension.XmlNamespace);

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

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

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

            if (value != null)
            {
                int result = String.Compare(this.Content, value.Content, StringComparison.OrdinalIgnoreCase);
                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");
            }
        }
        //============================================================
        //	PUBLIC METHODS
        //============================================================
        #region Load(XPathNavigator source)
        /// <summary>
        /// Loads this <see cref="YahooMediaTextConstruct"/> 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="YahooMediaTextConstruct"/> 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="YahooMediaTextConstruct"/>.
        /// </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 typeAttribute = source.GetAttribute("type", String.Empty);
                if (!String.IsNullOrEmpty(typeAttribute))
                {
                    YahooMediaTextConstructType type = YahooMediaTextConstruct.TextTypeByName(typeAttribute);
                    if (type != YahooMediaTextConstructType.None)
                    {
                        this.TextType = type;
                        wasLoaded     = true;
                    }
                }
            }

            if (!String.IsNullOrEmpty(source.Value))
            {
                this.Content = source.Value;
                wasLoaded    = true;
            }

            return(wasLoaded);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Modifies the classes 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 FillCommonObjectEntityClasses(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)
            {
                XPathNavigator titleNavigator       = source.SelectSingleNode("media:title", manager);
                XPathNavigator descriptionNavigator = source.SelectSingleNode("media:description", manager);
                XPathNavigator copyrightNavigator   = source.SelectSingleNode("media:copyright", manager);
                XPathNavigator playerNavigator      = source.SelectSingleNode("media:player", manager);
                XPathNavigator keywordNavigator     = source.SelectSingleNode("media:keywords", manager);

                if (titleNavigator != null)
                {
                    YahooMediaTextConstruct title   = new YahooMediaTextConstruct();
                    if (title.Load(titleNavigator))
                    {
                        target.Title    = title;
                        wasLoaded       = true;
                    }
                }

                if (descriptionNavigator != null)
                {
                    YahooMediaTextConstruct description = new YahooMediaTextConstruct();
                    if (description.Load(descriptionNavigator))
                    {
                        target.Description  = description;
                        wasLoaded           = true;
                    }
                }

                if (copyrightNavigator != null)
                {
                    YahooMediaCopyright copyright = new YahooMediaCopyright();
                    if (copyright.Load(copyrightNavigator))
                    {
                        target.Copyright    = copyright;
                        wasLoaded           = true;
                    }
                }

                if (playerNavigator != null)
                {
                    YahooMediaPlayer player = new YahooMediaPlayer();
                    if (player.Load(playerNavigator))
                    {
                        target.Player   = player;
                        wasLoaded       = true;
                    }
                }

                if (keywordNavigator != null && !String.IsNullOrEmpty(keywordNavigator.Value))
                {
                    if (keywordNavigator.Value.Contains(","))
                    {
                        string[] keywords = keywordNavigator.Value.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                        if (keywords.Length > 0)
                        {
                            foreach (string keyword in keywords)
                            {
                                target.Keywords.Add(keyword);
                            }
                            wasLoaded = true;
                        }
                    }
                    else
                    {
                        target.Keywords.Add(keywordNavigator.Value.Trim());
                        wasLoaded   = true;
                    }
                }
            }

            return wasLoaded;
        }
Exemplo n.º 8
0
        /// <summary>
        /// Modifies the classes 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 FillCommonObjectEntityClasses(IYahooMediaCommonObjectEntities target, XPathNavigator source, XmlNamespaceManager manager)
        {
            bool wasLoaded = false;

            Guard.ArgumentNotNull(target, "target");
            Guard.ArgumentNotNull(source, "source");
            Guard.ArgumentNotNull(manager, "manager");
            if (source.HasChildren)
            {
                XPathNavigator titleNavigator       = source.SelectSingleNode("media:title", manager);
                XPathNavigator descriptionNavigator = source.SelectSingleNode("media:description", manager);
                XPathNavigator copyrightNavigator   = source.SelectSingleNode("media:copyright", manager);
                XPathNavigator playerNavigator      = source.SelectSingleNode("media:player", manager);
                XPathNavigator keywordNavigator     = source.SelectSingleNode("media:keywords", manager);

                if (titleNavigator != null)
                {
                    YahooMediaTextConstruct title = new YahooMediaTextConstruct();
                    if (title.Load(titleNavigator))
                    {
                        target.Title = title;
                        wasLoaded    = true;
                    }
                }

                if (descriptionNavigator != null)
                {
                    YahooMediaTextConstruct description = new YahooMediaTextConstruct();
                    if (description.Load(descriptionNavigator))
                    {
                        target.Description = description;
                        wasLoaded          = true;
                    }
                }

                if (copyrightNavigator != null)
                {
                    YahooMediaCopyright copyright = new YahooMediaCopyright();
                    if (copyright.Load(copyrightNavigator))
                    {
                        target.Copyright = copyright;
                        wasLoaded        = true;
                    }
                }

                if (playerNavigator != null)
                {
                    YahooMediaPlayer player = new YahooMediaPlayer();
                    if (player.Load(playerNavigator))
                    {
                        target.Player = player;
                        wasLoaded     = true;
                    }
                }

                if (keywordNavigator != null && !String.IsNullOrEmpty(keywordNavigator.Value))
                {
                    if (keywordNavigator.Value.Contains(","))
                    {
                        string[] keywords = keywordNavigator.Value.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                        if (keywords.Length > 0)
                        {
                            foreach (string keyword in keywords)
                            {
                                target.Keywords.Add(keyword);
                            }
                            wasLoaded = true;
                        }
                    }
                    else
                    {
                        target.Keywords.Add(keywordNavigator.Value.Trim());
                        wasLoaded = true;
                    }
                }
            }

            return(wasLoaded);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Loads this <see cref="YahooMediaText"/> 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="YahooMediaText"/> 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="YahooMediaText"/>.
        /// </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 typeAttribute     = source.GetAttribute("type", String.Empty);
                string languageAttribute = source.GetAttribute("lang", String.Empty);
                string startAttribute    = source.GetAttribute("start", String.Empty);
                string endAttribute      = source.GetAttribute("end", String.Empty);

                if (!String.IsNullOrEmpty(typeAttribute))
                {
                    YahooMediaTextConstructType type = YahooMediaTextConstruct.TextTypeByName(typeAttribute);
                    if (type != YahooMediaTextConstructType.None)
                    {
                        this.TextType = type;
                        wasLoaded     = true;
                    }
                }

                if (!String.IsNullOrEmpty(languageAttribute))
                {
                    try
                    {
                        CultureInfo language = new CultureInfo(languageAttribute);
                        this.Language = language;
                        wasLoaded     = true;
                    }
                    catch (ArgumentException)
                    {
                        System.Diagnostics.Trace.TraceWarning("YahooMediaText was unable to determine CultureInfo with a name of {0}.", languageAttribute);
                    }
                }

                if (!String.IsNullOrEmpty(startAttribute))
                {
                    TimeSpan start;
                    if (TimeSpan.TryParse(startAttribute, out start))
                    {
                        this.Start = start;
                        wasLoaded  = true;
                    }
                }

                if (!String.IsNullOrEmpty(endAttribute))
                {
                    TimeSpan end;
                    if (TimeSpan.TryParse(endAttribute, out end))
                    {
                        this.End  = end;
                        wasLoaded = true;
                    }
                }
            }

            if (!String.IsNullOrEmpty(source.Value))
            {
                this.Content = source.Value;
                wasLoaded    = true;
            }

            return(wasLoaded);
        }