Ejemplo n.º 1
0
        /// <summary>
        /// 获取文档
        /// </summary>
        /// <param name="postid"></param>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public Post getPost(string postid, string username, string password)
        {
            Post    post = default(Post);
            UserDto user;

            if ((user = ValidUser(username, password)) != null)
            {
                ArchiveDto a = ServiceCall.Instance.ArchiveService.GetArchiveById(this.siteId, int.Parse(postid));

                if (a.Id > 0)
                {
                    CategoryDto category     = a.Category;
                    string      categoryName = category.Name;

                    post = new Post
                    {
                        postid      = a.Id,                                   //编号
                        title       = a.Title,                                //标题
                        categories  = new string[] { categoryName },          //栏目
                        description = a.Content,                              //内容
                        userid      = a.PublisherId.ToString(),               //作者
                        source      = new Source {
                            name = a.Source
                        },                                                              //来源
                        link = String.Format(post_uri,                                  //文档链接地址
                                             String.IsNullOrEmpty(a.Alias) ? a.StrId : a.Alias),
                    };
                }
            }
            return(post);
        }
Ejemplo n.º 2
0
        public string newPost(string blogid, string username, string password, CookComputing.MetaWeblog.Post post, bool publish)
        {
            CheckUserPassword(username, password);

            var folder = (new TextFolder(Repository, FolderHelper.SplitFullName(blogid))).AsActual();

            var values = new NameValueCollection();

            values["title"]       = post.title;
            values["description"] = post.description;
            values["body"]        = post.description;
            values["published"]   = publish.ToString();
            var content = ServiceFactory.GetService <TextContentManager>().Add(Repository, folder, values, null
                                                                               , GetCategories(folder, post.categories), username);

            var categories = GetCategories(folder, post.categories).ToArray();

            if (categories.Length > 0)
            {
                ServiceFactory.GetService <TextContentManager>().AddCategories(Repository, (TextContent)content, categories);
            }


            return(MetaWeblogHelper.CompositePostId((TextContent)content));
        }
