OnException() 공개 정적인 메소드

public static OnException ( Exception exception ) : void
exception System.Exception
리턴 void
예제 #1
0
        GraphMetricsAggregator_AggregationCompleted
        (
            object sender,
            RunWorkerCompletedEventArgs e
        )
        {
            AssertValid();

            EnableControls();

            if (e.Cancelled)
            {
            }
            else if (e.Error != null)
            {
                ErrorUtil.OnException(e.Error);
                slStatusLabel.Text = String.Empty;
            }
            else
            {
                // The final status message is a summary of what was done.  Show it
                // in a message box in addition to the StatusLabel.

                this.ShowInformation(slStatusLabel.Text);
                this.Close();
            }
        }
예제 #2
0
        btnOK_Click
        (
            object sender,
            System.EventArgs e
        )
        {
            if (!DoDataExchange(true))
            {
                return;
            }

            this.Cursor = Cursors.WaitCursor;

            try
            {
                ImportFromMatrixWorkbook();
            }
            catch (ImportWorkbookException oImportWorkbookException)
            {
                this.ShowWarning(oImportWorkbookException.Message);
                return;
            }
            catch (Exception oException)
            {
                ErrorUtil.OnException(oException);
                return;
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }

            DialogResult = DialogResult.OK;
            this.Close();
        }
        btnOK_Click
        (
            object sender,
            System.EventArgs e
        )
        {
            if (!DoDataExchange(true))
            {
                return;
            }

            try
            {
                ImportFromEdgeWorkbook();
            }
            catch (ImportWorkbookException oImportWorkbookException)
            {
                this.ShowWarning(oImportWorkbookException.Message);
                return;
            }
            catch (Exception oException)
            {
                ErrorUtil.OnException(oException);
                return;
            }

            DialogResult = DialogResult.OK;
            this.Close();
        }
예제 #4
0
        SelectEdgeOrVertexTableRows
        (
            Boolean bSelectEdgeTableRows
        )
        {
            AssertValid();

            Sheets1And2Helper oSheets1And2Helper = bSelectEdgeTableRows ?
                                                   m_oEdgeWorksheet.Sheets1And2Helper :
                                                   m_oVertexWorksheet.Sheets1And2Helper;

            if (!oSheets1And2Helper.TableExists)
            {
                return;
            }

            m_bIgnoreSelectionEvents = true;

            try
            {
                oSheets1And2Helper.SelectTableRowsByRowIDs(bSelectEdgeTableRows ?
                                                           m_oTaskPane.GetSelectedEdgeRowIDs() :
                                                           m_oTaskPane.GetSelectedVertexRowIDs()
                                                           );
            }
            catch (Exception oException)
            {
                ErrorUtil.OnException(oException);
            }
            finally
            {
                m_bIgnoreSelectionEvents = false;
            }
        }
        btnOK_Click
        (
            object sender,
            EventArgs e
        )
        {
            AssertValid();

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

            this.UseWaitCursor = true;

            try
            {
                GroupByVertexAttribute();

                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            catch (Exception oException)
            {
                ErrorUtil.OnException(oException);
            }
            finally
            {
                this.UseWaitCursor = false;
            }
        }
예제 #6
0
        SelectGroupTableRows()
        {
            AssertValid();

            SheetHelper oSheetHelper = m_oGroupWorksheet.SheetHelper;

            if (!oSheetHelper.TableExists)
            {
                return;
            }

            m_bIgnoreSelectionEvents = true;

            try
            {
                oSheetHelper.SelectTableRowsByColumnValues <String>(
                    GroupTableColumnNames.Name,
                    m_oTaskPane.GetSelectedCollapsedGroupNames(),
                    ExcelUtil.TryGetNonEmptyStringFromCell
                    );
            }
            catch (Exception oException)
            {
                ErrorUtil.OnException(oException);
            }
            finally
            {
                m_bIgnoreSelectionEvents = false;
            }
        }
예제 #7
0
        ConvertNodeXLWorkbook
        (
            String sOtherWorkbookFile,
            String sConvertedWorkbookFile
        )
        {
            AssertValid();
            Debug.Assert(!String.IsNullOrEmpty(sOtherWorkbookFile));
            Debug.Assert(!String.IsNullOrEmpty(sConvertedWorkbookFile));

            try
            {
                NodeXLWorkbookConverter.ConvertNodeXLWorkbook(sOtherWorkbookFile,
                                                              sConvertedWorkbookFile);
            }
            catch (NodeXLWorkbookConversionException
                   oNodeXLWorkbookConversionException)
            {
                this.ShowWarning(oNodeXLWorkbookConversionException.Message);

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

                return(false);
            }

            return(true);
        }
예제 #8
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);
            }
        }
        StartImageCreation()
        {
            AssertValid();
            Debug.Assert(m_oWorkbook != null);
            Debug.Assert(m_oSelectedVertexNames != null);

            // Read the workbook into a new IGraph.

            IGraph oGraph;

            try
            {
                oGraph = ReadWorkbook(m_oWorkbook);
            }
            catch (Exception oException)
            {
                ErrorUtil.OnException(oException);
                this.State = DialogState.Idle;

                return;
            }

            lblStatus.Text = "Creating subgraph images.";

            ICollection <IVertex> oSelectedVertices = new IVertex[0];

            if (m_oCreateSubgraphImagesDialogUserSettings.SelectedVerticesOnly)
            {
                // Get the vertices corresponding to the selected rows in the
                // vertex worksheet.

                oSelectedVertices = GetSelectedVertices(
                    oGraph, m_oSelectedVertexNames);
            }

            m_oSubgraphImageCreator.CreateSubgraphImagesAsync(
                oGraph,
                oSelectedVertices,
                m_oCreateSubgraphImagesDialogUserSettings.Levels,
                m_oCreateSubgraphImagesDialogUserSettings.SaveToFolder,
                m_oCreateSubgraphImagesDialogUserSettings.Folder,
                m_oCreateSubgraphImagesDialogUserSettings.ImageSizePx,
                m_oCreateSubgraphImagesDialogUserSettings.ImageFormat,
                m_oCreateSubgraphImagesDialogUserSettings.InsertThumbnails,
                m_oCreateSubgraphImagesDialogUserSettings.ThumbnailSizePx,
                m_oCreateSubgraphImagesDialogUserSettings.SelectedVerticesOnly,
                m_oCreateSubgraphImagesDialogUserSettings.SelectVertex,
                m_oCreateSubgraphImagesDialogUserSettings.SelectIncidentEdges,
                new GeneralUserSettings(),
                new LayoutUserSettings()
                );
        }
