FileIsNodeXLWorkbook() public static method

public static FileIsNodeXLWorkbook ( String filePath ) : System.Boolean
filePath String
return System.Boolean
Example #1
0
        AutomateFolder
        (
            String folderToAutomate,
            String workbookSettings
        )
        {
            Debug.Assert(!String.IsNullOrEmpty(folderToAutomate));
            Debug.Assert(!String.IsNullOrEmpty(workbookSettings));

            foreach (String sFileName in Directory.GetFiles(folderToAutomate,
                                                            "*.xlsx"))
            {
                String sFilePath = Path.Combine(folderToAutomate, sFileName);

                try
                {
                    if (!NodeXLWorkbookUtil.FileIsNodeXLWorkbook(sFilePath))
                    {
                        continue;
                    }
                }
                catch (IOException)
                {
                    // Skip any workbooks that are already open, or that have any
                    // other problems that prevent them from being opened.

                    continue;
                }

                AutomateOneWorkbookIndirect(sFilePath, workbookSettings);
            }
        }
        AggregateGraphMetricsInternal
        (
            AggregateGraphMetricsAsyncArgs oAggregateGraphMetricsAsyncArgs,
            BackgroundWorker oBackgroundWorker,
            DoWorkEventArgs oDoWorkEventArgs
        )
        {
            Debug.Assert(oAggregateGraphMetricsAsyncArgs != null);
            Debug.Assert(oBackgroundWorker != null);
            Debug.Assert(oDoWorkEventArgs != null);
            AssertValid();

            List <OverallMetricsInfo> oOverallMetricsInfos =
                new List <OverallMetricsInfo>();

            OverallMetricsReader oOverallMetricsReader =
                new OverallMetricsReader();

            foreach (String sFilePath in Directory.GetFiles(
                         oAggregateGraphMetricsAsyncArgs.SourceFolderPath, "*.xlsx"))
            {
                if (oBackgroundWorker.CancellationPending)
                {
                    oDoWorkEventArgs.Cancel = true;
                    return;
                }

                try
                {
                    if (!NodeXLWorkbookUtil.FileIsNodeXLWorkbook(sFilePath))
                    {
                        continue;
                    }
                }
                catch (IOException)
                {
                    // Skip any workbooks that are already open, or that have any
                    // other problems that prevent them from being opened.

                    continue;
                }

                oBackgroundWorker.ReportProgress(0,
                                                 String.Format(
                                                     "Reading \"{0}\"."
                                                     ,
                                                     Path.GetFileName(sFilePath)
                                                     ));

                OverallMetricsInfo oOverallMetricsInfo;

                for (Int32 iAttempt = 0; iAttempt < 2; iAttempt++)
                {
                    // Have overall metrics already been calculated for the
                    // workbook?

                    if (TryGetGraphMetricsForOneNodeXLWorkbook(sFilePath,
                                                               out oOverallMetricsInfo))
                    {
                        // Yes.

                        oOverallMetricsInfos.Add(oOverallMetricsInfo);
                        break;
                    }

                    if (iAttempt == 0)
                    {
                        // No.  Calculate them.

                        TaskAutomator.AutomateOneWorkbookIndirect(sFilePath,
                                                                  oAggregateGraphMetricsAsyncArgs.WorkbookSettings);
                    }
                }
            }

            if (oOverallMetricsInfos.Count > 0)
            {
                WriteOverallMetricsToNewWorkbook(
                    oAggregateGraphMetricsAsyncArgs.Workbook.Application,
                    oOverallMetricsInfos);
            }

            oBackgroundWorker.ReportProgress(0,
                                             String.Format(
                                                 "Done.  NodeXL workbooks aggregated: {0}."
                                                 ,
                                                 oOverallMetricsInfos.Count
                                                 ));
        }