コード例 #1
0
ファイル: SysInfoForm.cs プロジェクト: dox0/DotNet471RS3
 private void PopulateAssemblyInfo()
 {
     foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
     {
         AssemblyName name = asm.GetName();
         try {
             string fileVer = "n/a";
             if (name.EscapedCodeBase != null && name.EscapedCodeBase.Length > 0)
             {
                 Uri codeBase = new Uri(name.EscapedCodeBase);
                 if (codeBase.Scheme == "file")
                 {
                     fileVer = FileVersionInfo.GetVersionInfo(NativeMethods.GetLocalPath(name.EscapedCodeBase)).FileVersion;
                 }
             }
             ListViewItem item = new ListViewItem(new string[] {
                 name.Name,
                 fileVer,
                 name.Version.ToString(),
                 name.EscapedCodeBase
             });
             loadedAssemblyList.Items.Add(item);
         }
         catch {
             // ignore any exceptions... this dialog should never cause a fault...
             //
             loadedAssemblyList.Items.Add(new ListViewItem(new string[] { name.Name, "Exception loading information" }));
         }
     }
 }
コード例 #2
0
        private static Uri Resolve(string partialUri)
        {
            Debug.WriteLineIf(Help.WindowsFormsHelpTrace.TraceVerbose, "Help:: Resolve " + partialUri);
            Debug.Indent();

            Uri file = null;

            if (!string.IsNullOrEmpty(partialUri))
            {
                try {
                    file = new Uri(partialUri);
                }
                catch (UriFormatException) {
                    // Ignore invalid uris.
                }
            }

            if (file != null && file.Scheme == "file")
            {
                string localPath = NativeMethods.GetLocalPath(partialUri);
                Debug.WriteLineIf(Help.WindowsFormsHelpTrace.TraceVerbose, "file, check for existence");

                if (!File.Exists(localPath))
                {
                    // clear, and try relative to AppBase...
                    //
                    file = null;
                }
            }

            if (file == null)
            {
                Debug.WriteLineIf(Help.WindowsFormsHelpTrace.TraceVerbose, "try appbase relative");
                try {
                    // try relative to AppBase...
                    //
                    file = new Uri(new Uri(AppContext.BaseDirectory),
                                   partialUri);
                }
                catch (UriFormatException) {
                    // Ignore invalid uris.
                }

                if (file != null && file.Scheme == "file")
                {
                    string localPath = file.LocalPath + file.Fragment;
                    Debug.WriteLineIf(Help.WindowsFormsHelpTrace.TraceVerbose, "file, check for existence");
                    if (!File.Exists(localPath))
                    {
                        // clear - file isn't there...
                        //
                        file = null;
                    }
                }
            }

            Debug.Unindent();
            return(file);
        }
コード例 #3
0
ファイル: SysInfoForm.cs プロジェクト: dox0/DotNet471RS3
        private void WriteBugReport(TextWriter writer)
        {
            XmlTextWriter xml = new XmlTextWriter(writer);

            xml.Formatting = Formatting.Indented;

            xml.WriteStartElement("bug"); {
                xml.WriteAttributeString("product", ".NET Frameworks SDK");

                xml.WriteStartElement("problem"); {
                    xml.WriteString(bugReportDescription.Text);
                }
                xml.WriteEndElement();

                if (includeApplicationInformation.Checked)
                {
                    xml.WriteStartElement("assemblies"); {
                        foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
                        {
                            AssemblyName name = asm.GetName();
                            xml.WriteStartElement("assembly"); {
                                xml.WriteAttributeString("name", name.Name);
                                xml.WriteAttributeString("codebase", name.CodeBase);
                                xml.WriteAttributeString("version", name.Version.ToString());

                                string fileVer = "n/a";
                                if (name.EscapedCodeBase != null && name.EscapedCodeBase.Length > 0)
                                {
                                    Uri codeBase = new Uri(name.EscapedCodeBase);
                                    if (codeBase.Scheme == "file")
                                    {
                                        fileVer = FileVersionInfo.GetVersionInfo(NativeMethods.GetLocalPath(name.EscapedCodeBase)).FileVersion;
                                    }
                                }
                                xml.WriteAttributeString("win32version", fileVer);
                            }
                            xml.WriteEndElement();
                        }
                    }
                    xml.WriteEndElement();
                }

                if (includeSystemInformation.Checked)
                {
                    xml.WriteStartElement("system"); {
                        xml.WriteAttributeString("os", Environment.OSVersion.Platform.ToString("G") + " " + Environment.OSVersion.Version.ToString());
                    }
                    xml.WriteEndElement();
                }
            }
            xml.WriteEndElement();
        }
