/// <summary> /// Initializes a new instance of the <see cref="Atom10SyndicationResourceAdapter"/> class using the supplied <see cref="XPathNavigator"/> and <see cref="SyndicationResourceLoadSettings"/>. /// </summary> /// <param name="navigator">A read-only <see cref="XPathNavigator"/> object for navigating through the syndication feed information.</param> /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> object used to configure the load operation of the <see cref="AtomFeed"/>.</param> /// <remarks> /// This class expects the supplied <paramref name="navigator"/> to be positioned on the XML element that represents a <see cref="AtomFeed"/>. /// </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> public Atom10SyndicationResourceAdapter(XPathNavigator navigator, SyndicationResourceLoadSettings settings) : base(navigator, settings) { //------------------------------------------------------------ // Initialization and argument validation handled by base class //------------------------------------------------------------ }
//============================================================ // 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 //------------------------------------------------------------ SyndicationResourceLoadSettings value = obj as SyndicationResourceLoadSettings; if (value != null) { int result = String.Compare(this.CharacterEncoding.WebName, value.CharacterEncoding.WebName, StringComparison.OrdinalIgnoreCase); result = result | this.RetrievalLimit.CompareTo(value.RetrievalLimit); result = result | this.Timeout.CompareTo(value.Timeout); result = result | this.AutoDetectExtensions.CompareTo(value.AutoDetectExtensions); result = result | ComparisonUtility.CompareSequence(this.SupportedExtensions, value.SupportedExtensions); 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 a new instance of the <see cref="SyndicationResourceAdapter"/> class using the supplied <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="ISyndicationResource"/>.</param> /// <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> public SyndicationResourceAdapter(XPathNavigator navigator, SyndicationResourceLoadSettings settings) { //------------------------------------------------------------ // Validate parameters //------------------------------------------------------------ Guard.ArgumentNotNull(navigator, "navigator"); Guard.ArgumentNotNull(settings, "settings"); adapterNavigator = navigator; adapterSettings = settings; }
/// <summary> /// Loads this <see cref="AtomFeed"/> instance asynchronously using the specified <see cref="Uri"/>, <see cref="SyndicationResourceLoadSettings"/>, <see cref="ICredentials"/>, and <see cref="IWebProxy"/>. /// </summary> /// <param name="source">A <see cref="Uri"/> that represents the URL of the syndication resource XML data.</param> /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> object used to configure the <see cref="AtomFeed"/> instance. This value can be <b>null</b>.</param> /// <param name="options">A <see cref="WebRequestOptions"/> that holds options that should be applied to web requests.</param> /// <param name="userToken">A user-defined object that is passed to the method invoked when the asynchronous operation completes.</param> /// <remarks> /// <para> /// To receive notification when the operation has completed or the operation has been canceled, add an event handler to the <see cref="Loaded"/> event. /// You can cancel a <see cref="LoadAsync(Uri, SyndicationResourceLoadSettings, ICredentials, IWebProxy, Object)"/> operation by calling the <see cref="LoadAsyncCancel()"/> method. /// </para> /// <para> /// After calling <see cref="LoadAsync(Uri, SyndicationResourceLoadSettings, ICredentials, IWebProxy, Object)"/>, /// you must wait for the load operation to complete before attempting to load the syndication resource using the <see cref="LoadAsync(Uri, Object)"/> method. /// </para> /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="FormatException">The <paramref name="source"/> data does not conform to the expected syndication content format. In this case, the feed remains empty.</exception> /// <exception cref="InvalidOperationException">This <see cref="AtomFeed"/> has a <see cref="LoadAsync(Uri, SyndicationResourceLoadSettings, ICredentials, IWebProxy, Object)"/> call in progress.</exception> public void LoadAsync(Uri source, SyndicationResourceLoadSettings settings, WebRequestOptions options, Object userToken) { //------------------------------------------------------------ // Validate parameters //------------------------------------------------------------ Guard.ArgumentNotNull(source, "source"); //------------------------------------------------------------ // Use default settings if none specified by the caller //------------------------------------------------------------ if (settings == null) { settings = new SyndicationResourceLoadSettings(); } //------------------------------------------------------------ // Validate syndication resource state //------------------------------------------------------------ if (this.LoadOperationInProgress) { throw new InvalidOperationException(); } //------------------------------------------------------------ // Indicate that a load operation is in progress //------------------------------------------------------------ this.LoadOperationInProgress = true; //------------------------------------------------------------ // Reset the asynchronous load operation cancelled indicator //------------------------------------------------------------ this.AsyncLoadHasBeenCancelled = false; //------------------------------------------------------------ // Build HTTP web request used to retrieve the syndication resource //------------------------------------------------------------ asyncHttpWebRequest = SyndicationEncodingUtility.CreateWebRequest(source, options); asyncHttpWebRequest.Timeout = Convert.ToInt32(settings.Timeout.TotalMilliseconds, System.Globalization.NumberFormatInfo.InvariantInfo); //------------------------------------------------------------ // Get the async response to the web request //------------------------------------------------------------ object[] state = new object[6] { asyncHttpWebRequest, this, source, settings, options, userToken }; IAsyncResult result = asyncHttpWebRequest.BeginGetResponse(new AsyncCallback(AsyncLoadCallback), state); //------------------------------------------------------------ // Register the timeout callback //------------------------------------------------------------ ThreadPool.RegisterWaitForSingleObject(result.AsyncWaitHandle, new WaitOrTimerCallback(AsyncTimeoutCallback), state, settings.Timeout, true); }
/// <summary> /// Loads this <see cref="AtomFeed"/> instance asynchronously using the specified <see cref="Uri"/>, <see cref="SyndicationResourceLoadSettings"/>, <see cref="ICredentials"/>, and <see cref="IWebProxy"/>. /// </summary> /// <param name="source">A <see cref="Uri"/> that represents the URL of the syndication resource XML data.</param> /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> object used to configure the <see cref="AtomFeed"/> instance. This value can be <b>null</b>.</param> /// <param name="credentials"> /// A <see cref="ICredentials"/> that provides the proper set of credentials to the <paramref name="source"/> when required. This value can be <b>null</b>. /// </param> /// <param name="proxy"> /// A <see cref="IWebProxy"/> that provides proxy access to the <paramref name="source"/> when required. This value can be <b>null</b>. /// </param> /// <param name="userToken">A user-defined object that is passed to the method invoked when the asynchronous operation completes.</param> /// <remarks> /// <para> /// To receive notification when the operation has completed or the operation has been canceled, add an event handler to the <see cref="Loaded"/> event. /// You can cancel a <see cref="LoadAsync(Uri, SyndicationResourceLoadSettings, ICredentials, IWebProxy, Object)"/> operation by calling the <see cref="LoadAsyncCancel()"/> method. /// </para> /// <para> /// After calling <see cref="LoadAsync(Uri, SyndicationResourceLoadSettings, ICredentials, IWebProxy, Object)"/>, /// you must wait for the load operation to complete before attempting to load the syndication resource using the <see cref="LoadAsync(Uri, Object)"/> method. /// </para> /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="FormatException">The <paramref name="source"/> data does not conform to the expected syndication content format. In this case, the feed remains empty.</exception> /// <exception cref="InvalidOperationException">This <see cref="AtomFeed"/> has a <see cref="LoadAsync(Uri, SyndicationResourceLoadSettings, ICredentials, IWebProxy, Object)"/> call in progress.</exception> public void LoadAsync(Uri source, SyndicationResourceLoadSettings settings, ICredentials credentials, IWebProxy proxy, Object userToken) { //------------------------------------------------------------ // Create instance using supplied parameter and specified settings //------------------------------------------------------------ this.LoadAsync(source, settings, new WebRequestOptions(credentials, proxy), userToken); }
/// <summary> /// Loads the syndication resource from the supplied <see cref="Uri"/> using the specified <see cref="ICredentials">credentials</see>, <see cref="IWebProxy">proxy</see> and <see cref="SyndicationResourceLoadSettings"/>. /// </summary> /// <param name="source">A <see cref="Uri"/> that points to the location of the web resource used to load the syndication resource.</param> /// <param name="options">A <see cref="WebRequestOptions"/> that holds options that should be applied to web requests.</param> /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> object used to configure the <see cref="AtomFeed"/> instance. This value can be <b>null</b>.</param> /// <remarks> /// <para> /// <list type="bullet"> /// <item> /// <description> /// If <paramref name="settings"/> has a <see cref="SyndicationResourceLoadSettings.CharacterEncoding">character encoding</see> of <see cref="System.Text.Encoding.UTF8"/> /// the character encoding of the <paramref name="source"/> will be attempt to be determined automatically, otherwise the specified character encoding will be used. /// If automatic detection fails, a character encoding of <see cref="System.Text.Encoding.UTF8"/> is used by default. /// </description> /// </item> /// <item> /// <description> /// After the load operation has successfully completed, the <see cref="AtomFeed.Loaded"/> event will be raised. /// </description> /// </item> /// </list> /// </para> /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="FormatException">The <paramref name="source"/> data does not conform to the expected syndication content format. In this case, the feed remains empty.</exception> /// <exception cref="XmlException">There is a load or parse error in the XML. In this case, the feed remains empty.</exception> public void Load(Uri source, WebRequestOptions options, SyndicationResourceLoadSettings settings) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ XPathNavigator navigator = null; //------------------------------------------------------------ // Validate parameters //------------------------------------------------------------ Guard.ArgumentNotNull(source, "source"); //------------------------------------------------------------ // Use default settings if none specified by the caller //------------------------------------------------------------ if (settings == null) { settings = new SyndicationResourceLoadSettings(); } //------------------------------------------------------------ // Initialize XPathNavigator for supplied Uri, credentials, and proxy //------------------------------------------------------------ if (settings.CharacterEncoding == System.Text.Encoding.UTF8) { navigator = SyndicationEncodingUtility.CreateSafeNavigator(source, options, null); } else { navigator = SyndicationEncodingUtility.CreateSafeNavigator(source, options, settings.CharacterEncoding); } //------------------------------------------------------------ // Load syndication resource using the framework adapters //------------------------------------------------------------ this.Load(navigator, settings, new SyndicationResourceLoadedEventArgs(navigator, source, options)); }
/// <summary> /// Loads the syndication resource from the supplied <see cref="Uri"/> using the specified <see cref="ICredentials">credentials</see>, <see cref="IWebProxy">proxy</see> and <see cref="SyndicationResourceLoadSettings"/>. /// </summary> /// <param name="source">A <see cref="Uri"/> that points to the location of the web resource used to load the syndication resource.</param> /// <param name="credentials"> /// A <see cref="ICredentials"/> that provides the proper set of credentials to the <paramref name="source"/> resource when required. This value can be <b>null</b>. /// </param> /// <param name="proxy"> /// A <see cref="IWebProxy"/> that provides proxy access to the <paramref name="source"/> resource when required. This value can be <b>null</b>. /// </param> /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> object used to configure the <see cref="AtomFeed"/> instance. This value can be <b>null</b>.</param> /// <remarks> /// <para> /// <list type="bullet"> /// <item> /// <description> /// If <paramref name="credentials"/> is <b>null</b>, request is made using the default application credentials. /// </description> /// </item> /// <item> /// <description> /// If <paramref name="proxy"/> is <b>null</b>, request is made using the <see cref="WebRequest"/> default proxy settings. /// </description> /// </item> /// <item> /// <description> /// If <paramref name="settings"/> has a <see cref="SyndicationResourceLoadSettings.CharacterEncoding">character encoding</see> of <see cref="System.Text.Encoding.UTF8"/> /// the character encoding of the <paramref name="source"/> will be attempt to be determined automatically, otherwise the specified character encoding will be used. /// If automatic detection fails, a character encoding of <see cref="System.Text.Encoding.UTF8"/> is used by default. /// </description> /// </item> /// <item> /// <description> /// After the load operation has successfully completed, the <see cref="AtomFeed.Loaded"/> event will be raised. /// </description> /// </item> /// </list> /// </para> /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="FormatException">The <paramref name="source"/> data does not conform to the expected syndication content format. In this case, the feed remains empty.</exception> /// <exception cref="XmlException">There is a load or parse error in the XML. In this case, the feed remains empty.</exception> public void Load(Uri source, ICredentials credentials, IWebProxy proxy, SyndicationResourceLoadSettings settings) { //------------------------------------------------------------ // Load syndication resource using supplied settings //------------------------------------------------------------ this.Load(source, new WebRequestOptions(credentials, proxy), settings); }
/// <summary> /// Loads the syndication resource from the specified <see cref="XmlReader"/>. /// </summary> /// <param name="reader">The <b>XmlReader</b> used to load the syndication resource.</param> /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> object used to configure the <see cref="AtomFeed"/> instance. This value can be <b>null</b>.</param> /// <remarks> /// After the load operation has successfully completed, the <see cref="AtomFeed.Loaded"/> event will be raised. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="reader"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="FormatException">The <paramref name="reader"/> data does not conform to the expected syndication content format. In this case, the feed remains empty.</exception> /// <exception cref="XmlException">There is a load or parse error in the XML. In this case, the feed remains empty.</exception> public void Load(XmlReader reader, SyndicationResourceLoadSettings settings) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(reader, "reader"); //------------------------------------------------------------ // Use reader to create a IXPathNavigable to load from //------------------------------------------------------------ this.Load(new XPathDocument(reader), settings); }
/// <summary> /// Modifies the <see cref="AtomEntry"/> collection entities to match the supplied <see cref="XPathNavigator"/> data source. /// </summary> /// <param name="entry">The <see cref="AtomEntry"/> to be filled.</param> /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param> /// <param name="manager">The <see cref="XmlNamespaceManager"/> used to resolve XML namespace prefixes.</param> /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> used to configure the fill operation.</param> /// <remarks> /// This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="AtomEntry"/>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="entry"/> is a null reference (Nothing in Visual Basic).</exception> /// <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> /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception> private static void FillEntryCollections(AtomEntry entry, XPathNavigator source, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(entry, "entry"); Guard.ArgumentNotNull(source, "source"); Guard.ArgumentNotNull(manager, "manager"); Guard.ArgumentNotNull(settings, "settings"); //------------------------------------------------------------ // Attempt to extract syndication information //------------------------------------------------------------ XPathNodeIterator authorIterator = source.Select("atom:author", manager); XPathNodeIterator categoryIterator = source.Select("atom:category", manager); XPathNodeIterator contributorIterator = source.Select("atom:contributor", manager); XPathNodeIterator linkIterator = source.Select("atom:link", manager); if (authorIterator != null && authorIterator.Count > 0) { while (authorIterator.MoveNext()) { AtomPersonConstruct author = new AtomPersonConstruct(); if (author.Load(authorIterator.Current, settings)) { entry.Authors.Add(author); } } } if (categoryIterator != null && categoryIterator.Count > 0) { while (categoryIterator.MoveNext()) { AtomCategory category = new AtomCategory(); if (category.Load(categoryIterator.Current, settings)) { entry.Categories.Add(category); } } } if (contributorIterator != null && contributorIterator.Count > 0) { while (contributorIterator.MoveNext()) { AtomPersonConstruct contributor = new AtomPersonConstruct(); if (contributor.Load(contributorIterator.Current, settings)) { entry.Contributors.Add(contributor); } } } if (linkIterator != null && linkIterator.Count > 0) { while (linkIterator.MoveNext()) { AtomLink link = new AtomLink(); if (link.Load(linkIterator.Current, settings)) { entry.Links.Add(link); } } } }
/// <summary> /// Loads this <see cref="AtomSource"/> using the supplied <see cref="XPathNavigator"/> and <see cref="SyndicationResourceLoadSettings"/>. /// </summary> /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param> /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> used to configure the load operation.</param> /// <returns><b>true</b> if the <see cref="AtomSource"/> 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="AtomSource"/>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="source"/> 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> public bool Load(XPathNavigator source, SyndicationResourceLoadSettings settings) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ bool wasLoaded = false; //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(source, "source"); Guard.ArgumentNotNull(settings, "settings"); //------------------------------------------------------------ // Attempt to extract syndication information //------------------------------------------------------------ wasLoaded = this.Load(source); //------------------------------------------------------------ // Attempt to extract syndication extension information //------------------------------------------------------------ SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(source, settings); adapter.Fill(this); return wasLoaded; }
/// <summary> /// Creates a new <see cref="AtomFeed"/> instance using the specified <see cref="Uri"/>, <see cref="ICredentials"/>, <see cref="IWebProxy"/>, and <see cref="SyndicationResourceLoadSettings"/> object. /// </summary> /// <param name="source">A <see cref="Uri"/> that represents the URL of the syndication resource XML data.</param> /// <param name="options">A <see cref="WebRequestOptions"/> that holds options that should be applied to web requests.</param> /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> object used to configure the <see cref="AtomFeed"/> instance. This value can be <b>null</b>.</param> /// <returns>An <see cref="AtomFeed"/> object loaded using the <paramref name="source"/> data.</returns> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="FormatException">The <paramref name="source"/> data does not conform to the expected syndication content format. In this case, the feed remains empty.</exception> public static AtomFeed Create(Uri source, WebRequestOptions options, SyndicationResourceLoadSettings settings) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ AtomFeed syndicationResource = new AtomFeed(); //------------------------------------------------------------ // Validate parameters //------------------------------------------------------------ Guard.ArgumentNotNull(source, "source"); //------------------------------------------------------------ // Create new instance using supplied parameters //------------------------------------------------------------ syndicationResource.Load(source, options, settings); return syndicationResource; }
/// <summary> /// Creates a new <see cref="AtomFeed"/> instance using the specified <see cref="Uri"/>, <see cref="ICredentials"/>, <see cref="IWebProxy"/>, and <see cref="SyndicationResourceLoadSettings"/> object. /// </summary> /// <param name="source">A <see cref="Uri"/> that represents the URL of the syndication resource XML data.</param> /// <param name="credentials"> /// A <see cref="ICredentials"/> that provides the proper set of credentials to the <paramref name="source"/> when required. This value can be <b>null</b>. /// </param> /// <param name="proxy"> /// A <see cref="IWebProxy"/> that provides proxy access to the <paramref name="source"/> when required. This value can be <b>null</b>. /// </param> /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> object used to configure the <see cref="AtomFeed"/> instance. This value can be <b>null</b>.</param> /// <returns>An <see cref="AtomFeed"/> object loaded using the <paramref name="source"/> data.</returns> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="FormatException">The <paramref name="source"/> data does not conform to the expected syndication content format. In this case, the feed remains empty.</exception> public static AtomFeed Create(Uri source, ICredentials credentials, IWebProxy proxy, SyndicationResourceLoadSettings settings) { //------------------------------------------------------------ // Create instance using supplied parameters //------------------------------------------------------------ return AtomFeed.Create(source, new WebRequestOptions(credentials, proxy), settings); }
/// <summary> /// Modifies the <see cref="AtomFeed"/> optional entities to match the supplied <see cref="XPathNavigator"/> data source. /// </summary> /// <param name="feed">The <see cref="AtomFeed"/> to be filled.</param> /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param> /// <param name="manager">The <see cref="XmlNamespaceManager"/> used to resolve XML namespace prefixes.</param> /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> used to configure the fill operation.</param> /// <remarks> /// This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="AtomFeed"/>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="feed"/> is a null reference (Nothing in Visual Basic).</exception> /// <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> /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception> private static void FillFeedOptionals(AtomFeed feed, XPathNavigator source, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(feed, "feed"); Guard.ArgumentNotNull(source, "source"); Guard.ArgumentNotNull(manager, "manager"); Guard.ArgumentNotNull(settings, "settings"); //------------------------------------------------------------ // Attempt to extract syndication information //------------------------------------------------------------ XPathNavigator generatorNavigator = source.SelectSingleNode("atom:generator", manager); XPathNavigator iconNavigator = source.SelectSingleNode("atom:icon", manager); XPathNavigator logoNavigator = source.SelectSingleNode("atom:logo", manager); XPathNavigator rightsNavigator = source.SelectSingleNode("atom:rights", manager); XPathNavigator subtitleNavigator = source.SelectSingleNode("atom:subtitle", manager); if (generatorNavigator != null) { feed.Generator = new AtomGenerator(); feed.Generator.Load(generatorNavigator, settings); } if (iconNavigator != null) { feed.Icon = new AtomIcon(); feed.Icon.Load(iconNavigator, settings); } if (logoNavigator != null) { feed.Logo = new AtomLogo(); feed.Logo.Load(logoNavigator, settings); } if (rightsNavigator != null) { feed.Rights = new AtomTextConstruct(); feed.Rights.Load(rightsNavigator, settings); } if (subtitleNavigator != null) { feed.Subtitle = new AtomTextConstruct(); feed.Subtitle.Load(subtitleNavigator, settings); } }
/// <summary> /// Modifies the <see cref="AtomFeed"/> collection entities to match the supplied <see cref="XPathNavigator"/> data source. /// </summary> /// <param name="feed">The <see cref="AtomFeed"/> to be filled.</param> /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param> /// <param name="manager">The <see cref="XmlNamespaceManager"/> used to resolve XML namespace prefixes.</param> /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> used to configure the fill operation.</param> /// <remarks> /// This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="AtomFeed"/>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="feed"/> is a null reference (Nothing in Visual Basic).</exception> /// <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> /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception> private static void FillFeedCollections(AtomFeed feed, XPathNavigator source, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(feed, "feed"); Guard.ArgumentNotNull(source, "source"); Guard.ArgumentNotNull(manager, "manager"); Guard.ArgumentNotNull(settings, "settings"); //------------------------------------------------------------ // Attempt to extract syndication information //------------------------------------------------------------ XPathNodeIterator authorIterator = source.Select("atom:author", manager); XPathNodeIterator categoryIterator = source.Select("atom:category", manager); XPathNodeIterator contributorIterator = source.Select("atom:contributor", manager); XPathNodeIterator linkIterator = source.Select("atom:link", manager); XPathNodeIterator entryIterator = source.Select("atom:entry", manager); if (authorIterator != null && authorIterator.Count > 0) { while (authorIterator.MoveNext()) { AtomPersonConstruct author = new AtomPersonConstruct(); if (author.Load(authorIterator.Current, settings)) { feed.Authors.Add(author); } } } if (categoryIterator != null && categoryIterator.Count > 0) { while (categoryIterator.MoveNext()) { AtomCategory category = new AtomCategory(); if (category.Load(categoryIterator.Current, settings)) { feed.Categories.Add(category); } } } if (contributorIterator != null && contributorIterator.Count > 0) { while (contributorIterator.MoveNext()) { AtomPersonConstruct contributor = new AtomPersonConstruct(); if (contributor.Load(contributorIterator.Current, settings)) { feed.Contributors.Add(contributor); } } } if (entryIterator != null && entryIterator.Count > 0) { int counter = 0; while (entryIterator.MoveNext()) { AtomEntry entry = new AtomEntry(); counter++; Atom10SyndicationResourceAdapter.FillEntry(entry, entryIterator.Current, manager, settings); if (settings.RetrievalLimit != 0 && counter > settings.RetrievalLimit) { break; } ((Collection<AtomEntry>)feed.Entries).Add(entry); } } if (linkIterator != null && linkIterator.Count > 0) { while (linkIterator.MoveNext()) { AtomLink link = new AtomLink(); if (link.Load(linkIterator.Current, settings)) { feed.Links.Add(link); } } } }
/// <summary> /// Modifies the <see cref="AtomEntry"/> optional entities to match the supplied <see cref="XPathNavigator"/> data source. /// </summary> /// <param name="entry">The <see cref="AtomEntry"/> to be filled.</param> /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param> /// <param name="manager">The <see cref="XmlNamespaceManager"/> used to resolve XML namespace prefixes.</param> /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> used to configure the fill operation.</param> /// <remarks> /// This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="AtomEntry"/>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="entry"/> is a null reference (Nothing in Visual Basic).</exception> /// <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> /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception> private static void FillEntryOptionals(AtomEntry entry, XPathNavigator source, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(entry, "entry"); Guard.ArgumentNotNull(source, "source"); Guard.ArgumentNotNull(manager, "manager"); Guard.ArgumentNotNull(settings, "settings"); //------------------------------------------------------------ // Attempt to extract syndication information //------------------------------------------------------------ XPathNavigator contentNavigator = source.SelectSingleNode("atom:content", manager); XPathNavigator publishedNavigator = source.SelectSingleNode("atom:published", manager); XPathNavigator rightsNavigator = source.SelectSingleNode("atom:rights", manager); XPathNavigator sourceNavigator = source.SelectSingleNode("atom:source", manager); XPathNavigator summaryNavigator = source.SelectSingleNode("atom:summary", manager); if (contentNavigator != null) { entry.Content = new AtomContent(); entry.Content.Load(contentNavigator, settings); } if (publishedNavigator != null) { DateTime publishedOn; if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(publishedNavigator.Value, out publishedOn)) { entry.PublishedOn = publishedOn; } } if (rightsNavigator != null) { entry.Rights = new AtomTextConstruct(); entry.Rights.Load(rightsNavigator, settings); } if (sourceNavigator != null) { entry.Source = new AtomSource(); entry.Source.Load(sourceNavigator, settings); } if (summaryNavigator != null) { entry.Summary = new AtomTextConstruct(); entry.Summary.Load(summaryNavigator, settings); } }
/// <summary> /// Loads the syndication resource 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="AtomFeed"/>.</param> /// <param name="eventData">A <see cref="SyndicationResourceLoadedEventArgs"/> that contains the event data used when raising the <see cref="AtomFeed.Loaded"/> event.</param> /// <remarks> /// After the load operation has successfully completed, the <see cref="AtomFeed.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"); //------------------------------------------------------------ // Load syndication resource using the framework adapters //------------------------------------------------------------ SyndicationResourceAdapter adapter = new SyndicationResourceAdapter(navigator, settings); adapter.Fill(this, SyndicationContentFormat.Atom); //------------------------------------------------------------ // Raise Loaded event to notify registered handlers of state change //------------------------------------------------------------ this.OnFeedLoaded(eventData); }
/// <summary> /// Creates a new <see cref="AtomFeed"/> instance using the specified <see cref="Uri"/> and <see cref="SyndicationResourceLoadSettings"/> object. /// </summary> /// <param name="source">A <see cref="Uri"/> that represents the URL of the syndication resource XML data.</param> /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> object used to configure the <see cref="AtomFeed"/> instance. This value can be <b>null</b>.</param> /// <returns>An <see cref="AtomFeed"/> object loaded using the <paramref name="source"/> data.</returns> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="FormatException">The <paramref name="source"/> data does not conform to the expected syndication content format. In this case, the feed remains empty.</exception> public static AtomFeed Create(Uri source, SyndicationResourceLoadSettings settings) { //------------------------------------------------------------ // Create instance using supplied parameters and default settings //------------------------------------------------------------ return AtomFeed.Create(source, new WebRequestOptions(), settings); }
/// <summary> /// Loads the syndication resource from the specified <see cref="IXPathNavigable"/> and <see cref="SyndicationResourceLoadSettings"/>. /// </summary> /// <param name="source">The <b>IXPathNavigable</b> used to load the syndication resource.</param> /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> object used to configure the <see cref="AtomFeed"/> instance. This value can be <b>null</b>.</param> /// <remarks> /// After the load operation has successfully completed, the <see cref="AtomFeed.Loaded"/> event will be raised. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="FormatException">The <paramref name="source"/> data does not conform to the expected syndication content format. In this case, the feed remains empty.</exception> /// <exception cref="XmlException">There is a load or parse error in the XML. In this case, the feed remains empty.</exception> public void Load(IXPathNavigable source, SyndicationResourceLoadSettings settings) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(source, "source"); //------------------------------------------------------------ // Use default settings if none specified by the caller //------------------------------------------------------------ if (settings == null) { settings = new SyndicationResourceLoadSettings(); } //------------------------------------------------------------ // Load syndication resource using the framework adapters //------------------------------------------------------------ XPathNavigator navigator = source.CreateNavigator(); this.Load(navigator, settings, new SyndicationResourceLoadedEventArgs(navigator)); }
/// <summary> /// Loads the syndication resource from the specified <see cref="Stream"/>. /// </summary> /// <param name="stream">The <b>Stream</b> used to load the syndication resource.</param> /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> object used to configure the <see cref="AtomFeed"/> instance. This value can be <b>null</b>.</param> /// <remarks> /// After the load operation has successfully completed, the <see cref="AtomFeed.Loaded"/> event will be raised. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="stream"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="FormatException">The <paramref name="stream"/> data does not conform to the expected syndication content format. In this case, the feed remains empty.</exception> /// <exception cref="XmlException">There is a load or parse error in the XML. In this case, the feed remains empty.</exception> public void Load(Stream stream, SyndicationResourceLoadSettings settings) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(stream, "stream"); //------------------------------------------------------------ // Use stream to create a XPathNavigator to load from //------------------------------------------------------------ if (settings != null) { this.Load(SyndicationEncodingUtility.CreateSafeNavigator(stream, settings.CharacterEncoding), settings); } else { this.Load(SyndicationEncodingUtility.CreateSafeNavigator(stream), settings); } }
/// <summary> /// Modifies the <see cref="AtomEntry"/> to match the supplied <see cref="XPathNavigator"/> data source. /// </summary> /// <param name="entry">The <see cref="AtomEntry"/> to be filled.</param> /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param> /// <param name="manager">The <see cref="XmlNamespaceManager"/> used to resolve XML namespace prefixes.</param> /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> used to configure the fill operation.</param> /// <remarks> /// This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="AtomEntry"/>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="entry"/> is a null reference (Nothing in Visual Basic).</exception> /// <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 static void FillEntry(AtomEntry entry, XPathNavigator source, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(entry, "entry"); Guard.ArgumentNotNull(source, "source"); Guard.ArgumentNotNull(manager, "manager"); Guard.ArgumentNotNull(settings, "settings"); //------------------------------------------------------------ // Attempt to fill syndication resource //------------------------------------------------------------ AtomUtility.FillCommonObjectAttributes(entry, source); XPathNavigator idNavigator = source.SelectSingleNode("atom:id", manager); XPathNavigator titleNavigator = source.SelectSingleNode("atom:title", manager); XPathNavigator updatedNavigator = source.SelectSingleNode("atom:updated", manager); if (idNavigator != null) { entry.Id = new AtomId(); entry.Id.Load(idNavigator, settings); } if (titleNavigator != null) { entry.Title = new AtomTextConstruct(); entry.Title.Load(titleNavigator, settings); } if (updatedNavigator != null) { DateTime updatedOn; if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(updatedNavigator.Value, out updatedOn)) { entry.UpdatedOn = updatedOn; } } Atom10SyndicationResourceAdapter.FillEntryOptionals(entry, source, manager, settings); Atom10SyndicationResourceAdapter.FillEntryCollections(entry, source, manager, settings); SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(source, settings); adapter.Fill(entry, manager); }