Centralizes the sending and receiving of event-based commands.
This static class is used by senders to send event-based commands, and by receivers to receive such commands. See the class for details on the "chain of responsibility" pattern that NodeXL uses for sending commands from one UI object to another -- from the Ribbon to the TaskPane, for example.
Inheritance: Object
Exemplo n.º 1
0
        btnOK_Click
        (
            object sender,
            System.EventArgs e
        )
        {
            if (!DoDataExchange(true))
            {
                return;
            }

            m_oAutomateTasksUserSettings.Save();

            try
            {
                if (m_eMode == DialogMode.EditOnly)
                {
                    // (Just close the dialog.)
                }
                else if (m_oAutomateTasksUserSettings.AutomateThisWorkbookOnly)
                {
                    Debug.Assert(m_oNodeXLControl != null);

                    TaskAutomator.AutomateOneWorkbook(m_oThisWorkbook,
                                                      m_oNodeXLControl, m_oAutomateTasksUserSettings.TasksToRun,
                                                      m_oAutomateTasksUserSettings.FolderToSaveWorkbookTo);
                }
                else
                {
                    // The user settings for this workbook will be used for and
                    // stored in each workbook in the specified folder.

                    CommandDispatcher.SendCommand(this,
                                                  new RunNoParamCommandEventArgs(
                                                      NoParamCommand.SaveUserSettings));

                    String sWorkbookSettings = (new PerWorkbookSettings(
                                                    m_oThisWorkbook.InnerObject)).WorkbookSettings;

                    TaskAutomator.AutomateFolder(
                        m_oAutomateTasksUserSettings.FolderToAutomate,
                        sWorkbookSettings);
                }
            }
            catch (UnauthorizedAccessException oUnauthorizedAccessException)
            {
                // This occurs when a workbook is read-only.

                this.ShowWarning(
                    "A problem occurred while running tasks.  Details:"
                    + "\r\n\r\n"
                    + oUnauthorizedAccessException.Message
                    );

                return;
            }
            catch (Exception oException)
            {
                ErrorUtil.OnException(oException);
                return;
            }

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Exemplo n.º 2
0
        RunReadWorkbookTasks
        (
            ThisWorkbook oThisWorkbook,
            NodeXLControl oNodeXLControl,
            AutomationTasks eTasksToRun,
            String sFolderToSaveWorkbookTo
        )
        {
            Debug.Assert(oThisWorkbook != null);
            Debug.Assert(oNodeXLControl != null);

            Boolean bReadWorkbook = ShouldRunTask(
                eTasksToRun, AutomationTasks.ReadWorkbook);

            Boolean bSaveWorkbookIfNeverSaved = ShouldRunTask(
                eTasksToRun, AutomationTasks.SaveWorkbookIfNeverSaved);

            Boolean bSaveGraphImageFile = ShouldRunTask(
                eTasksToRun, AutomationTasks.SaveGraphImageFile);

            Boolean bExportToNodeXLGraphGallery = ShouldRunTask(
                eTasksToRun, AutomationTasks.ExportToNodeXLGraphGallery);

            Boolean bExportToEmail = ShouldRunTask(
                eTasksToRun, AutomationTasks.ExportToEmail);

            Microsoft.Office.Interop.Excel.Workbook oWorkbook =
                oThisWorkbook.InnerObject;

            if (bReadWorkbook)
            {
                // If the vertex X and Y columns were autofilled, the layout type
                // was set to LayoutType.Null.  This will cause
                // TaskPane.ReadWorkbook() to display a warning.  Temporarily turn
                // the warning off.

                Boolean bLayoutTypeIsNullNotificationsWereEnabled =
                    EnableLayoutTypeIsNullNotifications(false);

                if (
                    bSaveWorkbookIfNeverSaved
                    ||
                    bSaveGraphImageFile
                    ||
                    bExportToNodeXLGraphGallery
                    ||
                    bExportToEmail
                    )
                {
                    // These tasks need to wait until the workbook is read and the
                    // graph is laid out.

                    EventHandler <GraphLaidOutEventArgs> oGraphLaidOutEventHandler =
                        null;

                    oGraphLaidOutEventHandler =
                        delegate(Object sender, GraphLaidOutEventArgs e)
                    {
                        // This delegate remains forever, even when the dialog
                        // class is destroyed.  Prevent it from being called again.

                        oThisWorkbook.GraphLaidOut -= oGraphLaidOutEventHandler;

                        if (bSaveWorkbookIfNeverSaved)
                        {
                            if (!TrySaveWorkbookIfNeverSaved(oWorkbook,
                                                             sFolderToSaveWorkbookTo))
                            {
                                return;
                            }
                        }

                        if (bSaveGraphImageFile)
                        {
                            Debug.Assert(!String.IsNullOrEmpty(
                                             oThisWorkbook.Path));

                            SaveGraphImageFile(e.NodeXLControl, e.LegendControls,
                                               oThisWorkbook.FullName);
                        }

                        if (bExportToNodeXLGraphGallery)
                        {
                            if (!TryExportToNodeXLGraphGallery(
                                    oThisWorkbook.InnerObject, oNodeXLControl))
                            {
                                return;
                            }
                        }

                        if (bExportToEmail)
                        {
                            if (!TryExportToEmail(
                                    oThisWorkbook.InnerObject, oNodeXLControl))
                            {
                                return;
                            }
                        }
                    };

                    oThisWorkbook.GraphLaidOut += oGraphLaidOutEventHandler;
                }

                // Read the workbook and lay out the graph.

                CommandDispatcher.SendNoParamCommand(oThisWorkbook,
                                                     NoParamCommand.ShowGraphAndReadWorkbook);

                EnableLayoutTypeIsNullNotifications(
                    bLayoutTypeIsNullNotificationsWereEnabled);
            }
            else
            {
                if (bSaveWorkbookIfNeverSaved)
                {
                    if (!TrySaveWorkbookIfNeverSaved(oWorkbook,
                                                     sFolderToSaveWorkbookTo))
                    {
                        return;
                    }
                }
            }
        }