/// <summary> /// Provides example code for the SyndicationDiscoveryUtility.ConditionalGet(Uri, DateTime, string) method /// </summary> public static void ConditionalGetExample() { Uri source = new Uri("http://www.pwop.com/feed.aspx?show=dotnetrocks&filetype=master"); DateTime lastModified; string entityTag; HttpWebRequest httpRequest = (HttpWebRequest)HttpWebRequest.Create(source); httpRequest.AllowAutoRedirect = true; httpRequest.KeepAlive = true; httpRequest.UserAgent = "Some User Agent 1.0.0.0"; HttpWebResponse httpResponse = (HttpWebResponse)httpRequest.GetResponse(); lastModified = httpResponse.LastModified; entityTag = httpResponse.Headers[HttpResponseHeader.ETag]; /* * Typically the consumer would store the modification date and entity tag information for the resource, * and some amount of time passes. Consumer can now use a conditional GET operation to determine if * the web resource has changed since it was last retrieved. This minimizes bandwidth usage significantly. */ WebResponse conditionalResponse = SyndicationDiscoveryUtility.ConditionalGet(source, lastModified, entityTag); if (conditionalResponse != null) { // Web resource has been modified since last retrieval, consumer would process the new data. } }
public static void IsTrackbackEnabledExample() { Uri source = new Uri("http://blog.oppositionallydefiant.com/post/SystemIOIntuition-Leveraging-human-pattern-recognition.aspx"); if (SyndicationDiscoveryUtility.IsTrackbackEnabled(source)) { // Parse source for Trackback information } }
/// <summary> /// Provides example code for the SyndicationDiscoveryUtility.UriExists(Uri) method /// </summary> public static void UriExistsExample() { Uri source = new Uri("http://blog.oppositionallydefiant.com/"); if (SyndicationDiscoveryUtility.UriExists(source)) { // Perform some action based on source existing. } }
/// <summary> /// Provides example code for the SyndicationDiscoveryUtility.SourceReferencesTarget(Uri, Uri) method /// </summary> public static void SourceReferencesTargetExample() { // Certain syndication scenarios involve verifying that one web resource references or 'links' to another web resource. Uri source = new Uri("http://blog.oppositionallydefiant.com/post/SystemIOIntuition-Leveraging-human-pattern-recognition.aspx"); Uri target = new Uri("http://www.wikimindmap.org/"); if (SyndicationDiscoveryUtility.SourceReferencesTarget(source, target)) { // Perform some action based on source referencing the target. } }
/// <summary> /// Provides example code for the SyndicationDiscoveryUtility.SyndicationContentFormatGet(Uri) method /// </summary> public static void SyndicationContentFormatGetExample() { SyndicationContentFormat format = SyndicationContentFormat.None; Uri url = new Uri("http://feeds.feedburner.com/HanselminutesCompleteMP3?format=xml"); format = SyndicationDiscoveryUtility.SyndicationContentFormatGet(url); if (format != SyndicationContentFormat.None) { // Do something based on the determined content format } }
//============================================================ // PUBLIC METHODS //============================================================ #region ProcessRequest(HttpContext context) /// <summary> /// Enables processing of HTTP Web requests for syndicated content. /// </summary> /// <param name="context"> /// An <see cref="HttpContext"/> object that provides references to the intrinsic server objects /// (for example, <b>Request</b>, <b>Response</b>, <b>Session</b>, and <b>Server</b>) used to service HTTP requests. /// </param> /// <exception cref="ArgumentNullException">The <paramref name="context"/> is a null reference (Nothing in Visual Basic).</exception> public void ProcessRequest(HttpContext context) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ ISyndicationResource syndicationResource = null; //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(context, "context"); //------------------------------------------------------------ // Initialize handler state using query string parameters //------------------------------------------------------------ if (context.Request.QueryString["format"] != null && !String.IsNullOrEmpty(context.Request.QueryString["format"])) { SyndicationContentFormat format = SyndicationDiscoveryUtility.SyndicationContentFormatByName(context.Request.QueryString["format"]); if (format != SyndicationContentFormat.None) { this.Format = format; } } if (context.Request.QueryString["id"] != null && !String.IsNullOrEmpty(context.Request.QueryString["id"])) { this.Id = context.Request.QueryString["id"]; } //------------------------------------------------------------ // Get syndication resource using provider model //------------------------------------------------------------ if (this.Id != null) { syndicationResource = SyndicationManager.GetResource(this.Id); } else if (this.Format != SyndicationContentFormat.None) { Collection <ISyndicationResource> resources = SyndicationManager.GetResources(this.Format); if (resources != null && resources.Count > 0) { syndicationResource = resources[0]; } } //------------------------------------------------------------ // Write syndication resource data and header details //------------------------------------------------------------ if (syndicationResource != null) { this.WriteResource(context, syndicationResource); } }
public static void LocateTrackbackNotificationServersExample() { Uri source = new Uri("http://blog.oppositionallydefiant.com/post/SystemIOIntuition-Leveraging-human-pattern-recognition.aspx"); Collection <TrackbackDiscoveryMetadata> endpoints = SyndicationDiscoveryUtility.LocateTrackbackNotificationServers(source); foreach (TrackbackDiscoveryMetadata endpoint in endpoints) { Argotic.Net.TrackbackClient client = new Argotic.Net.TrackbackClient(endpoint.PingUrl); Argotic.Net.TrackbackMessage message = new Argotic.Net.TrackbackMessage(); // Build Trackback url-encoded message to be sent client.Send(message); } }
public static void LocatePingbackNotificationServerExample() { Uri source = new Uri("http://blog.oppositionallydefiant.com/post/SystemIOIntuition-Leveraging-human-pattern-recognition.aspx"); Uri pingbackServer = SyndicationDiscoveryUtility.LocatePingbackNotificationServer(source); if (pingbackServer != null) { Argotic.Net.XmlRpcClient client = new Argotic.Net.XmlRpcClient(pingbackServer); Argotic.Net.XmlRpcMessage message = new Argotic.Net.XmlRpcMessage(); // Build the Pingback XML-RPC message to be sent client.Send(message); } }
/// <summary> /// Provides example code for the SyndicationDiscoveryUtility.LocateDiscoverableSyndicationEndpoints(Uri) method /// </summary> public static void LocateDiscoverableSyndicationEndpointsExample() { Uri source = new Uri("http://www.dotnetrocks.com/"); Collection <DiscoverableSyndicationEndpoint> endpoints; endpoints = SyndicationDiscoveryUtility.LocateDiscoverableSyndicationEndpoints(source); foreach (DiscoverableSyndicationEndpoint endpoint in endpoints) { if (endpoint.ContentFormat == SyndicationContentFormat.Rss) { RssFeed feed = RssFeed.Create(endpoint.Source); if (feed.Channel.HasExtensions) { // Process feed extensions } } } }