コード例 #4
0
        /// <summary>
        ///    Initializes a new instance of the <see cref='System.Windows.Forms.ThreadExceptionDialog'/> class.
        /// </summary>
        public ThreadExceptionDialog(Exception t)
        {
            if (DpiHelper.IsScalingRequirementMet)
            {
                scaledMaxWidth                        = LogicalToDeviceUnits(MAXWIDTH);
                scaledMaxHeight                       = LogicalToDeviceUnits(MAXHEIGHT);
                scaledPaddingWidth                    = LogicalToDeviceUnits(PADDINGWIDTH);
                scaledPaddingHeight                   = LogicalToDeviceUnits(PADDINGHEIGHT);
                scaledMaxTextWidth                    = LogicalToDeviceUnits(MAXTEXTWIDTH);
                scaledMaxTextHeight                   = LogicalToDeviceUnits(MAXTEXTHEIGHT);
                scaledButtonTopPadding                = LogicalToDeviceUnits(BUTTONTOPPADDING);
                scaledButtonDetailsLeftPadding        = LogicalToDeviceUnits(BUTTONDETAILS_LEFTPADDING);
                scaledMessageTopPadding               = LogicalToDeviceUnits(MESSAGE_TOPPADDING);
                scaledHeightPadding                   = LogicalToDeviceUnits(HEIGHTPADDING);
                scaledButtonWidth                     = LogicalToDeviceUnits(BUTTONWIDTH);
                scaledButtonHeight                    = LogicalToDeviceUnits(BUTTONHEIGHT);
                scaledButtonAlignmentWidth            = LogicalToDeviceUnits(BUTTONALIGNMENTWIDTH);
                scaledButtonAlignmentPadding          = LogicalToDeviceUnits(BUTTONALIGNMENTPADDING);
                scaledDetailsWidthPadding             = LogicalToDeviceUnits(DETAILSWIDTHPADDING);
                scaledDetailsHeight                   = LogicalToDeviceUnits(DETAILSHEIGHT);
                scaledPictureWidth                    = LogicalToDeviceUnits(PICTUREWIDTH);
                scaledPictureHeight                   = LogicalToDeviceUnits(PICTUREHEIGHT);
                scaledExceptionMessageVerticalPadding = LogicalToDeviceUnits(EXCEPTIONMESSAGEVERTICALPADDING);
            }

            string messageFormat;
            string messageText;

            Button[] buttons;
            bool     detailAnchor = false;

            WarningException w = t as WarningException;

            if (w != null)
            {
                messageFormat = SR.ExDlgWarningText;
                messageText   = w.Message;
                if (w.HelpUrl == null)
                {
                    buttons = new Button[] { continueButton };
                }
                else
                {
                    buttons = new Button[] { continueButton, helpButton };
                }
            }
            else
            {
                messageText = t.Message;

                detailAnchor = true;

                if (Application.AllowQuit)
                {
                    if (t is System.Security.SecurityException)
                    {
                        messageFormat = SR.ExDlgSecurityErrorText;
                    }
                    else
                    {
                        messageFormat = SR.ExDlgErrorText;
                    }
                    buttons = new Button[] { detailsButton, continueButton, quitButton };
                }
                else
                {
                    if (t is System.Security.SecurityException)
                    {
                        messageFormat = SR.ExDlgSecurityContinueErrorText;
                    }
                    else
                    {
                        messageFormat = SR.ExDlgContinueErrorText;
                    }
                    buttons = new Button[] { detailsButton, continueButton };
                }
            }

            if (messageText.Length == 0)
            {
                messageText = t.GetType().Name;
            }
            if (t is System.Security.SecurityException)
            {
                messageText = string.Format(messageFormat, t.GetType().Name, Trim(messageText));
            }
            else
            {
                messageText = string.Format(messageFormat, Trim(messageText));
            }

            StringBuilder detailsTextBuilder = new StringBuilder();
            string        newline            = "\r\n";
            string        separator          = SR.ExDlgMsgSeperator;
            string        sectionseparator   = SR.ExDlgMsgSectionSeperator;

            if (Application.CustomThreadExceptionHandlerAttached)
            {
                detailsTextBuilder.Append(SR.ExDlgMsgHeaderNonSwitchable);
            }
            else
            {
                detailsTextBuilder.Append(SR.ExDlgMsgHeaderSwitchable);
            }
            detailsTextBuilder.Append(string.Format(CultureInfo.CurrentCulture, sectionseparator, SR.ExDlgMsgExceptionSection));
            detailsTextBuilder.Append(t.ToString());
            detailsTextBuilder.Append(newline);
            detailsTextBuilder.Append(newline);
            detailsTextBuilder.Append(string.Format(CultureInfo.CurrentCulture, sectionseparator, SR.ExDlgMsgLoadedAssembliesSection));

            foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
            {
                AssemblyName name    = asm.GetName();
                string       fileVer = SR.NotAvailable;

                try {
                    if (name.EscapedCodeBase != null && name.EscapedCodeBase.Length > 0)
                    {
                        Uri codeBase = new Uri(name.EscapedCodeBase);
                        if (codeBase.Scheme == "file")
                        {
                            fileVer = FileVersionInfo.GetVersionInfo(NativeMethods.GetLocalPath(name.EscapedCodeBase)).FileVersion;
                        }
                    }
                }
                catch (System.IO.FileNotFoundException) {
                }
                detailsTextBuilder.Append(string.Format(SR.ExDlgMsgLoadedAssembliesEntry, name.Name, name.Version, fileVer, name.EscapedCodeBase));
                detailsTextBuilder.Append(separator);
            }

            detailsTextBuilder.Append(string.Format(CultureInfo.CurrentCulture, sectionseparator, SR.ExDlgMsgJITDebuggingSection));
            if (Application.CustomThreadExceptionHandlerAttached)
            {
                detailsTextBuilder.Append(SR.ExDlgMsgFooterNonSwitchable);
            }
            else
            {
                detailsTextBuilder.Append(SR.ExDlgMsgFooterSwitchable);
            }

            detailsTextBuilder.Append(newline);
            detailsTextBuilder.Append(newline);

            string detailsText = detailsTextBuilder.ToString();

            Graphics g = message.CreateGraphicsInternal();

            Size textSize = new Size(scaledMaxWidth - scaledPaddingWidth, int.MaxValue);

            if (DpiHelper.IsScalingRequirementMet && Label.UseCompatibleTextRenderingDefault == false)
            {
                // we need to measure string using API that matches the rendering engine - TextRenderer.MeasureText for GDI
                textSize = Size.Ceiling(TextRenderer.MeasureText(messageText, Font, textSize, TextFormatFlags.WordBreak));
            }
            else
            {
                // if HighDpi improvements are not enabled, or rendering mode is GDI+, use Graphics.MeasureString
                textSize = Size.Ceiling(g.MeasureString(messageText, Font, textSize.Width));
            }

            textSize.Height += scaledExceptionMessageVerticalPadding;
            g.Dispose();

            if (textSize.Width < scaledMaxTextWidth)
            {
                textSize.Width = scaledMaxTextWidth;
            }
            if (textSize.Height > scaledMaxHeight)
            {
                textSize.Height = scaledMaxHeight;
            }

            int width     = textSize.Width + scaledPaddingWidth;
            int buttonTop = Math.Max(textSize.Height, scaledMaxTextHeight) + scaledPaddingHeight;

            Form activeForm = Form.ActiveForm;

            if (activeForm == null || activeForm.Text.Length == 0)
            {
                Text = SR.ExDlgCaption;
            }
            else
            {
                Text = string.Format(SR.ExDlgCaption2, activeForm.Text);
            }

            AcceptButton    = continueButton;
            CancelButton    = continueButton;
            FormBorderStyle = FormBorderStyle.FixedDialog;
            MaximizeBox     = false;
            MinimizeBox     = false;
            StartPosition   = FormStartPosition.CenterScreen;
            Icon            = null;
            ClientSize      = new Size(width, buttonTop + scaledButtonTopPadding);
            TopMost         = true;

            pictureBox.Location = new Point(scaledPictureWidth / 8, scaledPictureHeight / 8);
            pictureBox.Size     = new Size(scaledPictureWidth * 3 / 4, scaledPictureHeight * 3 / 4);
            pictureBox.SizeMode = PictureBoxSizeMode.StretchImage;
            if (t is System.Security.SecurityException)
            {
                pictureBox.Image = SystemIcons.Information.ToBitmap();
            }
            else
            {
                pictureBox.Image = SystemIcons.Error.ToBitmap();
            }
            Controls.Add(pictureBox);
            message.SetBounds(scaledPictureWidth,
                              scaledMessageTopPadding + (scaledMaxTextHeight - Math.Min(textSize.Height, scaledMaxTextHeight)) / 2,
                              textSize.Width, textSize.Height);
            message.Text = messageText;
            Controls.Add(message);

            continueButton.Text         = SR.ExDlgContinue;
            continueButton.FlatStyle    = FlatStyle.Standard;
            continueButton.DialogResult = DialogResult.Cancel;

            quitButton.Text         = SR.ExDlgQuit;
            quitButton.FlatStyle    = FlatStyle.Standard;
            quitButton.DialogResult = DialogResult.Abort;

            helpButton.Text         = SR.ExDlgHelp;
            helpButton.FlatStyle    = FlatStyle.Standard;
            helpButton.DialogResult = DialogResult.Yes;

            detailsButton.Text      = SR.ExDlgShowDetails;
            detailsButton.FlatStyle = FlatStyle.Standard;
            detailsButton.Click    += new EventHandler(DetailsClick);

            Button b          = null;
            int    startIndex = 0;

            if (detailAnchor)
            {
                b = detailsButton;

                expandImage   = DpiHelper.GetBitmapFromIcon(GetType(), DownBitmapName);
                collapseImage = DpiHelper.GetBitmapFromIcon(GetType(), UpBitmapName);

                if (DpiHelper.IsScalingRequirementMet)
                {
                    ScaleBitmapLogicalToDevice(ref expandImage);
                    ScaleBitmapLogicalToDevice(ref collapseImage);
                }

                b.SetBounds(scaledButtonDetailsLeftPadding, buttonTop, scaledButtonWidth, scaledButtonHeight);
                b.Image      = expandImage;
                b.ImageAlign = ContentAlignment.MiddleLeft;
                Controls.Add(b);
                startIndex = 1;
            }

            int buttonLeft = (width - scaledButtonDetailsLeftPadding - ((buttons.Length - startIndex) * scaledButtonAlignmentWidth - scaledButtonAlignmentPadding));

            for (int i = startIndex; i < buttons.Length; i++)
            {
                b = buttons[i];
                b.SetBounds(buttonLeft, buttonTop, scaledButtonWidth, scaledButtonHeight);
                Controls.Add(b);
                buttonLeft += scaledButtonAlignmentWidth;
            }

            details.Text          = detailsText;
            details.ScrollBars    = ScrollBars.Both;
            details.Multiline     = true;
            details.ReadOnly      = true;
            details.WordWrap      = false;
            details.TabStop       = false;
            details.AcceptsReturn = false;

            details.SetBounds(scaledButtonDetailsLeftPadding, buttonTop + scaledButtonTopPadding, width - scaledDetailsWidthPadding, scaledDetailsHeight);
            details.Visible = detailsVisible;
            Controls.Add(details);
            if (DpiHelper.IsScalingRequirementMet)
            {
                DpiChanged += ThreadExceptionDialog_DpiChanged;
            }
        }