예제 #10
0
        OpenSampleNodeXLWorkbook()
        {
            // To create the sample workbook, an empty NodeXL workbook is created
            // from the NodeXL template, and then a GraphML file containing the
            // sample data is imported into it.  It would be simpler to just
            // distribute a complete sample workbook with NodeXL, but that workbook
            // would have to be updated every time the NodeXL template changes.
            // This way, the latest template is always used.

            String sSampleNodeXLWorkbookSubfolderPath = Path.Combine(
                GetApplicationFolder(), SampleNodeXLWorkbookSubfolder);

            XmlDocument oGraphMLDocument = new XmlDocument();

            try
            {
                oGraphMLDocument.Load(Path.Combine(
                                          sSampleNodeXLWorkbookSubfolderPath,
                                          SampleNodeXLWorkbookAsGraphMLFileName));
            }
            catch (Exception oException)
            {
                ErrorUtil.OnException(oException);
                return;
            }

            // The sample workbook data contains placeholders for the path to the
            // image files used in the workbook.  Replace those placeholders with a
            // real image path.

            String sImagePath = Path.Combine(sSampleNodeXLWorkbookSubfolderPath,
                                             SampleNodeXLWorkbookImageSubfolder);

            oGraphMLDocument.LoadXml(oGraphMLDocument.OuterXml.Replace(
                                         SampleNodeXLWorkbookImagePlaceholder, sImagePath));

            try
            {
                GraphMLToNodeXLWorkbookConverter.SaveGraphToNodeXLWorkbook(
                    oGraphMLDocument, null, null, null, false);
            }
            catch (ConvertGraphMLToNodeXLWorkbookException
                   oConvertGraphMLToNodeXLWorkbookException)
            {
                FormUtil.ShowWarning(
                    oConvertGraphMLToNodeXLWorkbookException.Message);
            }
        }
