Beispiel #1
0
 public SolutionFileParser(string solutionFileFilePath)
 {
     this.SolutionFile          = new VisualStudioSolutionFile();
     this.SolutionFile.FilePath = solutionFileFilePath;
     using (var stream = File.OpenRead(solutionFileFilePath))
         using (var reader = new StreamReader(stream))
         {
             while (!reader.EndOfStream)
             {
                 var line = reader.ReadLine();
                 this.SolutionFile.RawFileText.Add(line);
             }
         }
 }
        public void EvaluateNamespacesAndSolutionFolders()
        {
            var slndir = new DirectoryInfo(System.AppDomain.CurrentDomain.BaseDirectory);

            while (slndir != null)
            {
                if (slndir.GetFiles().Any(f => f.Name.Equals(SolutionName)))
                {
                    break;
                }

                Console.WriteLine("Looking for solution folder in directory " + slndir.FullName);

                slndir = slndir.Parent;
            }
            Assert.IsNotNull(slndir, "Failed to find " + SolutionName + " in any parent directories");

            Console.WriteLine("Found solution folder in directory:" + slndir.FullName);

            var sln = new VisualStudioSolutionFile(slndir, slndir.GetFiles().Single(f => f.Name.Equals(SolutionName)));

            ProcessFolderRecursive(sln.RootFolders, slndir);

            foreach (VisualStudioProjectReference rootLevelProjects in sln.RootProjects)
            {
                FindProjectInFolder(rootLevelProjects, slndir);
            }

            var foundProjects = new Dictionary <VisualStudioProjectReference, List <string> >();

            foreach (VisualStudioProjectReference project in sln.Projects)
            {
                foundProjects.Add(project, new List <string>());
            }

            FindUnreferencedProjectsRescursively(foundProjects, slndir);

            foreach (KeyValuePair <VisualStudioProjectReference, List <string> > kvp in foundProjects)
            {
                if (kvp.Value.Count == 0)
                {
                    Error("FAIL: Did not find project " + kvp.Key.Name + " while traversing solution directories and subdirectories");
                }

                if (kvp.Value.Count > 1)
                {
                    Error("FAIL: Found 2+ copies of project " + kvp.Key.Name + " while traversing solution directories and subdirectories:" + Environment.NewLine + string.Join(Environment.NewLine, kvp.Value));
                }
            }

            Assert.AreEqual(0, errors.Count);

            //      DependenciesEvaluation dependencies = new DependenciesEvaluation();
            //     dependencies.FindProblems(sln);

            InterfaceDeclarationsCorrect interfaces = new InterfaceDeclarationsCorrect();

            interfaces.FindProblems(CatalogueRepository.MEF);

            AllImportantClassesDocumented documented = new AllImportantClassesDocumented();

            documented.FindProblems(csFilesFound);

            var uiStandardisationTest = new UserInterfaceStandardisationChecker();

            uiStandardisationTest.FindProblems(csFilesFound, RepositoryLocator.CatalogueRepository.MEF);

            var crossExamination = new DocumentationCrossExaminationTest(slndir);

            crossExamination.FindProblems(csFilesFound);

            //Assuming all files are present and correct we can now evaluate the RDMP specific stuff:
            var otherTestRunner = new RDMPFormInitializationTests();

            otherTestRunner.FindUninitializedForms(csFilesFound);

            var propertyChecker = new SuspiciousRelationshipPropertyUse(CatalogueRepository.MEF);

            propertyChecker.FindPropertyMisuse(csFilesFound);

            var explicitDatabaseNamesChecker = new ExplicitDatabaseNameChecker();

            explicitDatabaseNamesChecker.FindProblems(csFilesFound);

            var noMappingToDatabaseComments = new AutoCommentsEvaluator();

            noMappingToDatabaseComments.FindProblems(CatalogueRepository.MEF, csFilesFound);

            var copyrightHeaderEvaluator = new CopyrightHeaderEvaluator();

            copyrightHeaderEvaluator.FindProblems(csFilesFound);

            //foreach (var file in slndir.EnumerateFiles("*.cs", SearchOption.AllDirectories))
            //{

            //    if (file.Name.StartsWith("AssemblyInfo") || file.Name.StartsWith("TemporaryGenerated") || file.Name.EndsWith("Designer.cs"))
            //        continue;

            //    var line = File.ReadLines(file.FullName).FirstOrDefault();
            //    if (line != null && line.StartsWith("// Copyright"))
            //        continue;



            //    Console.WriteLine(file.FullName);
            //}
        }
