コード例 #1
0
        public ContentEditorProxy(ContentEditorFactory factory, IContentEditorSite contentEditorSite, IInternetSecurityManager internetSecurityManager, IHTMLDocument2 htmlDocument, HtmlInsertOptions options, int dlControlFlags, string color, string wpost)
        {
            string content = htmlDocument.body.innerHTML;

            htmlDocument.body.innerHTML = "{post-body}";
            string   wysiwygHTML                   = HTMLDocumentHelper.HTMLDocToString(htmlDocument);
            BlogPost documentToBeLoaded            = null;
            IBlogPostEditingContext editingContext = null;

            if (string.IsNullOrEmpty(wpost) || !File.Exists(wpost))
            {
                documentToBeLoaded = new BlogPost();
                editingContext     = new BlogPostEditingContext(ContentEditorAccountAdapter.AccountId,
                                                                documentToBeLoaded);
            }
            else
            {
                PostEditorFile wpostxFile = PostEditorFile.GetExisting(new FileInfo(wpost));
                editingContext = wpostxFile.Load(false);
                editingContext.BlogPost.Contents = "";
            }

            if (!string.IsNullOrEmpty(content))
            {
                delayedInsertOperations.Enqueue(new DelayedInsert(content, options));
            }

            ContentEditorProxyCore(factory, contentEditorSite, internetSecurityManager, wysiwygHTML, null, editingContext, new ContentEditorTemplateStrategy(), dlControlFlags, color);
        }
コード例 #2
0
 private void CreateBlogPost(string blogId, string postId, string title)
 {
     BlogPost post = new BlogPost();
     if (postId != null)
         post.Id = postId;
     post.Title = title;
     BlogPostEditingContext ctx = new BlogPostEditingContext(blogId, post);
     PostEditorFile file = PostEditorFile.CreateNew(tempDir);
     file.SaveBlogPost(ctx);
 }
コード例 #3
0
        public ContentEditorProxy(ContentEditorFactory factory, IContentEditorSite contentEditorSite, IInternetSecurityManager internetSecurityManager, IHTMLDocument2 htmlDocument, HtmlInsertOptions options, int dlControlFlags, string color, string wpost)
        {
            string content = htmlDocument.body.innerHTML;
            htmlDocument.body.innerHTML = "{post-body}";
            string wysiwygHTML = HTMLDocumentHelper.HTMLDocToString(htmlDocument);
            BlogPost documentToBeLoaded = null;
            IBlogPostEditingContext editingContext = null;

            if (string.IsNullOrEmpty(wpost) || !File.Exists(wpost))
            {
                documentToBeLoaded = new BlogPost();
                editingContext = new BlogPostEditingContext(ContentEditorAccountAdapter.AccountId,
                                                                               documentToBeLoaded);
            }
            else
            {
                PostEditorFile wpostxFile = PostEditorFile.GetExisting(new FileInfo(wpost));
                editingContext = wpostxFile.Load(false);
                editingContext.BlogPost.Contents = "";
            }

            if (!string.IsNullOrEmpty(content))
                delayedInsertOperations.Enqueue(new DelayedInsert(content, options));

            ContentEditorProxyCore(factory, contentEditorSite, internetSecurityManager, wysiwygHTML, null, editingContext, new ContentEditorTemplateStrategy(), dlControlFlags, color);

        }
