Exemplo n.º 1
0
        TryExportToNodeXLGraphGallery
        (
            Microsoft.Office.Interop.Excel.Workbook oWorkbook,
            NodeXLControl oNodeXLControl
        )
        {
            Debug.Assert(oWorkbook != null);
            Debug.Assert(oNodeXLControl != null);

            ExportToNodeXLGraphGalleryUserSettings
                oExportToNodeXLGraphGalleryUserSettings =
                new ExportToNodeXLGraphGalleryUserSettings();

            String sAuthor, sPassword;

            GetGraphGalleryAuthorAndPassword(
                oExportToNodeXLGraphGalleryUserSettings, out sAuthor,
                out sPassword);

            // Note that a graph summary is used for the description.

            try
            {
                (new NodeXLGraphGalleryExporter()).ExportToNodeXLGraphGallery(
                    oWorkbook,
                    oNodeXLControl,
                    GraphTitleCreator.CreateGraphTitle(oWorkbook),
                    GraphSummarizer.SummarizeGraph(oWorkbook),
                    oExportToNodeXLGraphGalleryUserSettings.SpaceDelimitedTags,
                    sAuthor,
                    sPassword,

                    oExportToNodeXLGraphGalleryUserSettings
                    .ExportWorkbookAndSettings,

                    oExportToNodeXLGraphGalleryUserSettings.ExportGraphML,
                    oExportToNodeXLGraphGalleryUserSettings.UseFixedAspectRatio
                    );

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

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

                return(false);
            }
        }
Exemplo n.º 2
0
        DoDataExchange
        (
            Boolean bFromControls
        )
        {
            if (bFromControls)
            {
                String sTitle;

                if (!ValidateRequiredTextBox(txbTitle, "Enter a title.",
                                             out sTitle))
                {
                    return(false);
                }

                m_oExportToNodeXLGraphGalleryUserSettings.UseCredentials =
                    radUseCredentials.Checked;

                String sAuthor   = null;
                String sPassword = null;

                if (m_oExportToNodeXLGraphGalleryUserSettings.UseCredentials)
                {
                    if (
                        !ValidateRequiredTextBox(txbAuthor,
                                                 "Enter a user name.", out sAuthor)
                        ||
                        !ValidateRequiredTextBox(txbPassword,
                                                 "Enter a password.", out sPassword)
                        )
                    {
                        return(false);
                    }
                }
                else
                {
                    if (
                        !ValidateRequiredTextBox(txbGuestName,
                                                 "Enter a guest name.", out sAuthor)
                        )
                    {
                        return(false);
                    }
                }

                if (!usrExportedFiles.Validate())
                {
                    return(false);
                }

                m_oExportToNodeXLGraphGalleryUserSettings.SpaceDelimitedTags =
                    txbSpaceDelimitedTags.Text.Trim();

                m_oExportToNodeXLGraphGalleryUserSettings.
                ExportWorkbookAndSettings =
                    usrExportedFiles.ExportWorkbookAndSettings;

                m_oExportToNodeXLGraphGalleryUserSettings.ExportGraphML =
                    usrExportedFiles.ExportGraphML;

                m_oExportToNodeXLGraphGalleryUserSettings
                .UseFixedAspectRatio = usrExportedFiles.UseFixedAspectRatio;

                m_oExportToNodeXLGraphGalleryUserSettings.Author = sAuthor;

                m_oPasswordUserSettings.NodeXLGraphGalleryPassword =
                    sPassword;
            }
            else
            {
                if (m_eMode == DialogMode.Normal)
                {
                    txbTitle.Text =
                        GraphTitleCreator.CreateGraphTitle(m_oWorkbook);

                    txbDescription.Text = GetDefaultDescription();
                }

                txbSpaceDelimitedTags.Text =
                    m_oExportToNodeXLGraphGalleryUserSettings.
                    SpaceDelimitedTags;

                usrExportedFiles.ExportWorkbookAndSettings =
                    m_oExportToNodeXLGraphGalleryUserSettings.
                    ExportWorkbookAndSettings;

                usrExportedFiles.ExportGraphML =
                    m_oExportToNodeXLGraphGalleryUserSettings.ExportGraphML;

                usrExportedFiles.UseFixedAspectRatio =
                    m_oExportToNodeXLGraphGalleryUserSettings
                    .UseFixedAspectRatio;

                if (m_oExportToNodeXLGraphGalleryUserSettings.UseCredentials)
                {
                    radUseCredentials.Checked = true;

                    txbAuthor.Text =
                        m_oExportToNodeXLGraphGalleryUserSettings.Author;

                    txbPassword.Text =
                        m_oPasswordUserSettings.NodeXLGraphGalleryPassword;
                }
                else
                {
                    radAsGuest.Checked = true;

                    txbGuestName.Text =
                        m_oExportToNodeXLGraphGalleryUserSettings.Author;
                }

                EnableControls();
            }

            return(true);
        }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
