Smrf.NodeXL.ExcelTemplate.EmailExceptionHandler.TryGetMessageForRecognizedException C# (CSharp) Method

TryGetMessageForRecognizedException() public static method

public static TryGetMessageForRecognizedException ( Exception exception, String &message ) : System.Boolean
exception System.Exception
message String
return System.Boolean
    TryGetMessageForRecognizedException
    (
        Exception exception,
        out String message
    )
    {
        Debug.Assert(exception != null);

        if (exception is EmailAddressFormatException)
        {
            const String FormatMessage =
                "  An email address should look like \"[email protected]\".";

            switch ( ( (EmailAddressFormatException)exception )
                .EmailAddressType )
            {
                case EmailAddressType.To:

                    message =
                        "One of the \"To\" addresses is not in a recognized"
                        + " format." + FormatMessage
                        ;

                    break;

                case EmailAddressType.From:

                    message =
                        "The \"from\" address is not in a recognized format."
                        + FormatMessage
                        ;

                    break;

                default:

                    Debug.Assert(false);
                    throw exception;
            }
        }
        else if (exception is SmtpException)
        {
            message =
                "A problem occurred while sending the email.  Details:"
                + "\r\n\r\n"
                + exception.Message
                ;
        }
        else
        {
            message = null;

            return (false);
        }

        return (true);
    }
}

Usage Example

コード例 #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);
            }
        }
All Usage Examples Of Smrf.NodeXL.ExcelTemplate.EmailExceptionHandler::TryGetMessageForRecognizedException