MetaWeblogHandler.cs :  » Content-Management-Systems-CMS » Kooboo » Everest » CmsServices » Rfc » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Content Management Systems CMS » Kooboo 
Kooboo » Everest » CmsServices » Rfc » MetaWeblogHandler.cs
using System;
using System.Web;
using System.Collections.Generic;
using System.Linq;
using System.Text;


using CookComputing.XmlRpc;
using CookComputing.Blogger;
using CookComputing.MetaWeblog;

using Everest.CmsServices.Models;
using Everest.CmsServices.MvcHelper;
using Everest.CmsServices.Services;
using Everest.Library;
using Everest.Library.Data.Entity;
using Everest.CmsServices.Providers;
using System.Collections.Specialized;
using System.Linq.Expressions;
using Everest.Library.ExtensionMethod;
using Everest.Library.Web;
using System.IO;
using System.Web.Security;
namespace Everest.CmsServices.Rfc{
    public class MetaWeblogHandler : XmlRpcService, CookComputing.Blogger.IBlogger, CookComputing.MetaWeblog.IMetaWeblog, IRfcHandler
    {
        private string application;
        public string Application
        {
            get
            {
                if (string.IsNullOrEmpty(application))
                {
                    return Context.Request.QueryString["Application"];
                }
                return application;
            }
            set
            {
                application = value;
            }
        }

        private void CheckArguments()
        {
            if (string.IsNullOrEmpty(Application))
            {
                throw new Exception(Resources.Metaweblog_ApplicationIsRequired);
            }
        }

        private void CheckUserPassword(string userName, string password)
        {
            if (string.IsNullOrEmpty(userName))
            {
                throw new Exception(Resources.Account_SpecifyUserName);
            }
            var isValid = Membership.ValidateUser(userName, password);
            if (!isValid)
            {
                throw new Exception(Resources.Account_UserNameOrPasswordIncorrect);
            }
        }


        #region IBlogger Members

        public bool deletePost(string appKey, string postid, string username, string password, bool publish)
        {
            CheckArguments();
            CheckUserPassword(username, password);
            TextContentService textContentService = new TextContentService();

            var contentUUID = new Guid(postid);
            textContentService.Delete(contentUUID, username);

            return true;
        }

        public object editPost(string appKey, string postid, string username, string password, string content, bool publish)
        {
            throw new NotImplementedException();
        }

        public CookComputing.Blogger.Category[] getCategories(string blogid, string username, string password)
        {
            List<CookComputing.Blogger.Category> categories = new List<CookComputing.Blogger.Category>();
            Guid folderUUID = new Guid(blogid);
            var schema = CachedData.GetSchemaByFolder(folderUUID);
            TextContentService textContentService = new TextContentService();

            foreach (var content in textContentService.GetCategories(Application, schema.UUID))
            {
                categories.Add(new CookComputing.Blogger.Category()
                {
                    categoryid = content["UUID"].ToString(),
                    title = content["Title"].ToString(),
                    description = content["Body"] == null ? "" : content["Body"].ToString()
                });
            }


            return categories.ToArray();
        }

        public CookComputing.Blogger.Post getPost(string appKey, string postid, string username, string password)
        {
            throw new NotImplementedException();
        }

        public CookComputing.Blogger.Post[] getRecentPosts(string appKey, string blogid, string username, string password, int numberOfPosts)
        {
            throw new NotImplementedException();
        }

        public string getTemplate(string appKey, string blogid, string username, string password, string templateType)
        {
            throw new NotImplementedException();
        }

        public CookComputing.Blogger.UserInfo getUserInfo(string appKey, string username, string password)
        {
            throw new NotImplementedException();
        }

        public BlogInfo[] getUsersBlogs(string appKey, string username, string password)
        {
            CheckArguments();
            CheckUserPassword(username, password);

            string folderName = Context.Request.QueryString["Folder"];

            List<BlogInfo> blogs = new List<BlogInfo>();

            string applicationUrl = "http://localhost:10655/kooboo";

            IEverestCmsDataContext dataContext = EverestCmsEntities.GetDataContext();
            var folders = dataContext.QueryFolders(Application, FolderType.TextContent);
            if (!string.IsNullOrEmpty(folderName))
            {
                folders = folders.Where(f => f.FolderName.Contains(folderName));
            }
            PermissionService permissionService = new PermissionService();

            foreach (var folder in folders)
            {
                if (permissionService.IsAllowedEditContent(username, folder.UUID, Application, ActionType.View))
                    blogs.Add(new BlogInfo() { blogid = folder.UUID.ToString(), blogName = folder.FolderName, url = applicationUrl });
            }
            return blogs.ToArray();
        }

        public string newPost(string appKey, string blogid, string username, string password, string content, bool publish)
        {
            throw new NotImplementedException();
        }

        public bool setTemplate(string appKey, string blogid, string username, string password, string template, string templateType)
        {
            throw new NotImplementedException();
        }

        #endregion

        #region IMetaWeblog Members

        public object editPost(string postid, string username, string password, CookComputing.MetaWeblog.Post post, bool publish)
        {
            CheckArguments();
            CheckUserPassword(username, password);

            Guid contentUUID = new Guid(postid);
            TextContentService textContentService = new TextContentService();

            var oldValue = textContentService.QueryContent(contentUUID, username);

