/// <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); } DublinCoreElementSetSyndicationExtension value = obj as DublinCoreElementSetSyndicationExtension; if (value != null) { int result = String.Compare(this.Description, value.Description, StringComparison.OrdinalIgnoreCase); result = result | Uri.Compare(this.Documentation, value.Documentation, UriComponents.AbsoluteUri, UriFormat.SafeUnescaped, StringComparison.OrdinalIgnoreCase); result = result | String.Compare(this.Name, value.Name, StringComparison.OrdinalIgnoreCase); result = result | this.Version.CompareTo(value.Version); result = result | String.Compare(this.XmlNamespace, value.XmlNamespace, StringComparison.Ordinal); result = result | String.Compare(this.XmlPrefix, value.XmlPrefix, StringComparison.Ordinal); result = result | String.Compare(this.Context.Contributor, value.Context.Contributor, StringComparison.OrdinalIgnoreCase); result = result | String.Compare(this.Context.Coverage, value.Context.Coverage, StringComparison.OrdinalIgnoreCase); result = result | String.Compare(this.Context.Creator, value.Context.Creator, StringComparison.OrdinalIgnoreCase); result = result | this.Context.Date.CompareTo(value.Context.Date); result = result | String.Compare(this.Context.Description, value.Context.Description, StringComparison.OrdinalIgnoreCase); result = result | String.Compare(this.Context.Format, value.Context.Format, StringComparison.OrdinalIgnoreCase); result = result | String.Compare(this.Context.Identifier, value.Context.Identifier, StringComparison.Ordinal); if (this.Context.Language != null) { if (value.Context.Language != null) { result = result | String.Compare(this.Context.Language.Name, value.Context.Language.Name, StringComparison.OrdinalIgnoreCase); } else { result = result | 1; } } else if (this.Context.Language == null && value.Context.Language != null) { result = result | -1; } result = result | String.Compare(this.Context.Publisher, value.Context.Publisher, StringComparison.OrdinalIgnoreCase); result = result | String.Compare(this.Context.Relation, value.Context.Relation, StringComparison.OrdinalIgnoreCase); result = result | String.Compare(this.Context.Rights, value.Context.Rights, StringComparison.OrdinalIgnoreCase); result = result | String.Compare(this.Context.Source, value.Context.Source, StringComparison.OrdinalIgnoreCase); result = result | String.Compare(this.Context.Subject, value.Context.Subject, StringComparison.OrdinalIgnoreCase); result = result | String.Compare(this.Context.Title, value.Context.Title, StringComparison.OrdinalIgnoreCase); result = result | this.Context.TypeVocabulary.CompareTo(value.Context.TypeVocabulary); 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> /// Initializes the syndication extension context optional elements using the supplied <see cref="XPathNavigator"/>. /// </summary> /// <param name="source">The <b>XPathNavigator</b> used to load this <see cref="DublinCoreElementSetSyndicationExtensionContext"/>.</param> /// <param name="manager">The <see cref="XmlNamespaceManager"/> object used to resolve prefixed syndication extension elements and attributes.</param> /// <returns><b>true</b> if the <see cref="DublinCoreElementSetSyndicationExtensionContext"/> was able to be initialized using the supplied <paramref name="source"/>; otherwise <b>false</b>.</returns> /// <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) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ bool wasLoaded = false; //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(source, "source"); Guard.ArgumentNotNull(manager, "manager"); //------------------------------------------------------------ // Attempt to extract syndication extension information //------------------------------------------------------------ XPathNavigator coverageNavigator = source.SelectSingleNode("dc:coverage", manager); XPathNavigator formatNavigator = source.SelectSingleNode("dc:format", manager); XPathNavigator identifierNavigator = source.SelectSingleNode("dc:identifier", manager); XPathNavigator relationNavigator = source.SelectSingleNode("dc:relation", manager); XPathNavigator sourceNavigator = source.SelectSingleNode("dc:source", manager); XPathNavigator subjectNavigator = source.SelectSingleNode("dc:subject", manager); XPathNavigator typeNavigator = source.SelectSingleNode("dc:type", manager); if (coverageNavigator != null && !String.IsNullOrEmpty(coverageNavigator.Value)) { this.Coverage = coverageNavigator.Value; wasLoaded = true; } if (formatNavigator != null && !String.IsNullOrEmpty(formatNavigator.Value)) { this.Format = formatNavigator.Value; wasLoaded = true; } if (identifierNavigator != null && !String.IsNullOrEmpty(identifierNavigator.Value)) { this.Identifier = identifierNavigator.Value; wasLoaded = true; } if (relationNavigator != null && !String.IsNullOrEmpty(relationNavigator.Value)) { this.Relation = relationNavigator.Value; wasLoaded = true; } if (sourceNavigator != null && !String.IsNullOrEmpty(sourceNavigator.Value)) { this.Source = sourceNavigator.Value; wasLoaded = true; } if (subjectNavigator != null && !String.IsNullOrEmpty(subjectNavigator.Value)) { this.Subject = subjectNavigator.Value; wasLoaded = true; } if (typeNavigator != null && !String.IsNullOrEmpty(typeNavigator.Value)) { DublinCoreTypeVocabularies typeVocabulary = DublinCoreElementSetSyndicationExtension.TypeVocabularyByName(typeNavigator.Value); if (typeVocabulary != DublinCoreTypeVocabularies.None) { this.TypeVocabulary = typeVocabulary; wasLoaded = true; } } return(wasLoaded); }
/// <summary> /// Writes the current context to the specified <see cref="XmlWriter"/>. /// </summary> /// <param name="writer">The <b>XmlWriter</b> to which you want to write the current context.</param> /// <param name="xmlNamespace">The XML namespace used to qualify prefixed syndication extension elements and attributes.</param> /// <exception cref="ArgumentNullException">The <paramref name="writer"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="xmlNamespace"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="xmlNamespace"/> is an empty string.</exception> public void WriteTo(XmlWriter writer, string xmlNamespace) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(writer, "writer"); Guard.ArgumentNotNullOrEmptyString(xmlNamespace, "xmlNamespace"); //------------------------------------------------------------ // Write current extension details to the writer //------------------------------------------------------------ if (!String.IsNullOrEmpty(this.Contributor)) { writer.WriteElementString("contributor", xmlNamespace, this.Contributor); } if (!String.IsNullOrEmpty(this.Coverage)) { writer.WriteElementString("coverage", xmlNamespace, this.Coverage); } if (!String.IsNullOrEmpty(this.Creator)) { writer.WriteElementString("creator", xmlNamespace, this.Creator); } if (this.Date != DateTime.MinValue) { writer.WriteElementString("date", xmlNamespace, SyndicationDateTimeUtility.ToRfc3339DateTime(this.Date)); } if (!String.IsNullOrEmpty(this.Description)) { writer.WriteElementString("description", xmlNamespace, this.Description); } if (!String.IsNullOrEmpty(this.Format)) { writer.WriteElementString("format", xmlNamespace, this.Format); } if (!String.IsNullOrEmpty(this.Identifier)) { writer.WriteElementString("identifier", xmlNamespace, this.Identifier); } if (this.Language != null) { writer.WriteElementString("language", xmlNamespace, this.Language.Name); } if (!String.IsNullOrEmpty(this.Publisher)) { writer.WriteElementString("publisher", xmlNamespace, this.Publisher); } if (!String.IsNullOrEmpty(this.Relation)) { writer.WriteElementString("relation", xmlNamespace, this.Relation); } if (!String.IsNullOrEmpty(this.Rights)) { writer.WriteElementString("rights", xmlNamespace, this.Rights); } if (!String.IsNullOrEmpty(this.Source)) { writer.WriteElementString("source", xmlNamespace, this.Source); } if (!String.IsNullOrEmpty(this.Subject)) { writer.WriteElementString("subject", xmlNamespace, this.Subject); } if (!String.IsNullOrEmpty(this.Title)) { writer.WriteElementString("title", xmlNamespace, this.Title); } if (this.TypeVocabulary != DublinCoreTypeVocabularies.None) { writer.WriteElementString("type", xmlNamespace, DublinCoreElementSetSyndicationExtension.TypeVocabularyAsString(this.TypeVocabulary)); } }
private DublinCoreElementSetSyndicationExtension CreateExtension2() { var dub = new DublinCoreElementSetSyndicationExtension(); dub.Context.Contributor = "Helper-er"; dub.Context.Coverage = "US"; dub.Context.Creator = "The Not-So-Big Guy"; dub.Context.Date = new DateTime(2010, 8, 1); dub.Context.Description = "This kind of thing"; dub.Context.Format = "CDROM"; dub.Context.Identifier = "MYTESTCDROM-2"; dub.Context.Language = new CultureInfo("en-US"); dub.Context.Publisher = "MeMyselfI"; dub.Context.Relation = "MYTESTCDROM-1"; dub.Context.Rights = "Copyright 2010"; dub.Context.Source = "Nowheres, man"; dub.Context.Subject = "Test data (Son of)"; dub.Context.Title = "More Stupid test data"; dub.Context.TypeVocabulary = DublinCoreTypeVocabularies.PhysicalObject; return dub; }
public void DublinCoreElementSet_LoadTest() { DublinCoreElementSetSyndicationExtension target = new DublinCoreElementSetSyndicationExtension(); // TODO: Initialize to an appropriate value var nt = new NameTable(); var ns = new XmlNamespaceManager(nt); var xpc = new XmlParserContext(nt, ns, "US-en",XmlSpace.Default); var strXml = ExtensionTestUtil.GetWrappedXml(namespc, strExtXml); using (XmlReader reader = new XmlTextReader(strXml, XmlNodeType.Document, xpc) ) { #if false //var document = new XPathDocument(reader); //var nav = document.CreateNavigator(); //nav.Select("//item"); do { if (!reader.Read()) break; } while (reader.NodeType != XmlNodeType.EndElement || reader.Name != "webMaster"); bool expected = true; bool actual; actual = target.Load(reader); Assert.AreEqual(expected, actual); #else RssFeed feed = new RssFeed(); feed.Load(reader); #endif } }
public void DublinCoreElementSetSyndicationExtensionConstructorTest() { DublinCoreElementSetSyndicationExtension target = new DublinCoreElementSetSyndicationExtension(); Assert.IsNotNull(target); Assert.IsInstanceOfType(target, typeof(DublinCoreElementSetSyndicationExtension)); }