//============================================================ // 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 //------------------------------------------------------------ RssCloud value = obj as RssCloud; if (value != null) { int result = String.Compare(this.Domain, value.Domain, StringComparison.OrdinalIgnoreCase); result = result | String.Compare(this.Path, value.Path, StringComparison.OrdinalIgnoreCase); result = result | this.Port.CompareTo(value.Port); result = result | this.Protocol.CompareTo(value.Protocol); result = result | String.Compare(this.RegisterProcedure, value.RegisterProcedure, StringComparison.OrdinalIgnoreCase); 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> /// Saves the current <see cref="RssCloud"/> 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"); //------------------------------------------------------------ // Write XML representation of the current instance //------------------------------------------------------------ writer.WriteStartElement("cloud"); writer.WriteAttributeString("domain", this.Domain); writer.WriteAttributeString("path", this.Path); writer.WriteAttributeString("port", this.Port.ToString(System.Globalization.NumberFormatInfo.InvariantInfo)); writer.WriteAttributeString("protocol", RssCloud.CloudProtocolAsString(this.Protocol)); writer.WriteAttributeString("registerProcedure", this.RegisterProcedure); //------------------------------------------------------------ // Write the syndication extensions of the current instance //------------------------------------------------------------ SyndicationExtensionAdapter.WriteExtensionsTo(this.Extensions, writer); writer.WriteEndElement(); }
/// <summary> /// Loads this <see cref="RssCloud"/> 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="RssCloud"/> 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="RssCloud"/>. /// </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 domain = source.GetAttribute("domain", String.Empty); string path = source.GetAttribute("path", String.Empty); string port = source.GetAttribute("port", String.Empty); string protocol = source.GetAttribute("protocol", String.Empty); string registerProcedure = source.GetAttribute("registerProcedure", String.Empty); if (!String.IsNullOrEmpty(domain)) { this.Domain = domain; wasLoaded = true; } if (!String.IsNullOrEmpty(path)) { this.Path = path; wasLoaded = true; } if (!String.IsNullOrEmpty(port)) { int tcpPort; if (Int32.TryParse(port, System.Globalization.NumberStyles.Integer, System.Globalization.NumberFormatInfo.InvariantInfo, out tcpPort)) { if (tcpPort > 0) { this.Port = tcpPort; wasLoaded = true; } } } if (!String.IsNullOrEmpty(protocol)) { RssCloudProtocol serviceProtocol = RssCloud.CloudProtocolByName(protocol); if (serviceProtocol != RssCloudProtocol.None) { this.Protocol = serviceProtocol; wasLoaded = true; } } if (!String.IsNullOrEmpty(registerProcedure)) { this.RegisterProcedure = registerProcedure; wasLoaded = true; } } return(wasLoaded); }
/// <summary> /// Saves the current <see cref="RssCloud"/> 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"); writer.WriteStartElement("cloud"); writer.WriteAttributeString("domain", this.Domain); writer.WriteAttributeString("path", this.Path); writer.WriteAttributeString("port", this.Port.ToString(System.Globalization.NumberFormatInfo.InvariantInfo)); writer.WriteAttributeString("protocol", RssCloud.CloudProtocolAsString(this.Protocol)); writer.WriteAttributeString("registerProcedure", this.RegisterProcedure); SyndicationExtensionAdapter.WriteExtensionsTo(this.Extensions, writer); 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); } RssCloud value = obj as RssCloud; if (value != null) { int result = String.Compare(this.Domain, value.Domain, StringComparison.OrdinalIgnoreCase); result = result | String.Compare(this.Path, value.Path, StringComparison.OrdinalIgnoreCase); result = result | this.Port.CompareTo(value.Port); result = result | this.Protocol.CompareTo(value.Protocol); result = result | String.Compare(this.RegisterProcedure, value.RegisterProcedure, StringComparison.OrdinalIgnoreCase); 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="RssCloud"/> using the specified <see cref="XPathNavigator"/> and <see cref="XmlNamespaceManager"/>. /// </summary> /// <param name="cloud">The <see cref="RssCloud"/> to be filled.</param> /// <param name="navigator">The <see cref="XPathNavigator"/> used to navigate the cloud 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 of the <see cref="RssFeed"/>.</param> /// <exception cref="ArgumentNullException">The <paramref name="cloud"/> 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 FillCloud(RssCloud cloud, XPathNavigator navigator, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings) { //------------------------------------------------------------ // Validate parameters //------------------------------------------------------------ Guard.ArgumentNotNull(cloud, "cloud"); Guard.ArgumentNotNull(navigator, "navigator"); Guard.ArgumentNotNull(manager, "manager"); Guard.ArgumentNotNull(settings, "settings"); //------------------------------------------------------------ // Attempt to extract category information //------------------------------------------------------------ if (navigator.HasAttributes) { string domainAttribute = navigator.GetAttribute("domain", String.Empty); string portAttribute = navigator.GetAttribute("port", String.Empty); string pathAttribute = navigator.GetAttribute("path", String.Empty); string registerProcedureAttribute = navigator.GetAttribute("registerProcedure", String.Empty); string protocolAttribute = navigator.GetAttribute("protocol", String.Empty); if (!String.IsNullOrEmpty(domainAttribute)) { cloud.Domain = domainAttribute; } if (!String.IsNullOrEmpty(portAttribute)) { int port; if (Int32.TryParse(portAttribute, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out port)) { cloud.Port = port; } } if (!String.IsNullOrEmpty(pathAttribute)) { cloud.Path = pathAttribute; } if (!String.IsNullOrEmpty(registerProcedureAttribute)) { cloud.RegisterProcedure = registerProcedureAttribute; } if (!String.IsNullOrEmpty(protocolAttribute)) { RssCloudProtocol protocol = RssCloud.CloudProtocolByName(protocolAttribute); if (protocol != RssCloudProtocol.None) { cloud.Protocol = protocol; } } } SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(navigator, settings); adapter.Fill(cloud); }