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);
            }
        }
        public MissingPostLinkForm(PostInfo postInfo)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            this.buttonOK.Text = Res.Get(StringId.OKButtonText);
            this.labelTitle.Text = Res.Get(StringId.MissingPostLinkCaption);
            this.labelExplanation.Text = Res.Get(StringId.MissingPostLinkExplanation);
            this.Text = Res.Get(StringId.MissingPostLinkTitle);

            this.labelTitle.Font = Res.GetFont(FontSize.XLarge, FontStyle.Bold);
            string entityName = postInfo.IsPage ? Res.Get(StringId.Page) : Res.Get(StringId.Post) ;
            string entityNameLower = postInfo.IsPage ? Res.Get(StringId.PageLower) : Res.Get(StringId.PostLower) ;

            labelTitle.Text = String.Format(CultureInfo.CurrentCulture, labelTitle.Text, entityName ) ;
            labelExplanation.Text = String.Format(CultureInfo.CurrentCulture, labelExplanation.Text, entityNameLower, ApplicationEnvironment.ProductName) ;
        }
        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;
            }
        }
        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);
            }
        }
        private string FormatDateString(PostInfo post)
        {
            if ( post.DateModifiedSpecified )
            {
                return post.PrettyDateDisplay ;
            }
            else
            {
                return String.Empty ;
            }

        }
 private string FormatToolTipText(PostInfo post)
 {
     if (post.BlogName != string.Empty)
         return String.Format(CultureInfo.CurrentCulture, Res.Get(StringId.PostLinkTooltipFormat), post.Title, post.BlogName, FormatDateString(post)) ;
     else
         return String.Format(CultureInfo.CurrentCulture, Res.Get(StringId.PostLinkTooltipFormatNoBlogTitle), post.Title, FormatDateString(post)) ;
 }
        public void SetPosts(PostInfo[] posts)
        {
            // copy posts into link labels
            for ( int i=0; i<MAX_POSTS; i++)
            {
                if ( posts.Length > i )
                {
                    string postType = posts[i].IsPage ? Res.Get(StringId.Page) : Res.Get(StringId.Post);
                    LinkLabels[i].AccessibleName = string.Format(CultureInfo.CurrentCulture, AccessibilityNameFormat, postType);
                    DeleteButtons[i].AccessibleName = string.Format(CultureInfo.CurrentCulture, Res.Get(StringId.DeleteSomething), LinkLabels[i].AccessibleName);

                    LinkLabels[i].Text = posts[i].Title ;
                    string tooltipText = FormatToolTipText(posts[i]);
                    LinkLabels[i].AccessibleDescription = tooltipText;
                    LinkLabels[i].LinkColor = ColorizedResources.Instance.SidebarLinkColor;
                    _toolTip.SetToolTip(LinkLabels[i], tooltipText);
                    LinkLabels[i].Tag = posts[i] ;
                    LinkLabels[i].Visible = true ;
                    _toolTip.SetToolTip(DeleteButtons[i], DeleteButtonToolTip);
                    DeleteButtons[i].Tag = posts[i] ;
                    DeleteButtons[i].Visible = true ;
                    DeleteButtons[i].AccessibleDescription = string.Format(CultureInfo.CurrentCulture, Res.Get(StringId.DeleteSomething), posts[i].Title);
                }
                else
                {
                    LinkLabels[i].Text = String.Empty ;
                    LinkLabels[i].Tag = null ;
                    LinkLabels[i].Visible = false ;
                    DeleteButtons[i].Tag = null ;
                    DeleteButtons[i].Visible = false ;
                }
            }

            // note whether we have posts to display
            _havePostsToDisplay = posts.Length > 0 ;
        }
Example #8
0
 public static PostInfo GetPostInfo(FileInfo file)
 {
     try
     {
         // get post
         using (Storage postStorage = new Storage(file.FullName, StorageMode.Open, false))
         {
             PostInfo postInfo = new PostInfo();
             postInfo.Id = file.FullName;
             postInfo.Title = ReadString(postStorage, POST_TITLE);
             postInfo.Permalink = SafeReadString(postStorage, POST_PERMALINK, String.Empty);
             postInfo.IsPage = SafeReadBoolean(postStorage, POST_ISPAGE, false);
             postInfo.BlogName = ReadBlogName(postStorage);
             postInfo.BlogId = ReadString(postStorage, DESTINATION_BLOG_ID);
             postInfo.BlogPostId = ReadString(postStorage, POST_ID);
             postInfo.Contents = ReadStringUtf8(postStorage, POST_CONTENTS);
             postInfo.DateModified = file.LastWriteTimeUtc;
             return postInfo;
         }
     }
     catch (Exception ex)
     {
         throw PostEditorStorageException.Create(ex);
     }
 }
