示例#1
0
        private void buttonOptions_Click(object sender, System.EventArgs e)
        {
            ContentSourceInfo selectedContentSource = GetSelectedPlugin();

            if (selectedContentSource != null)
            {
                if (selectedContentSource.WriterPluginHasEditableOptions)
                {
                    try
                    {
                        selectedContentSource.Instance.EditOptions(FindForm());
                    }
                    catch (NotImplementedException ex)
                    {
                        ContentSourceManager.DisplayContentRetreivalError(FindForm(), ex, selectedContentSource);
                    }
                    catch (Exception exception)
                    {
                        Trace.Fail(exception.ToString());
                        DisplayableException dex = new DisplayableException(
                            Res.Get(StringId.UnexpectedErrorPluginTitle),
                            string.Format(CultureInfo.CurrentCulture, Res.Get(StringId.UnexpectedErrorPluginDescription), selectedContentSource.Name, exception.Message));
                        DisplayableExceptionDisplayForm.Show(FindForm(), dex);
                    }
                }
            }
        }
示例#2
0
        public void DeleteSelectedPost()
        {
            if (SelectedIndex == -1 || !AllowDelete)
            {
                return;
            }

            PostInfo  selectedPost = SelectedPost;
            string    type         = selectedPost.IsPage ? Res.Get(StringId.PageLower) : Res.Get(StringId.PostLower);
            MessageId messageId    = PostSource is LocalDraftsPostSource ? MessageId.ConfirmDeleteDraft : MessageId.ConfirmDeletePost;

            if (DisplayMessage.Show(messageId, this, type, selectedPost.Title) == DialogResult.Yes)
            {
                try
                {
                    // delete the underlying post
                    Update();
                    using (new WaitCursor())
                    {
                        // delete the post
                        if (PostSource.DeletePost(selectedPost.Id, selectedPost.IsPage))
                        {
                            // note the selected index prior to deleting
                            int selectedIndex = SelectedIndex;

                            // remove that post from the list
                            RemoveItem(selectedPost);

                            // try to reselect intelligently
                            if (Items.Count > 0)
                            {
                                SelectedIndex = Math.Min(selectedIndex, Items.Count - 1);
                            }
                            else
                            {
                                ShowEmptyPostListControl();
                            }

                            // fire notification
                            if (UserDeletedPost != null)
                            {
                                UserDeletedPost(selectedPost);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    DisplayableExceptionDisplayForm.Show(this, ex);
                }
            }

            // This is because of a bug on XP that caused the focus to go in a weird place,
            // and the list box to draw the wrong color.
            Select();
            Focus();
            Refresh();
        }
示例#3
0
        /// <summary>
        /// Notify the user that an error has occurred.
        /// </summary>
        /// <param name="title">Error title (used as the error caption).</param>
        /// <param name="description">Error description (displayed within a scrolling
        /// text-box so can be longer and/or display diagnostic information).</param>
        public static void DisplayError(string title, string description)
        {
            LogError(String.Format(CultureInfo.CurrentCulture, "{0}: {1}", title, description));

            DisplayableException displayableException = new DisplayableException(title, description);

            using (DisplayableExceptionDisplayForm form = new DisplayableExceptionDisplayForm(displayableException))
                form.ShowDialog(Win32WindowImpl.ForegroundWin32Window);
        }
示例#4
0
        private void _pendingRecentPostsOperation_Failed(object sender, ThreadExceptionEventArgs e)
        {
            // end the session
            EndGetRecentPostsAsync();

            // show the no-posts UI
            ShowEmptyPostListControl();

            // show the error
            if (!(e.Exception is BlogClientOperationCancelledException))
            {
                DisplayableExceptionDisplayForm.Show(FindForm(), e.Exception);
            }
            else
            {
                Debug.WriteLine("BlogClient operation cancelled");
            }
        }
示例#5
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);
     }
 }
示例#6
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);
     }
 }
