Inheritance: NodeXLApplicationSettingsBase
    //*************************************************************************
    //  Constructor: GraphMetricsDialog()
    //
    /// <summary>
    /// Initializes a new instance of the <see cref="GraphMetricsDialog" />
    /// class.
    /// </summary>
    ///
    /// <param name="mode">
    /// Indicates the mode in which the dialog is being used.
    /// </param>
    ///
    /// <param name="workbook">
    /// Workbook containing the graph contents.
    /// </param>
    //*************************************************************************

    public GraphMetricsDialog
    (
        DialogMode mode,
        Microsoft.Office.Interop.Excel.Workbook workbook
    )
    {
        InitializeComponent();

        m_eMode = mode;
        m_oWorkbook = workbook;
        m_oGraphMetricUserSettings = new GraphMetricUserSettings();

        // Instantiate an object that saves and retrieves the position of this
        // dialog.  Note that the object automatically saves the settings when
        // the form closes.

        m_oGraphMetricsDialogUserSettings =
            new GraphMetricsDialogUserSettings(this);

        if (m_eMode == DialogMode.EditOnly)
        {
            this.Text += " Options";
            btnOK.Text = "OK";
        }

        clbGraphMetrics.Items.AddRange(
            GraphMetricInformation.GetAllGraphMetricInformation() );

        clbGraphMetrics.SetSelected(0, true);

        DoDataExchange(false);

        AssertValid();
    }