Ejemplo n.º 3
0
        private void updateCategories(Document doc, Post post, Channel userChannel)
        {
            if (userChannel.FieldCategoriesAlias != null && userChannel.FieldCategoriesAlias != "")
            {
                ContentType  blogPostType = ContentType.GetByAlias(userChannel.DocumentTypeAlias);
                PropertyType categoryType = blogPostType.getPropertyType(userChannel.FieldCategoriesAlias);

                String[]            categories    = post.categories;
                string              categoryValue = "";
                interfaces.IUseTags tags          = UseTags(categoryType);
                if (tags != null)
                {
                    tags.RemoveTagsFromNode(doc.Id);
                    for (int i = 0; i < categories.Length; i++)
                    {
                        tags.AddTagToNode(doc.Id, categories[i]);
                    }
                }
                else
                {
                    for (int i = 0; i < categories.Length; i++)
                    {
                        PreValue pv = new PreValue(categoryType.DataTypeDefinition.Id, categories[i]);
                        categoryValue += pv.Id + ",";
                    }
                }
                if (categoryValue.Length > 0)
                {
                    categoryValue = categoryValue.Substring(0, categoryValue.Length - 1);
                }

                doc.getProperty(userChannel.FieldCategoriesAlias).Value = categoryValue;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 创建新文档
        /// </summary>
        /// <param name="blogid"></param>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <param name="post"></param>
        /// <param name="publish"></param>
        /// <returns></returns>
        public string newPost(string blogid, string username, string password, Post post, bool publish)
        {
            UserDto user;

            if ((user = ValidUser(username, password)) != null)
            {
                int    categoryId   = 0;
                string categoryName = post.categories[0];

                //根据提交的栏目设置栏目ID
                if (post.categories.Length != 0)
                {
                    var category = ServiceCall.Instance.SiteService.GetCategoryByName(this.siteId, categoryName);
                    if (category.Id > 0)
                    {
                        categoryId = category.Id;
                    }
                }

                //如果栏目ID仍然为0,则设置第一个栏目
                if (categoryId == 0)
                {
                    throw new Exception("请选择分类!");
                }

                string flag = ArchiveFlag.GetFlagString(false, false, publish, false, null);

                ArchiveDto dto = new ArchiveDto
                {
                    Title       = post.title,
                    PublisherId = user.Id,
                    Outline     = String.Empty,
                    Content     = post.description,
                    CreateDate  = post.dateCreated,
                    Source      = post.source.name,
                    ViewCount   = 1,
                    Flags       = flag,
                    Tags        = String.Empty
                };
                dto.Category = new CategoryDto {
                    Id = categoryId
                };

                return(ServiceCall.Instance.ArchiveService.SaveArchive(this.siteId, dto).ToString());;

                //执行监视服务

                /*
                 * try
                 * {
                 *  WatchService.PublishArchive(abll.GetArchiveByID(id));
                 * }
                 * catch { }
                 */
            }

            return(null);
        }
Ejemplo n.º 5
0
        public string newPost(
            string blogid,
            string username,
            string password,
            Post post,
            bool publish)
        {
            if (validateUser(username, password))
            {
                Channel  userChannel = new Channel(username);
                User     u           = new User(username);
                Document doc         =
                    Document.MakeNew(HttpContext.Current.Server.HtmlDecode(post.title),
                                     DocumentType.GetByAlias(userChannel.DocumentTypeAlias), u,
                                     userChannel.StartNode);


                // Excerpt
                if (userChannel.FieldExcerptAlias != null && userChannel.FieldExcerptAlias != "")
                {
                    doc.getProperty(userChannel.FieldExcerptAlias).Value = removeLeftUrl(post.mt_excerpt);
                }


                // Description
                if (UmbracoSettings.TidyEditorContent)
                {
                    doc.getProperty(userChannel.FieldDescriptionAlias).Value = library.Tidy(removeLeftUrl(post.description), false);
                }
                else
                {
                    doc.getProperty(userChannel.FieldDescriptionAlias).Value = removeLeftUrl(post.description);
                }

                // Categories
                updateCategories(doc, post, userChannel);

                // check release date
                if (post.dateCreated.Year > 0001)
                {
                    publish         = false;
                    doc.ReleaseDate = post.dateCreated;
                }

                if (publish)
                {
                    doc.Publish(new User(username));
                    library.PublishSingleNode(doc.Id);
                }
                return(doc.Id.ToString());
            }
            else
            {
                throw new ArgumentException("Error creating post");
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 编辑文档
        /// </summary>
        /// <param name="postid"></param>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <param name="post"></param>
        /// <param name="publish"></param>
        /// <returns></returns>
        public object editPost(string postid, string username, string password, Post post, bool publish)
        {
            UserDto user;

            if ((user = ValidUser(username, password)) != null)
            {
                ArchiveDto a = ServiceCall.Instance.ArchiveService.GetArchiveById(this.siteId, int.Parse(postid));
                if (a.Id > 0)
                {
                    //设置栏目
                    if (post.categories.Length != 0)
                    {
                        CategoryDto category = ServiceCall.Instance.SiteService.GetCategoryByName(this.siteId, post.categories[0]);

                        if (category.Id > 0)
                        {
                            a.Category = category;
                        }
                        else
                        {
                            return("");
                        }
                    }

                    a.Title       = post.title;
                    a.Content     = post.description;
                    a.PublisherId = user.Id;
                    a.Source      = !String.IsNullOrEmpty(post.source.name) ? post.source.name : a.Source;

                    //更新
                    ServiceCall.Instance.ArchiveService.SaveArchive(this.siteId, a);

                    //执行监视服务

                    /*
                     * try
                     * {
                     *  WatchService.UpdateArchive(a);
                     * }
                     * catch { }
                     */
                }
                else
                {
                    throw new XmlRpcFaultException(0, "文档不存在或已经被删除");
                }
            }
            return(null);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 获取历史文档
        /// </summary>
        /// <param name="blogid"></param>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <param name="numberOfPosts"></param>
        /// <returns></returns>
        public Post[] getRecentPosts(string blogid, string username, string password, int numberOfPosts)
        {
            Post[] posts;
            User   user;

            if ((user = ValidUser(username, password)) != null)
            {
                User usr = ubll.GetUser(username);

                int totalRecords, pages;

                string[,] flags = new string[, ] {
                    { ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.IsSystem), "" },
                    { ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.IsSpecial), "" },
                    { ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.Visible), "" },
                    { ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.AsPage), "" }
                };

                DataTable dt = ServiceCall.Instance.ArchiveService.GetPagedArchives(
                    this.siteId, null,
                    usr.Group == UserGroups.Master ? null : username, flags, null,
                    false, numberOfPosts, 1, out totalRecords, out pages);

                //如果返回的数量没有制定数多
                posts = new Post[dt.Rows.Count < numberOfPosts ? dt.Rows.Count : numberOfPosts];

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    posts[i] = new Post
                    {
                        postid      = dt.Rows[i]["id"].ToString(),                            //编号
                        title       = dt.Rows[i]["title"].ToString(),                         //标题
                        categories  = new string[] { dt.Rows[i]["cid"].ToString() },          //栏目
                        description = dt.Rows[i]["content"].ToString(),                       //内容
                        userid      = dt.Rows[i]["author"].ToString(),                        //作者
                        source      = new Source {
                            name = dt.Rows[i]["source"].ToString()
                        },                                                                          //来源
                        link = String.Format(post_uri,                                              //文档链接地址
                                             String.IsNullOrEmpty(dt.Rows[i]["aias"] as string) ?
                                             dt.Rows[i]["strid"].ToString() : dt.Rows[i]["alias"].ToString()),
                    };
                }

                return(posts);
            }
            return(null);
        }