예제 #11
0
        OnLoad
        (
            EventArgs e
        )
        {
            AssertValid();

            base.OnLoad(e);

            // Start the calculations.

            try
            {
                if (m_oGraphMetricCalculators != null)
                {
                    // Use the specified graph metric calculators.

                    m_oGraphMetricCalculationManager.CalculateGraphMetricsAsync(
                        m_oGraph, m_oWorkbook, m_oGraphMetricCalculators);
                }
                else
                {
                    // Use a default list of graph metric calculators.

                    m_oGraphMetricCalculationManager.CalculateGraphMetricsAsync(
                        m_oGraph, m_oWorkbook);
                }
            }
            catch (Exception oException)
            {
                // An exception was thrown from the synchronous code within
                // CalculateGraphMetricsAsync().  (Exceptions thrown from the
                // asynchronous code are handled by the
                // GraphMetricCalculationCompleted event handler.)

                ErrorUtil.OnException(oException);

                this.Close();
            }
        }
예제 #12
0
        WriteGraphMetricColumnsToWorkbook
        (
            GraphMetricColumn [] aoGraphMetricColumns
        )
        {
            Debug.Assert(aoGraphMetricColumns != null);
            AssertValid();

            Microsoft.Office.Interop.Excel.Application oApplication =
                m_oWorkbook.Application;

            GraphMetricWriter oGraphMetricWriter = new GraphMetricWriter();

            oApplication.ScreenUpdating = false;

            try
            {
                oGraphMetricWriter.WriteGraphMetricColumnsToWorkbook(
                    aoGraphMetricColumns, m_oWorkbook);

                if (m_bActivateRelevantWorksheetWhenDone)
                {
                    // Let the user know that graph metrics have been calculated.

                    oGraphMetricWriter.ActivateRelevantWorksheet(
                        aoGraphMetricColumns, m_oWorkbook);
                }
            }
            catch (Exception oException)
            {
                oApplication.ScreenUpdating = true;

                ErrorUtil.OnException(oException);

                this.Close();
                return;
            }

            oApplication.ScreenUpdating = true;
        }
        GraphMLFilesImporter_ImportationCompleted
        (
            object sender,
            RunWorkerCompletedEventArgs e
        )
        {
            AssertValid();

            EnableControls();

            if (e.Cancelled)
            {
            }
            else if (e.Error != null)
            {
                Exception oException = e.Error;

                if (oException is ConvertGraphMLToNodeXLWorkbookException)
                {
                    this.ShowWarning(oException.Message);
                }
                else
                {
                    ErrorUtil.OnException(oException);
                }

                slStatusLabel.Text = String.Empty;
            }
            else
            {
                // The final status message is a summary of what was done.  Show it
                // in a message box in addition to the StatusLabel.

                this.ShowInformation(slStatusLabel.Text);

                CheckForInvalidGraphMLFileNames();
                this.Close();
            }
        }
예제 #14
0
        TryAutoFillWorkbook
        (
            ThisWorkbook oThisWorkbook
        )
        {
            Debug.Assert(oThisWorkbook != null);

            try
            {
                WorkbookAutoFiller.AutoFillWorkbook(
                    oThisWorkbook.InnerObject, new AutoFillUserSettings());

                oThisWorkbook.OnWorkbookAutoFilled(false);

                return(true);
            }
            catch (Exception oException)
            {
                ErrorUtil.OnException(oException);
                return(false);
            }
        }
예제 #15
0
        GraphMetricCalculationManager_GraphMetricCalculationCompleted
        (
            object sender,
            RunWorkerCompletedEventArgs e
        )
        {
            AssertValid();

            Exception oException = e.Error;

            if (oException != null)
            {
                if (oException is GraphMetricException)
                {
                    // This is a known exception.

                    this.ShowWarning(oException.Message);
                }
                else
                {
                    // The exception is unexpected.

                    ErrorUtil.OnException(oException);
                }
            }
            else if (!e.Cancelled)
            {
                Debug.Assert(e.Result is GraphMetricColumn[]);

                WriteGraphMetricColumnsToWorkbook(
                    ( GraphMetricColumn[] )e.Result);

                // Everything succeeded.

                this.DialogResult = DialogResult.OK;
            }

            this.Close();
        }