コード例 #5
0
        public ThreadExceptionDialog(Exception t)
        {
            if (DpiHelper.IsScalingRequirementMet)
            {
                scaledMaxWidth                        = LogicalToDeviceUnits(MAXWIDTH);
                scaledMaxHeight                       = LogicalToDeviceUnits(MAXHEIGHT);
                scaledPaddingWidth                    = LogicalToDeviceUnits(PADDINGWIDTH);
                scaledPaddingHeight                   = LogicalToDeviceUnits(PADDINGHEIGHT);
                scaledMaxTextWidth                    = LogicalToDeviceUnits(MAXTEXTWIDTH);
                scaledMaxTextHeight                   = LogicalToDeviceUnits(MAXTEXTHEIGHT);
                scaledButtonTopPadding                = LogicalToDeviceUnits(BUTTONTOPPADDING);
                scaledButtonDetailsLeftPadding        = LogicalToDeviceUnits(BUTTONDETAILS_LEFTPADDING);
                scaledMessageTopPadding               = LogicalToDeviceUnits(MESSAGE_TOPPADDING);
                scaledHeightPadding                   = LogicalToDeviceUnits(HEIGHTPADDING);
                scaledButtonWidth                     = LogicalToDeviceUnits(BUTTONWIDTH);
                scaledButtonHeight                    = LogicalToDeviceUnits(BUTTONHEIGHT);
                scaledButtonAlignmentWidth            = LogicalToDeviceUnits(BUTTONALIGNMENTWIDTH);
                scaledButtonAlignmentPadding          = LogicalToDeviceUnits(BUTTONALIGNMENTPADDING);
                scaledDetailsWidthPadding             = LogicalToDeviceUnits(DETAILSWIDTHPADDING);
                scaledDetailsHeight                   = LogicalToDeviceUnits(DETAILSHEIGHT);
                scaledPictureWidth                    = LogicalToDeviceUnits(PICTUREWIDTH);
                scaledPictureHeight                   = LogicalToDeviceUnits(PICTUREHEIGHT);
                scaledExceptionMessageVerticalPadding = LogicalToDeviceUnits(EXCEPTIONMESSAGEVERTICALPADDING);
            }

            string messageFormat;
            string messageText;

            Button[] buttons;
            bool     detailAnchor = false;

            if (t is WarningException w)
            {
                messageFormat = SR.ExDlgWarningText;
                messageText   = w.Message;
                if (w.HelpUrl is null)
                {
                    buttons = new Button[] { continueButton };
                }
                else
                {
                    buttons = new Button[] { continueButton, helpButton };
                }
            }
            else
            {
                messageText = t.Message;

                detailAnchor = true;

                if (Application.AllowQuit)
                {
                    if (t is Security.SecurityException)
                    {
                        messageFormat = SR.ExDlgSecurityErrorText;
                    }
                    else
                    {
                        messageFormat = SR.ExDlgErrorText;
                    }
                    buttons = new Button[] { detailsButton, continueButton, quitButton };
                }
                else
                {
                    if (t is Security.SecurityException)
                    {
                        messageFormat = SR.ExDlgSecurityContinueErrorText;
                    }
                    else
                    {
                        messageFormat = SR.ExDlgContinueErrorText;
                    }
                    buttons = new Button[] { detailsButton, continueButton };
                }
            }

            if (messageText.Length == 0)
            {
                messageText = t.GetType().Name;
            }
            if (t is Security.SecurityException)
            {
                messageText = string.Format(messageFormat, t.GetType().Name, Trim(messageText));
            }
            else
            {
                messageText = string.Format(messageFormat, Trim(messageText));
            }

            StringBuilder detailsTextBuilder = new StringBuilder();
            string        newline            = "\r\n";
            string        separator          = SR.ExDlgMsgSeperator;
            string        sectionseparator   = SR.ExDlgMsgSectionSeperator;

            if (Application.CustomThreadExceptionHandlerAttached)
            {
                detailsTextBuilder.Append(SR.ExDlgMsgHeaderNonSwitchable);
            }
            else
            {
                detailsTextBuilder.Append(SR.ExDlgMsgHeaderSwitchable);
            }
            detailsTextBuilder.Append(string.Format(CultureInfo.CurrentCulture, sectionseparator, SR.ExDlgMsgExceptionSection));
            detailsTextBuilder.Append(t.ToString());
            detailsTextBuilder.Append(newline);
            detailsTextBuilder.Append(newline);
            detailsTextBuilder.Append(string.Format(CultureInfo.CurrentCulture, sectionseparator, SR.ExDlgMsgLoadedAssembliesSection));

            foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
            {
                AssemblyName name    = asm.GetName();
                string       fileVer = SR.NotAvailable;

                try
                {
                    if (name.EscapedCodeBase is not null && name.EscapedCodeBase.Length > 0)
                    {
                        Uri codeBase = new Uri(name.EscapedCodeBase);
                        if (codeBase.Scheme == "file")
                        {
                            fileVer = FileVersionInfo.GetVersionInfo(NativeMethods.GetLocalPath(name.EscapedCodeBase)).FileVersion;
                        }
                    }
                }
                catch (IO.FileNotFoundException)
                {
                }
                detailsTextBuilder.Append(string.Format(SR.ExDlgMsgLoadedAssembliesEntry, name.Name, name.Version, fileVer, name.EscapedCodeBase));
                detailsTextBuilder.Append(separator);
            }

            detailsTextBuilder.Append(string.Format(CultureInfo.CurrentCulture, sectionseparator, SR.ExDlgMsgJITDebuggingSection));
            if (Application.CustomThreadExceptionHandlerAttached)
            {
                detailsTextBuilder.Append(SR.ExDlgMsgFooterNonSwitchable);
            }
            else
            {
                detailsTextBuilder.Append(SR.ExDlgMsgFooterSwitchable);
            }

            detailsTextBuilder.Append(newline);
            detailsTextBuilder.Append(newline);

            string detailsText = detailsTextBuilder.ToString();

            Graphics g = message.CreateGraphicsInternal();

            Size textSize = new Size(scaledMaxWidth - scaledPaddingWidth, int.MaxValue);

            if (DpiHelper.IsScalingRequirementMet && !Control.UseCompatibleTextRenderingDefault)
            {
                // we need to measure string using API that matches the rendering engine - TextRenderer.MeasureText for GDI
                textSize = Size.Ceiling(TextRenderer.MeasureText(messageText, Font, textSize, TextFormatFlags.WordBreak));
            }
            else
            {
                // if HighDpi improvements are not enabled, or rendering mode is GDI+, use Graphics.MeasureString
                textSize = Size.Ceiling(g.MeasureString(messageText, Font, textSize.Width));
            }

            textSize.Height += scaledExceptionMessageVerticalPadding;
            g.Dispose();

            if (textSize.Width < scaledMaxTextWidth)
            {
                textSize.Width = scaledMaxTextWidth;
            }

            if (textSize.Height > scaledMaxHeight)
            {
                textSize.Height = scaledMaxHeight;
            }

            int width     = textSize.Width + scaledPaddingWidth;
            int buttonTop = Math.Max(textSize.Height, scaledMaxTextHeight) + scaledPaddingHeight;

            Form activeForm = Form.ActiveForm;

            if (activeForm is null || activeForm.Text.Length == 0)
            {
                Text = SR.ExDlgCaption;
            }
コード例 #6
0
        /// <include file='doc\ThreadExceptionDialog.uex' path='docs/doc[@for="ThreadExceptionDialog.ThreadExceptionDialog"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Initializes a new instance of the <see cref='System.Windows.Forms.ThreadExceptionDialog'/> class.
        ///
        ///    </para>
        /// </devdoc>
        public ThreadExceptionDialog(Exception t)
        {
            string messageRes;
            string messageText;

            Button[] buttons;
            bool     detailAnchor = false;

            WarningException w = t as WarningException;

            if (w != null)
            {
                messageRes  = SR.ExDlgWarningText;
                messageText = w.Message;
                if (w.HelpUrl == null)
                {
                    buttons = new Button[] { continueButton };
                }
                else
                {
                    buttons = new Button[] { continueButton, helpButton };
                }
            }
            else
            {
                messageText = t.Message;

                detailAnchor = true;

                if (Application.AllowQuit)
                {
                    if (t is SecurityException)
                    {
                        messageRes = "ExDlgSecurityErrorText";
                    }
                    else
                    {
                        messageRes = "ExDlgErrorText";
                    }
                    buttons = new Button[] { detailsButton, continueButton, quitButton };
                }
                else
                {
                    if (t is SecurityException)
                    {
                        messageRes = "ExDlgSecurityContinueErrorText";
                    }
                    else
                    {
                        messageRes = "ExDlgContinueErrorText";
                    }
                    buttons = new Button[] { detailsButton, continueButton };
                }
            }

            if (messageText.Length == 0)
            {
                messageText = t.GetType().Name;
            }
            if (t is SecurityException)
            {
                messageText = SR.GetString(messageRes, t.GetType().Name, Trim(messageText));
            }
            else
            {
                messageText = SR.GetString(messageRes, Trim(messageText));
            }

            StringBuilder detailsTextBuilder = new StringBuilder();
            string        newline            = "\r\n";
            string        separator          = SR.GetString(SR.ExDlgMsgSeperator);
            string        sectionseparator   = SR.GetString(SR.ExDlgMsgSectionSeperator);

            if (Application.CustomThreadExceptionHandlerAttached)
            {
                detailsTextBuilder.Append(SR.GetString(SR.ExDlgMsgHeaderNonSwitchable));
            }
            else
            {
                detailsTextBuilder.Append(SR.GetString(SR.ExDlgMsgHeaderSwitchable));
            }
            detailsTextBuilder.Append(string.Format(CultureInfo.CurrentCulture, sectionseparator, SR.GetString(SR.ExDlgMsgExceptionSection)));
            detailsTextBuilder.Append(t.ToString());
            detailsTextBuilder.Append(newline);
            detailsTextBuilder.Append(newline);
            detailsTextBuilder.Append(string.Format(CultureInfo.CurrentCulture, sectionseparator, SR.GetString(SR.ExDlgMsgLoadedAssembliesSection)));
            new FileIOPermission(PermissionState.Unrestricted).Assert();
            try {
                foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
                {
                    AssemblyName name    = asm.GetName();
                    string       fileVer = SR.GetString(SR.NotAvailable);

                    try {
                        // bug 113573 -- if there's a path with an escaped value in it
                        // like c:\temp\foo%2fbar, the AssemblyName call will unescape it to
                        // c:\temp\foo\bar, which is wrong, and this will fail.   It doesn't look like the
                        // assembly name class handles this properly -- even the "CodeBase" property is un-escaped
                        // so we can't circumvent this.
                        //
                        if (name.EscapedCodeBase != null && name.EscapedCodeBase.Length > 0)
                        {
                            Uri codeBase = new Uri(name.EscapedCodeBase);
                            if (codeBase.Scheme == "file")
                            {
                                fileVer = FileVersionInfo.GetVersionInfo(NativeMethods.GetLocalPath(name.EscapedCodeBase)).FileVersion;
                            }
                        }
                    }
                    catch (System.IO.FileNotFoundException) {
                    }
                    detailsTextBuilder.Append(SR.GetString(SR.ExDlgMsgLoadedAssembliesEntry, name.Name, name.Version, fileVer, name.EscapedCodeBase));
                    detailsTextBuilder.Append(separator);
                }
            }
            finally {
                CodeAccessPermission.RevertAssert();
            }

            detailsTextBuilder.Append(string.Format(CultureInfo.CurrentCulture, sectionseparator, SR.GetString(SR.ExDlgMsgJITDebuggingSection)));
            if (Application.CustomThreadExceptionHandlerAttached)
            {
                detailsTextBuilder.Append(SR.GetString(SR.ExDlgMsgFooterNonSwitchable));
            }
            else
            {
                detailsTextBuilder.Append(SR.GetString(SR.ExDlgMsgFooterSwitchable));
            }

            detailsTextBuilder.Append(newline);
            detailsTextBuilder.Append(newline);

            string detailsText = detailsTextBuilder.ToString();

            Graphics g = message.CreateGraphicsInternal();

            Size textSize = Size.Ceiling(g.MeasureString(messageText, Font, MAXWIDTH - 84));

            textSize.Height += 4;
            g.Dispose();

            if (textSize.Width < 180)
            {
                textSize.Width = 180;
            }
            if (textSize.Height > MAXHEIGHT)
            {
                textSize.Height = MAXHEIGHT;
            }

            int width     = textSize.Width + 84;
            int buttonTop = Math.Max(textSize.Height, 40) + 26;

            // SECREVIEW : We must get a hold of the parent to get at it's text
            //           : to make this dialog look like the parent.
            //
            IntSecurity.GetParent.Assert();
            try {
                Form activeForm = Form.ActiveForm;
                if (activeForm == null || activeForm.Text.Length == 0)
                {
                    Text = SR.GetString(SR.ExDlgCaption);
                }
                else
                {
                    Text = SR.GetString(SR.ExDlgCaption2, activeForm.Text);
                }
            }
            finally {
                CodeAccessPermission.RevertAssert();
            }
            AcceptButton    = continueButton;
            CancelButton    = continueButton;
            FormBorderStyle = FormBorderStyle.FixedDialog;
            MaximizeBox     = false;
            MinimizeBox     = false;
            StartPosition   = FormStartPosition.CenterScreen;
            Icon            = null;
            ClientSize      = new Size(width, buttonTop + 31);
            TopMost         = true;

            pictureBox.Location = new Point(0, 0);
            pictureBox.Size     = new Size(64, 64);
            pictureBox.SizeMode = PictureBoxSizeMode.CenterImage;
            if (t is SecurityException)
            {
                pictureBox.Image = SystemIcons.Information.ToBitmap();
            }
            else
            {
                pictureBox.Image = SystemIcons.Error.ToBitmap();
            }
            Controls.Add(pictureBox);
            message.SetBounds(64,
                              8 + (40 - Math.Min(textSize.Height, 40)) / 2,
                              textSize.Width, textSize.Height);
            message.Text = messageText;
            Controls.Add(message);

            continueButton.Text         = SR.GetString(SR.ExDlgContinue);
            continueButton.FlatStyle    = FlatStyle.Standard;
            continueButton.DialogResult = DialogResult.Cancel;

            quitButton.Text         = SR.GetString(SR.ExDlgQuit);
            quitButton.FlatStyle    = FlatStyle.Standard;
            quitButton.DialogResult = DialogResult.Abort;

            helpButton.Text         = SR.GetString(SR.ExDlgHelp);
            helpButton.FlatStyle    = FlatStyle.Standard;
            helpButton.DialogResult = DialogResult.Yes;

            detailsButton.Text      = SR.GetString(SR.ExDlgShowDetails);
            detailsButton.FlatStyle = FlatStyle.Standard;
            detailsButton.Click    += new EventHandler(DetailsClick);

            Button b          = null;
            int    startIndex = 0;

            if (detailAnchor)
            {
                b = detailsButton;

                expandImage = new Bitmap(this.GetType(), "down.bmp");
                expandImage.MakeTransparent();
                collapseImage = new Bitmap(this.GetType(), "up.bmp");
                collapseImage.MakeTransparent();

                b.SetBounds(8, buttonTop, 100, 23);
                b.Image      = expandImage;
                b.ImageAlign = ContentAlignment.MiddleLeft;
                Controls.Add(b);
                startIndex = 1;
            }

            int buttonLeft = (width - 8 - ((buttons.Length - startIndex) * 105 - 5));

            for (int i = startIndex; i < buttons.Length; i++)
            {
                b = buttons[i];
                b.SetBounds(buttonLeft, buttonTop, 100, 23);
                Controls.Add(b);
                buttonLeft += 105;
            }

            details.Text          = detailsText;
            details.ScrollBars    = ScrollBars.Both;
            details.Multiline     = true;
            details.ReadOnly      = true;
            details.WordWrap      = false;
            details.TabStop       = false;
            details.AcceptsReturn = false;

            details.SetBounds(8, buttonTop + 31, width - 16, 154);
            Controls.Add(details);
        }
コード例 #7
0
ファイル: help.cs プロジェクト: wolewd/Windows-Server-2003
        private static Uri Resolve(string partialUri)
        {
            Debug.WriteLineIf(Help.WindowsFormsHelpTrace.TraceVerbose, "Help:: Resolve " + partialUri);
            Debug.Indent();

            Uri file = null;

            try {
                file = new Uri(partialUri);
            }
            catch {
                // eat URI parse exceptions...
                //
            }

            if (file != null && file.Scheme == "file")
            {
                string localPath = NativeMethods.GetLocalPath(partialUri);
                Debug.WriteLineIf(Help.WindowsFormsHelpTrace.TraceVerbose, "file, check for existence");
                new FileIOPermission(FileIOPermissionAccess.Read, localPath).Assert();
                try {
                    if (!File.Exists(localPath))
                    {
                        // nuke, and try relative to AppBase...
                        //
                        file = null;
                    }
                }
                finally {
                    CodeAccessPermission.RevertAssert();
                }
            }

            if (file == null)
            {
                Debug.WriteLineIf(Help.WindowsFormsHelpTrace.TraceVerbose, "try appbase relative");
                try {
                    // try relative to AppBase...
                    //
                    file = new Uri(new Uri(AppDomain.CurrentDomain.SetupInformation.ApplicationBase),
                                   partialUri);
                }
                catch {
                    // eat URI parse exceptions...
                    //
                }

                if (file != null && file.Scheme == "file")
                {
                    string localPath = file.LocalPath + file.Fragment;
                    Debug.WriteLineIf(Help.WindowsFormsHelpTrace.TraceVerbose, "file, check for existence");
                    new FileIOPermission(FileIOPermissionAccess.Read, localPath).Assert();
                    try {
                        if (!File.Exists(localPath))
                        {
                            // nuke - file isn't there...
                            //
                            file = null;
                        }
                    }
                    finally {
                        CodeAccessPermission.RevertAssert();
                    }
                }
            }



            Debug.Unindent();
            return(file);
        }
コード例 #8
0
        /// <include file='doc\ThreadExceptionDialog.uex' path='docs/doc[@for="ThreadExceptionDialog.ThreadExceptionDialog"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Initializes a new instance of the <see cref='System.Windows.Forms.ThreadExceptionDialog'/> class.
        ///
        ///    </para>
        /// </devdoc>
        public ThreadExceptionDialog(Exception t)
        {
            if (DpiHelper.EnableThreadExceptionDialogHighDpiImprovements)
            {
                scaledMaxWidth                        = DpiHelper.LogicalToDeviceUnitsX(MAXWIDTH);
                scaledMaxHeight                       = DpiHelper.LogicalToDeviceUnitsY(MAXHEIGHT);
                scaledPaddingWidth                    = DpiHelper.LogicalToDeviceUnitsX(PADDINGWIDTH);
                scaledPaddingHeight                   = DpiHelper.LogicalToDeviceUnitsY(PADDINGHEIGHT);
                scaledMaxTextWidth                    = DpiHelper.LogicalToDeviceUnitsX(MAXTEXTWIDTH);
                scaledMaxTextHeight                   = DpiHelper.LogicalToDeviceUnitsY(MAXTEXTHEIGHT);
                scaledButtonTopPadding                = DpiHelper.LogicalToDeviceUnitsY(BUTTONTOPPADDING);
                scaledButtonDetailsLeftPadding        = DpiHelper.LogicalToDeviceUnitsX(BUTTONDETAILS_LEFTPADDING);
                scaledMessageTopPadding               = DpiHelper.LogicalToDeviceUnitsY(MESSAGE_TOPPADDING);
                scaledHeightPadding                   = DpiHelper.LogicalToDeviceUnitsY(HEIGHTPADDING);
                scaledButtonWidth                     = DpiHelper.LogicalToDeviceUnitsX(BUTTONWIDTH);
                scaledButtonHeight                    = DpiHelper.LogicalToDeviceUnitsY(BUTTONHEIGHT);
                scaledButtonAlignmentWidth            = DpiHelper.LogicalToDeviceUnitsX(BUTTONALIGNMENTWIDTH);
                scaledButtonAlignmentPadding          = DpiHelper.LogicalToDeviceUnitsX(BUTTONALIGNMENTPADDING);
                scaledDetailsWidthPadding             = DpiHelper.LogicalToDeviceUnitsX(DETAILSWIDTHPADDING);
                scaledDetailsHeight                   = DpiHelper.LogicalToDeviceUnitsY(DETAILSHEIGHT);
                scaledPictureWidth                    = DpiHelper.LogicalToDeviceUnitsX(PICTUREWIDTH);
                scaledPictureHeight                   = DpiHelper.LogicalToDeviceUnitsY(PICTUREHEIGHT);
                scaledExceptionMessageVerticalPadding = DpiHelper.LogicalToDeviceUnitsY(EXCEPTIONMESSAGEVERTICALPADDING);
            }

            string messageRes;
            string messageText;

            Button[] buttons;
            bool     detailAnchor = false;

            WarningException w = t as WarningException;

            if (w != null)
            {
                messageRes  = SR.ExDlgWarningText;
                messageText = w.Message;
                if (w.HelpUrl == null)
                {
                    buttons = new Button[] { continueButton };
                }
                else
                {
                    buttons = new Button[] { continueButton, helpButton };
                }
            }
            else
            {
                messageText = t.Message;

                detailAnchor = true;

                if (Application.AllowQuit)
                {
                    if (t is SecurityException)
                    {
                        messageRes = "ExDlgSecurityErrorText";
                    }
                    else
                    {
                        messageRes = "ExDlgErrorText";
                    }
                    buttons = new Button[] { detailsButton, continueButton, quitButton };
                }
                else
                {
                    if (t is SecurityException)
                    {
                        messageRes = "ExDlgSecurityContinueErrorText";
                    }
                    else
                    {
                        messageRes = "ExDlgContinueErrorText";
                    }
                    buttons = new Button[] { detailsButton, continueButton };
                }
            }

            if (messageText.Length == 0)
            {
                messageText = t.GetType().Name;
            }
            if (t is SecurityException)
            {
                messageText = SR.GetString(messageRes, t.GetType().Name, Trim(messageText));
            }
            else
            {
                messageText = SR.GetString(messageRes, Trim(messageText));
            }

            StringBuilder detailsTextBuilder = new StringBuilder();
            string        newline            = "\r\n";
            string        separator          = SR.GetString(SR.ExDlgMsgSeperator);
            string        sectionseparator   = SR.GetString(SR.ExDlgMsgSectionSeperator);

            if (Application.CustomThreadExceptionHandlerAttached)
            {
                detailsTextBuilder.Append(SR.GetString(SR.ExDlgMsgHeaderNonSwitchable));
            }
            else
            {
                detailsTextBuilder.Append(SR.GetString(SR.ExDlgMsgHeaderSwitchable));
            }
            detailsTextBuilder.Append(string.Format(CultureInfo.CurrentCulture, sectionseparator, SR.GetString(SR.ExDlgMsgExceptionSection)));
            detailsTextBuilder.Append(t.ToString());
            detailsTextBuilder.Append(newline);
            detailsTextBuilder.Append(newline);
            detailsTextBuilder.Append(string.Format(CultureInfo.CurrentCulture, sectionseparator, SR.GetString(SR.ExDlgMsgLoadedAssembliesSection)));
            new FileIOPermission(PermissionState.Unrestricted).Assert();
            try {
                foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
                {
                    AssemblyName name    = asm.GetName();
                    string       fileVer = SR.GetString(SR.NotAvailable);

                    try {
                        // bug 113573 -- if there's a path with an escaped value in it
                        // like c:\temp\foo%2fbar, the AssemblyName call will unescape it to
                        // c:\temp\foo\bar, which is wrong, and this will fail.   It doesn't look like the
                        // assembly name class handles this properly -- even the "CodeBase" property is un-escaped
                        // so we can't circumvent this.
                        //
                        if (name.EscapedCodeBase != null && name.EscapedCodeBase.Length > 0)
                        {
                            Uri codeBase = new Uri(name.EscapedCodeBase);
                            if (codeBase.Scheme == "file")
                            {
                                fileVer = FileVersionInfo.GetVersionInfo(NativeMethods.GetLocalPath(name.EscapedCodeBase)).FileVersion;
                            }
                        }
                    }
                    catch (System.IO.FileNotFoundException) {
                    }
                    detailsTextBuilder.Append(SR.GetString(SR.ExDlgMsgLoadedAssembliesEntry, name.Name, name.Version, fileVer, name.EscapedCodeBase));
                    detailsTextBuilder.Append(separator);
                }
            }
            finally {
                CodeAccessPermission.RevertAssert();
            }

            detailsTextBuilder.Append(string.Format(CultureInfo.CurrentCulture, sectionseparator, SR.GetString(SR.ExDlgMsgJITDebuggingSection)));
            if (Application.CustomThreadExceptionHandlerAttached)
            {
                detailsTextBuilder.Append(SR.GetString(SR.ExDlgMsgFooterNonSwitchable));
            }
            else
            {
                detailsTextBuilder.Append(SR.GetString(SR.ExDlgMsgFooterSwitchable));
            }

            detailsTextBuilder.Append(newline);
            detailsTextBuilder.Append(newline);

            string detailsText = detailsTextBuilder.ToString();

            Graphics g = message.CreateGraphicsInternal();

            Size textSize = new Size(scaledMaxWidth - scaledPaddingWidth, int.MaxValue);

            if (DpiHelper.EnableThreadExceptionDialogHighDpiImprovements && (Label.UseCompatibleTextRenderingDefault == false))
            {
                // we need to measure string using API that matches the rendering engine - TextRenderer.MeasureText for GDI
                textSize = Size.Ceiling(TextRenderer.MeasureText(messageText, Font, textSize, TextFormatFlags.WordBreak));
            }
            else
            {
                // if HighDpi improvements are not enabled, or rendering mode is GDI+, use Graphics.MeasureString
                textSize = Size.Ceiling(g.MeasureString(messageText, Font, textSize.Width));
            }

            textSize.Height += scaledExceptionMessageVerticalPadding;
            g.Dispose();

            if (textSize.Width < scaledMaxTextWidth)
            {
                textSize.Width = scaledMaxTextWidth;
            }
            if (textSize.Height > scaledMaxHeight)
            {
                textSize.Height = scaledMaxHeight;
            }

            int width     = textSize.Width + scaledPaddingWidth;
            int buttonTop = Math.Max(textSize.Height, scaledMaxTextHeight) + scaledPaddingHeight;

            // SECREVIEW : We must get a hold of the parent to get at it's text
            //           : to make this dialog look like the parent.
            //
            IntSecurity.GetParent.Assert();
            try {
                Form activeForm = Form.ActiveForm;
                if (activeForm == null || activeForm.Text.Length == 0)
                {
                    Text = SR.GetString(SR.ExDlgCaption);
                }
                else
                {
                    Text = SR.GetString(SR.ExDlgCaption2, activeForm.Text);
                }
            }
            finally {
                CodeAccessPermission.RevertAssert();
            }
            AcceptButton    = continueButton;
            CancelButton    = continueButton;
            FormBorderStyle = FormBorderStyle.FixedDialog;
            MaximizeBox     = false;
            MinimizeBox     = false;
            StartPosition   = FormStartPosition.CenterScreen;
            Icon            = null;
            ClientSize      = new Size(width, buttonTop + scaledButtonTopPadding);
            TopMost         = true;

            pictureBox.Location = new Point(0, 0);
            pictureBox.Size     = new Size(scaledPictureWidth, scaledPictureHeight);
            pictureBox.SizeMode = PictureBoxSizeMode.CenterImage;
            if (t is SecurityException)
            {
                pictureBox.Image = SystemIcons.Information.ToBitmap();
            }
            else
            {
                pictureBox.Image = SystemIcons.Error.ToBitmap();
            }
            Controls.Add(pictureBox);
            message.SetBounds(scaledPictureWidth,
                              scaledMessageTopPadding + (scaledMaxTextHeight - Math.Min(textSize.Height, scaledMaxTextHeight)) / 2,
                              textSize.Width, textSize.Height);
            message.Text = messageText;
            Controls.Add(message);

            continueButton.Text         = SR.GetString(SR.ExDlgContinue);
            continueButton.FlatStyle    = FlatStyle.Standard;
            continueButton.DialogResult = DialogResult.Cancel;

            quitButton.Text         = SR.GetString(SR.ExDlgQuit);
            quitButton.FlatStyle    = FlatStyle.Standard;
            quitButton.DialogResult = DialogResult.Abort;

            helpButton.Text         = SR.GetString(SR.ExDlgHelp);
            helpButton.FlatStyle    = FlatStyle.Standard;
            helpButton.DialogResult = DialogResult.Yes;

            detailsButton.Text      = SR.GetString(SR.ExDlgShowDetails);
            detailsButton.FlatStyle = FlatStyle.Standard;
            detailsButton.Click    += new EventHandler(DetailsClick);

            Button b          = null;
            int    startIndex = 0;

            if (detailAnchor)
            {
                b = detailsButton;

                expandImage = new Bitmap(this.GetType(), "down.bmp");
                expandImage.MakeTransparent();
                collapseImage = new Bitmap(this.GetType(), "up.bmp");
                collapseImage.MakeTransparent();

                if (DpiHelper.EnableThreadExceptionDialogHighDpiImprovements)
                {
                    DpiHelper.ScaleBitmapLogicalToDevice(ref expandImage);
                    DpiHelper.ScaleBitmapLogicalToDevice(ref collapseImage);
                }

                b.SetBounds(scaledButtonDetailsLeftPadding, buttonTop, scaledButtonWidth, scaledButtonHeight);
                b.Image      = expandImage;
                b.ImageAlign = ContentAlignment.MiddleLeft;
                Controls.Add(b);
                startIndex = 1;
            }

            int buttonLeft = (width - scaledButtonDetailsLeftPadding - ((buttons.Length - startIndex) * scaledButtonAlignmentWidth - scaledButtonAlignmentPadding));

            for (int i = startIndex; i < buttons.Length; i++)
            {
                b = buttons[i];
                b.SetBounds(buttonLeft, buttonTop, scaledButtonWidth, scaledButtonHeight);
                Controls.Add(b);
                buttonLeft += scaledButtonAlignmentWidth;
            }

            details.Text          = detailsText;
            details.ScrollBars    = ScrollBars.Both;
            details.Multiline     = true;
            details.ReadOnly      = true;
            details.WordWrap      = false;
            details.TabStop       = false;
            details.AcceptsReturn = false;

            details.SetBounds(scaledButtonDetailsLeftPadding, buttonTop + scaledButtonTopPadding, width - scaledDetailsWidthPadding, scaledDetailsHeight);
            Controls.Add(details);
        }
コード例 #9
0
ファイル: Help.cs プロジェクト: akrisiun/winforms
        private static Uri Resolve(string partialUri)
        {
            Debug.WriteLineIf(Help.WindowsFormsHelpTrace.TraceVerbose, "Help:: Resolve " + partialUri);
            Debug.Indent();

            Uri file = null;

            if (!string.IsNullOrEmpty(partialUri))
            {
                try {
                    file = new Uri(partialUri);
                }
                catch (UriFormatException) {
                    // eat URI parse exceptions...
                    //
                }
                catch (ArgumentNullException) {
                    // Catch specific exceptions
                    // Shouldnt get here...
                }
            }

            if (file != null && file.Scheme == "file")
            {
                string localPath = NativeMethods.GetLocalPath(partialUri);
                Debug.WriteLineIf(Help.WindowsFormsHelpTrace.TraceVerbose, "file, check for existence");

                //

                new FileIOPermission(FileIOPermissionAccess.Read, localPath).Assert();
                try {
                    if (!File.Exists(localPath))
                    {
                        // clear, and try relative to AppBase...
                        //
                        file = null;
                    }
                }
                finally {
                    CodeAccessPermission.RevertAssert();
                }
            }

            if (file == null)
            {
                Debug.WriteLineIf(Help.WindowsFormsHelpTrace.TraceVerbose, "try appbase relative");
                try {
                    // try relative to AppBase...
                    //
                    file = new Uri(new Uri(AppContext.BaseDirectory),
                                   partialUri);
                }
                catch (UriFormatException) {
                    // Catch specific exceptions
                    // eat URI parse exceptions...
                    //
                }
                catch (ArgumentNullException) {
                    // Catch specific exceptions
                    // Shouldnt get here...
                }

                if (file != null && file.Scheme == "file")
                {
                    string localPath = file.LocalPath + file.Fragment;
                    Debug.WriteLineIf(Help.WindowsFormsHelpTrace.TraceVerbose, "file, check for existence");
                    new FileIOPermission(FileIOPermissionAccess.Read, localPath).Assert();
                    try {
                        if (!File.Exists(localPath))
                        {
                            // clear - file isn't there...
                            //
                            file = null;
                        }
                    }
                    finally {
                        CodeAccessPermission.RevertAssert();
                    }
                }
            }



            Debug.Unindent();
            return(file);
        }