Example #2
0
        //*************************************************************************
        //  Constructor: GraphMetricsDialog()
        //
        /// <summary>
        /// Initializes a new instance of the <see cref="GraphMetricsDialog" />
        /// class.
        /// </summary>
        ///
        /// <param name="mode">
        /// Indicates the mode in which the dialog is being used.
        /// </param>
        ///
        /// <param name="workbook">
        /// Workbook containing the graph contents.
        /// </param>
        //*************************************************************************

        public GraphMetricsDialog
        (
            DialogMode mode,
            Microsoft.Office.Interop.Excel.Workbook workbook
        )
        {
            InitializeComponent();

            m_eMode     = mode;
            m_oWorkbook = workbook;
            m_oGraphMetricUserSettings = new GraphMetricUserSettings();

            // Instantiate an object that saves and retrieves the position of this
            // dialog.  Note that the object automatically saves the settings when
            // the form closes.

            m_oGraphMetricsDialogUserSettings =
                new GraphMetricsDialogUserSettings(this);

            if (m_eMode == DialogMode.EditOnly)
            {
                this.Text += " Options";
                btnOK.Text = "OK";
            }

            clbGraphMetrics.Items.AddRange(
                GraphMetricInformation.GetAllGraphMetricInformation());

            clbGraphMetrics.SetSelected(0, true);

            DoDataExchange(false);

            AssertValid();
        }
        TryCalculateWordMetrics
        (
            IGraph graph,
            CalculateGraphMetricsContext calculateGraphMetricsContext,
            String statusColumnName,
            out GraphMetricColumn [] wordMetricColumns
        )
        {
            Debug.Assert(graph != null);
            Debug.Assert(calculateGraphMetricsContext != null);
            Debug.Assert(!String.IsNullOrEmpty(statusColumnName));

            // Use the WordMetricCalculator2() class to calculate word metrics for
            // all groups.
            //
            // This is somewhat wasteful, because we don't actually need all the
            // word metrics for all groups.  A future version might refactor common
            // code out of WordMetricCalculator2() that can be called by that class
            // and this one.

            GraphMetricUserSettings oGraphMetricUserSettings =
                calculateGraphMetricsContext.GraphMetricUserSettings;

            WordMetricUserSettings oWordMetricUserSettings =
                oGraphMetricUserSettings.WordMetricUserSettings;

            GraphMetrics eOriginalGraphMetricsToCalculate =
                oGraphMetricUserSettings.GraphMetricsToCalculate;

            Boolean bOriginalTextColumnIsOnEdgeWorksheet =
                oWordMetricUserSettings.TextColumnIsOnEdgeWorksheet;

            String sOriginalTextColumnName =
                oWordMetricUserSettings.TextColumnName;

            Boolean bOriginalCountByGroup = oWordMetricUserSettings.CountByGroup;

            oGraphMetricUserSettings.GraphMetricsToCalculate    = GraphMetrics.Words;
            oWordMetricUserSettings.TextColumnIsOnEdgeWorksheet = true;
            oWordMetricUserSettings.TextColumnName = statusColumnName;
            oWordMetricUserSettings.CountByGroup   = true;

            try
            {
                return((new WordMetricCalculator2()).TryCalculateGraphMetrics(
                           graph, calculateGraphMetricsContext, out wordMetricColumns));
            }
            finally
            {
                oGraphMetricUserSettings.GraphMetricsToCalculate =
                    eOriginalGraphMetricsToCalculate;

                oWordMetricUserSettings.TextColumnIsOnEdgeWorksheet =
                    bOriginalTextColumnIsOnEdgeWorksheet;

                oWordMetricUserSettings.TextColumnName = sOriginalTextColumnName;
                oWordMetricUserSettings.CountByGroup   = bOriginalCountByGroup;
            }
        }
        //*************************************************************************
        //  Constructor: CalculateGraphMetricsContext()
        //
        /// <summary>
        /// Initializes a new instance of the <see
        /// cref="CalculateGraphMetricsContext" /> class.
        /// </summary>
        ///
        /// <param name="graphMetricUserSettings">
        /// Stores the user's settings for calculating graph metrics.
        /// </param>
        ///
        /// <param name="backgroundWorker">
        /// The BackgroundWorker object that is performing all graph metric
        /// calculations.
        /// </param>
        //*************************************************************************

        public CalculateGraphMetricsContext
        (
            GraphMetricUserSettings graphMetricUserSettings,
            BackgroundWorker backgroundWorker
        )
        {
            m_oGraphMetricUserSettings = graphMetricUserSettings;
            m_oBackgroundWorker        = backgroundWorker;

            AssertValid();
        }
    //*************************************************************************
    //  Constructor: CalculateGraphMetricsContext()
    //
    /// <summary>
    /// Initializes a new instance of the <see
    /// cref="CalculateGraphMetricsContext" /> class.
    /// </summary>
    ///
    /// <param name="graphMetricUserSettings">
    /// Stores the user's settings for calculating graph metrics.
    /// </param>
    ///
    /// <param name="backgroundWorker">
    /// The BackgroundWorker object that is performing all graph metric
    /// calculations.
    /// </param>
    //*************************************************************************

    public CalculateGraphMetricsContext
    (
        GraphMetricUserSettings graphMetricUserSettings,
        BackgroundWorker backgroundWorker
    )
    {
        m_oGraphMetricUserSettings = graphMetricUserSettings;
        m_oBackgroundWorker = backgroundWorker;

        AssertValid();
    }
        GetWorkbookSettings
        (
            Microsoft.Office.Interop.Excel.Workbook oWorkbook
        )
        {
            Debug.Assert(oWorkbook != null);
            AssertValid();

            // Temporarily change some settings.

            AutomateTasksUserSettings oAutomateTasksUserSettings =
                new AutomateTasksUserSettings();

            AutomationTasks eOriginalTasksToRun =
                oAutomateTasksUserSettings.TasksToRun;

            oAutomateTasksUserSettings.TasksToRun =
                AutomationTasks.CalculateGraphMetrics;

            oAutomateTasksUserSettings.Save();

            GraphMetricUserSettings oGraphMetricUserSettings =
                new GraphMetricUserSettings();

            GraphMetrics eOriginalGraphMetricsToCalculate =
                oGraphMetricUserSettings.GraphMetricsToCalculate;

            oGraphMetricUserSettings.GraphMetricsToCalculate =
                GraphMetrics.OverallMetrics;

            oGraphMetricUserSettings.Save();

            // Get the workbook settings that include the temporary changes.

            String sWorkbookSettings =
                (new PerWorkbookSettings(oWorkbook)).WorkbookSettings;

            // Restore the original settings.

            oAutomateTasksUserSettings.TasksToRun = eOriginalTasksToRun;

            oAutomateTasksUserSettings.Save();

            oGraphMetricUserSettings.GraphMetricsToCalculate =
                eOriginalGraphMetricsToCalculate;

            oGraphMetricUserSettings.Save();

            return(sWorkbookSettings);
        }
    GetWorkbookSettings
    (
        Microsoft.Office.Interop.Excel.Workbook oWorkbook
    )
    {
        Debug.Assert(oWorkbook != null);
        AssertValid();

        // Temporarily change some settings.

        AutomateTasksUserSettings oAutomateTasksUserSettings =
            new AutomateTasksUserSettings();

        AutomationTasks eOriginalTasksToRun =
            oAutomateTasksUserSettings.TasksToRun;

        oAutomateTasksUserSettings.TasksToRun =
            AutomationTasks.CalculateGraphMetrics;

        oAutomateTasksUserSettings.Save();

        GraphMetricUserSettings oGraphMetricUserSettings =
            new GraphMetricUserSettings();

        GraphMetrics eOriginalGraphMetricsToCalculate =
            oGraphMetricUserSettings.GraphMetricsToCalculate;

        oGraphMetricUserSettings.GraphMetricsToCalculate =
            GraphMetrics.OverallMetrics;

        oGraphMetricUserSettings.Save();

        // Get the workbook settings that include the temporary changes.

        String sWorkbookSettings =
            ( new PerWorkbookSettings(oWorkbook) ).WorkbookSettings;

        // Restore the original settings.

        oAutomateTasksUserSettings.TasksToRun = eOriginalTasksToRun;

        oAutomateTasksUserSettings.Save();

        oGraphMetricUserSettings.GraphMetricsToCalculate =
            eOriginalGraphMetricsToCalculate;

        oGraphMetricUserSettings.Save();

        return (sWorkbookSettings);
    }