예제 #16
0
        btnCustomizeVertexMenu_Click
        (
            object sender,
            EventArgs e
        )
        {
            AssertValid();

            const String Message =
                "Use this to add custom menu items to the menu that appears when"
                + " you right-click a vertex in the graph pane."
                + "\r\n\r\n"
                + "Clicking \"Yes\" below will add a pair of columns to the"
                + " Vertices worksheet -- one for menu item text and another for"
                + " the action to take when the menu item is selected."
                + "\r\n\r\n"
                + "For example, if you add the column pair and enter \"Send Mail"
                + " To\" for a vertex's menu item text and \"mailto:[email protected]\""
                + " for the action, then right-clicking the vertex in the NodeXL"
                + " graph and selecting \"Send Mail To\" from the right-click menu"
                + " will open a new email message addressed to [email protected]."
                + "\r\n\r\n"
                + "If you want to open a Web page when the menu item is selected,"
                + " enter an URL for the action."
                + "\r\n\r\n"
                + "If you want to add more than one custom menu item to a vertex's"
                + " right-click menu, run this again to add another pair of"
                + " columns."
                + "\r\n\r\n"
                + "Do you want to add a pair of columns to the Vertices worksheet?"
            ;

            if (MessageBox.Show(Message, this.ApplicationName,
                                MessageBoxButtons.YesNo, MessageBoxIcon.Information) !=
                DialogResult.Yes)
            {
                return;
            }

            // Create and use the object that adds the columns to the vertex
            // table.

            TableColumnAdder oTableColumnAdder = new TableColumnAdder();

            this.UseWaitCursor = true;

            try
            {
                oTableColumnAdder.AddColumnPair(m_oWorkbook,
                                                WorksheetNames.Vertices, TableNames.Vertices,
                                                VertexTableColumnNames.CustomMenuItemTextBase,
                                                CustomMenuItemTextColumnWidth,
                                                VertexTableColumnNames.CustomMenuItemActionBase,
                                                CustomMenuItemActionColumnWidth
                                                );

                this.UseWaitCursor = false;
            }
            catch (Exception oException)
            {
                this.UseWaitCursor = false;

                ErrorUtil.OnException(oException);
            }
        }
예제 #17
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();
        }
예제 #18
0
        OnEdgeOrVertexTableSelectionChange
        (
            Boolean bChangeInEdgeTable
        )
        {
            AssertValid();

            Sheets1And2Helper oSheets1And2Helper = bChangeInEdgeTable ?
                                                   m_oEdgeWorksheet.Sheets1And2Helper :
                                                   m_oVertexWorksheet.Sheets1And2Helper;

            if (IgnoreTableSelectionChange(oSheets1And2Helper))
            {
                return;
            }

            m_bIgnoreSelectionEvents = true;

            try
            {
                // (The following comments are for the bChangeInEdgeTable=true
                // case.

                // Get an array of unique row IDs for all edge rows that have at
                // least one cell selected.

                ICollection <Int32> oSelectedRowIDs =
                    oSheets1And2Helper.GetSelectedRowIDs();

                // Select those edges (and possibly their adjacent vertices) in the
                // TaskPane.  This will cause the TaskPane.SelectionChangedInGraph
                // event to fire, but this class will ignore it because
                // m_bIgnoreSelectionEvents is currently set to true.

                if (bChangeInEdgeTable)
                {
                    m_oTaskPane.SetSelectedEdgesByRowID(oSelectedRowIDs);
                }
                else
                {
                    m_oTaskPane.SetSelectedVerticesByRowID(oSelectedRowIDs);
                }

                // The selection in the vertex table may now be out of sync with
                // the TaskPane.  Ideally, the vertex table would be updated right
                // now.  However, you can't select rows in a worksheet that isn't
                // active.  As a workaround, set a flag that will cause the
                // selection in the vertex table to be updated the next time the
                // vertex worksheet is activated.
                //
                // It would be possible to avoid deferring the selection by turning
                // off screen updating and temporarily selecting the vertex
                // worksheet.  Selecting a worksheet is slow, however, even with
                // screen updating turned off.  It takes about 250ms on a fast
                // machine.  That's too slow to keep up with the user if he is
                // scrolling through a table with the down-arrow key, for example.

                if (bChangeInEdgeTable)
                {
                    m_bUpdateVertexSelectionOnActivation = true;
                }
                else
                {
                    m_bUpdateEdgeSelectionOnActivation = true;
                }

                // Selecting an edge or vertex invalidates any selected groups.

                m_bUpdateGroupSelectionOnActivation = true;

                // Enable the "set visual attribute" buttons in the Ribbon.

                m_oThisWorkbook.EnableSetVisualAttributes();
            }
            catch (COMException)
            {
                // A user reported a bug in which Application.Intersect() throws a
                // COMException with an HRESULT of 0x800AC472.
                // (Application.Intersect() gets called indirectly by
                // OnSelectionChangedInTable().)  The bug occurred while switching
                // windows.  I couldn't reproduce the bug, but the following post
                // suggests that the HRESULT, which is VBA_E_IGNORE, occurs when an
                // object model call is made while the object model is "suspended."
                //
                // http://social.msdn.microsoft.com/forums/en-US/vsto/thread/
                // 9168f9f2-e5bc-4535-8d7d-4e374ab8ff09/
                //
                // Other posts also mention that it can occur during window
                // switches.
                //
                // I can't reproduce the bug and I'm not sure of the root cause,
                // but catching and ignoring the error should lead to nothing worse
                // than a mouse click being ignored.
                //
                // Update, May 2012:
                //
                // ExcelUtil.TryGetIntersection() now retries the
                // Application.Intersect() call if it fails with a COMException.
                // If it fails repeatedly, the exception will eventually get
                // rethrown here.
            }
            catch (Exception oException)
            {
                ErrorUtil.OnException(oException);
            }
            finally
            {
                m_bIgnoreSelectionEvents = false;
            }
        }
        OnImageCreationCompleted
        (
            RunWorkerCompletedEventArgs e
        )
        {
            AssertValid();
            Debug.Assert(m_oWorkbook != null);
            Debug.Assert(m_oSelectedVertexNames != null);

            if (e.Cancelled)
            {
                this.State = DialogState.Idle;

                lblStatus.Text = "Image creation stopped.";
            }
            else if (e.Error != null)
            {
                this.State = DialogState.Idle;

                Exception oException = e.Error;

                if (oException is System.IO.IOException)
                {
                    lblStatus.Text = "Image creation error.";

                    this.ShowWarning(oException.Message);
                }
                else
                {
                    ErrorUtil.OnException(oException);
                }
            }
            else
            {
                // Success.  Were temporary images created that need to be inserted
                // into the vertex worksheet?

                Debug.Assert(e.Result is TemporaryImages);

                TemporaryImages oTemporaryImages = (TemporaryImages)e.Result;

                if (oTemporaryImages.Folder != null)
                {
                    // Yes.  Insert them, then delete the temporary images.

                    this.State = DialogState.PopulatingImageColumn;

                    String sLastStatusFromSubgraphImageCreator = lblStatus.Text;

                    lblStatus.Text =
                        "Inserting subgraph thumbnails into the worksheet.  Please"
                        + " wait...";

                    SubgraphImageColumnPopulator.PopulateSubgraphImageColumn(
                        m_oWorkbook, oTemporaryImages);

                    lblStatus.Text = sLastStatusFromSubgraphImageCreator;
                }

                this.State = DialogState.Idle;

                if (m_eMode == DialogMode.Automate)
                {
                    this.Close();
                }
            }
        }