            NameValueCollection newValues = new NameValueCollection();
            newValues["UserName"] = username;
            newValues["Title"] = post.title;
            newValues["UserKey"] = oldValue["UserKey"].ToString();
            newValues["Body"] = post.description;
            newValues["Published"] = publish.ToString();
            if (post.categories!=null)
            {
                newValues["ReferenceContents"] = string.Join(",", GetCategoryIds(oldValue["FolderUUID"].ToString(), post.categories));
            }            

            var content = textContentService.UpdateContent(contentUUID, newValues, username, null, false);

            return content.UUID.ToString();
        }

        CategoryInfo[] IMetaWeblog.getCategories(string blogid, string username, string password)
        {
            CheckArguments();
            CheckUserPassword(username, password);

            List<CookComputing.MetaWeblog.CategoryInfo> categories = GetCategories(blogid);

            return categories.ToArray();
        }

        private List<CookComputing.MetaWeblog.CategoryInfo> GetCategories(string blogid)
        {
            List<CookComputing.MetaWeblog.CategoryInfo> categories = new List<CookComputing.MetaWeblog.CategoryInfo>();
            Guid folderUUID = new Guid(blogid);
            var schema = CachedData.GetSchemaByFolder(folderUUID);
            TextContentService textContentService = new TextContentService();

            foreach (var content in textContentService.GetCategories(Application, schema.UUID))
            {
                categories.Add(new CookComputing.MetaWeblog.CategoryInfo()
                {
                    categoryid = content["UUID"].ToString(),
                    title = content["Title"].ToString(),
                    description = content["Title"].ToString(),
                    htmlUrl = "",
                    rssUrl = ""
                });
            }
            return categories;
        }

        public CookComputing.MetaWeblog.Post getPost(string postid, string username, string password)
        {
            CheckArguments();
            CheckUserPassword(username, password);
            Guid contentUUID = new Guid(postid);
            CookComputing.MetaWeblog.Post post = GetPost(username, contentUUID);

            return post;
        }

        private static CookComputing.MetaWeblog.Post GetPost(string username, Guid contentUUID)
        {
            TextContentService textContentService = new TextContentService();

            var detail = textContentService.QueryContent(contentUUID, username);
            var body = detail.Keys.Contains("Body") ? detail["Body"].ToString() : "";
            //var contentCategories = detail["ReferenceContents"].ToString().Split(',');
            CookComputing.MetaWeblog.Post post = new CookComputing.MetaWeblog.Post()
            {
                postid = detail["UUID"].ToString(),
                title = detail["Title"].ToString(),
                dateCreated = (DateTime)detail["PostDate"],
                description = body,
                categories = GetContentCategories(detail),
                userid = detail["UserName"].ToString()
            };
            return post;
        }
        private static string[] GetContentCategories(IDictionary<string, object> content)
        {
            List<string> categories = new List<string>();
            foreach (var value in content.Values)
            {
                if (value is RefContentSelect)
                {
                    categories.AddRange(((RefContentSelect)value).Title);
                }
            }
            return categories.ToArray();
        }

        public CookComputing.MetaWeblog.Post[] getRecentPosts(string blogid, string username, string password, int numberOfPosts)
        {
            CheckArguments();
            CheckUserPassword(username, password);

            List<CookComputing.MetaWeblog.Post> posts = new List<CookComputing.MetaWeblog.Post>();
            Guid folderUUID = new Guid(blogid);
            TextContentService textContentService = new TextContentService();

            int count;
            var contents = textContentService.QueryContents(folderUUID, "", new System.Collections.Specialized.NameValueCollection(), "", username, null, 1, numberOfPosts, out count);
            foreach (var content in contents)
            {
                posts.Add(GetPost(username, (Guid)content["UUID"]));
            }

            return posts.ToArray();
        }

        public string newPost(string blogid, string username, string password, CookComputing.MetaWeblog.Post post, bool publish)
        {
            CheckArguments();
            CheckUserPassword(username, password);

            Guid folderUUID = new Guid(blogid);
            TextContentService textContentService = new TextContentService();

            NameValueCollection values = new NameValueCollection();

            values["FolderUUID"] = blogid;
            values["UserName"] = username;
            values["Title"] = post.title;
            values["Body"] = post.description;
            values["Published"] = publish.ToString();
            if (post.categories != null)
            {
                values["ReferenceContents"] = string.Join(",", GetCategoryIds(blogid, post.categories));
            }
            var content = textContentService.AddContent(values, username, null);

            return content.UUID.ToString();
        }

        private string[] GetCategoryIds(string blogid, string[] categories)
        {
            if (categories == null)
            {
                return new string[0];
            }
            return GetCategories(blogid).Where(c => categories.Contains(c.title)).Select(c => c.categoryid).ToArray();
        }

        public UrlData newMediaObject(string blogid, string username, string password, FileData file)
        {
            CheckArguments();
            CheckUserPassword(username, password);

            var fileName = Path.GetFileName(file.name);
            string userContentFilePath = ContentFileManager.GetMetablogContentFilePath(username);
            string filePath = Path.Combine(userContentFilePath, fileName);
            UrlData urlData = new UrlData();

            Uri absoluteUri = new Uri(new Uri(Context.Request.Url.AbsoluteUri), UrlConvertor.AbsolutePathToAbsoluteUrl(StreamExtensions.SaveAs(file.bits, filePath, false)));

            urlData.url = absoluteUri.ToString();

            return urlData;

        }

        #endregion

    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.