示例#7
0
        public void DisplayException(IWin32Window owner, Exception ex)
        {
            // display a custom display message for exceptions that have one
            // registered, otherwise display the generic error form
            if (ex is BlogClientProviderException)
            {
                IBlogProvider provider = BlogProviderManager.FindProvider(_settings.ProviderId);
                if (provider != null)
                {
                    BlogClientProviderException pe = ex as BlogClientProviderException;
                    MessageId messageId            = provider.DisplayMessageForProviderError(pe.ErrorCode, pe.ErrorString);
                    if (messageId != MessageId.None)
                    {
                        DisplayMessage.Show(messageId, owner);
                        return;
                    }
                }
            }
            else if (ex is WebException)
            {
                WebException    we   = (WebException)ex;
                HttpWebResponse resp = we.Response as HttpWebResponse;
                if (resp != null)
                {
                    string friendlyError = HttpRequestHelper.GetFriendlyErrorMessage(we);
                    Trace.WriteLine("Server response body:\r\n" + friendlyError);
                    ex = new BlogClientHttpErrorException(
                        UrlHelper.SafeToAbsoluteUri(resp.ResponseUri),
                        friendlyError,
                        we);
                }
                else
                {
                    DisplayMessage msg = new DisplayMessage(MessageId.ErrorConnecting);
                    ex = new BlogClientException(msg.Title, msg.Text);
                }
                HttpRequestHelper.LogException(we);
            }

            // no custom message, use default UI
            DisplayableExceptionDisplayForm.Show(owner, ex);
        }
 BlogPostCategory[] IBlogCategorySettings.RefreshCategories(bool ignoreErrors)
 {
     try
     {
         _targetBlog.RefreshCategories();
     }
     catch (BlogClientOperationCancelledException)
     {
         // show no UI for operation cancelled
         Debug.WriteLine("BlogClient operation cancelled");
     }
     catch (Exception ex)
     {
         if (!ignoreErrors)
         {
             DisplayableExceptionDisplayForm.Show(_parentFrame, ex);
         }
     }
     return(_targetBlog.Categories);
 }
        private void AcceptSelectedPost()
        {
            // see if there is anyone listening to the validate event (to veto the selection)
            if (ValidateSelectedPost())
            {
                // get the post from the list box
                try
                {
                    // get the post
                    using (new WaitCursor())
                        _selectedPost = listBoxPosts.RetrieveSelectedPost();

                    // if that succeeded then allow the dialog to be dismissed
                    DialogResult = DialogResult.OK;
                }
                catch (Exception ex)
                {
                    DisplayableExceptionDisplayForm.Show(this, ex);
                }
            }
        }
示例#10
0
 private PostInfo[] GetRecentPostsSync(bool getPages)
 {
     try
     {
         using (new WaitCursor())
         {
             if (getPages)
             {
                 return(PostSource.GetPages(RecentPostRequest));
             }
             else
             {
                 return(PostSource.GetRecentPosts(RecentPostRequest));
             }
         }
     }
     catch (Exception ex)
     {
         DisplayableExceptionDisplayForm.Show(FindForm(), ex);
         return(new PostInfo[] {});
     }
 }
示例#11
0
        public static bool SafeDeleteRemotePost(string blogId, string postId, bool isPage)
        {
            // screen non-existent blog ids
            if (!BlogSettings.BlogIdIsValid(blogId))
            {
                return(true);
            }

            using (Blog blog = new Blog(blogId))
            {
                try
                {
                    if (blog.VerifyCredentials())
                    {
                        // try to delete the post on the remote blog
                        blog.DeletePost(postId, isPage, true);

                        // return success
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                catch (BlogClientOperationCancelledException)
                {
                    // show no UI for operation cancelled
                    Debug.WriteLine("BlogClient operation cancelled");
                    return(false);
                }
                catch (Exception ex)
                {
                    DisplayableExceptionDisplayForm.Show(Win32WindowImpl.ForegroundWin32Window, ex);
                    return(false);
                }
            }
        }