예제 #20
0
        AutomateOneWorkbookIndirect
        (
            String nodeXLWorkbookFilePath,
            String workbookSettings
        )
        {
            Debug.Assert(!String.IsNullOrEmpty(nodeXLWorkbookFilePath));
            Debug.Assert(!String.IsNullOrEmpty(workbookSettings));

            // Ideally, the Excel API would be used here to open the workbook
            // and run the AutomateOneWorkbook() method on it.  Two things
            // make that impossible:
            //
            //   1. When you open a workbook using
            //      Application.Workbooks.Open(), you get only a native Excel
            //      workbook, not an "extended" ThisWorkbook object.
            //
            //      Although a GetVstoObject() extension method is available to
            //      convert a native Excel workbook to an extended workbook,
            //      that method doesn't work on a native workbook opened via
            //      the Excel API -- it always returns null.
            //
            //      It might be possible to refactor AutomateOneWorkbook() to
            //      require only a native workbook.  However, problem 2 would
            //      still make things impossible...
            //
            //   2. If this method is being run from a modal dialog, which it
            //      is (see AutomateTasksDialog), then code in the workbook
            //      that needs to be automated doesn't run until the modal
            //      dialog closes.
            //
            // The following code works around these problems.

            Microsoft.Office.Interop.Excel.Application oExcelApplication =
                null;

            ExcelApplicationKiller oExcelApplicationKiller = null;

            try
            {
                // Use a new Application object for each workbook.  If the same
                // Application object is reused, the memory used by each
                // workbook is never released and the machine will eventually
                // run out of memory.

                oExcelApplication =
                    new Microsoft.Office.Interop.Excel.Application();

                if (oExcelApplication == null)
                {
                    throw new Exception("Excel couldn't be opened.");
                }

                // ExcelApplicationKiller requires that the application be
                // visible.

                oExcelApplication.Visible = true;

                oExcelApplicationKiller = new ExcelApplicationKiller(
                    oExcelApplication);

                // Store an "automate tasks on open" flag in the workbook,
                // indicating that task automation should be run on it the next
                // time it's opened.  This can be done via the Excel API.

                Microsoft.Office.Interop.Excel.Workbook oWorkbookToAutomate =
                    ExcelUtil.OpenWorkbook(nodeXLWorkbookFilePath,
                                           oExcelApplication);

                PerWorkbookSettings oPerWorkbookSettings =
                    new PerWorkbookSettings(oWorkbookToAutomate);

                oPerWorkbookSettings.WorkbookSettings    = workbookSettings;
                oPerWorkbookSettings.AutomateTasksOnOpen = true;
                oWorkbookToAutomate.Save();
                oWorkbookToAutomate.Close(false, Missing.Value, Missing.Value);
                oExcelApplication.Quit();
            }
            catch (Exception oException)
            {
                ErrorUtil.OnException(oException);
                return;
            }
            finally
            {
                // Quitting the Excel application does not remove it from
                // memory.  Kill its process.

                oExcelApplicationKiller.KillExcelApplication();
                oExcelApplication       = null;
                oExcelApplicationKiller = null;
            }

            try
            {
                // Now open the workbook in another instance of Excel, which
                // bypasses problem 2.  Code in the workbook's Ribbon will
                // detect the flag's presence, run task automation on it, close
                // the workbook, and close the other instance of Excel.

                OpenWorkbookToAutomate(nodeXLWorkbookFilePath, 60 * 60);
            }
            catch (Exception oException)
            {
                ErrorUtil.OnException(oException);
                return;
            }
        }
