示例#1
0
        private void MenuFileViewPluginLoadErrors_Click(object sender, EventArgs e)
        {
            IList <Triple <Assembly, Type, Exception> > allErrors = AppWorkspace.GetEffectLoadErrors();
            IList <Triple <Assembly, Type, Exception> > errors    = RemoveDuplicates(allErrors);

            using (Form errorsDialog = new Form())
            {
                errorsDialog.Icon = Utility.ImageToIcon(PdnResources.GetImageResource("Icons.MenuFileViewPluginLoadErrorsIcon.png").Reference);
                errorsDialog.Text = PdnResources.GetString("Effects.PluginLoadErrorsDialog.Text");

                Label messageLabel = new Label();
                messageLabel.Name = "messageLabel";
                messageLabel.Text = PdnResources.GetString("Effects.PluginLoadErrorsDialog.Message.Text");

                TextBox errorsBox = new TextBox();
                errorsBox.Font       = new Font(FontFamily.GenericMonospace, errorsBox.Font.Size);
                errorsBox.ReadOnly   = true;
                errorsBox.Multiline  = true;
                errorsBox.ScrollBars = ScrollBars.Vertical;

                StringBuilder allErrorsText    = new StringBuilder();
                string        headerTextFormat = PdnResources.GetString("EffectErrorMessage.HeaderFormat");

                for (int i = 0; i < errors.Count; ++i)
                {
                    Assembly  assembly  = errors[i].First;
                    Type      type      = errors[i].Second;
                    Exception exception = errors[i].Third;

                    string headerText = string.Format(headerTextFormat, i + 1, errors.Count);
                    string errorText  = AppWorkspace.GetLocalizedEffectErrorMessage(assembly, type, exception);

                    allErrorsText.Append(headerText);
                    allErrorsText.Append(Environment.NewLine);
                    allErrorsText.Append(errorText);

                    if (i != errors.Count - 1)
                    {
                        allErrorsText.Append(Environment.NewLine);
                    }
                }

                errorsBox.Text = allErrorsText.ToString();

                errorsDialog.Layout +=
                    delegate(object sender2, LayoutEventArgs e2)
                {
                    int hMargin    = UI.ScaleWidth(8);
                    int vMargin    = UI.ScaleHeight(8);
                    int insetWidth = errorsDialog.ClientSize.Width - (hMargin * 2);

                    messageLabel.Location = new Point(hMargin, vMargin);
                    messageLabel.Width    = insetWidth;
                    messageLabel.Size     = messageLabel.GetPreferredSize(new Size(messageLabel.Width, 1));

                    errorsBox.Location = new Point(hMargin, messageLabel.Bottom + vMargin);
                    errorsBox.Width    = insetWidth;
                    errorsBox.Height   = errorsDialog.ClientSize.Height - vMargin - errorsBox.Top;
                };

                errorsDialog.StartPosition = FormStartPosition.CenterParent;
                errorsDialog.ShowInTaskbar = false;
                errorsDialog.MinimizeBox   = false;
                errorsDialog.Width        *= 2;
                errorsDialog.Size          = UI.ScaleSize(errorsDialog.Size);
                errorsDialog.Controls.Add(messageLabel);
                errorsDialog.Controls.Add(errorsBox);

                errorsDialog.ShowDialog(AppWorkspace);
            }
        }
示例#2
0
        private void HandleEffectException(AppWorkspace appWorkspace, Effect effect, Exception ex)
        {
            try
            {
                AppWorkspace.Widgets.StatusBarProgress.ResetProgressStatusBar();
                AppWorkspace.Widgets.StatusBarProgress.EraseProgressStatusBar();
            }

            catch (Exception)
            {
            }

            // Figure out if it's a built-in effect, or a plug-in
            if (IsBuiltInEffect(effect))
            {
                // For built-in effects, tear down Paint.NET which will result in a crash log
                throw new ApplicationException("Effect threw an exception", ex);
            }
            else
            {
                Icon formIcon = Utility.ImageToIcon(PdnResources.GetImageResource("Icons.BugWarning.png").Reference);

                string formTitle = PdnResources.GetString("Effect.PluginErrorDialog.Title");

                Image taskImage = null;

                string introText = PdnResources.GetString("Effect.PluginErrorDialog.IntroText");

                TaskButton restartTB = new TaskButton(
                    PdnResources.GetImageResource("Icons.RightArrowBlue.png").Reference,
                    PdnResources.GetString("Effect.PluginErrorDialog.RestartTB.ActionText"),
                    PdnResources.GetString("Effect.PluginErrorDialog.RestartTB.ExplanationText"));

                TaskButton doNotRestartTB = new TaskButton(
                    PdnResources.GetImageResource("Icons.WarningIcon.png").Reference,
                    PdnResources.GetString("Effect.PluginErrorDialog.DoNotRestartTB.ActionText"),
                    PdnResources.GetString("Effect.PluginErrorDialog.DoNotRestartTB.ExplanationText"));

                string auxButtonText = PdnResources.GetString("Effect.PluginErrorDialog.AuxButton1.Text");

                void AuxButtonClickHandler(object sender, EventArgs e)
                {
                    using (PdnBaseForm textBoxForm = new PdnBaseForm())
                    {
                        textBoxForm.Name = "EffectCrash";

                        TextBox exceptionBox = new TextBox();

                        textBoxForm.Icon = Utility.ImageToIcon(PdnResources.GetImageResource("Icons.WarningIcon.png").Reference);
                        textBoxForm.Text = PdnResources.GetString("Effect.PluginErrorDialog.Title");

                        exceptionBox.Dock      = DockStyle.Fill;
                        exceptionBox.ReadOnly  = true;
                        exceptionBox.Multiline = true;

                        string exceptionText = AppWorkspace.GetLocalizedEffectErrorMessage(effect.GetType().Assembly, effect.GetType(), ex);

                        exceptionBox.Font       = new Font(FontFamily.GenericMonospace, exceptionBox.Font.Size);
                        exceptionBox.Text       = exceptionText;
                        exceptionBox.ScrollBars = ScrollBars.Vertical;

                        textBoxForm.StartPosition = FormStartPosition.CenterParent;
                        textBoxForm.ShowInTaskbar = false;
                        textBoxForm.MinimizeBox   = false;
                        textBoxForm.Controls.Add(exceptionBox);
                        textBoxForm.Width = UI.ScaleWidth(700);

                        textBoxForm.ShowDialog();
                    }
                }

                TaskButton clickedTB = TaskDialog.Show(
                    appWorkspace,
                    formIcon,
                    formTitle,
                    taskImage,
                    true,
                    introText,
                    new TaskButton[] { restartTB, doNotRestartTB },
                    restartTB,
                    doNotRestartTB,
                    TaskDialog.DefaultPixelWidth96Dpi * 2,
                    auxButtonText,
                    AuxButtonClickHandler);

                if (clickedTB == restartTB)
                {
                    // Next, apply restart logic
                    CloseAllWorkspacesAction cawa = new CloseAllWorkspacesAction();
                    cawa.PerformAction(appWorkspace);

                    if (!cawa.Cancelled)
                    {
                        SystemLayer.Shell.RestartApplication();
                        Startup.CloseApplication();
                    }
                }
            }
        }