//*************************************************************************
        //  Method: TryCalculateGraphMetrics()
        //
        /// <summary>
        /// Attempts to calculate a set of one or more related metrics.
        /// </summary>
        ///
        /// <param name="graph">
        /// The graph to calculate metrics for.  The graph may contain duplicate
        /// edges and self-loops.
        /// </param>
        ///
        /// <param name="calculateGraphMetricsContext">
        /// Provides access to objects needed for calculating graph metrics.
        /// </param>
        ///
        /// <param name="oneDoubleGraphMetricCalculator">
        /// Graph metric calculator in the Algorithms namespace that calculates
        /// one graph metric of type Double.
        /// </param>
        ///
        /// <param name="calculateGraphMetric">
        /// true to calculate the graph metric, false to skip it.
        /// </param>
        ///
        /// <param name="columnName">
        /// Name of the column to write to in the vertex table.
        /// </param>
        ///
        /// <param name="columnWidthChars">
        /// Width of the column, in characters, or <see
        /// cref="Microsoft.Research.CommunityTechnologies.AppLib.ExcelUtil.
        /// AutoColumnWidth" /> to set the width automatically.
        /// </param>
        ///
        /// <param name="style">
        /// Style of the column, or null to apply Excel's normal style.  Sample:
        /// "Bad".
        /// </param>
        ///
        /// <param name="graphMetricColumns">
        /// Where an array of GraphMetricColumn objects gets stored if true is
        /// returned, one for each related metric calculated by this method.
        /// </param>
        ///
        /// <returns>
        /// true if the graph metrics were calculated or don't need to be
        /// calculated, false if the user wants to cancel.
        /// </returns>
        ///
        /// <remarks>
        /// This method periodically checks BackgroundWorker.<see
        /// cref="BackgroundWorker.CancellationPending" />.  If true, the method
        /// immediately returns false.
        ///
        /// <para>
        /// It also periodically reports progress by calling the
        /// BackgroundWorker.<see
        /// cref="BackgroundWorker.ReportProgress(Int32, Object)" /> method.  The
        /// userState argument is a <see cref="GraphMetricProgress" /> object.
        /// </para>
        ///
        /// <para>
        /// Calculated metrics for hidden rows are ignored by the caller, because
        /// Excel misbehaves when values are written to hidden cells.
        /// </para>
        ///
        /// </remarks>
        //*************************************************************************
        protected Boolean TryCalculateGraphMetrics(
            IGraph graph,
            CalculateGraphMetricsContext calculateGraphMetricsContext,
            
            Algorithms.OneDoubleGraphMetricCalculatorBase
            oneDoubleGraphMetricCalculator,
            
            Boolean calculateGraphMetric,
            String columnName,
            Double columnWidthChars,
            String style,
            out GraphMetricColumn [] graphMetricColumns
            )
        {
            Debug.Assert(graph != null);
            Debug.Assert(calculateGraphMetricsContext != null);
            Debug.Assert(oneDoubleGraphMetricCalculator != null);
            Debug.Assert( !String.IsNullOrEmpty(columnName) );

            Debug.Assert(columnWidthChars == ExcelUtil.AutoColumnWidth ||
            columnWidthChars > 0);

            AssertValid();

            graphMetricColumns = new GraphMetricColumn[0];

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

            // Calculate the graph metrics for each vertex using the
            // OneDoubleGraphMetricCalculatorBase object, which knows nothing about
            // Excel.

            Dictionary<Int32, Double> oGraphMetrics;

            if ( !oneDoubleGraphMetricCalculator.TryCalculateGraphMetrics(graph,
            calculateGraphMetricsContext.BackgroundWorker, out oGraphMetrics) )
            {
            // The user cancelled.

            return (false);
            }

            // Transfer the graph metrics to an array of GraphMetricValue objects.

            List<GraphMetricValueWithID> oGraphMetricValues =
            new List<GraphMetricValueWithID>();

            foreach (IVertex oVertex in graph.Vertices)
            {
            // Try to get the row ID stored in the worksheet.

            Int32 iRowID;

            if ( TryGetRowID(oVertex, out iRowID) )
            {
                oGraphMetricValues.Add( new GraphMetricValueWithID(
                    iRowID, oGraphMetrics[oVertex.ID] ) );
            }
            }

            graphMetricColumns = new GraphMetricColumn [] {
            new GraphMetricColumnWithID( WorksheetNames.Vertices,
                TableNames.Vertices, columnName, columnWidthChars,
                NumericFormat, style, oGraphMetricValues.ToArray()
                ) };

            return (true);
        }