コード例 #1
0
 public static bool SafeDeleteLocalPost(string blogId, string postId)
 {
     try
     {
         PostEditorFile post = PostEditorFile.FindPost(PostEditorFile.RecentPostsFolder, blogId, postId);
         if (post != null)
         {
             post.Delete();
         }
         return(true);
     }
     catch (Exception ex)
     {
         DisplayableException displayableException = new DisplayableException(
             StringId.ErrorOccurredDeletingDraft, StringId.ErrorOccurredDeletingDraftDetails, ex.Message);
         DisplayableExceptionDisplayForm.Show(Win32WindowImpl.ForegroundWin32Window, displayableException);
         return(false);
     }
 }
コード例 #2
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);
                }
            }
        }