Handles exceptions caught when a graph is exported to email.
상속: Object
예제 #1
0
        TryExportToEmail
        (
            Microsoft.Office.Interop.Excel.Workbook oWorkbook,
            NodeXLControl oNodeXLControl
        )
        {
            Debug.Assert(oWorkbook != null);
            Debug.Assert(oNodeXLControl != null);

            ExportToEmailUserSettings oExportToEmailUserSettings =
                new ExportToEmailUserSettings();

            String sSmtpPassword = (new PasswordUserSettings()).SmtpPassword;

            if (!ExportToEmailUserSettingsAreComplete(
                    oExportToEmailUserSettings, sSmtpPassword))
            {
                FormUtil.ShowWarning(
                    "The graph can't be exported to email because all required"
                    + " email options haven't been specified yet.  Go to NodeXL,"
                    + " Graph, Automate to fix this."
                    );

                return(false);
            }

            try
            {
                (new EmailExporter()).ExportToEmail(
                    oWorkbook,
                    oNodeXLControl,
                    oExportToEmailUserSettings.SpaceDelimitedToAddresses.Split(' '),
                    oExportToEmailUserSettings.FromAddress,
                    GraphTitleCreator.CreateGraphTitle(oWorkbook),
                    oExportToEmailUserSettings.MessageBody,
                    oExportToEmailUserSettings.SmtpHost,
                    oExportToEmailUserSettings.SmtpPort,
                    oExportToEmailUserSettings.UseSslForSmtp,
                    oExportToEmailUserSettings.SmtpUserName,
                    sSmtpPassword,
                    oExportToEmailUserSettings.ExportWorkbookAndSettings,
                    oExportToEmailUserSettings.ExportGraphML,
                    oExportToEmailUserSettings.UseFixedAspectRatio
                    );

                return(true);
            }
            catch (Exception oException)
            {
                String sMessage;

                if (EmailExceptionHandler.TryGetMessageForRecognizedException(
                        oException, out sMessage))
                {
                    FormUtil.ShowWarning(sMessage);
                }
                else
                {
                    ErrorUtil.OnException(oException);
                }

                return(false);
            }
        }
예제 #2
0
        btnOK_Click
        (
            object sender,
            EventArgs e
        )
        {
            AssertValid();

            if (!DoDataExchange(true))
            {
                return;
            }

            if (m_eMode == DialogMode.Normal)
            {
                this.Cursor = Cursors.WaitCursor;

                try
                {
                    (new EmailExporter()).ExportToEmail(
                        m_oWorkbook,
                        m_oNodeXLControl,

                        m_oExportToEmailUserSettings
                        .SpaceDelimitedToAddresses.Split(' '),

                        m_oExportToEmailUserSettings.FromAddress,
                        txbSubject.Text,
                        m_oExportToEmailUserSettings.MessageBody,
                        m_oExportToEmailUserSettings.SmtpHost,
                        m_oExportToEmailUserSettings.SmtpPort,
                        m_oExportToEmailUserSettings.UseSslForSmtp,
                        m_oExportToEmailUserSettings.SmtpUserName,
                        m_oPasswordUserSettings.SmtpPassword,
                        m_oExportToEmailUserSettings.ExportWorkbookAndSettings,
                        m_oExportToEmailUserSettings.ExportGraphML,
                        m_oExportToEmailUserSettings.UseFixedAspectRatio
                        );
                }
                catch (Exception oException)
                {
                    String sMessage;

                    if (EmailExceptionHandler
                        .TryGetMessageForRecognizedException(oException,
                                                             out sMessage))
                    {
                        if (oException is EmailAddressFormatException)
                        {
                            switch (((EmailAddressFormatException)oException)
                                    .EmailAddressType)
                            {
                            case EmailAddressType.To:

                                OnInvalidTextBox(txbToAddresses, sMessage);
                                break;

                            case EmailAddressType.From:

                                OnInvalidTextBox(txbFromAddress, sMessage);
                                break;

                            default:

                                Debug.Assert(false);
                                break;
                            }
                        }
                        else
                        {
                            this.ShowWarning(sMessage);
                        }
                    }
                    else
                    {
                        ErrorUtil.OnException(oException);
                    }

                    return;
                }
                finally
                {
                    this.Cursor = Cursors.Default;
                }
            }

            m_oExportToEmailUserSettings.Save();
            m_oPasswordUserSettings.Save();

            this.DialogResult = DialogResult.OK;
            this.Close();
        }