//============================================================ // 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 //------------------------------------------------------------ RssImage value = obj as RssImage; if (value != null) { int result = String.Compare(this.Description, value.Description, StringComparison.OrdinalIgnoreCase); result = result | this.Height.CompareTo(value.Height); result = result | Uri.Compare(this.Link, value.Link, UriComponents.AbsoluteUri, UriFormat.SafeUnescaped, StringComparison.OrdinalIgnoreCase); result = result | String.Compare(this.Title, value.Title, StringComparison.OrdinalIgnoreCase); 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"); } }
//============================================================ // CLASS SUMMARY //============================================================ /// <summary> /// Provides example code for the RssImage class. /// </summary> public static void ClassExample() { #region RssImage RssFeed feed = new RssFeed(); feed.Channel.Title = "Dallas Times-Herald"; feed.Channel.Link = new Uri("http://dallas.example.com"); feed.Channel.Description = "Current headlines from the Dallas Times-Herald newspaper"; RssImage image = new RssImage(new Uri("http://dallas.example.com"), "Dallas Times-Herald", new Uri("http://dallas.example.com/masthead.gif")); image.Description = "Read the Dallas Times-Herald"; image.Height = 32; image.Width = 96; feed.Channel.Image = image; #endregion }
//============================================================ // CLASS SUMMARY //============================================================ /// <summary> /// Provides example code for the RssChannel class. /// </summary> public static void ClassExample() { #region RssChannel RssFeed feed = new RssFeed(); feed.Channel.Title = "Dallas Times-Herald"; feed.Channel.Link = new Uri("http://dallas.example.com"); feed.Channel.Description = "Current headlines from the Dallas Times-Herald newspaper"; feed.Channel.Categories.Add(new RssCategory("Media")); feed.Channel.Categories.Add(new RssCategory("News/Newspapers/Regional/United_States/Texas", "dmoz")); feed.Channel.Cloud = new RssCloud("server.example.com", "/rpc", 80, RssCloudProtocol.XmlRpc, "cloud.notify"); feed.Channel.Copyright = "Copyright 2007 Dallas Times-Herald"; feed.Channel.Generator = "Microsoft Spaces v1.1"; RssImage image = new RssImage(new Uri("http://dallas.example.com"), "Dallas Times-Herald", new Uri("http://dallas.example.com/masthead.gif")); image.Description = "Read the Dallas Times-Herald"; image.Height = 32; image.Width = 96; feed.Channel.Image = image; feed.Channel.Language = new CultureInfo("en-US"); feed.Channel.LastBuildDate = new DateTime(2007, 10, 14, 17, 17, 44); feed.Channel.ManagingEditor = "[email protected] (Jim Lehrer)"; feed.Channel.PublicationDate = new DateTime(2007, 10, 14, 5, 0, 0); feed.Channel.Rating = "(PICS-1.1 \"http://www.rsac.org/ratingsv01.html\" l by \"[email protected]\" on \"2007.01.29T10:09-0800\" r (n 0 s 0 v 0 l 0))"; feed.Channel.SkipDays.Add(DayOfWeek.Saturday); feed.Channel.SkipDays.Add(DayOfWeek.Sunday); feed.Channel.SkipHours.Add(0); feed.Channel.SkipHours.Add(1); feed.Channel.SkipHours.Add(2); feed.Channel.SkipHours.Add(22); feed.Channel.SkipHours.Add(23); feed.Channel.TextInput = new RssTextInput("What software are you using?", new Uri("http://www.cadenhead.org/textinput.php"), "query", "TextInput Inquiry"); feed.Channel.TimeToLive = 60; feed.Channel.Webmaster = "*****@*****.**"; #endregion }
/// <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); } RssImage value = obj as RssImage; if (value != null) { int result = String.Compare(this.Description, value.Description, StringComparison.OrdinalIgnoreCase); result = result | this.Height.CompareTo(value.Height); result = result | Uri.Compare(this.Link, value.Link, UriComponents.AbsoluteUri, UriFormat.SafeUnescaped, StringComparison.OrdinalIgnoreCase); result = result | String.Compare(this.Title, value.Title, StringComparison.OrdinalIgnoreCase); 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> /// Loads the optional elements of this <see cref="RssChannel"/> using the supplied <see cref="XPathNavigator"/>. /// </summary> /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param> /// <param name="manager">The <see cref="XmlNamespaceManager"/> used to resolve namespace prefixes.</param> /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> used to configure the load operation.</param> /// <returns><b>true</b> if the <see cref="RssChannel"/> 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="RssChannel"/>. /// </remarks> /// <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 bool LoadOptionals(XPathNavigator source, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ bool wasLoaded = false; //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(source, "source"); Guard.ArgumentNotNull(manager, "manager"); Guard.ArgumentNotNull(settings, "settings"); //------------------------------------------------------------ // Attempt to extract syndication information //------------------------------------------------------------ XPathNavigator cloudNavigator = source.SelectSingleNode("cloud", manager); XPathNavigator copyrightNavigator = source.SelectSingleNode("copyright", manager); XPathNavigator generatorNavigator = source.SelectSingleNode("generator", manager); XPathNavigator imageNavigator = source.SelectSingleNode("image", manager); XPathNavigator languageNavigator = source.SelectSingleNode("language", manager); XPathNavigator lastBuildDateNavigator = source.SelectSingleNode("lastBuildDate", manager); XPathNavigator managingEditorNavigator = source.SelectSingleNode("managingEditor", manager); XPathNavigator publicationNavigator = source.SelectSingleNode("pubDate", manager); XPathNavigator ratingNavigator = source.SelectSingleNode("rating", manager); XPathNavigator textInputNavigator = source.SelectSingleNode("textInput", manager); XPathNavigator timeToLiveNavigator = source.SelectSingleNode("ttl", manager); XPathNavigator webMasterNavigator = source.SelectSingleNode("webMaster", manager); if (cloudNavigator != null) { RssCloud cloud = new RssCloud(); if (cloud.Load(cloudNavigator, settings)) { this.Cloud = cloud; wasLoaded = true; } } if (copyrightNavigator != null) { this.Copyright = copyrightNavigator.Value; wasLoaded = true; } if (generatorNavigator != null) { this.Generator = generatorNavigator.Value; wasLoaded = true; } if (imageNavigator != null) { RssImage image = new RssImage(); if (image.Load(imageNavigator, settings)) { this.Image = image; wasLoaded = true; } } if (languageNavigator != null && !String.IsNullOrEmpty(languageNavigator.Value)) { try { CultureInfo language = new CultureInfo(languageNavigator.Value); this.Language = language; wasLoaded = true; } catch (ArgumentException) { System.Diagnostics.Trace.TraceWarning("RssChannel unable to determine CultureInfo with a name of {0}.", languageNavigator.Value); } } if (lastBuildDateNavigator != null) { DateTime lastBuildDate; if (SyndicationDateTimeUtility.TryParseRfc822DateTime(lastBuildDateNavigator.Value, out lastBuildDate)) { this.LastBuildDate = lastBuildDate; wasLoaded = true; } } if (managingEditorNavigator != null) { this.ManagingEditor = managingEditorNavigator.Value; wasLoaded = true; } if (publicationNavigator != null) { DateTime publicationDate; if (SyndicationDateTimeUtility.TryParseRfc822DateTime(publicationNavigator.Value, out publicationDate)) { this.PublicationDate = publicationDate; wasLoaded = true; } } if (ratingNavigator != null) { this.Rating = ratingNavigator.Value; wasLoaded = true; } if (textInputNavigator != null) { RssTextInput textInput = new RssTextInput(); if (textInput.Load(textInputNavigator, settings)) { this.TextInput = textInput; wasLoaded = true; } } if (timeToLiveNavigator != null) { int timeToLive; if (Int32.TryParse(timeToLiveNavigator.Value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out timeToLive)) { this.TimeToLive = timeToLive; wasLoaded = true; } } if (webMasterNavigator != null) { this.Webmaster = webMasterNavigator.Value; wasLoaded = true; } return wasLoaded; }
/// <summary> /// Initializes the supplied <see cref="RssImage"/> using the specified <see cref="XPathNavigator"/> and <see cref="XmlNamespaceManager"/>. /// </summary> /// <param name="image">The <see cref="RssImage"/> to be filled.</param> /// <param name="navigator">The <see cref="XPathNavigator"/> used to navigate the image XML data.</param> /// <param name="manager">The <see cref="XmlNamespaceManager"/> used to resolve XML namespace prefixes.</param> /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> object used to configure the load operation.</param> /// <exception cref="ArgumentNullException">The <paramref name="image"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="navigator"/> 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> /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception> private static void FillImage(RssImage image, XPathNavigator navigator, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings) { //------------------------------------------------------------ // Validate parameters //------------------------------------------------------------ Guard.ArgumentNotNull(image, "image"); Guard.ArgumentNotNull(navigator, "navigator"); Guard.ArgumentNotNull(manager, "manager"); Guard.ArgumentNotNull(settings, "settings"); //------------------------------------------------------------ // Attempt to extract image information //------------------------------------------------------------ XPathNavigator linkNavigator = navigator.SelectSingleNode("link", manager); XPathNavigator titleNavigator = navigator.SelectSingleNode("title", manager); XPathNavigator urlNavigator = navigator.SelectSingleNode("url", manager); XPathNavigator descriptionNavigator = navigator.SelectSingleNode("description", manager); XPathNavigator heightNavigator = navigator.SelectSingleNode("height", manager); XPathNavigator widthNavigator = navigator.SelectSingleNode("width", manager); if (linkNavigator != null) { Uri link; if (Uri.TryCreate(linkNavigator.Value, UriKind.RelativeOrAbsolute, out link)) { image.Link = link; } } if (titleNavigator != null) { if (!String.IsNullOrEmpty(titleNavigator.Value)) { image.Title = titleNavigator.Value; } } if (urlNavigator != null) { Uri url; if (Uri.TryCreate(urlNavigator.Value, UriKind.RelativeOrAbsolute, out url)) { image.Url = url; } } if (descriptionNavigator != null) { image.Description = descriptionNavigator.Value; } if (heightNavigator != null) { int height; if (Int32.TryParse(heightNavigator.Value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out height)) { image.Height = height < RssImage.HeightMaximum ? height : RssImage.HeightMaximum; } } if (widthNavigator != null) { int width; if (Int32.TryParse(widthNavigator.Value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out width)) { image.Width = width < RssImage.WidthMaximum ? width : RssImage.WidthMaximum; } } SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(navigator, settings); adapter.Fill(image); }
/// <summary> /// Initializes the supplied <see cref="RssImage"/> using the specified <see cref="XPathNavigator"/> and <see cref="XmlNamespaceManager"/>. /// </summary> /// <param name="image">The <see cref="RssImage"/> to be filled.</param> /// <param name="navigator">The <see cref="XPathNavigator"/> used to navigate the image XML data.</param> /// <param name="manager">The <see cref="XmlNamespaceManager"/> used to resolve XML namespace prefixes.</param> /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> object used to configure the load operation.</param> /// <exception cref="ArgumentNullException">The <paramref name="image"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="navigator"/> 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> /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception> private static void FillImage(RssImage image, XPathNavigator navigator, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings) { //------------------------------------------------------------ // Validate parameters //------------------------------------------------------------ Guard.ArgumentNotNull(image, "image"); Guard.ArgumentNotNull(navigator, "navigator"); Guard.ArgumentNotNull(manager, "manager"); Guard.ArgumentNotNull(settings, "settings"); //------------------------------------------------------------ // Attempt to extract image information //------------------------------------------------------------ XPathNavigator linkNavigator = navigator.SelectSingleNode("rss:link", manager); XPathNavigator titleNavigator = navigator.SelectSingleNode("rss:title", manager); XPathNavigator urlNavigator = navigator.SelectSingleNode("rss:url", manager); if (linkNavigator != null) { Uri link; if (Uri.TryCreate(linkNavigator.Value, UriKind.RelativeOrAbsolute, out link)) { image.Link = link; } } if (titleNavigator != null) { if (!String.IsNullOrEmpty(titleNavigator.Value)) { image.Title = titleNavigator.Value; } } if (urlNavigator != null) { Uri url; if (Uri.TryCreate(urlNavigator.Value, UriKind.RelativeOrAbsolute, out url)) { image.Url = url; } } SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(navigator, settings); adapter.Fill(image); }