Smrf.NodeXL.ExcelTemplate.TaskAutomator.RunReadWorkbookTasks C# (CSharp) Method

RunReadWorkbookTasks() private static method

private static RunReadWorkbookTasks ( ThisWorkbook oThisWorkbook, NodeXLControl oNodeXLControl, AutomationTasks eTasksToRun, String sFolderToSaveWorkbookTo ) : void
oThisWorkbook ThisWorkbook
oNodeXLControl Smrf.NodeXL.Visualization.Wpf.NodeXLControl
eTasksToRun AutomationTasks
sFolderToSaveWorkbookTo String
return void
    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;
                }
            }
        }
    }