예제 #21
0
        btnOK_Click
        (
            object sender,
            System.EventArgs e
        )
        {
            AssertValid();

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

            this.Cursor = Cursors.WaitCursor;
            Exception oExpectedException = null;

            try
            {
                OpenUcinetFile();
            }
            catch (IOException oIOException)
            {
                oExpectedException = oIOException;
            }
            catch (UnauthorizedAccessException oUnauthorizedAccessException)
            {
                oExpectedException = oUnauthorizedAccessException;
            }
            catch (FormatException oFormatException)
            {
                oExpectedException = oFormatException;
            }
            catch (Exception oUnexpectedException)
            {
                ErrorUtil.OnException(oUnexpectedException);
                return;
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }

            if (oExpectedException != null)
            {
                String sMessage =
                    "The file could not be opened.  Details:\n\n"
                    + oExpectedException.Message;

                if (oExpectedException is FormatException)
                {
                    sMessage +=
                        "\n\nThis does not appear to be a UCINET full matrix DL"
                        + " file.  "
                        + FormatMessage
                    ;
                }

                this.ShowWarning(sMessage);
                return;
            }

            DialogResult = DialogResult.OK;
            this.Close();
        }
예제 #22
0
        btnOK_Click
        (
            object sender,
            EventArgs e
        )
        {
            AssertValid();

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

            if (m_eMode == DialogMode.Normal)
            {
                NodeXLGraphGalleryExporter oNodeXLGraphGalleryExporter =
                    new NodeXLGraphGalleryExporter();

                this.Cursor = Cursors.WaitCursor;

                try
                {
                    Debug.Assert(m_oNodeXLControl != null);

                    oNodeXLGraphGalleryExporter.ExportToNodeXLGraphGallery(

                        m_oWorkbook, m_oNodeXLControl,

                        txbTitle.Text,
                        txbDescription.Text,

                        m_oExportToNodeXLGraphGalleryUserSettings.
                        SpaceDelimitedTags,

                        m_oExportToNodeXLGraphGalleryUserSettings.Author,

                        m_oExportToNodeXLGraphGalleryUserSettings.UseCredentials
                        ? m_oPasswordUserSettings.NodeXLGraphGalleryPassword
                        : null,

                        m_oExportToNodeXLGraphGalleryUserSettings.
                        ExportWorkbookAndSettings,

                        m_oExportToNodeXLGraphGalleryUserSettings.ExportGraphML,

                        m_oExportToNodeXLGraphGalleryUserSettings
                        .UseFixedAspectRatio
                        );
                }
                catch (Exception oException)
                {
                    String sMessage;

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

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

            m_oExportToNodeXLGraphGalleryUserSettings.Save();
            m_oPasswordUserSettings.Save();

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
예제 #23
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();
        }
예제 #24
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);
            }
        }