예제 #1
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);
                        string cov         = sr.ReadLine();

                        if (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.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;
                            }

                            lookup.Add(currentFile.ToLower(), new Tuple <BitVector, ProfileVector>(currentVector, currentProfile));
                        }
                    }
                    // otherwise: ignore; grab next line

                    name = sr.ReadLine();
                }
            }
        }
예제 #2
0
        public NativeData(string filename, DTE dte, OutputWindow output)
        {
            // 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 = System.IO.Path.GetDirectoryName(dte.Solution.FullName);
                            currentFile = System.IO.Path.Combine(solutionDir, currentFile);

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

                        string cov = sr.ReadLine();

                        if (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.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(currentFile.ToLower(), new Tuple <BitVector, ProfileVector>(currentVector, currentProfile));
                            }
                            catch (Exception e)
                            {
                                output.WriteLine("Error loading coverage report: {0} with key {1}", e.Message, currentFile.ToLower());
                            }
                        }
                    }
                    // otherwise: ignore; grab next line

                    name = sr.ReadLine();
                }
            }
        }