using System;
namespace RSSBlogAPI{
using CommunityServer;
/// <summary>
/// Blog API for Community Server
/// </summary>
public class CommunityServerAPI : BlogAPIBase
{
public override bool HasCategories
{
get { return true; }
}
public override bool HasBlogId
{
get { return false; }
}
public override string EngineName
{
get { return ".TEXT SimpleBlogService"; }
}
public override string HelpText
{
get { return ".Text Blog sites"; }
}
public override void Test()
{
this.GetCategories();
}
/// <summary>
/// Retrieve categories by calling the SimpleBlogService webservice
/// </summary>
/// <returns></returns>
public override Category [] GetCategories()
{
string [] categories = this.GetService().GetPostCategories( );
Category [] output = new Category [ categories.Length ];
for( int i=0; i<categories.Length; i++ )
output[i] = new Category( 0, string.Empty, categories[i] );
return output;
}
private BlogService GetService()
{
ServiceCredentials credentials = new ServiceCredentials();
credentials.SectionName = this.BlogId;
credentials.Password = this.Password;
credentials.Username = this.Username;
BlogService svc = new BlogService();
svc.Url = this.Url;
svc.Proxy = this.ProxyServer;
svc.ServiceCredentialsValue = credentials;
return svc;
}
/// <summary>
/// Post a blog entry by calling simple blog service
/// </summary>
/// <param name="post"></param>
/// <returns></returns>
public override string PostItem( Post log )
{
string [] cats = new string[ log.Categories.Length ];
for( int i=0; i<log.Categories.Length; i++ )
cats[i] = log.Categories[i].Title;
BlogPost post = new BlogPost();
post.Body = log.Text;
post.Categories = cats;
post.Date = log.Date;
post.DisplayOnHome = true;
post.EnableComments = true;
post.EnableRatings = true;
post.EnableTrackbacks = true;
post.Excerpt = post.Title;
post.IsPublished = true;
post.ModerationType = CommentModerationType.None;
post.Name = this.Username;
post.SydicateRoot = true;
post.Syndicate = true;
post.Title = log.Title;
return this.GetService().Create( post ).ToString();
}
}
}
|