xml-rpc(2)-first demo_v2
[XmlRpcMethod("blogger.getUsersBlogs", Description = "获取博客信息")]
public BlogInfo[] getUsersBlogs(string appKey, string username, string password)
{
BlogInfo[] infoarr = new BlogInfo[1];
for (int i = 0; i < 1; i++)
{
Member member = GetUser(username, password);
if (member != null)
{
infoarr[i].url = GetAppPath() + "Blog/User/Default.aspx?UserName=" + HttpContext.Current.Server.UrlEncode(member.UserName);
infoarr[i].blogName = GetBlogSetting(Convert.ToInt32(member.MemberID)).BlogName;
infoarr[i].blogid = member.MemberID.ToString();
}
}
return infoarr;
}
[XmlRpcMethod("metaWeblog.getCategories", Description = "获取分类列表")]
public CategoryInfo[] getCategories(string blogid, string username, string password)
{
TList<BlogKind> list = GetBlogKind(int.Parse(blogid));
CategoryInfo[] infoarr = new CategoryInfo[list.Count];
for (int i = 0; i < infoarr.Length; i++)
{
infoarr[i].categoryid = list[i].BlogKindID.ToString();
infoarr[i].description = list[i].KindName;
infoarr[i].htmlUrl = "";
infoarr[i].rssUrl = "";
infoarr[i].title = list[i].KindName;
}
return infoarr;
}
[XmlRpcMethod("metaWeblog.newPost", Description = "发表日志")]
public string newPost(string blogid, string username, string password, CookComputing.MetaWeblog.Post post, bool publish)
{
Member member = GetUser(username, password);
if (member != null)
{
BlogTopic xBlogTopic = new BlogTopic();
xBlogTopic.Title = post.title;
xBlogTopic.Content = post.description;
xBlogTopic.Weather = 0;
xBlogTopic.Face = 1;
xBlogTopic.CommentNum = 0;
xBlogTopic.IsBast = 0;
xBlogTopic.IsShow = 1;
xBlogTopic.ComeFrom = username;
xBlogTopic.Summary = "";
xBlogTopic.IsTop = 0;
xBlogTopic.LastIp = HttpContext.Current.Request.Url.Host;
xBlogTopic.Hits = 0;
xBlogTopic.CheckInTime = DateTime.Now;
xBlogTopic.Status = 1;
xBlogTopic.MemberID = Convert.ToInt32(blogid);
xBlogTopic.Tags = "";
xBlogTopic.BlogSystemTypeID = null;
xBlogTopic.Score = 0;
if (!string.IsNullOrEmpty(post.categories[0]))
{
foreach (CategoryInfo info in getCategories(blogid, username, password))
{
if (info.title == post.categories[0])
{
xBlogTopic.BlogKindID = int.Parse(info.categoryid);
break;
}
}
}
xBlogTopic.BastTime = null;
BlogTopicSystem.Instance.Create(xBlogTopic);
return xBlogTopic.BlogTopicID.ToString();
}
return "0";
}
public BlogInfo[] getUsersBlogs(string appKey, string username, string password)
{
BlogInfo[] infoarr = new BlogInfo[1];
for (int i = 0; i < 1; i++)
{
Member member = GetUser(username, password);
if (member != null)
{
infoarr[i].url = GetAppPath() + "Blog/User/Default.aspx?UserName=" + HttpContext.Current.Server.UrlEncode(member.UserName);
infoarr[i].blogName = GetBlogSetting(Convert.ToInt32(member.MemberID)).BlogName;
infoarr[i].blogid = member.MemberID.ToString();
}
}
return infoarr;
}
[XmlRpcMethod("metaWeblog.getCategories", Description = "获取分类列表")]
public CategoryInfo[] getCategories(string blogid, string username, string password)
{
TList<BlogKind> list = GetBlogKind(int.Parse(blogid));
CategoryInfo[] infoarr = new CategoryInfo[list.Count];
for (int i = 0; i < infoarr.Length; i++)
{
infoarr[i].categoryid = list[i].BlogKindID.ToString();
infoarr[i].description = list[i].KindName;
infoarr[i].htmlUrl = "";
infoarr[i].rssUrl = "";
infoarr[i].title = list[i].KindName;
}
return infoarr;
}
[XmlRpcMethod("metaWeblog.newPost", Description = "发表日志")]
public string newPost(string blogid, string username, string password, CookComputing.MetaWeblog.Post post, bool publish)
{
Member member = GetUser(username, password);
if (member != null)
{
BlogTopic xBlogTopic = new BlogTopic();
xBlogTopic.Title = post.title;
xBlogTopic.Content = post.description;
xBlogTopic.Weather = 0;
xBlogTopic.Face = 1;
xBlogTopic.CommentNum = 0;
xBlogTopic.IsBast = 0;
xBlogTopic.IsShow = 1;
xBlogTopic.ComeFrom = username;
xBlogTopic.Summary = "";
xBlogTopic.IsTop = 0;
xBlogTopic.LastIp = HttpContext.Current.Request.Url.Host;
xBlogTopic.Hits = 0;
xBlogTopic.CheckInTime = DateTime.Now;
xBlogTopic.Status = 1;
xBlogTopic.MemberID = Convert.ToInt32(blogid);
xBlogTopic.Tags = "";
xBlogTopic.BlogSystemTypeID = null;
xBlogTopic.Score = 0;
if (!string.IsNullOrEmpty(post.categories[0]))
{
foreach (CategoryInfo info in getCategories(blogid, username, password))
{
if (info.title == post.categories[0])
{
xBlogTopic.BlogKindID = int.Parse(info.categoryid);
break;
}
}
}
xBlogTopic.BastTime = null;
BlogTopicSystem.Instance.Create(xBlogTopic);
return xBlogTopic.BlogTopicID.ToString();
}
return "0";
}