//============================================================ // 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 //------------------------------------------------------------ TrackbackDiscoveryMetadata value = obj as TrackbackDiscoveryMetadata; if (value != null) { int result = Uri.Compare(this.About, value.About, UriComponents.AbsoluteUri, UriFormat.SafeUnescaped, StringComparison.OrdinalIgnoreCase); result = result | Uri.Compare(this.Identifier, value.Identifier, UriComponents.AbsoluteUri, UriFormat.SafeUnescaped, StringComparison.OrdinalIgnoreCase); result = result | Uri.Compare(this.PingUrl, value.PingUrl, UriComponents.AbsoluteUri, UriFormat.SafeUnescaped, StringComparison.OrdinalIgnoreCase); result = result | String.Compare(this.Title, value.Title, 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"); } }
public static Collection<TrackbackDiscoveryMetadata> ExtractTrackbackNotificationServers(string content) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ Collection<TrackbackDiscoveryMetadata> results = new Collection<TrackbackDiscoveryMetadata>(); Regex rdfPattern = new Regex("<rdf:RDF\b[^>]*>(.*?)</rdf:RDF>", RegexOptions.IgnoreCase | RegexOptions.Singleline); XmlNamespaceManager manager = new XmlNamespaceManager(new NameTable()); //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNullOrEmptyString(content, "content"); //------------------------------------------------------------ // Initialize XML namespace manager with expected namespaces //------------------------------------------------------------ manager.AddNamespace("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"); manager.AddNamespace("dc", "http://purl.org/dc/elements/1.1/"); manager.AddNamespace("trackback", "http://madskills.com/public/xml/rss/module/trackback/"); //------------------------------------------------------------ // Extract <rdf:RDF> elements using pattern matching //------------------------------------------------------------ MatchCollection embeddedRdfs = rdfPattern.Matches(content); foreach (Match embeddedRdf in embeddedRdfs) { using (StringReader reader = new StringReader(embeddedRdf.Value)) { XPathDocument document = new XPathDocument(reader); XPathNavigator navigator = document.CreateNavigator(); TrackbackDiscoveryMetadata trackbackMetadata = new TrackbackDiscoveryMetadata(); if (trackbackMetadata.Load(navigator)) { results.Add(trackbackMetadata); } } } return results; }