コード例 #4
0
        /// <summary>
        /// Synchronize the local and remote copies of the recent post to create an
        /// edit context that combines the latest HTML content, etc. from the web
        /// with the local image editing context
        /// </summary>
        /// <param name="editingContext"></param>
        /// <returns></returns>
        public static IBlogPostEditingContext Synchronize(IWin32Window mainFrameWindow, IBlogPostEditingContext editingContext)
        {
            // reloading a local draft does not require synchronization
            if (editingContext.LocalFile.IsDraft && editingContext.LocalFile.IsSaved)
            {
                return(editingContext);
            }
            else if (editingContext.LocalFile.IsRecentPost)
            {
                // search for a draft of this post which has already been initialized for offline editing of the post
                // (we don't want to allow opening multiple local "drafts" of edits to the same remote post
                PostEditorFile postEditorFile = PostEditorFile.FindPost(PostEditorFile.DraftsFolder, editingContext.BlogId, editingContext.BlogPost.Id);
                if (postEditorFile != null)
                {
                    // return the draft
                    return(postEditorFile.Load());
                }

                //verify synchronization is supported for this blog service
                if (!SynchronizationSupportedForBlog(editingContext.BlogId))
                {
                    Debug.WriteLine("Post synchronization is not supported");
                    return(editingContext);
                }

                // opening local copy, try to marry with up to date post content on the server
                // (will return the existing post if an error occurs or the user cancels)
                BlogPost serverBlogPost = SafeGetPostFromServer(mainFrameWindow, editingContext.BlogId, editingContext.BlogPost);
                if (serverBlogPost != null)
                {
                    // if the server didn't return a post-id then replace it with the
                    // known post id
                    if (serverBlogPost.Id == String.Empty)
                    {
                        serverBlogPost.Id = editingContext.BlogPost.Id;
                    }

                    // merge trackbacks
                    MergeTrackbacksFromClient(serverBlogPost, editingContext.BlogPost);

                    // create new init params
                    IBlogPostEditingContext newEditingContext = new BlogPostEditingContext(
                        editingContext.BlogId,
                        serverBlogPost, // swap-in blog post from server
                        editingContext.LocalFile,
                        null,
                        editingContext.ServerSupportingFileDirectory,
                        editingContext.SupportingFileStorage,
                        editingContext.ImageDataList,
                        editingContext.ExtensionDataList,
                        editingContext.SupportingFileService);

                    SynchronizeLocalContentsWithEditingContext(editingContext.BlogPost.Contents,
                                                               editingContext.BlogPost.ContentsVersionSignature, newEditingContext);

                    // return new init params
                    return(newEditingContext);
                }
                else
                {
                    return(editingContext);
                }
            }
            else if (editingContext.LocalFile.IsSaved)
            {
                // Opening draft from somewhere other than the official drafts directory
                return(editingContext);
            }
            else
            {
                // opening from the server, first see if the user already has a draft
                // "checked out" for this post
                PostEditorFile postEditorFile = PostEditorFile.FindPost(PostEditorFile.DraftsFolder, editingContext.BlogId, editingContext.BlogPost.Id);
                if (postEditorFile != null)
                {
                    return(postEditorFile.Load());
                }

                // no draft, try to marry with local copy of recent post
                PostEditorFile recentPost = PostEditorFile.FindPost(
                    PostEditorFile.RecentPostsFolder,
                    editingContext.BlogId,
                    editingContext.BlogPost.Id);

                if (recentPost != null)
                {
                    // load the recent post
                    IBlogPostEditingContext newEditingContext = recentPost.Load();

                    string localContents          = newEditingContext.BlogPost.Contents;
                    string localContentsSignature = newEditingContext.BlogPost.ContentsVersionSignature;

                    // merge trackbacks from client
                    MergeTrackbacksFromClient(editingContext.BlogPost, newEditingContext.BlogPost);

                    // copy the BlogPost properties from the server (including merged trackbacks)
                    newEditingContext.BlogPost.CopyFrom(editingContext.BlogPost);

                    SynchronizeLocalContentsWithEditingContext(localContents, localContentsSignature, newEditingContext);

                    // return the init params
                    return(newEditingContext);
                }
                else
                {
                    return(editingContext);
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// Synchronize the local and remote copies of the recent post to create an
        /// edit context that combines the latest HTML content, etc. from the web
        /// with the local image editing context
        /// </summary>
        /// <param name="editingContext"></param>
        /// <returns></returns>
        public static IBlogPostEditingContext Synchronize(IWin32Window mainFrameWindow, IBlogPostEditingContext editingContext)
        {
            // reloading a local draft does not require syncronization
            if (editingContext.LocalFile.IsDraft && editingContext.LocalFile.IsSaved)
            {
                return editingContext;
            }
            else if (editingContext.LocalFile.IsRecentPost)
            {
                // search for a draft of this post which has already been initialized for offline editing of the post
                // (we don't want to allow opening multiple local "drafts" of edits to the same remote post
                PostEditorFile postEditorFile = PostEditorFile.FindPost(PostEditorFile.DraftsFolder, editingContext.BlogId, editingContext.BlogPost.Id);
                if (postEditorFile != null)
                {
                    // return the draft
                    return postEditorFile.Load();
                }

                //verify synchronization is supported for this blog service
                if (!SynchronizationSupportedForBlog(editingContext.BlogId))
                {
                    Debug.WriteLine("Post synchronization is not supported");
                    return editingContext;
                }

                // opening local copy, try to marry with up to date post content on the server
                // (will return the existing post if an error occurs or the user cancels)
                BlogPost serverBlogPost = SafeGetPostFromServer(mainFrameWindow, editingContext.BlogId, editingContext.BlogPost);
                if (serverBlogPost != null)
                {
                    // if the server didn't return a post-id then replace it with the
                    // known post id
                    if (serverBlogPost.Id == String.Empty)
                        serverBlogPost.Id = editingContext.BlogPost.Id;

                    // merge trackbacks
                    MergeTrackbacksFromClient(serverBlogPost, editingContext.BlogPost);

                    // create new init params
                    IBlogPostEditingContext newEditingContext = new BlogPostEditingContext(
                        editingContext.BlogId,
                        serverBlogPost, // swap-in blog post from server
                        editingContext.LocalFile,
                        null,
                        editingContext.ServerSupportingFileDirectory,
                        editingContext.SupportingFileStorage,
                        editingContext.ImageDataList,
                        editingContext.ExtensionDataList,
                        editingContext.SupportingFileService);

                    SynchronizeLocalContentsWithEditingContext(editingContext.BlogPost.Contents,
                                                                editingContext.BlogPost.ContentsVersionSignature, newEditingContext);

                    // return new init params
                    return newEditingContext;
                }
                else
                {
                    return editingContext;
                }
            }
            else if (editingContext.LocalFile.IsSaved)
            {
                // Opening draft from somewhere other than the official drafts directory
                return editingContext;
            }
            else
            {
                // opening from the server, first see if the user already has a draft
                // "checked out" for this post
                PostEditorFile postEditorFile = PostEditorFile.FindPost(PostEditorFile.DraftsFolder, editingContext.BlogId, editingContext.BlogPost.Id);
                if (postEditorFile != null)
                {
                    return postEditorFile.Load();
                }

                // no draft, try to marry with local copy of recent post
                PostEditorFile recentPost = PostEditorFile.FindPost(
                    PostEditorFile.RecentPostsFolder,
                    editingContext.BlogId,
                    editingContext.BlogPost.Id);

                if (recentPost != null)
                {
                    // load the recent post
                    IBlogPostEditingContext newEditingContext = recentPost.Load();

                    string localContents = newEditingContext.BlogPost.Contents;
                    string localContentsSignature = newEditingContext.BlogPost.ContentsVersionSignature;

                    // merge trackbacks from client
                    MergeTrackbacksFromClient(editingContext.BlogPost, newEditingContext.BlogPost);

                    // copy the BlogPost properties from the server (including merged trackbacks)
                    newEditingContext.BlogPost.CopyFrom(editingContext.BlogPost);

                    SynchronizeLocalContentsWithEditingContext(localContents, localContentsSignature, newEditingContext);

                    // return the init params
                    return newEditingContext;
                }
                else
                {
                    return editingContext;
                }
            }

        }