protected static bool TryParseBlogMLResource(XPathNavigator resource, out XPathNavigator navigator, out Version version) { bool resourceConformsToFormat = false; XmlNamespaceManager manager = null; Guard.ArgumentNotNull(resource, "resource"); manager = new XmlNamespaceManager(resource.NameTable); manager.AddNamespace("blogML", "http://www.blogml.com/2006/09/BlogML"); version = null; if ((navigator = resource.SelectSingleNode("blog", manager)) != null || (navigator = resource.SelectSingleNode("blogML:blog", manager)) != null) { version = SyndicationResourceMetadata.GetVersionFromAttribute(navigator, "version"); Dictionary <string, string> namespaces = (Dictionary <string, string>)navigator.GetNamespacesInScope(XmlNamespaceScope.ExcludeXml); if (namespaces.ContainsValue("http://www.blogml.com/2006/09/BlogML")) { resourceConformsToFormat = true; if (version == null) { version = new Version(2, 0); } } } return(resourceConformsToFormat); }
protected static bool TryParseOpenSearchDescriptionResource(XPathNavigator resource, out XPathNavigator navigator, out Version version) { bool resourceConformsToFormat = false; XmlNamespaceManager manager = null; Guard.ArgumentNotNull(resource, "resource"); manager = new XmlNamespaceManager(resource.NameTable); manager.AddNamespace("search", "http://a9.com/-/spec/opensearch/1.1/"); version = null; if ((navigator = resource.SelectSingleNode("OpenSearchDescription", manager)) != null || (navigator = resource.SelectSingleNode("search:OpenSearchDescription", manager)) != null) { version = SyndicationResourceMetadata.GetVersionFromAttribute(navigator, "version"); Dictionary <string, string> namespaces = (Dictionary <string, string>)navigator.GetNamespacesInScope(XmlNamespaceScope.ExcludeXml); if (namespaces.ContainsValue("http://a9.com/-/spec/opensearch/1.1/")) { resourceConformsToFormat = true; if (version == null) { version = new Version(1, 1); } } } return(resourceConformsToFormat); }
protected static bool TryParseRsdResource(XPathNavigator resource, out XPathNavigator navigator, out Version version) { bool resourceConformsToFormat = false; XmlNamespaceManager manager = null; Guard.ArgumentNotNull(resource, "resource"); manager = new XmlNamespaceManager(resource.NameTable); manager.AddNamespace("rsd", "http://archipelago.phrasewise.com/rsd"); version = null; if ((navigator = resource.SelectSingleNode("rsd", manager)) != null || (navigator = resource.SelectSingleNode("rsd:rsd", manager)) != null) { version = SyndicationResourceMetadata.GetVersionFromAttribute(navigator, "version"); Dictionary <string, string> namespaces = (Dictionary <string, string>)navigator.GetNamespacesInScope(XmlNamespaceScope.ExcludeXml); if (namespaces.ContainsValue("http://archipelago.phrasewise.com/rsd")) { resourceConformsToFormat = true; if (version == null) { version = new Version(1, 0); } } else if (String.Compare(navigator.Name, "rsd", StringComparison.OrdinalIgnoreCase) == 0 && version != null) { // Most web log software actually fails to provide the default XML namespace per RSD spec, so this is a hack/compromise resourceConformsToFormat = true; } } return(resourceConformsToFormat); }
protected static bool TryParseMicroSummaryGeneratorResource(XPathNavigator resource, out XPathNavigator navigator, out Version version) { bool resourceConformsToFormat = false; XmlNamespaceManager manager = null; Guard.ArgumentNotNull(resource, "resource"); manager = new XmlNamespaceManager(resource.NameTable); manager.AddNamespace("micro", "http://www.mozilla.org/microsummaries/0.1"); version = null; if ((navigator = resource.SelectSingleNode("generator", manager)) != null || (navigator = resource.SelectSingleNode("micro:generator", manager)) != null) { version = SyndicationResourceMetadata.GetVersionFromAttribute(navigator, "version"); Dictionary <string, string> namespaces = (Dictionary <string, string>)navigator.GetNamespacesInScope(XmlNamespaceScope.ExcludeXml); if (namespaces.ContainsValue("http://www.mozilla.org/microsummaries/0.1")) { resourceConformsToFormat = true; if (version == null) { version = new Version(0, 1); } } } return(resourceConformsToFormat); }
protected static bool TryParseAtomPublishingServiceResource(XPathNavigator resource, out XPathNavigator navigator, out Version version) { bool resourceConformsToFormat = false; XmlNamespaceManager manager = null; Guard.ArgumentNotNull(resource, "resource"); manager = new XmlNamespaceManager(resource.NameTable); manager.AddNamespace("atom", "http://www.w3.org/2005/Atom"); manager.AddNamespace("atom03", "http://purl.org/atom/ns#"); manager.AddNamespace("app", "http://www.w3.org/2007/app"); version = null; if ((navigator = resource.SelectSingleNode("service", manager)) != null || (navigator = resource.SelectSingleNode("app:service", manager)) != null) { version = SyndicationResourceMetadata.GetVersionFromAttribute(navigator, "version"); Dictionary <string, string> namespaces = (Dictionary <string, string>)navigator.GetNamespacesInScope(XmlNamespaceScope.ExcludeXml); if (namespaces.ContainsValue("http://www.w3.org/2007/app")) { resourceConformsToFormat = true; if (version == null) { version = new Version(1, 0); } } } return(resourceConformsToFormat); }
/// <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); } SyndicationResourceMetadata value = obj as SyndicationResourceMetadata; if (value != null) { int result = this.Format.CompareTo(value.Format); if (this.Version != null) { result = result | this.Version.CompareTo(value.Version); } else if (value.Version != null) { result = result | -1; } if (this.Namespaces != null && value.Namespaces != null) { result = result | ComparisonUtility.CompareSequence(this.Namespaces, value.Namespaces, StringComparison.Ordinal); } else if (this.Namespaces != null && value.Namespaces == null) { result = result | 1; } else if (this.Namespaces == null && value.Namespaces != null) { result = result | -1; } if (this.Resource != null && value.Resource != null) { result = result | String.Compare(this.Resource.OuterXml, value.Resource.OuterXml, StringComparison.OrdinalIgnoreCase); } else if (this.Resource != null && value.Resource == null) { result = result | 1; } else if (this.Resource == null && value.Resource != null) { result = result | -1; } 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"); } }
protected static bool TryParseRssResource(XPathNavigator resource, out XPathNavigator navigator, out Version version) { bool resourceConformsToFormat = false; XmlNamespaceManager manager = null; Guard.ArgumentNotNull(resource, "resource"); manager = new XmlNamespaceManager(resource.NameTable); manager.AddNamespace("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"); manager.AddNamespace("rss09", "http://my.netscape.com/rdf/simple/0.9/"); manager.AddNamespace("rss10", "http://purl.org/rss/1.0/"); version = null; if ((navigator = resource.SelectSingleNode("rss", manager)) != null) { version = SyndicationResourceMetadata.GetVersionFromAttribute(navigator, "version"); Dictionary <string, string> namespaces = (Dictionary <string, string>)navigator.GetNamespacesInScope(XmlNamespaceScope.ExcludeXml); resourceConformsToFormat = true; if (version == null) { version = new Version(2, 0); } } else if ((navigator = resource.SelectSingleNode("rdf:RDF", manager)) != null) { version = SyndicationResourceMetadata.GetVersionFromAttribute(navigator, "version"); Dictionary <string, string> namespaces = (Dictionary <string, string>)navigator.GetNamespacesInScope(XmlNamespaceScope.ExcludeXml); if (namespaces.ContainsValue("http://purl.org/rss/1.0/")) { resourceConformsToFormat = true; version = new Version(1, 0); } else if (namespaces.ContainsValue("http://my.netscape.com/rdf/simple/0.9/")) { resourceConformsToFormat = true; version = new Version(0, 9); } } return(resourceConformsToFormat); }
protected static bool TryParseOpmlResource(XPathNavigator resource, out XPathNavigator navigator, out Version version) { bool resourceConformsToFormat = false; Guard.ArgumentNotNull(resource, "resource"); version = null; if ((navigator = resource.SelectSingleNode("opml")) != null) { version = SyndicationResourceMetadata.GetVersionFromAttribute(navigator, "version"); resourceConformsToFormat = true; if (version == null) { version = new Version(2, 0); } } return(resourceConformsToFormat); }
/// <summary> /// Modifies the <see cref="ISyndicationResource"/> to match the data source. /// </summary> /// <param name="resource">The Really Simple Syndication (RSS) <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 FillRssResource(ISyndicationResource resource, SyndicationResourceMetadata resourceMetadata) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(resource, "resource"); Guard.ArgumentNotNull(resourceMetadata, "resourceMetadata"); //------------------------------------------------------------ // Fill syndication resource using appropriate data adapter //------------------------------------------------------------ RssFeed rssFeed = resource as RssFeed; if (resourceMetadata.Version == new Version("2.0")) { Rss20SyndicationResourceAdapter rss20Adapter = new Rss20SyndicationResourceAdapter(this.Navigator, this.Settings); rss20Adapter.Fill(rssFeed); } if (resourceMetadata.Version == new Version("1.0")) { Rss10SyndicationResourceAdapter rss10Adapter = new Rss10SyndicationResourceAdapter(this.Navigator, this.Settings); rss10Adapter.Fill(rssFeed); } if (resourceMetadata.Version == new Version("0.92")) { Rss092SyndicationResourceAdapter rss092Adapter = new Rss092SyndicationResourceAdapter(this.Navigator, this.Settings); rss092Adapter.Fill(rssFeed); } if (resourceMetadata.Version == new Version("0.91")) { Rss091SyndicationResourceAdapter rss091Adapter = new Rss091SyndicationResourceAdapter(this.Navigator, this.Settings); rss091Adapter.Fill(rssFeed); } if (resourceMetadata.Version == new Version("0.9")) { Rss090SyndicationResourceAdapter rss090Adapter = new Rss090SyndicationResourceAdapter(this.Navigator, this.Settings); rss090Adapter.Fill(rssFeed); } }
/// <summary> /// Modifies the <see cref="ISyndicationResource"/> to match the data source. /// </summary> /// <param name="resource">The Really Simple Discovery (RSD) <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 FillRsdResource(ISyndicationResource resource, SyndicationResourceMetadata resourceMetadata) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(resource, "resource"); Guard.ArgumentNotNull(resourceMetadata, "resourceMetadata"); //------------------------------------------------------------ // Fill syndication resource using appropriate data adapter //------------------------------------------------------------ RsdDocument rsdDocument = resource as RsdDocument; if (resourceMetadata.Version == new Version("1.0")) { Rsd10SyndicationResourceAdapter rsd10Adapter = new Rsd10SyndicationResourceAdapter(this.Navigator, this.Settings); rsd10Adapter.Fill(rsdDocument); } if (resourceMetadata.Version == new Version("0.6")) { Rsd06SyndicationResourceAdapter rsd06Adapter = new Rsd06SyndicationResourceAdapter(this.Navigator, this.Settings); rsd06Adapter.Fill(rsdDocument); } }
/// <summary> /// Modifies the <see cref="ISyndicationResource"/> to match the data source. /// </summary> /// <param name="resource">The Outline Processor Markup Language (OPML) <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 FillOpmlResource(ISyndicationResource resource, SyndicationResourceMetadata resourceMetadata) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(resource, "resource"); Guard.ArgumentNotNull(resourceMetadata, "resourceMetadata"); //------------------------------------------------------------ // Fill syndication resource using appropriate data adapter //------------------------------------------------------------ OpmlDocument opmlDocument = resource as OpmlDocument; Opml20SyndicationResourceAdapter opml20Adapter = new Opml20SyndicationResourceAdapter(this.Navigator, this.Settings); if (resourceMetadata.Version == new Version("2.0")) { opml20Adapter.Fill(opmlDocument); } if (resourceMetadata.Version == new Version("1.1")) { opml20Adapter.Fill(opmlDocument); } if (resourceMetadata.Version == new Version("1.0")) { opml20Adapter.Fill(opmlDocument); } }
/// <summary> /// Modifies the <see cref="ISyndicationResource"/> to match the data source. /// </summary> /// <param name="resource">The BlogML <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 FillBlogMLResource(ISyndicationResource resource, SyndicationResourceMetadata resourceMetadata) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(resource, "resource"); Guard.ArgumentNotNull(resourceMetadata, "resourceMetadata"); //------------------------------------------------------------ // Fill syndication resource using appropriate data adapter //------------------------------------------------------------ BlogMLDocument blogMLDocument = resource as BlogMLDocument; BlogML20SyndicationResourceAdapter blogML20Adapter = new BlogML20SyndicationResourceAdapter(this.Navigator, this.Settings); if (resourceMetadata.Version == new Version("2.0")) { blogML20Adapter.Fill(blogMLDocument); } }
/// <summary> /// Modifies the <see cref="ISyndicationResource"/> to match the data source. /// </summary> /// <param name="resource">The Atom <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 FillAtomResource(ISyndicationResource resource, SyndicationResourceMetadata resourceMetadata) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(resource, "resource"); Guard.ArgumentNotNull(resourceMetadata, "resourceMetadata"); //------------------------------------------------------------ // Fill syndication resource using appropriate data adapter //------------------------------------------------------------ AtomFeed atomFeed = resource as AtomFeed; AtomEntry atomEntry = resource as AtomEntry; if (resourceMetadata.Version == new Version("1.0")) { Atom10SyndicationResourceAdapter atom10Adapter = new Atom10SyndicationResourceAdapter(this.Navigator, this.Settings); if (atomFeed != null) { atom10Adapter.Fill(atomFeed); } else if (atomEntry != null) { atom10Adapter.Fill(atomEntry); } } if (resourceMetadata.Version == new Version("0.3")) { Atom03SyndicationResourceAdapter atom03Adapter = new Atom03SyndicationResourceAdapter(this.Navigator, this.Settings); if (atomFeed != null) { atom03Adapter.Fill(atomFeed); } else if (atomEntry != null) { atom03Adapter.Fill(atomEntry); } } }
/// <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> /// Modifies the <see cref="ISyndicationResource"/> to match the data source. /// </summary> /// <param name="resource">The Attention Profiling Markup Language (APML) <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 FillApmlResource(ISyndicationResource resource, SyndicationResourceMetadata resourceMetadata) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(resource, "resource"); Guard.ArgumentNotNull(resourceMetadata, "resourceMetadata"); //------------------------------------------------------------ // Fill syndication resource using appropriate data adapter //------------------------------------------------------------ ApmlDocument apmlDocument = resource as ApmlDocument; if (resourceMetadata.Version == new Version("0.6")) { Apml06SyndicationResourceAdapter apml06Adapter = new Apml06SyndicationResourceAdapter(this.Navigator, this.Settings); apml06Adapter.Fill(apmlDocument); } }
/// <summary> /// Called when a corresponding asynchronous load operation completes. /// </summary> /// <param name="result">The result of the asynchronous operation.</param> private static void AsyncLoadCallback(IAsyncResult result) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ System.Text.Encoding encoding = System.Text.Encoding.UTF8; XPathNavigator navigator = null; WebRequest httpWebRequest = null; GenericSyndicationFeed feed = null; Uri source = null; WebRequestOptions options = null; SyndicationResourceLoadSettings settings = null; //------------------------------------------------------------ // Determine if the async send operation completed //------------------------------------------------------------ if (result.IsCompleted) { //------------------------------------------------------------ // Extract the send operations parameters from the user state //------------------------------------------------------------ object[] parameters = (object[])result.AsyncState; httpWebRequest = parameters[0] as WebRequest; feed = parameters[1] as GenericSyndicationFeed; source = parameters[2] as Uri; settings = parameters[3] as SyndicationResourceLoadSettings; options = parameters[4] as WebRequestOptions; object userToken = parameters[5]; //------------------------------------------------------------ // Verify expected parameters were found //------------------------------------------------------------ if (feed != null) { //------------------------------------------------------------ // Get the response to the syndication resource request //------------------------------------------------------------ WebResponse httpWebResponse = (WebResponse)httpWebRequest.EndGetResponse(result); //------------------------------------------------------------ // Load syndication resource //------------------------------------------------------------ using (Stream stream = httpWebResponse.GetResponseStream()) { if (settings != null) { encoding = settings.CharacterEncoding; } using (StreamReader streamReader = new StreamReader(stream, encoding)) { XmlReaderSettings readerSettings = new XmlReaderSettings(); readerSettings.IgnoreComments = true; readerSettings.IgnoreWhitespace = true; readerSettings.ProhibitDtd = false; using (XmlReader reader = XmlReader.Create(streamReader, readerSettings)) { if (encoding == System.Text.Encoding.UTF8) { navigator = SyndicationEncodingUtility.CreateSafeNavigator(source, options, null); } else { navigator = SyndicationEncodingUtility.CreateSafeNavigator(source, options, settings.CharacterEncoding); } //------------------------------------------------------------ // Initialize generic feed based on syndication resource format //------------------------------------------------------------ SyndicationResourceMetadata metadata = new SyndicationResourceMetadata(navigator); if (metadata.Format == SyndicationContentFormat.Atom) { AtomFeed atomFeed = new AtomFeed(); SyndicationResourceAdapter adapter = new SyndicationResourceAdapter(navigator, settings); adapter.Fill(atomFeed, SyndicationContentFormat.Atom); feed.Parse(atomFeed); } else if (metadata.Format == SyndicationContentFormat.Rss) { RssFeed rssFeed = new RssFeed(); SyndicationResourceAdapter adapter = new SyndicationResourceAdapter(navigator, settings); adapter.Fill(rssFeed, SyndicationContentFormat.Rss); feed.Parse(rssFeed); } //------------------------------------------------------------ // Raise Loaded event to notify registered handlers of state change //------------------------------------------------------------ feed.OnFeedLoaded(new SyndicationResourceLoadedEventArgs(navigator, source, options, userToken)); } } } //------------------------------------------------------------ // Reset load operation in progress indicator //------------------------------------------------------------ feed.LoadOperationInProgress = false; } } }
/// <summary> /// Extracts the content format, version, and XML namespaces for a syndication resource from the supplied <see cref="XPathNavigator"/>. /// </summary> /// <param name="resource">The <see cref="XPathNavigator"/> to extract the syndication resource meta-data from.</param> /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception> private void Load(XPathNavigator resource) { XPathNavigator navigator = null; Version version = null; Guard.ArgumentNotNull(resource, "resource"); Dictionary <string, string> namespaces = (Dictionary <string, string>)resource.GetNamespacesInScope(XmlNamespaceScope.ExcludeXml); foreach (string prefix in namespaces.Keys) { resourceNamespaces.Add(prefix, namespaces[prefix]); } resourceVersion = SyndicationResourceMetadata.GetVersionFromAttribute(resource, "version"); if (SyndicationResourceMetadata.TryParseApmlResource(resource, out navigator, out version)) { resourceFormat = SyndicationContentFormat.Apml; resourceRootNode = navigator; resourceVersion = version; } else if (SyndicationResourceMetadata.TryParseAtomResource(resource, out navigator, out version)) { resourceFormat = SyndicationContentFormat.Atom; resourceRootNode = navigator; resourceVersion = version; } else if (SyndicationResourceMetadata.TryParseAtomPublishingCategoriesResource(resource, out navigator, out version)) { resourceFormat = SyndicationContentFormat.AtomCategoryDocument; resourceRootNode = navigator; resourceVersion = version; } else if (SyndicationResourceMetadata.TryParseAtomPublishingServiceResource(resource, out navigator, out version)) { resourceFormat = SyndicationContentFormat.AtomServiceDocument; resourceRootNode = navigator; resourceVersion = version; } else if (SyndicationResourceMetadata.TryParseBlogMLResource(resource, out navigator, out version)) { resourceFormat = SyndicationContentFormat.BlogML; resourceRootNode = navigator; resourceVersion = version; } else if (SyndicationResourceMetadata.TryParseMicroSummaryGeneratorResource(resource, out navigator, out version)) { resourceFormat = SyndicationContentFormat.MicroSummaryGenerator; resourceRootNode = navigator; resourceVersion = version; } else if (SyndicationResourceMetadata.TryParseNewsMLResource(resource, out navigator, out version)) { resourceFormat = SyndicationContentFormat.NewsML; resourceRootNode = navigator; resourceVersion = version; } else if (SyndicationResourceMetadata.TryParseOpenSearchDescriptionResource(resource, out navigator, out version)) { resourceFormat = SyndicationContentFormat.OpenSearchDescription; resourceRootNode = navigator; resourceVersion = version; } else if (SyndicationResourceMetadata.TryParseOpmlResource(resource, out navigator, out version)) { resourceFormat = SyndicationContentFormat.Opml; resourceRootNode = navigator; resourceVersion = version; } else if (SyndicationResourceMetadata.TryParseRsdResource(resource, out navigator, out version)) { resourceFormat = SyndicationContentFormat.Rsd; resourceRootNode = navigator; resourceVersion = version; } else if (SyndicationResourceMetadata.TryParseRssResource(resource, out navigator, out version)) { resourceFormat = SyndicationContentFormat.Rss; resourceRootNode = navigator; resourceVersion = version; } else { resourceFormat = SyndicationContentFormat.None; resourceRootNode = null; resourceVersion = null; } }
/// <summary> /// Loads the generic syndication feed using the specified <see cref="XPathNavigator"/> and <see cref="SyndicationResourceLoadSettings"/>. /// </summary> /// <param name="navigator">A read-only <see cref="XPathNavigator"/> object for navigating through the syndication resource information.</param> /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> object used to configure the load operation of the <see cref="GenericSyndicationFeed"/>.</param> /// <param name="eventData">A <see cref="SyndicationResourceLoadedEventArgs"/> that contains the event data used when raising the <see cref="GenericSyndicationFeed.Loaded"/> event.</param> /// <remarks> /// After the load operation has successfully completed, the <see cref="GenericSyndicationFeed.Loaded"/> event is raised using the specified <paramref name="eventData"/>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="navigator"/> 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> /// <exception cref="ArgumentNullException">The <paramref name="eventData"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="FormatException">The <paramref name="navigator"/> data does not conform to the expected syndication content format. In this case, the feed remains empty.</exception> private void Load(XPathNavigator navigator, SyndicationResourceLoadSettings settings, SyndicationResourceLoadedEventArgs eventData) { //------------------------------------------------------------ // Validate parameters //------------------------------------------------------------ Guard.ArgumentNotNull(navigator, "navigator"); Guard.ArgumentNotNull(settings, "settings"); Guard.ArgumentNotNull(eventData, "eventData"); //------------------------------------------------------------ // Initialize generic feed based on syndication resource format //------------------------------------------------------------ SyndicationResourceMetadata metadata = new SyndicationResourceMetadata(navigator); if (metadata.Format == SyndicationContentFormat.Atom) { AtomFeed feed = new AtomFeed(); SyndicationResourceAdapter adapter = new SyndicationResourceAdapter(navigator, settings); adapter.Fill(feed, SyndicationContentFormat.Atom); this.Parse(feed); } else if (metadata.Format == SyndicationContentFormat.Rss) { RssFeed feed = new RssFeed(); SyndicationResourceAdapter adapter = new SyndicationResourceAdapter(navigator, settings); adapter.Fill(feed, SyndicationContentFormat.Rss); this.Parse(feed); } else if (metadata.Format == SyndicationContentFormat.Opml) { OpmlDocument opmlDoc = new OpmlDocument(); SyndicationResourceAdapter adapter = new SyndicationResourceAdapter(navigator, settings); adapter.Fill(opmlDoc, SyndicationContentFormat.Opml); this.Parse(opmlDoc); } //------------------------------------------------------------ // Raise Loaded event to notify registered handlers of state change //------------------------------------------------------------ this.OnFeedLoaded(eventData); }
/// <summary> /// Modifies the <see cref="ISyndicationResource"/> to match the data source. /// </summary> /// <param name="resource">The <see cref="ISyndicationResource"/> to be filled.</param> /// <param name="format">The <see cref="SyndicationContentFormat"/> enumeration value that indicates the type of syndication format that the <paramref name="resource"/> is expected to conform to.</param> /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentException">The <paramref name="format"/> is equal to <see cref="SyndicationContentFormat.None"/>.</exception> /// <exception cref="FormatException">The <paramref name="resource"/> data does not conform to the specified <paramref name="format"/>.</exception> public void Fill(ISyndicationResource resource, SyndicationContentFormat format) { //------------------------------------------------------------ // Validate parameters //------------------------------------------------------------ Guard.ArgumentNotNull(resource, "resource"); if (format == SyndicationContentFormat.None) { throw new ArgumentException(String.Format(null, "The specified syndication content format of {0} is invalid.", format), "format"); } //------------------------------------------------------------ // Extract syndication resource meta-data //------------------------------------------------------------ SyndicationResourceMetadata resourceMetadata = new SyndicationResourceMetadata(this.Navigator); //------------------------------------------------------------ // Verify resource conforms to specified format //------------------------------------------------------------ if (format != resourceMetadata.Format) { throw new FormatException(String.Format(null, "The supplied syndication resource has a content format of {0}, which does not match the expected content format of {1}.", resourceMetadata.Format, format)); } //------------------------------------------------------------ // Fill syndication resource using appropriate data adapter //------------------------------------------------------------ switch (format) { case SyndicationContentFormat.Apml: this.FillApmlResource(resource, resourceMetadata); break; case SyndicationContentFormat.Atom: this.FillAtomResource(resource, resourceMetadata); break; case SyndicationContentFormat.AtomCategoryDocument: this.FillAtomPublishingResource(resource, resourceMetadata); break; case SyndicationContentFormat.AtomServiceDocument: this.FillAtomPublishingResource(resource, resourceMetadata); break; case SyndicationContentFormat.BlogML: this.FillBlogMLResource(resource, resourceMetadata); break; case SyndicationContentFormat.Opml: this.FillOpmlResource(resource, resourceMetadata); break; case SyndicationContentFormat.Rsd: this.FillRsdResource(resource, resourceMetadata); break; case SyndicationContentFormat.Rss: this.FillRssResource(resource, resourceMetadata); break; } }