public void UpdateReport()
        {
            CoverageEnvironment.print("Coverage: Report has changed -> reading");

            CoverageEnvironment.report = UpdateData();

            CoverageEnvironment.print("Coverage: Report is ready into CoverageEnvironment");

            CoverageEnvironment.emitReportUpdated();
        }
        /// <summary>
        /// Initializes the current coverage data
        /// </summary>
        private void InitCurrent()
        {
            CoverageState[] currentFile = new CoverageState[0];
            ProfileVector   currentProf = new Data.ProfileVector(0);

            // Check report exists
            if (CoverageEnvironment.ShowCodeCoverage && CoverageEnvironment.report != null)
            {
                string activeFilename = System.IO.Path.GetFullPath(GetActiveFilename());
                if (activeFilename != null)
                {
                    CoverageEnvironment.print("Coverage: Print report on " + activeFilename);

                    Tuple <BitVector, ProfileVector> activeReport = null;
                    DateTime activeFileLastWrite = File.GetLastWriteTimeUtc(activeFilename);

                    if (CoverageEnvironment.report.FileDate >= activeFileLastWrite)
                    {
                        CoverageEnvironment.print("Coverage: Report is up to date");
                        activeReport = CoverageEnvironment.report.GetData(activeFilename);

                        if (activeReport != null)
                        {
                            CoverageEnvironment.print("Coverage: File is inside report");
                            currentProf = activeReport.Item2;
                            currentFile = new CoverageState[activeReport.Item1.Count];

                            foreach (var item in activeReport.Item1.Enumerate())
                            {
                                if (item.Value)
                                {
                                    currentFile[item.Key] = CoverageState.Covered;
                                }
                                else
                                {
                                    currentFile[item.Key] = CoverageState.Uncovered;
                                }
                            }
                        }
                        else
                        {
                            CoverageEnvironment.print("Coverage: File " + activeFilename + " is not inside report");
                        }
                    }
                    else
                    {
                        CoverageEnvironment.print("Coverage: Report is too old compare to file.");
                    }
                }
            }

            this.currentCoverage = currentFile;
            this.currentProfile  = currentProf;
        }
Beispiel #3
0
        public NativeData(string filename)
        {
            // Get file date (for modified checks)
            FileDate = new System.IO.FileInfo(filename).LastWriteTimeUtc;

            // Read file:
            using (var sr = new System.IO.StreamReader(filename))
            {
                string name = sr.ReadLine();
                while (name != null)
                {
                    if (name.StartsWith("FILE: "))
                    {
                        string currentFile = name.Substring("FILE: ".Length);
                        // If relative, we add solutionDir to relative directory.
                        if (!System.IO.Path.IsPathRooted(currentFile))
                        {
                            // Here: we can add a list of ordered registered folders and try to find file inside.
                            string solutionDir = CoverageEnvironment.solutionPath;
                            currentFile = System.IO.Path.Combine(solutionDir, currentFile);

                            if (!System.IO.File.Exists(currentFile))
                            {
                                CoverageEnvironment.console.WriteLine("Impossible to find into solution: {0}", currentFile);
                            }
                        }

                        string cov = sr.ReadLine();

                        if (cov != null && cov.StartsWith("RES: "))
                        {
                            cov = cov.Substring("RES: ".Length);

                            BitVector currentVector = new Data.BitVector();

                            for (int i = 0; i < cov.Length; ++i)
                            {
                                char c = cov[i];
                                if (c == 'c' || c == 'p')
                                {
                                    currentVector.Set(i + 1, true);
                                }
                                else if (c == 'u')
                                {
                                    currentVector.Set(i + 1, false);
                                }
                                else
                                {
                                    currentVector.Ensure(i + 1);
                                }
                            }

                            ProfileVector currentProfile = new Data.ProfileVector(currentVector.Count);

                            string prof = sr.ReadLine();
                            if (prof != null && prof.StartsWith("PROF: "))
                            {
                                prof = prof.Substring("PROF: ".Length);
                                int line = 0;

                                for (int i = 0; i < prof.Length;)
                                {
                                    int deep = 0;
                                    while (i < prof.Length && prof[i] != ',')
                                    {
                                        char c = prof[i];
                                        deep = deep * 10 + (c - '0');
                                        ++i;
                                    }
                                    ++i;

                                    int shallow = 0;
                                    while (i < prof.Length && prof[i] != ',')
                                    {
                                        char c = prof[i];
                                        shallow = shallow * 10 + (c - '0');
                                        ++i;
                                    }
                                    ++i;

                                    currentProfile.Set(line, deep, shallow);
                                    ++line;
                                }
                            }
                            else
                            {
                                name = prof;
                                continue;
                            }

                            try
                            {
                                lookup.Add(System.IO.Path.GetFullPath(currentFile), new Tuple <BitVector, ProfileVector>(currentVector, currentProfile));
                            }
                            catch (Exception e)
                            {
                                CoverageEnvironment.console.WriteLine("Error loading coverage report: {0} with key {1}", e.Message, currentFile.ToLower());
                            }
                        }
                    }
                    // otherwise: ignore; grab next line

                    name = sr.ReadLine();
                }
            }

            CoverageEnvironment.print("Coverage: Report " + filename + " has been properly read: " + lookup.Count + " items found.");
        }