Example #9
0
 public void DeleteLocalPost(PostInfo postInfo)
 {
     throw new NotImplementedException();
 }
Example #10
0
 public GetPostThread(PostInfo postInfo)
 {
     _postInfo = postInfo;
 }
        private void openPostForm_UserDeletedPost(PostInfo deletedPost)
        {
            // See if the file currently being edited was deleted. In this case
            // clear out the post editor
            if (LocalFile != null && LocalFile.IsDeleted)
                ClearPost();

            // Fire notification
            if (UserDeletedPost != null)
                UserDeletedPost(this, EventArgs.Empty);
        }
        public void DeleteLocalPost(PostInfo postInfo)
        {
            // get the post file associated with this post
            PostEditorFile postFile = PostEditorFile.GetExisting(new FileInfo(postInfo.Id));

            // prompt the user to confirm deletion
            string type = BlogPost.IsPage ? Res.Get(StringId.PageLower) : Res.Get(StringId.PostLower);
            MessageId messageId = postFile.IsDraft ? MessageId.ConfirmDeleteDraft : MessageId.ConfirmDeletePost;
            if (DisplayMessage.Show(messageId, _mainFrameWindow, type, postInfo.Title) == DialogResult.Yes)
            {
                // update main window to eliminate artifacts
                _mainFrameWindow.Update();

                // see if we are deleting the currently active file
                bool deletingCurrentDraft = (postFile.Equals(LocalFile));

                if (DeletePostFile(postFile))
                {
                    // fire notification of the delete
                    if (UserDeletedPost != null)
                        UserDeletedPost(this, EventArgs.Empty);

                    // open a new untitled post if we just deleted the current draft
                    if (deletingCurrentDraft)
                        ClearPost();
                }
            }

        }
        public void OpenLocalPost(PostInfo postInfo)
        {
            using (new WaitCursor())
            {
                // get file path
                string postFilePath = postInfo.Id;

                // screen non-existent files
                if (!File.Exists(postFilePath))
                {
                    DisplayMessage.Show(MessageId.PostFileNoExist, _mainFrameWindow, postInfo.Title);
                }
                // screen invalid files
                else if (!PostEditorFile.IsValid(postInfo.Id))
                {
                    DisplayMessage.Show(MessageId.PostFileInvalid, _mainFrameWindow, postInfo.Title);
                }
                else
                {
                    PostEditorFile postEditorFile = PostEditorFile.GetExisting(new FileInfo(postInfo.Id));
                    IBlogPostEditingContext editingContext = postEditorFile.Load();
                    OpenPost(editingContext);
                }
            }
        }
 public GetPostThread(PostInfo postInfo)
 {
     _postInfo = postInfo;
 }
 private void _draftsPostList_PostDeleteRequested(PostInfo post)
 {
     _postEditingSite.DeleteLocalPost(post) ;
     UpdatePostLists() ;
 }
 void IBlogPostEditingSite.OpenLocalPost(PostInfo postInfo)
 {
     _editingManager.OpenLocalPost(postInfo);
 }
 private void _recentPostList_PostSelected(PostInfo post)
 {
     WindowCascadeHelper.SetNextOpenedLocation(_postEditingSite.FrameWindow.Location);
     _postEditingSite.OpenLocalPost(post);
 }
 void IBlogPostEditingSite.DeleteLocalPost(PostInfo postInfo)
 {
     try
     {
         _editingManager.DeleteLocalPost(postInfo);
     }
     catch (Exception ex)
     {
         DisplayableExceptionDisplayForm.Show(_mainFrameWindow, ex);
     }
 }
 public void DeleteLocalPost(PostInfo postInfo)
 {
     throw new NotImplementedException();
 }
        private PostInfo[] GetPosts(RecentPostRequest request, bool getPages)
        {
            using (Blog blog = new Blog(_blogId))
            {
                if (getPages)
                    _blogPosts = blog.GetPages(request.NumberOfPosts);
                else
                    _blogPosts = blog.GetRecentPosts(request.NumberOfPosts, false);

                ArrayList recentPosts = new ArrayList();
                foreach (BlogPost blogPost in _blogPosts)
                {
                    PostInfo postInfo = new PostInfo();
                    postInfo.Id = blogPost.Id;
                    postInfo.IsPage = blogPost.IsPage;
                    postInfo.Title = blogPost.Title;
                    postInfo.Permalink = blogPost.Permalink;
                    postInfo.BlogId = blog.Id;
                    postInfo.BlogName = blog.Name;
                    postInfo.BlogPostId = blogPost.Id;
                    postInfo.Contents = blogPost.Contents;
                    postInfo.DateModified = blogPost.DatePublished;
                    recentPosts.Add(postInfo);
                }
                return (PostInfo[])recentPosts.ToArray(typeof(PostInfo));
            }
        }