/// <summary> /// Modifies the <see cref="ISyndicationResource"/> to match the data source. /// </summary> /// <param name="resource">The Atom Publishing Protocol <see cref="ISyndicationResource"/> to be filled.</param> /// <param name="resourceMetadata">A <see cref="SyndicationResourceMetadata"/> object that represents the meta-data describing the <paramref name="resource"/>.</param> /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="resourceMetadata"/> is a null reference (Nothing in Visual Basic).</exception> private void FillAtomPublishingResource(ISyndicationResource resource, SyndicationResourceMetadata resourceMetadata) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(resource, "resource"); Guard.ArgumentNotNull(resourceMetadata, "resourceMetadata"); //------------------------------------------------------------ // Fill syndication resource using appropriate data adapter //------------------------------------------------------------ AtomCategoryDocument categoryDocument = resource as AtomCategoryDocument; AtomServiceDocument serviceDocument = resource as AtomServiceDocument; if (resourceMetadata.Version == new Version("1.0")) { AtomPublishing10SyndicationResourceAdapter atomPublishing10Adapter = new AtomPublishing10SyndicationResourceAdapter(this.Navigator, this.Settings); if (categoryDocument != null) { atomPublishing10Adapter.Fill(categoryDocument); } else if (serviceDocument != null) { atomPublishing10Adapter.Fill(serviceDocument); } } }
/// <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); } AtomMemberResources value = obj as AtomMemberResources; if (value != null) { int result = Uri.Compare(this.Uri, value.Uri, UriComponents.AbsoluteUri, UriFormat.SafeUnescaped, StringComparison.OrdinalIgnoreCase); result = result | this.Title.CompareTo(value.Title); result = result | AtomMemberResources.CompareSequence(this.Accepts, value.Accepts); result = result | AtomCategoryDocument.CompareSequence(this.Categories, value.Categories); 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> /// Modifies the <see cref="AtomCategoryDocument"/> to match the data source. /// </summary> /// <param name="resource">The <see cref="AtomCategoryDocument"/> to be filled.</param> /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception> public void Fill(AtomCategoryDocument resource) { Guard.ArgumentNotNull(resource, "resource"); XmlNamespaceManager manager = AtomUtility.CreateNamespaceManager(this.Navigator.NameTable); XPathNavigator documentNavigator = this.Navigator.SelectSingleNode("app:categories", manager); if (documentNavigator != null) { AtomUtility.FillCommonObjectAttributes(resource, documentNavigator); if (documentNavigator.HasChildren) { if (documentNavigator.HasAttributes) { string fixedAttribute = documentNavigator.GetAttribute("fixed", String.Empty); string schemeAttribute = documentNavigator.GetAttribute("scheme", String.Empty); string hrefAttribute = documentNavigator.GetAttribute("href", String.Empty); if (!String.IsNullOrEmpty(fixedAttribute)) { if (String.Compare(fixedAttribute, "yes", StringComparison.OrdinalIgnoreCase) == 0) { resource.IsFixed = true; } else if (String.Compare(fixedAttribute, "no", StringComparison.OrdinalIgnoreCase) == 0) { resource.IsFixed = false; } } if (!String.IsNullOrEmpty(schemeAttribute)) { Uri scheme; if (Uri.TryCreate(schemeAttribute, UriKind.RelativeOrAbsolute, out scheme)) { resource.Scheme = scheme; } } if (!String.IsNullOrEmpty(hrefAttribute)) { Uri href; if (Uri.TryCreate(hrefAttribute, UriKind.RelativeOrAbsolute, out href)) { resource.Uri = href; } } } if (documentNavigator.HasChildren) { XPathNodeIterator categoryIterator = documentNavigator.Select("atom:category", manager); if (categoryIterator != null && categoryIterator.Count > 0) { while (categoryIterator.MoveNext()) { AtomCategory category = new AtomCategory(); if (category.Load(categoryIterator.Current, this.Settings)) { resource.AddCategory(category); } } } } } SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(documentNavigator, this.Settings); adapter.Fill(resource, manager); } }
/// <summary> /// Loads this <see cref="AtomMemberResources"/> using the supplied <see cref="IXPathNavigable"/>. /// </summary> /// <param name="source">The <see cref="IXPathNavigable"/> to extract information from.</param> /// <returns><b>true</b> if the <see cref="AtomMemberResources"/> 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="AtomMemberResources"/>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> public override bool Load(IXPathNavigable source) { bool wasLoaded = false; Guard.ArgumentNotNull(source, "source"); XPathNavigator navigator = source.CreateNavigator(); XmlNamespaceManager manager = AtomUtility.CreateNamespaceManager(navigator.NameTable); if (AtomUtility.FillCommonObjectAttributes(this, navigator)) { wasLoaded = true; } if (navigator.HasAttributes) { string hrefAttribute = navigator.GetAttribute("href", String.Empty); if (!String.IsNullOrEmpty(hrefAttribute)) { Uri href; if (Uri.TryCreate(hrefAttribute, UriKind.RelativeOrAbsolute, out href)) { this.Uri = href; wasLoaded = true; } } } if (navigator.HasChildren) { XPathNavigator titleNavigator = navigator.SelectSingleNode("atom:title", manager); XPathNodeIterator acceptIterator = navigator.Select("app:accept", manager); XPathNodeIterator categoriesIterator = navigator.Select("app:categories", manager); if (titleNavigator != null) { this.Title = new AtomTextConstruct(); if (this.Title.Load(titleNavigator)) { wasLoaded = true; } } if (acceptIterator != null && acceptIterator.Count > 0) { while (acceptIterator.MoveNext()) { AtomAcceptedMediaRange mediaRange = new AtomAcceptedMediaRange(); if (mediaRange.Load(acceptIterator.Current)) { this.Accepts.Add(mediaRange); wasLoaded = true; } } } if (categoriesIterator != null && categoriesIterator.Count > 0) { while (categoriesIterator.MoveNext()) { AtomCategoryDocument categories = new AtomCategoryDocument(); categories.Load(categoriesIterator.Current); wasLoaded = true; } } } return(wasLoaded); }