Sitefinity CMS

Implementing IRssProvider Send comments on this topic.
See Also
Developing with Sitefinity > Services > RSS Service > Implementing IRssProvider

Glossary Item Box

IRssProvider determines the logic of the Rss - what information to be extracted and displayed by the Rss providers. 

 

In order to implement that functionality, we will create a new public class - JobsChannelProvider - and place it in a newly created folder - Rss -  in the Samples.Jobs.Pluggable module.  

 

Inherited Members

The following Members are an implementation of the IRssProvider interface:  

 

ShowMembers

Public Methods

 

Name Description Parameters Description
IList <RssItem> GetRssItems Creates the Rss item using the settings' values and the provided query. The method returns a list of RssItem objects.    NameValueCollection query It is taken from the requested URL.
void Initialize Initializes this instance with the provided settings of type IDictionary, which is a key value collection of settings. 

IDictionary<string,string> settings

As all settings in the parameter are strings, this method is used to parse them to the needed types. The settings are later used in the GetRssItems() method.

 

Public Properties

 

Name Description
string Name Name of the provider.
string Description A detailed description about the provider appears when the mouse goes over the channel provider in the Admin part. The description is taken from a resource file.

 

 

JobsChannelProvider Copy Code
public IList<RssItem> GetRssItems(System.Collections.Specialized.NameValueCollection query)
{
 IList blogs;
 BlogManager manager =
new BlogManager(this.blogProvider);
 
if (this.selectedBlogs == null || this.selectedBlogs.Length == 0)
   blogs = manager.GetBlogs();
 
else
   
blogs = manager.GetBlogs(this.selectedBlogs);
 List<RssItem> items =
new List<RssItem>();
 
foreach (IBlog blog in blogs)
   
foreach (IContent post in blog.Posts)
   {
     RssItem item =
new RssItem();
     
string path;
     
if (!this.postUrl.StartsWith("http://"))
       path = String.Concat(
"http://", HttpContext.Current.Request.ServerVariables["SERVER_NAME"], this.postUrl);
    
else
       
path = this.postUrl;
    
int idx = path.LastIndexOf('.');
    
if (idx > -1)
      path = path.Substring(0, idx);
    
if (!path.EndsWith("/"))
      path +=
"/";
    item.Link =
new Uri(String.Concat(path, UrlRewriterService.FormatURL(post, manager.SettingsElement)), UriKind.Absolute);
    UserManager man =
new UserManager();
    MembershipUser user = man.GetUser(post.GetMetaData(
"Author") as string);
    
if (user != null && !String.IsNullOrEmpty(user.Email))
      item.Author = user.Email;
    item.Comments =
new Uri(String.Concat(path, UrlRewriterService.FormatURL(post, manager.SettingsElement)), UriKind.Absolute).ToString();
    item.PubDate = (DateTime)post.GetMetaData(
"Publication_Date");
    item.Title = post.GetMetaData(
"Title") as string;
    item.Guid =
new RssGuid(post.ID.ToString(), false);
    
switch (this.syndicationType)
    {
      
case SyndicationType.Full:
        item.Description = post.Content.ToString();
        
break;
      
case SyndicationType.Summary:
        item.Description =
this.CreatePostSummary(post.Content.ToString());
        
break;
      
case SyndicationType.TitleOnly:
        item.Description = item.Title;
        
break;
    }
    
if (items.Count < this.itemCount)
      items.Add(item);
    
else
      
break;
  }
  
if (items.Count == 0)
  {
    RssItem item =
new RssItem();
    item.Link =
new Uri(this.postUrl, UriKind.RelativeOrAbsolute);
    item.Comments =
this.postUrl;
    item.Title = Messages.NoBlogsSoFar;
    items.Add(item);
  }
  
return items;
}
public void Initialize(IDictionary<string, string> settings)
{
 
string val;
 
if (settings.TryGetValue(KeyItemCount, out val) && !String.IsNullOrEmpty(val))
 {
   
if (!int.TryParse(val, out this.itemCount))
     
this.itemCount = 15;
 }
 
else
   
this.itemCount = 15;
 
if (settings.TryGetValue(KeyPostUrl, out val))
   
this.postUrl = HttpContext.Current.Response.ApplyAppPathModifier(val);
 
else
   
this.postUrl = HttpContext.Current.Request.Url.AbsoluteUri;
 
if (settings.TryGetValue(KeySelectedBlogs, out val) && !String.IsNullOrEmpty(val))
 {
   List<Guid> list =
new List<Guid>();
   
string[] sids = val.Split(';');
   
foreach (string sid in sids)
   {
     
string sval = sid.Trim();
     
if (sval.Length > 0)
     {
       Guid id = Guid.Empty;
       
try
       {
         
id = new Guid(sval);
       }
       
catch { }
         
list.Add(id);
     }
   }
   
this.selectedBlogs = list.ToArray();
 }
 
else
 {
   
this.selectedBlogs = new Guid[0];
 }
 
if (settings.TryGetValue(KeyBlogProvider, out val))
   
this.blogProvider = val;
 
else
   
this.blogProvider = String.Empty;
 
if (settings.TryGetValue(KeySyndicationType, out val))
 {
   
try
   {
     
this.syndicationType = (SyndicationType)Enum.Parse(typeof(SyndicationType), val);
   }
   
catch (ArgumentException)
   {
     
this.syndicationType = SyndicationType.Full;
   }
 }
 
else
   
this.syndicationType = SyndicationType.Full;
 
if (settings.TryGetValue(KeySummaryLength, out val))
 {
   
if (!Int32.TryParse(val, out this.summaryLength))
     
this.summaryLength = 250;
 }
 
else
   
this.summaryLength = 250;
}

 

See Also