Beispiel #3
0
        public void FindProblems(VisualStudioSolutionFile sln)
        {
            List <string> problems = new List <string>();

            foreach (string nuspecFile in _nuspecFiles)
            {
                var filePath = Path.Combine(sln.SolutionDirectory.FullName, nuspecFile);
                var text     = File.ReadAllText(filePath);


                //<dependency id="jacobslusser.ScintillaNET" version="3.6.3"

                Regex r = new Regex(@"dependency id=([A-Za-z.0-9""]*)\s+version=([0-9.""]*)");

                foreach (Match match in r.Matches(text))
                {
                    var assembly = match.Groups[1].Value;
                    var version  = match.Groups[2].Value;

                    if (!Dependencies.ContainsKey(assembly))
                    {
                        Dependencies.Add(assembly, version);
                    }
                    else
                    {
                        if (!Equals(Dependencies[assembly], version))
                        {
                            throw new Exception("nuspec files could not agree on standard version for " + assembly);
                        }
                    }
                }
            }

            foreach (var project in sln.Projects)
            {
                FileInfo csproj = new FileInfo(Path.Combine(sln.SolutionDirectory.FullName, project.Path));

                FileInfo fappConfig = new FileInfo(Path.Combine(csproj.Directory.FullName, "app.config"));

                if (fappConfig.Exists)
                {
                    ProcessAppConfig(fappConfig, problems);
                }

                FileInfo fExeConfig = new FileInfo(Path.Combine(csproj.Directory.FullName, "RDMPAutomationService.exe.config"));

                if (fExeConfig.Exists)
                {
                    ProcessAppConfig(fExeConfig, problems);
                }

                FileInfo fappPackages = new FileInfo(Path.Combine(csproj.Directory.FullName, "packages.config"));
                if (fappPackages.Exists)
                {
                    //look for dodgy packages
                    //<package id="NUnit" version="2.6.4" />

                    XmlDocument dc = new XmlDocument();
                    dc.Load(fappPackages.FullName);

                    foreach (XmlElement dependency in dc.GetElementsByTagName("package"))
                    {
                        var assembly = '"' + dependency.Attributes["id"].Value + '"';
                        var version  = '"' + dependency.Attributes["version"].Value + '"';

                        if (Dependencies.ContainsKey(assembly))
                        {
                            if (!Equals(Dependencies[assembly], version))
                            {
                                problems.Add("In package " + fappPackages.FullName + " you reference " + assembly +
                                             " with version " + version + " but your nuspec has version " +
                                             Dependencies[assembly]);
                            }
                        }
                        else
                        {
                            problems.Add("In package " + fappPackages.FullName + " you reference " + assembly +
                                         "  (version " + version +
                                         ") but no corresponding dependency listed in any of your nuspec files.");
                        }
                    }
                }

                var csprojFileContexnts = File.ReadAllText(csproj.FullName);

                //look for dodgy reference includes
                foreach (KeyValuePair <string, string> dependency in Dependencies)
                {
                    //Reference Include="MySql.Data, Version=8.0.12.0
                    Regex r = new Regex(dependency.Key.Trim('"') + @", Version=([0-9.""]*)");

                    foreach (Match match in r.Matches(csprojFileContexnts))
                    {
                        var versionInCsproj = match.Groups[1].Value;
                        var versionInNuspec = dependency.Value;

                        if (!AreProbablyCompatibleVersions(versionInNuspec, versionInCsproj))
                        {
                            problems.Add("csproj file " + project.Name + " lists dependency of " + dependency.Key +
                                         " with version " + versionInCsproj + " while in the nuspec it is " +
                                         versionInNuspec);
                        }
                    }
                }
            }

            foreach (var problem in problems)
            {
                Console.WriteLine(problem);
            }

            Assert.AreEqual(0, problems.Count);
        }