Ejemplo n.º 8
0
        public object editPost(
            string postid,
            string username,
            string password,
            Post post,
            bool publish)
        {
            if (ValidateUser(username, password))
            {
                Channel  userChannel = new Channel(username);
                Document doc         = new Document(Convert.ToInt32(postid));


                doc.Text = HttpContext.Current.Server.HtmlDecode(post.title);

                // Excerpt
                if (userChannel.FieldExcerptAlias != null && userChannel.FieldExcerptAlias != "")
                {
                    doc.getProperty(userChannel.FieldExcerptAlias).Value = RemoveLeftUrl(post.mt_excerpt);
                }


                if (UmbracoConfig.For.UmbracoSettings().Content.TidyEditorContent)
                {
                    doc.getProperty(userChannel.FieldDescriptionAlias).Value = library.Tidy(RemoveLeftUrl(post.description), false);
                }
                else
                {
                    doc.getProperty(userChannel.FieldDescriptionAlias).Value = RemoveLeftUrl(post.description);
                }

                UpdateCategories(doc, post, userChannel);


                if (publish)
                {
                    doc.SaveAndPublish(new User(username));
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Constructor that copies the members from MetaWeblog post object.
 /// </summary>
 /// <param name="post"></param>
 public PostData(CookComputing.MetaWeblog.Post post)
 {
     dateCreated       = post.dateCreated;
     description       = post.description;
     title             = post.title;
     categories        = post.categories;
     enclosure         = post.enclosure;
     link              = post.link;
     permalink         = post.permalink;
     postid            = Convert.ToInt32(post.postid);
     source            = post.source;
     userid            = post.userid;
     mt_allow_comments = post.mt_allow_comments;
     mt_allow_pings    = post.mt_allow_pings;
     mt_convert_breaks = post.mt_convert_breaks;
     mt_text_more      = post.mt_text_more;
     mt_excerpt        = post.mt_excerpt;
 }
Ejemplo n.º 10
0
        public Post getPost(
            string postid,
            string username,
            string password)
        {
            if (ValidateUser(username, password))
            {
                Channel  userChannel = new Channel(username);
                Document d           = new Document(int.Parse(postid));
                Post     p           = new Post();
                p.title       = d.Text;
                p.description = d.getProperty(userChannel.FieldDescriptionAlias).Value.ToString();

                // Excerpt
                if (userChannel.FieldExcerptAlias != null && userChannel.FieldExcerptAlias != "")
                {
                    p.mt_excerpt = d.getProperty(userChannel.FieldExcerptAlias).Value.ToString();
                }

                // Categories
                if (userChannel.FieldCategoriesAlias != null && userChannel.FieldCategoriesAlias != "" &&
                    d.getProperty(userChannel.FieldCategoriesAlias) != null &&
                    d.getProperty(userChannel.FieldCategoriesAlias).Value != null &&
                    d.getProperty(userChannel.FieldCategoriesAlias).Value.ToString() != "")
                {
                    String   categories  = d.getProperty(userChannel.FieldCategoriesAlias).Value.ToString();
                    char[]   splitter    = { ',' };
                    String[] categoryIds = categories.Split(splitter);
                    p.categories = categoryIds;
                }

                p.postid      = postid;
                p.permalink   = library.NiceUrl(d.Id);
                p.dateCreated = d.CreateDateTime;
                p.link        = p.permalink;
                return(p);
            }
            else
            {
                throw new ArgumentException(string.Format("Error retriving post with id: '{0}'", postid));
            }
        }
Ejemplo n.º 11
0
        private static void UpdateCategories(Document doc, Post post, Channel userChannel)
        {
            if (userChannel.FieldCategoriesAlias != null && userChannel.FieldCategoriesAlias != "")
            {
                ContentType  blogPostType = ContentType.GetByAlias(userChannel.DocumentTypeAlias);
                PropertyType categoryType = blogPostType.getPropertyType(userChannel.FieldCategoriesAlias);

                String[]            categories    = post.categories;
                string              categoryValue = "";
                interfaces.IUseTags tags          = UseTags(categoryType);
                if (tags != null)
                {
                    tags.RemoveTagsFromNode(doc.Id);
                    for (int i = 0; i < categories.Length; i++)
                    {
                        tags.AddTagToNode(doc.Id, categories[i]);
                    }
                    //If the IUseTags provider manually set the property value to something on the IData interface then we should persist this
                    //code commented as for some reason, even though the IUseTags control is setting IData.Value it is null here
                    //could be a cache issue, or maybe it's a different instance of the IData or something, rather odd
                    //doc.getProperty(userChannel.FieldCategoriesAlias).Value = categoryType.DataTypeDefinition.DataType.Data.Value;

                    //Instead, set the document property to CSV of the tags - this WILL break custom editors for tags which don't adhere to the
                    //pseudo standard that the .Value of the property contains CSV tags.
                    doc.getProperty(userChannel.FieldCategoriesAlias).Value = string.Join(",", categories);
                }
                else
                {
                    for (int i = 0; i < categories.Length; i++)
                    {
                        PreValue pv = new PreValue(categoryType.DataTypeDefinition.Id, categories[i]);
                        categoryValue += pv.Id + ",";
                    }
                    if (categoryValue.Length > 0)
                    {
                        categoryValue = categoryValue.Substring(0, categoryValue.Length - 1);
                    }

                    doc.getProperty(userChannel.FieldCategoriesAlias).Value = categoryValue;
                }
            }
        }
Ejemplo n.º 12
0
        public object editPost(string postid, string username, string password, CookComputing.MetaWeblog.Post post, bool publish)
        {
            CheckUserPassword(username, password);
            string folderName;
            string userKey;
            string contentId  = MetaWeblogHelper.ParsePostId(postid, out folderName, out userKey);
            var    textFolder = new TextFolder(Repository, FolderHelper.SplitFullName(folderName));
            var    content    = textFolder.CreateQuery().WhereEquals("UUID", contentId).First();


            var values = new NameValueCollection();

            values["title"]       = post.title;
            values["description"] = post.description;
            values["body"]        = post.description;
            values["userKey"]     = userKey;
            values["published"]   = publish.ToString();

            ServiceFactory.GetService <TextContentManager>().Update(Repository, textFolder, content.UUID, values, username);


            var old_categories = GetCategories(textFolder, content);

            var removedCategories = old_categories.Where(it => !post.categories.Any(c => string.Compare(c, it, true) == 0));
            var addedCategories   = post.categories.Where(it => !old_categories.Any(c => string.Compare(c, it, true) == 0));

            var removed = GetCategories(textFolder, removedCategories).ToArray();

            if (removed.Length > 0)
            {
                ServiceFactory.GetService <TextContentManager>().RemoveCategories(Repository, (TextContent)content, removed);
            }

            var added = GetCategories(textFolder, addedCategories).ToArray();

            if (added.Length > 0)
            {
                ServiceFactory.GetService <TextContentManager>().AddCategories(Repository, (TextContent)content, added);
            }

            return(MetaWeblogHelper.CompositePostId(content));
        }
Ejemplo n.º 13
0
        public object editPost(
            string postid,
            string username,
            string password,
            Post post,
            bool publish)
        {
            if (validateUser(username, password))
            {
                Channel userChannel = new Channel(username);
                Document doc = new Document(Convert.ToInt32(postid));


                doc.Text = HttpContext.Current.Server.HtmlDecode(post.title);

                // Excerpt
                if (userChannel.FieldExcerptAlias != null && userChannel.FieldExcerptAlias != "")
                    doc.getProperty(userChannel.FieldExcerptAlias).Value = removeLeftUrl(post.mt_excerpt);

                if (UmbracoSettings.TidyEditorContent)
                    doc.getProperty(userChannel.FieldDescriptionAlias).Value = library.Tidy(removeLeftUrl(post.description), false);
                else
                    doc.getProperty(userChannel.FieldDescriptionAlias).Value = removeLeftUrl(post.description);

                updateCategories(doc, post, userChannel);


                if (publish)
                {
                    doc.Publish(new User(username));
                    library.UpdateDocumentCache(doc.Id);
                }
                return true;
            }
            else
            {
                return false;
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 获取文档
        /// </summary>
        /// <param name="postid"></param>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public Post getPost(string postid, string username, string password)
        {
            Post post = default(Post);
            User user;
            if ((user = ValidUser(username, password)) != null)
            {
                ArchiveDto a = ServiceCall.Instance.ArchiveService.GetArchiveById(this.siteId, int.Parse(postid));

                if (a.Id > 0)
                {
                    CategoryDto category = a.Category;
                    string categoryName = category.Name;

                    post = new Post
                    {
                        postid = a.Id,                                                  //编号
                        title = a.Title,                                                 //标题
                        categories = new string[] { categoryName },           //栏目
                        description = a.Content,                                         //内容
                        userid = a.Author,                                               //作者
                        source = new Source { name = a.Source },                        //来源
                        link = String.Format(post_uri,                                  //文档链接地址
                                        String.IsNullOrEmpty(a.Alias) ? a.StrId : a.Alias),

                    };

                }
            }
            return post;
        }
Ejemplo n.º 15
0
        /// <summary>
        /// 编辑文档
        /// </summary>
        /// <param name="postid"></param>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <param name="post"></param>
        /// <param name="publish"></param>
        /// <returns></returns>
        public object editPost(string postid, string username, string password, Post post, bool publish)
        {
            User user;
            if ((user = ValidUser(username, password)) != null)
            {
                ArchiveDto a = ServiceCall.Instance.ArchiveService.GetArchiveById(this.siteId, int.Parse(postid));
                if (a.Id > 0)
                {
                    //设置栏目
                    if (post.categories.Length != 0)
                    {
                        CategoryDto category = ServiceCall.Instance.SiteService.GetCategoryByName(this.siteId, post.categories[0]);

                        if (category.Id > 0) a.Category = category;
                        else return "";
                    }

                    a.Title = post.title;
                    a.Content = post.description;
                    a.Author = username;
                    a.Source = !String.IsNullOrEmpty(post.source.name) ? post.source.name : a.Source;

                    //更新
                    ServiceCall.Instance.ArchiveService.SaveArchive(this.siteId, a);

                    //执行监视服务
                    /*
                    try
                    {
                        WatchService.UpdateArchive(a);
                    }
                    catch { }
                     */
                }
                else
                {
                    throw new XmlRpcFaultException(0, "文档不存在或已经被删除");
                }

            }
            return null;
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Inserts a post.
        /// </summary>
        /// <param name="serviceUrl">The service URL of the blog.</param>
        /// <param name="blogId">The blog Id.</param>
        /// <param name="username">The blog username.</param>
        /// <param name="password">The blog password.</param>
        /// <param name="title">The post title.</param>
        /// <param name="content">The post content.</param>
        /// <param name="authorid">The post author id.</param>
        /// <param name="dateCreated">The post creation date.</param>
        /// <param name="categories">The post categories.</param>
        /// <returns>Post object that was created by the server.</returns>
        public Post InsertPost(string serviceUrl, string blogId, string username, 
            string password, string title, string content,
            string authorid, DateTime dateCreated,
            List<string> categories)
        {
            Post results;
             String postResult;
             Post TestPost;

             IMetaWeblog proxy = (IMetaWeblog)XmlRpcProxyGen.Create(typeof(IMetaWeblog));
             XmlRpcClientProtocol cp = (XmlRpcClientProtocol)proxy;
             cp.Url = serviceUrl;

             try
             {
            TestPost = new Post();
            TestPost.dateCreated = dateCreated;
            TestPost.userid = authorid;
            TestPost.title = title;
            TestPost.description = content;
            TestPost.categories = categories.ToArray();

            postResult = proxy.newPost(blogId, username, password, TestPost, true);

            if (!String.IsNullOrEmpty(postResult))
            {
               results = proxy.getPost(postResult, username, password);
            }
            else
            {
               throw new Exception("Post not created.");
            }
             }
             catch (XmlRpcFaultException fex)
             {
            throw fex;
             }
             catch (Exception ex)
             {
            throw ex;
             }

             return results;
        }
Ejemplo n.º 17
0
        private void updateCategories(Document doc, Post post, Channel userChannel)
        {
            if (userChannel.FieldCategoriesAlias != null && userChannel.FieldCategoriesAlias != "")
            {
                ContentType blogPostType = ContentType.GetByAlias(userChannel.DocumentTypeAlias);
                PropertyType categoryType = blogPostType.getPropertyType(userChannel.FieldCategoriesAlias);

                String[] categories = post.categories;
                string categoryValue = "";
                interfaces.IUseTags tags = UseTags(categoryType);
                if (tags != null)
                {
                    tags.RemoveTagsFromNode(doc.Id);
                    for (int i = 0; i < categories.Length; i++)
                    {
                        tags.AddTagToNode(doc.Id, categories[i]);
                    }

                }
                else
                {
                    for (int i = 0; i < categories.Length; i++)
                    {
                        PreValue pv = new PreValue(categoryType.DataTypeDefinition.Id, categories[i]);
                        categoryValue += pv.Id + ",";
                    }
                }
                if (categoryValue.Length > 0)
                    categoryValue = categoryValue.Substring(0, categoryValue.Length - 1);

                doc.getProperty(userChannel.FieldCategoriesAlias).Value = categoryValue;
            }
        }
        public Post getPost(
            string postid,
            string username,
            string password)
        {
            if (validateUser(username, password))
            {
                Channel userChannel = new Channel(username);
                Document d = new Document(int.Parse(postid));
                Post p = new Post();
                p.title = d.Text;
                p.description = d.getProperty(userChannel.FieldDescriptionAlias).Value.ToString();

                // Excerpt
                if (userChannel.FieldExcerptAlias != null && userChannel.FieldExcerptAlias != "")
                    p.mt_excerpt = d.getProperty(userChannel.FieldExcerptAlias).Value.ToString();

                // Categories
                if (userChannel.FieldCategoriesAlias != null && userChannel.FieldCategoriesAlias != "" &&
                    d.getProperty(userChannel.FieldCategoriesAlias) != null &&
                    d.getProperty(userChannel.FieldCategoriesAlias).Value != null &&
                    d.getProperty(userChannel.FieldCategoriesAlias).Value.ToString() != "")
                {
                    String categories = d.getProperty(userChannel.FieldCategoriesAlias).Value.ToString();
                    char[] splitter = { ',' };
                    String[] categoryIds = categories.Split(splitter);
                    p.categories = categoryIds;
                }

                p.postid = postid;
                p.permalink = library.NiceUrl(d.Id);
                p.dateCreated = d.CreateDateTime;
                p.link = p.permalink;
                return p;
            }
            else
                throw new ArgumentException(string.Format("Error retriving post with id: '{0}'", postid));
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Inserts a test post.
        /// </summary>
        /// <param name="serviceUrl">The service URL to connect to.</param>
        /// <param name="blogId">The blog Id to login with.</param>
        /// <param name="username">The username to login with.</param>
        /// <param name="password">The password to login with.</param>
        /// <returns>Message indicating success or failure.</returns>
        /// <history>
        /// Sean Patterson    11/3/2010   [Created]
        /// </history>
        public string InsertSamplePost(string serviceUrl, string blogId,
            string username, string password)
        {
            String Results;
             String postResult;
             Post TestPost;
             Post ReturnPost;

             IMetaWeblog proxy = (IMetaWeblog)XmlRpcProxyGen.Create(typeof(IMetaWeblog));
             XmlRpcClientProtocol cp = (XmlRpcClientProtocol)proxy;
             cp.Url = serviceUrl;

             try
             {
               TestPost = new Post();
               TestPost.categories = new string[] {"Cool Category"};
               TestPost.dateCreated = DateTime.Now;
               TestPost.userid = username;
               TestPost.title = "Cool new XML-RPC test!";
               TestPost.description = "This is the main body of the post. " +
                                      "It has lots of cool things here to " +
                                      "test the migration I'm about to do.";

               postResult = proxy.newPost(blogId, username, password, TestPost, true);

               if (!String.IsNullOrEmpty(postResult))
               {
                  ReturnPost = proxy.getPost(postResult, username, password);

                  Results = "Success! Post Id = " + ReturnPost.postid
                            + Environment.NewLine +
                            "Link to post is: " + ReturnPost.link;
               }
               else
               {
                  Results = "Fail. No new post.";
               }
             }
             catch (XmlRpcFaultException fex)
             {
               Results = "XML-RPC error connecting to server: " + fex.ToString();
             }
             catch (Exception ex)
             {
               Results = "General error connecting to server: " + ex.ToString();
             }

             return Results;
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Retrieves a blog post.
        /// </summary>
        /// <param name="serviceUrl">The service URL to connect to.</param>
        /// <param name="postId">The post Id to retrieve.</param>
        /// <param name="username">The username to login with.</param>
        /// <param name="password">The password to login with.</param>
        /// <returns>List collection of posts.</returns>
        /// <history>
        /// Sean Patterson    11/7/2010   [Created]
        /// </history>
        public Post GetPost(string serviceUrl, int postId, string username, 
            string password)
        {
            Post results = new Post();

             IMetaWeblog proxy = (IMetaWeblog)XmlRpcProxyGen.Create(typeof(IMetaWeblog));
             XmlRpcClientProtocol cp = (XmlRpcClientProtocol)proxy;
             cp.Url = serviceUrl;

             try
             {
            results = proxy.getPost(postId.ToString(), username, password);
             }
             catch (XmlRpcFaultException fex)
             {
               throw fex;
             }
             catch (Exception ex)
             {
               throw ex;
             }

             return results;
        }
        public string newPost(
            string blogid,
            string username,
            string password,
            Post post,
            bool publish)
        {
            if (validateUser(username, password))
            {
                Channel userChannel = new Channel(username);
                User u = new User(username);
                Document doc =
                    Document.MakeNew(HttpContext.Current.Server.HtmlDecode(post.title),
                                     DocumentType.GetByAlias(userChannel.DocumentTypeAlias), u,
                                     userChannel.StartNode);


                // Excerpt
                if (userChannel.FieldExcerptAlias != null && userChannel.FieldExcerptAlias != "")
                    doc.getProperty(userChannel.FieldExcerptAlias).Value = removeLeftUrl(post.mt_excerpt);


                // Description
                if (UmbracoSettings.TidyEditorContent)
                    doc.getProperty(userChannel.FieldDescriptionAlias).Value = library.Tidy(removeLeftUrl(post.description), false);
                else
                    doc.getProperty(userChannel.FieldDescriptionAlias).Value = removeLeftUrl(post.description);

                // Categories
                updateCategories(doc, post, userChannel);

                // check release date
                if (post.dateCreated.Year > 0001)
                {
                    publish = false;
                    doc.ReleaseDate = post.dateCreated;
                }

                if (publish)
                {
                    doc.SaveAndPublish(new User(username));
                }
                return doc.Id.ToString();
            }
            else
                throw new ArgumentException("Error creating post");
        }
Ejemplo n.º 22
0
        public Post[] getRecentPosts(
            string blogid,
            string username,
            string password,
            int numberOfPosts)
        {
            if (ValidateUser(username, password))
            {
                ArrayList blogPosts        = new ArrayList();
                ArrayList blogPostsObjects = new ArrayList();

                User    u           = new User(username);
                Channel userChannel = new Channel(u.Id);


                Document rootDoc;
                if (userChannel.StartNode > 0)
                {
                    rootDoc = new Document(userChannel.StartNode);
                }
                else
                {
                    if (u.StartNodeId == -1)
                    {
                        rootDoc = Document.GetRootDocuments()[0];
                    }
                    else
                    {
                        rootDoc = new Document(u.StartNodeId);
                    }
                }

                //store children array here because iterating over an Array object is very inneficient.
                var c = rootDoc.Children;
                foreach (Document d in c)
                {
                    int count = 0;
                    blogPosts.AddRange(
                        findBlogPosts(userChannel, d, u.Name, ref count, numberOfPosts, userChannel.FullTree));
                }

                blogPosts.Sort(new DocumentSortOrderComparer());

                foreach (Object o in blogPosts)
                {
                    Document d = (Document)o;
                    Post     p = new Post();
                    p.dateCreated = d.CreateDateTime;
                    p.userid      = username;
                    p.title       = d.Text;
                    p.permalink   = library.NiceUrl(d.Id);
                    p.description = d.getProperty(userChannel.FieldDescriptionAlias).Value.ToString();
                    p.link        = library.NiceUrl(d.Id);
                    p.postid      = d.Id.ToString();

                    if (userChannel.FieldCategoriesAlias != null && userChannel.FieldCategoriesAlias != "" &&
                        d.getProperty(userChannel.FieldCategoriesAlias) != null &&
                        d.getProperty(userChannel.FieldCategoriesAlias).Value != null &&
                        d.getProperty(userChannel.FieldCategoriesAlias).Value.ToString() != "")
                    {
                        String   categories  = d.getProperty(userChannel.FieldCategoriesAlias).Value.ToString();
                        char[]   splitter    = { ',' };
                        String[] categoryIds = categories.Split(splitter);
                        p.categories = categoryIds;
                    }

                    // Excerpt
                    if (userChannel.FieldExcerptAlias != null && userChannel.FieldExcerptAlias != "")
                    {
                        p.mt_excerpt = d.getProperty(userChannel.FieldExcerptAlias).Value.ToString();
                    }


                    blogPostsObjects.Add(p);
                }


                return((Post[])blogPostsObjects.ToArray(typeof(Post)));
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 23
0
        /// <summary>
        /// 获取历史文档
        /// </summary>
        /// <param name="blogid"></param>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <param name="numberOfPosts"></param>
        /// <returns></returns>
        public Post[] getRecentPosts(string blogid, string username, string password, int numberOfPosts)
        {
            Post[] posts;
            User user;
            if ((user = ValidUser(username, password)) != null)
            {
                User usr = ubll.GetUser(username);

                int totalRecords, pages;

                string[,] flags = new string[,]{
                {ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.IsSystem),""},
                {ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.IsSpecial),""},
                {ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.Visible),""},
                {ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.AsPage),""}
                };

                DataTable dt = ServiceCall.Instance.ArchiveService.GetPagedArchives(
                    this.siteId, null,
                    usr.Group == UserGroups.Master ? null : username, flags, null,
                    false, numberOfPosts, 1, out totalRecords, out pages);

                //如果返回的数量没有制定数多
                posts = new Post[dt.Rows.Count < numberOfPosts ? dt.Rows.Count : numberOfPosts];

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    posts[i] = new Post
                    {
                        postid = dt.Rows[i]["id"].ToString(),                                       //编号
                        title = dt.Rows[i]["title"].ToString(),                                     //标题
                        categories = new string[] { dt.Rows[i]["cid"].ToString() },           //栏目
                        description = dt.Rows[i]["content"].ToString(),                             //内容
                        userid = dt.Rows[i]["author"].ToString(),                                     //作者
                        source = new Source { name = dt.Rows[i]["source"].ToString() },             //来源
                        link = String.Format(post_uri,                                              //文档链接地址
                                       String.IsNullOrEmpty(dt.Rows[i]["aias"] as string) ?
                                       dt.Rows[i]["strid"].ToString() : dt.Rows[i]["alias"].ToString()),

                    };
                }

                return posts;
            }
            return null;
        }
Ejemplo n.º 24
0
        /// <summary>
        /// 创建新文档
        /// </summary>
        /// <param name="blogid"></param>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <param name="post"></param>
        /// <param name="publish"></param>
        /// <returns></returns>
        public string newPost(string blogid, string username, string password, Post post, bool publish)
        {
            User user;
            if ((user = ValidUser(username, password)) != null)
            {
                int categoryId = 0;
                string categoryName = post.categories[0];

                //根据提交的栏目设置栏目ID
                if (post.categories.Length != 0)
                {
                    var category = ServiceCall.Instance.SiteService.GetCategoryByName(this.siteId, categoryName);
                    if (category.Id > 0) categoryId = category.Id;
                }

                //如果栏目ID仍然为0,则设置第一个栏目
                if (categoryId == 0)
                {
                    throw new Exception("请选择分类!");
                }

                string flag = ArchiveFlag.GetFlagString(false, false, publish, false, null);

                ArchiveDto dto = new ArchiveDto
                {
                    Title = post.title,
                    Author = username,
                    Outline = String.Empty,
                    Content = post.description,
                    CreateDate = post.dateCreated,
                    Source = post.source.name,
                    ViewCount = 1,
                    Flags = flag,
                    Tags = String.Empty
                };
                dto.Category = new CategoryDto { Id = categoryId };

                return ServiceCall.Instance.ArchiveService.SaveArchive(this.siteId, dto).ToString(); ;

                //执行监视服务
                /*
                try
                {
                    WatchService.PublishArchive(abll.GetArchiveByID(id));
                }
                catch { }
                 */
            }

            return null;
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Inserts a post.
        /// </summary>
        /// <param name="serviceUrl">The service URL of the blog.</param>
        /// <param name="blogId">The blog Id.</param>
        /// <param name="username">The blog username.</param>
        /// <param name="password">The blog password.</param>
        /// <param name="postItem">The post object.</param>
        /// <returns>Post object that was created by the server.</returns>
        public Post InsertPost(string serviceUrl, string blogId, string username, 
            string password, Post postItem)
        {
            Post results;
             Post tempPost;
             String postResult;

             IMetaWeblog proxy = (IMetaWeblog)XmlRpcProxyGen.Create(typeof(IMetaWeblog));
             XmlRpcClientProtocol cp = (XmlRpcClientProtocol)proxy;
             cp.Url = serviceUrl;
             cp.NonStandard = XmlRpcNonStandard.All;

             try
             {
            tempPost = new Post();
            tempPost.dateCreated = postItem.dateCreated;
            tempPost.userid = username;
            tempPost.title = postItem.title;
            tempPost.description = postItem.description;
            tempPost.categories = postItem.categories;

            postResult = proxy.newPost(blogId, username, password, tempPost, true);

            if (!String.IsNullOrEmpty(postResult))
            {
               results = proxy.getPost(postResult, username, password);
            }
            else
            {
               throw new Exception("Post not created.");
            }
             }
             catch (XmlRpcFaultException fex)
             {
            throw fex;
             }
             catch (Exception ex)
             {
            throw ex;
             }

             return results;
        }
        public Post[] getRecentPosts(
            string blogid,
            string username,
            string password,
            int numberOfPosts)
        {
            if (validateUser(username, password))
            {
                ArrayList blogPosts = new ArrayList();
                ArrayList blogPostsObjects = new ArrayList();

                User u = new User(username);
                Channel userChannel = new Channel(u.Id);


                Document rootDoc;
                if (userChannel.StartNode > 0)
                    rootDoc = new Document(userChannel.StartNode);
                else
                {
                    if (u.StartNodeId == -1)
                    {
                        rootDoc = Document.GetRootDocuments()[0];
                    }
                    else
                    {
                        rootDoc = new Document(u.StartNodeId);
                    }
                }

                //store children array here because iterating over an Array object is very inneficient.
                var c = rootDoc.Children;
                foreach (Document d in c)
                {
                    int count = 0;
                    blogPosts.AddRange(
                        findBlogPosts(userChannel, d, u.Name, ref count, numberOfPosts, userChannel.FullTree));
                }

                blogPosts.Sort(new DocumentSortOrderComparer());

                foreach (Object o in blogPosts)
                {
                    Document d = (Document)o;
                    Post p = new Post();
                    p.dateCreated = d.CreateDateTime;
                    p.userid = username;
                    p.title = d.Text;
                    p.permalink = library.NiceUrl(d.Id);
                    p.description = d.getProperty(userChannel.FieldDescriptionAlias).Value.ToString();
                    p.link = library.NiceUrl(d.Id);
                    p.postid = d.Id.ToString();

                    if (userChannel.FieldCategoriesAlias != null && userChannel.FieldCategoriesAlias != "" &&
                        d.getProperty(userChannel.FieldCategoriesAlias) != null &&
                        d.getProperty(userChannel.FieldCategoriesAlias).Value != null &&
                        d.getProperty(userChannel.FieldCategoriesAlias).Value.ToString() != "")
                    {
                        String categories = d.getProperty(userChannel.FieldCategoriesAlias).Value.ToString();
                        char[] splitter = { ',' };
                        String[] categoryIds = categories.Split(splitter);
                        p.categories = categoryIds;
                    }

                    // Excerpt
                    if (userChannel.FieldExcerptAlias != null && userChannel.FieldExcerptAlias != "")
                        p.mt_excerpt = d.getProperty(userChannel.FieldExcerptAlias).Value.ToString();


                    blogPostsObjects.Add(p);
                }


                return (Post[])blogPostsObjects.ToArray(typeof(Post));
            }
            else
            {
                return null;
            }
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Updates the post.
        /// </summary>
        /// <param name="serviceUrl">The service URL of the blog.</param>
        /// <param name="username">The blog username.</param>
        /// <param name="password">The blog password.</param>
        /// <param name="postItem">The post object.</param>
        /// <returns>True/False indicating if post was updated.</returns>
        /// <remarks>
        /// It is assumed that the Post object already has the updated 
        /// details in it.
        /// </remarks>
        public bool UpdatePost(string serviceUrl, string username, string password,
            Post postItem)
        {
            object results;

             IMetaWeblog proxy = (IMetaWeblog)XmlRpcProxyGen.Create(typeof(IMetaWeblog));
             XmlRpcClientProtocol cp = (XmlRpcClientProtocol)proxy;
             cp.Url = serviceUrl;

             try
             {
            results = proxy.editPost(postItem.postid.ToString(), username, password,
                                     postItem, true);
             }
             catch (XmlRpcFaultException fex)
             {
            throw fex;
             }
             catch (Exception ex)
             {
            throw ex;
             }

             return (bool)results;
        }
        private void updateCategories(Document doc, Post post, Channel userChannel)
        {
            if (userChannel.FieldCategoriesAlias != null && userChannel.FieldCategoriesAlias != "")
            {
                ContentType blogPostType = ContentType.GetByAlias(userChannel.DocumentTypeAlias);
                PropertyType categoryType = blogPostType.getPropertyType(userChannel.FieldCategoriesAlias);

                String[] categories = post.categories;
                string categoryValue = "";
                interfaces.IUseTags tags = UseTags(categoryType);
                if (tags != null)
                {
                    tags.RemoveTagsFromNode(doc.Id);
                    for (int i = 0; i < categories.Length; i++)
                    {
                        tags.AddTagToNode(doc.Id, categories[i]);
                    }
                    //If the IUseTags provider manually set the property value to something on the IData interface then we should persist this
                    //code commented as for some reason, even though the IUseTags control is setting IData.Value it is null here
                    //could be a cache issue, or maybe it's a different instance of the IData or something, rather odd
                    //doc.getProperty(userChannel.FieldCategoriesAlias).Value = categoryType.DataTypeDefinition.DataType.Data.Value;

                    //Instead, set the document property to CSV of the tags - this WILL break custom editors for tags which don't adhere to the
                    //pseudo standard that the .Value of the property contains CSV tags. 
                    doc.getProperty(userChannel.FieldCategoriesAlias).Value = string.Join(",", categories);
                }
                else
                {
                    for (int i = 0; i < categories.Length; i++)
                    {
                        PreValue pv = new PreValue(categoryType.DataTypeDefinition.Id, categories[i]);
                        categoryValue += pv.Id + ",";
                    }
                    if (categoryValue.Length > 0)
                        categoryValue = categoryValue.Substring(0, categoryValue.Length - 1);

                    doc.getProperty(userChannel.FieldCategoriesAlias).Value = categoryValue;
                }
            }
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Publishes posts to the destination blog from a BlogML object.
        /// </summary>
        /// <history>
        /// Sean Patterson   11/15/2010   [Created]
        /// </history>
        public void ImportXMLPosts()
        {
            Services blogService = new Services();
               Post resultPost;
               Post newPost;
               StreamWriter swLog;
               Generator myGenerator = new Generator();
               BlogML.categoryRefType currCatRef;
               string categoryName;
               BlogML.postType currPost;
               List<string> categoryList;
               WorkerArgs args = new WorkerArgs();

               string LogFile = App.sourceBlog.serviceType + "_" +
                            App.destBlog.serviceType + "_Migration-" +
                            DateTime.Now.ToString("yyyy_MM_dd_hhMMss") + ".csv";

               // Load document.
               swLog = new StreamWriter(LogFile);
               swLog.WriteLine("Source Id, Source Link, Destination Id, " +
                           "Destination Link");

               swLog.Flush();

               try
               {
              args.status = "Migrating posts from " + App.sourceBlog.serviceType +
                            " to " + App.destBlog.serviceType;
              migrationWorker.ReportProgress(15, args);

              for (int i = 0; i <= App.sourceBlog.blogData.posts.Length - 1; i++)
              {
                 currPost = App.sourceBlog.blogData.posts[i];

                 if (App.sourceBlog.postsToMigrate.Contains(Convert.ToInt32(currPost.id)))
                 {
                    args.status = "Writing Post: " + string.Join(" ", currPost.title.Text);
                    migrationWorker.ReportProgress(20, args);

                    newPost = new Post();
                    newPost.title = string.Join(" ", currPost.title.Text);
                    newPost.dateCreated = currPost.datecreated;
                    newPost.userid = App.destBlog.username;
                    newPost.postid = currPost.id;
                    newPost.description = currPost.content.Value;
                    newPost.link = App.sourceBlog.rootUrl + currPost.posturl;

                    // Post Tags/Categories (currently only categories are implemented with BlogML
                    if (currPost.categories != null)
                    {
                       categoryList = new List<string>();

                       for (int j = 0; j <= currPost.categories.Length - 1; j++)
                       {
                          currCatRef = currPost.categories[j];
                          categoryName = myGenerator.GetCategoryById
                                                     (App.sourceBlog.blogData,
                                                      Convert.ToInt32(currCatRef.@ref));
                          categoryList.Add(categoryName);
                       }

                       newPost.categories = categoryList.ToArray();
                    }

                    resultPost = blogService.InsertPost
                                               (App.destBlog.serviceUrl, App.destBlog.blogId,
                                                App.destBlog.username, App.destBlog.password,
                                                newPost);

                    swLog.WriteLine(newPost.postid.ToString() + "," + newPost.link + "," +
                                    resultPost.postid.ToString() + "," + resultPost.link);

                    swLog.Flush();

                    // Rewrite posts can still be done "live" even if a BlogML
                    // file is being imported provided the serviceUrl details
                    // are provided.
                    if (App.rewritePosts)
                    {
                       Post updatePost = newPost;
                       string newUrl = "<a href='" + resultPost.link + "'>" + resultPost.link + "</a>";
                       string newMessage = App.rewriteMessage.Replace("[URL]", newUrl);
                       updatePost.description = newMessage;

                       blogService.UpdatePost(App.sourceBlog.serviceUrl,
                                              App.sourceBlog.username,
                                              App.sourceBlog.password,
                                              updatePost);
                    }
                 }
              }

              swLog.Close();
               }
               catch (Exception ex)
               {
              swLog.Flush();
              swLog.Close();
              MessageBox.Show("An error occurred migrating blog posts:" +
                              Environment.NewLine + Environment.NewLine +
                              ex.ToString() +
                              Environment.NewLine + Environment.NewLine +
                              "Please verify your settings and try migrating " +
                              "posts again.", "Error Migrating Posts",
                              MessageBoxButton.OK, MessageBoxImage.Error);

              migrationWorker.CancelAsync();
               }
        }