0
        DoDataExchange
        (
            Boolean bFromControls
        )
        {
            if (bFromControls)
            {
                String sToAddresses, sFromAddress, sSubject, sSmtpHost,
                       sSmtpUserName, sSmtpPassword;

                Int32 iSmtpPort;

                if (
                    !ValidateRequiredTextBox(txbToAddresses,

                                             "Enter one or more \"to\" email addresses, separated with"
                                             + " spaces, commas or returns.",

                                             out sToAddresses)
                    ||
                    !ValidateRequiredTextBox(txbFromAddress,
                                             "Enter a \"from\" email address.",
                                             out sFromAddress)
                    ||
                    !ValidateRequiredTextBox(txbSubject,
                                             "Enter a subject.",
                                             out sSubject)
                    ||
                    !ValidateRequiredTextBox(txbSmtpHost,

                                             "Enter the name of an SMTP server, such as"
                                             + " smtp.gmail.com.",

                                             out sSmtpHost)
                    ||
                    !ValidateInt32TextBox(txbSmtpPort, 1, 65535,
                                          "Enter the SMTP port number.",
                                          out iSmtpPort)
                    ||
                    !ValidateRequiredTextBox(txbSmtpUserName,
                                             "Enter the user name for an account on the SMTP server.",
                                             out sSmtpUserName)
                    ||
                    !ValidateRequiredTextBox(txbSmtpPassword,
                                             "Enter the password for an account on the SMTP server.",
                                             out sSmtpPassword)
                    ||
                    !usrExportedFiles.Validate()
                    )
                {
                    return(false);
                }

                m_oExportToEmailUserSettings.SpaceDelimitedToAddresses =
                    String.Join(" ", StringUtil.SplitOnCommonDelimiters(
                                    sToAddresses));

                m_oExportToEmailUserSettings.FromAddress = sFromAddress;
                m_oExportToEmailUserSettings.MessageBody = txbMessageBody.Text;
                m_oExportToEmailUserSettings.SmtpHost    = sSmtpHost;
                m_oExportToEmailUserSettings.SmtpPort    = iSmtpPort;

                m_oExportToEmailUserSettings.UseSslForSmtp =
                    chkUseSslForSmtp.Checked;

                m_oExportToEmailUserSettings.SmtpUserName = sSmtpUserName;
                m_oPasswordUserSettings.SmtpPassword      = sSmtpPassword;

                m_oExportToEmailUserSettings.ExportWorkbookAndSettings =
                    usrExportedFiles.ExportWorkbookAndSettings;

                m_oExportToEmailUserSettings.ExportGraphML =
                    usrExportedFiles.ExportGraphML;

                m_oExportToEmailUserSettings.UseFixedAspectRatio =
                    usrExportedFiles.UseFixedAspectRatio;
            }
            else
            {
                txbToAddresses.Text =
                    m_oExportToEmailUserSettings.SpaceDelimitedToAddresses;

                txbFromAddress.Text = m_oExportToEmailUserSettings.FromAddress;

                if (m_eMode == DialogMode.Normal)
                {
                    txbSubject.Text =
                        GraphTitleCreator.CreateGraphTitle(m_oWorkbook);
                }

                txbMessageBody.Text = m_oExportToEmailUserSettings.MessageBody;
                txbSmtpHost.Text    = m_oExportToEmailUserSettings.SmtpHost;

                txbSmtpPort.Text =
                    m_oExportToEmailUserSettings.SmtpPort.ToString(
                        CultureInfo.InvariantCulture);

                chkUseSslForSmtp.Checked =
                    m_oExportToEmailUserSettings.UseSslForSmtp;

                txbSmtpUserName.Text =
                    m_oExportToEmailUserSettings.SmtpUserName;

                txbSmtpPassword.Text = m_oPasswordUserSettings.SmtpPassword;

                usrExportedFiles.ExportWorkbookAndSettings =
                    m_oExportToEmailUserSettings.ExportWorkbookAndSettings;

                usrExportedFiles.ExportGraphML =
                    m_oExportToEmailUserSettings.ExportGraphML;

                usrExportedFiles.UseFixedAspectRatio =
                    m_oExportToEmailUserSettings.UseFixedAspectRatio;
            }

            return(true);
        }