public EditPostVM(BlogPost post) : this()
        {
            _post = post.Clone();//We don't want to trash main window

            Title   = _post.Title;
            Content = _post.Content;
        }
        public static BlogPost SafeRetrievePost(PostInfo postInfo, int timeoutMs)
        {
            try
            {
                // null for invalid blogs
                if (!BlogSettings.BlogIdIsValid(postInfo.BlogId))
                {
                    return(null);
                }

                // null if the user can't authenticate
                using (Blog blog = new Blog(postInfo.BlogId))
                {
                    if (!blog.VerifyCredentials())
                    {
                        return(null);
                    }
                }

                // fire up the get post thread
                GetPostThread getPostThread = new GetPostThread(postInfo);
                Thread        thread        = ThreadHelper.NewThread(new ThreadStart(getPostThread.ThreadMain), "GetPostThread", true, false, true);
                thread.Start();

                // wait for it to complete
                thread.Join(timeoutMs);

                // return the post if we successfully got one
                BlogPost blogPost = getPostThread.BlogPost;
                if (blogPost != null)
                {
                    // Clone in case there are ever issues sharing these accross threads
                    // (not aware of any right now)
                    return(blogPost.Clone() as BlogPost);
                }
                else
                {
                    return(null);
                }
            }
            catch
            {
                return(null);
            }
        }
Example #3
0
        public BlogPost CloneBlogPostAsDraft(BlogPost blogPost, string userId)
        {
            var oldVersionInfo = _contentManager.GetVersionInfo(CONTENT_TYPE_BLOGPOST, blogPost.Id, blogPost.VersionCode).Result;

            if (oldVersionInfo == null)
            {
                throw new Exception($"Cannot clone BlogPost. BlogPost {blogPost.Id}, version {blogPost.VersionCode} does not exist.");
            }

            var versionInfo       = _contentManager.CreateDraftVersion(CONTENT_TYPE_BLOGPOST, blogPost.Id, userId).Result;
            var clonedContentTree = _contentManager.CloneContentTree(blogPost.ContentTreeId, versionInfo.VersionCode).Result;
            var clonedBlogPost    = blogPost.Clone();

            clonedBlogPost.Status        = versionInfo.Status;
            clonedBlogPost.VersionCode   = versionInfo.VersionCode;
            clonedBlogPost.ContentTreeId = clonedContentTree.Id;

            var versionData = ExtractVersionData(clonedBlogPost);

            _contentManager.SetVersionModelData(versionInfo, versionData).Wait();

            return(clonedBlogPost);
        }