예제 #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);
        }
 public BlogPostEditingContext(string destinationBlogId, BlogPost blogPost, PostEditorFile localFile, PostEditorFile autoSaveLocalFile, string serverSupportingFileDirectory, BlogPostSupportingFileStorage supportingFileStorage, BlogPostImageDataList imageDataList, BlogPostExtensionDataList extensionDataList, ISupportingFileService supportingFileService)
     : this(destinationBlogId, blogPost, localFile)
 {
     _serverSupportingFileDirectory = serverSupportingFileDirectory;
     _supportingFileStorage         = supportingFileStorage;
     _imageDataList     = imageDataList;
     _extensionDataList = extensionDataList;
     _fileService       = supportingFileService;
     _autoSaveLocalFile = autoSaveLocalFile;
 }
예제 #3
0
 public static void Update()
 {
     lock (_lock)
     {
         // Cache our recent drafts/post list
         _draftList = PostEditorFile.GetRecentPosts(PostEditorFile.DraftsFolder, new RecentPostRequest(MaxItems));
         _postList  = PostEditorFile.GetRecentPosts(PostEditorFile.RecentPostsFolder, new RecentPostRequest(MaxItems));
         _refresh   = false;
     }
 }
예제 #4
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);
 }
예제 #5
0
        private static void ExecutePostEditorFile(string filename, IDisposable splashScreen)
        {
            if (VerifyPostEditorFileIsEditable(filename))
            {
                // load the contents of the file
                PostEditorFile          postEditorFile = PostEditorFile.GetExisting(new FileInfo(filename));
                IBlogPostEditingContext editingContext = postEditorFile.Load();

                // launch the editing form (request post synchronization)
                PostEditorForm.Launch(editingContext, true, splashScreen);
            }
            else
            {
                if (splashScreen != null)
                {
                    splashScreen.Dispose();
                }
            }
        }
예제 #6
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);
     }
 }
예제 #7
0
 public static bool SafeDeleteLocalPost(FileInfo postFile)
 {
     try
     {
         PostEditorFile postEditorFile = PostEditorFile.GetExisting(postFile);
         if (postEditorFile != null)
         {
             postEditorFile.Delete();
         }
         return(true);
     }
     catch (Exception ex)
     {
         DisplayableException displayableException = new DisplayableException(
             StringId.ErrorOccurredDeletingDraft, StringId.ErrorOccurredDeletingDraftDetails, ex.Message);
         DisplayableExceptionDisplayForm.Show(Win32WindowImpl.ForegroundWin32Window, displayableException);
         return(false);
     }
 }
        public override bool DeletePost(string postId, bool isPage)
        {
            FileInfo postFile = new FileInfo(postId);
            PostInfo postInfo = PostEditorFile.GetPostInfo(postFile);

            if (postInfo != null)
            {
                bool deletedRemotePost = PostDeleteHelper.SafeDeleteRemotePost(postInfo.BlogId, postInfo.BlogPostId, postInfo.IsPage);
                if (!deletedRemotePost)
                {
                    DialogResult result = DisplayMessage.Show(MessageId.LocalDeleteConfirmation, isPage ? Res.Get(StringId.PageLower) : Res.Get(StringId.PostLower));
                    if (result == DialogResult.No)
                    {
                        return(false);
                    }
                }

                return(PostDeleteHelper.SafeDeleteLocalPost(postFile));
            }
            else
            {
                return(false);
            }
        }
        /// <summary>
        /// Launches a window as part of the starting of a process.
        /// </summary>
        private static void LaunchFirstInstance(IDisposable splashScreen, string[] args)
        {
            try
            {
                PostEditorFile.Initialize();

                MaybeMigrateSettings();

                // Make sure editor options are available before we launch the first instance.
                GlobalEditorOptions.Init(new OpenLiveWriterContentTarget(), new OpenLiveWriterSettingsProvider());

                // register file associations
                // Removing this call, as it causes exceptions in Vista
                // RegisterFileAssociations() ;
                Trace.WriteLine(String.Format(CultureInfo.InvariantCulture, "Starting {0} {1}", ApplicationEnvironment.ProductNameQualified, ApplicationEnvironment.ProductVersion));
                Trace.WriteLine(String.Format(CultureInfo.InvariantCulture, ".NET version: {0}", Environment.Version));
                // force initialization which may fail with error dialogs
                // and/or cause the whole application to not load
                if (PostEditorLifetimeManager.Initialize())
                {
                    initComplete = true;

                    // launch blogging form
                    ApplicationLauncher.LaunchBloggingForm(args, splashScreen, true);
                }

                ManualKeepalive.Wait(true);
            }
            catch (DirectoryException ex)
            {
                if (ex.MessageId != null)
                {
                    DisplayMessage.Show(ex.MessageId.Value);
                }
                else if (ex.Path != null)
                {
                    DisplayMessage.Show(MessageId.DirectoryFail, ex.Path);
                }
                else
                {
                    UnexpectedErrorMessage.Show(ex);
                }
            }
            catch (Exception ex)
            {
                UnexpectedErrorMessage.Show(ex);
            }
            finally
            {
                try
                {
                    // shut down
                    PostEditorLifetimeManager.Uninitialize();
                    TempFileManager.Instance.Dispose();

                    // Delete legacy post supporting files that might have
                    // been orphaned by a previous version of Writer. We
                    // now keep these in the temp directory like everything
                    // else
                    string legacyPostSupportingFiles = Path.Combine(ApplicationEnvironment.ApplicationDataDirectory, "PostSupportingFiles");
                    if (Directory.Exists(legacyPostSupportingFiles))
                    {
                        Directory.Delete(legacyPostSupportingFiles, true);
                    }
                }
                catch (Exception ex2)
                {
                    Trace.Fail(ex2.ToString());
                }
            }
        }
예제 #10
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);
                }
            }
        }
        public IBlogPostEditingContext GetPost(string postId)
        {
            PostEditorFile postEditorFile = PostEditorFile.GetExisting(new FileInfo(postId));

            return(postEditorFile.Load());
        }
 public PostInfo[] GetRecentPosts(RecentPostRequest request)
 {
     return(PostEditorFile.GetRecentPosts(_directory, request));
 }
 private BlogPostEditingContext(string destinationBlogId, BlogPost blogPost, PostEditorFile localFile)
 {
     _blogId    = destinationBlogId;
     _blogPost  = blogPost;
     _localFile = localFile;
 }
 public BlogPostEditingContext(string destinationBlogId, BlogPost blogPost, BlogPostExtensionDataList extensionDataList)
     : this(destinationBlogId, blogPost, PostEditorFile.CreateNew(PostEditorFile.DraftsFolder))
 {
     _extensionDataList = extensionDataList;
 }
 public BlogPostEditingContext(string destinationBlogId, BlogPost blogPost)
     : this(destinationBlogId, blogPost, PostEditorFile.CreateNew(PostEditorFile.DraftsFolder))
 {
 }
예제 #16
0
 public ContentEditorProxy(ContentEditorFactory factory, IContentEditorSite contentEditorSite, IInternetSecurityManager internetSecurityManager, string wysiwygHTML, string previewHTML, string pathToFile, int dlControlFlags)
 {
     ContentEditorProxyCore(factory, contentEditorSite, internetSecurityManager, wysiwygHTML, previewHTML, PostEditorFile.GetExisting(new FileInfo(pathToFile)).Load(false), new ContentEditorTemplateStrategy(), dlControlFlags, null);
 }