예제 #1
0
 private void SaveAsCsv(object sender, EventArgs e)
 {
     try
     {
         string outputPaneContent = GetAllTextFromPane(GetOutputBuildPane()); // Output Build Pane/Window can be cleared even during build, so this is not perfect solution...
         SaveCsv.SaveAsCsv(outputPaneContent);
     }
     catch
     {
         Debug.Assert(false, "Saving .csv failure! Exception thrown while trying save .csv file.");
     }
 }
예제 #2
0
        static public void SaveAsCsv(string outputPaneContent)
        {
            Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog
            {
                FileName   = DataModel.Instance.GetSaveFileNamePrefix(),
                DefaultExt = ".csv",                        // Default file extension
                Filter     = "Comma-separated values|*.csv" // Filter files by extension
            };

            if (dlg.ShowDialog() != true)
            {
                return;
            }

            SaveCsv.SaveCriticalPathAsCsv(dlg.FileName, outputPaneContent);
        }
예제 #3
0
        static public bool SaveCriticalPathAsCsv(string FileName, string outputPaneContent)
        {
            bool result = true;
            ReadOnlyCollection <BuildInfo> criticalPath = DataModel.Instance.CriticalPath;

            if (criticalPath.Count < 1)
            {
                Debug.Assert(false, "SaveCriticalPathAsCsv() failed! No data in DataModel.CriticalPath. Fix data or disable command.");
                return(false);
            }


            Dictionary <int, List <int?> > detailedReport = null;
            List <string> detailedReportCoulmnNames       = null;
            { // Prepare dara for "Build Timing" detailed report
                HashSet <int> only = new HashSet <int>();
                foreach (BuildInfo bi in criticalPath)
                {
                    only.Add((int)(bi.ProjectBuildOrderNumber));
                }

                result &= SaveCsv.GetBuildTimingsFromOutput(outputPaneContent, only, out Dictionary <int, Dictionary <string, int> > all, out Dictionary <string, int> sums);
                Dictionary <string, int> columnIndex = GetColumIndexesAndNamesFromSums(sums, out detailedReportCoulmnNames);
                result &= SaveCsv.SortBuildTimings(all, columnIndex, out detailedReport);

                if (detailedReportCoulmnNames != null)
                {
                    for (int idx = 0; idx < detailedReportCoulmnNames.Count; idx++)
                    {
                        if (detailedReportCoulmnNames[idx] != null)
                        {
                            detailedReportCoulmnNames[idx] += " [ms]";
                        }
                    }
                }

                if ((detailedReport == null) || (detailedReportCoulmnNames == null))
                {
                    if ((detailedReport != null) || (detailedReportCoulmnNames != null))
                    {
                        Debug.Assert(false, "Problem while saving Critical Path .csv report. Bug in SaveCriticalPathAsCsv() method. Something wrong while processing \"Build Timing\" detailed report data.");
                    }

                    detailedReport            = null;
                    detailedReportCoulmnNames = null;
                }
            }

            bool wasSolutionBuildSuccessful = !(DataModel.Instance.FinishedBuilds.Any(bi => bi.success != true));

            // Sort by Build time descending
            List <BuildInfo> criticalPathSorted = new List <BuildInfo>(criticalPath);

            criticalPathSorted.Sort(new ShorterElapsedTimeFirstInTheListComparer());
            criticalPathSorted.Reverse();

            // SummaryDetailedColumnSeparator
            string sdColumnSeparator = null;

            try
            {
                using (StreamWriter file = new StreamWriter(FileName, false /*false means overwrite existing file*/))
                {
                    string solutionNameWithMachineInfo = "CRICTICAL PATH for " + DataModel.Instance.GetSolutionNameWithMachineInfo("  |  ", true /*WithBuildStartedStr*/);

                    file.WriteLine(EscapeRow(new List <object>()
                    {
                        solutionNameWithMachineInfo
                    }));

                    if (!wasSolutionBuildSuccessful)
                    {
                        file.WriteLine(EscapeRow(null));
                        file.WriteLine(EscapeRow(new List <object> {
                            "WARNING! One or more projects build failed! Report does not reflect real build times!"
                        }));
                        file.WriteLine(EscapeRow(null));
                    }

                    List <object> summaryDetailedPreHeader = new List <object> {
                        "Summary Report:"
                    };
                    if (detailedReport != null)
                    {
                        summaryDetailedPreHeader.AddRange(new List <object> {
                            null, null, null, null
                        });                                                                             // rest columns for "Summary Report:"
                        summaryDetailedPreHeader.Add(sdColumnSeparator);
                        summaryDetailedPreHeader.Add("Detailed Report: (Columns Sorted Descending according to sum for column)");
                    }

                    List <object> summaryDetailedHeader = new List <object> {
                        "Critical Path Order", "Project Name", "Build Time in [s] " /*+ Environment.NewLine this should be here but it does NOT work in Excel. It works correctly on Google Doc */ + "(Sorted Descending)", "Start Time [s]", "End Time [s]"
                    };
                    if (detailedReportCoulmnNames != null)
                    {
                        summaryDetailedHeader.Add(sdColumnSeparator);
                        summaryDetailedHeader.AddRange(detailedReportCoulmnNames);
                    }

                    file.WriteLine(EscapeRow(summaryDetailedPreHeader));
                    file.WriteLine(EscapeRow(summaryDetailedHeader));

                    foreach (BuildInfo bi in criticalPathSorted)
                    {
                        List <object> data = new List <object>
                        {
                            criticalPath.IndexOf(bi) + 1, bi.ProjectName, Utils.TicksToSeconds(bi.ElapsedTime), Utils.TicksToSeconds(bi.begin), Utils.TicksToSeconds(bi.end)
                        };
                        if (detailedReport != null)
                        {
                            data.Add(sdColumnSeparator);
                            int projectBuildOrderNumber = (int)(bi.ProjectBuildOrderNumber);
                            if (detailedReport.ContainsKey(projectBuildOrderNumber))
                            { // C# project doesn't contain detailed reports. Skip them.
                                foreach (int?value in detailedReport[projectBuildOrderNumber])
                                {
                                    data.Add(value);
                                }
                            }
                        }

                        file.WriteLine(EscapeRow(data));
                    }
                }
            }
            catch
            {
                Debug.Assert(false, "Problem while saving Critical Path .csv report. Bug in SaveCriticalPathAsCsv() method. Problem with algorithm that create .csv table.");
                return(false);
            }

            return(result);
        }