Beispiel #1
0
        /// <summary>
        /// Iterates the types in the project
        /// </summary>
        /// <param name="visitor">The visitor for the iterator</param>
        public void IterateTypes(TypeVisitor visitor)
        {
            _visitor = visitor;
            Solution sol = _workspace.CurrentSolution;
            ProjectDependencyGraph graph = sol.GetProjectDependencyGraph();

            // Typescript projects show up with the same project path, so make sure it supports compilation
            Project mainProj = sol.Projects.Where(proj => proj.Id.Equals(_projectId) && proj.SupportsCompilation).FirstOrDefault();

            if (mainProj == null)
            {
                throw new InvalidOperationException($"Project with path {_projectId} does not exist.");
            }

            // Get a list of all classes being extracted
            Dictionary <string, Compilation> compilations = new Dictionary <string, Compilation>();

            AddCompiledProjects(sol, new List <ProjectId> {
                mainProj.Id
            }, compilations);
            AddCompiledProjects(sol, graph.GetProjectsThatThisProjectDirectlyDependsOn(mainProj.Id), compilations);
            AddCompiledProjects(sol, graph.GetProjectsThatThisProjectTransitivelyDependsOn(mainProj.Id), compilations);

            foreach (Compilation comp in compilations.Values)
            {
                CompilationParser parser = new CompilationParser(comp, _options);
                parser.IterateTypes(_visitor);
            }
        }
        private void VerifyTransitiveReferences(Solution solution, ProjectDependencyGraph projectDependencyGraph, string project, string[] expectedResults)
        {
            var projectId  = solution.GetProjectsByName(project).Single().Id;
            var projectIds = projectDependencyGraph.GetProjectsThatThisProjectTransitivelyDependsOn(projectId);

            var actualResults = projectIds.Select(id => solution.GetRequiredProject(id).Name);

            Assert.Equal <string>(
                expectedResults.OrderBy(n => n),
                actualResults.OrderBy(n => n));
        }
        /// <summary>
        /// Links the solution project assemblies to the given P# project.
        /// </summary>
        private void LinkSolutionAssembliesToProject(Project project, ProjectDependencyGraph graph)
        {
            var projectPath = this.OutputDirectoryMap[project.AssemblyName];

            foreach (var projectId in graph.GetProjectsThatThisProjectTransitivelyDependsOn(project.Id))
            {
                var requiredProject = this.CompilationContext.GetSolution().GetProject(projectId);
                var assemblyPath    = this.ProjectAssemblyPathMap[requiredProject.AssemblyName];
                var fileName        = projectPath + Path.DirectorySeparatorChar + requiredProject.AssemblyName + ".dll";

                CopyAssembly(assemblyPath, fileName);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Links the solution project assemblies to the given P# project.
        /// </summary>
        /// <param name="project">Project</param>
        /// <param name="graph">ProjectDependencyGraph</param>
        private static void LinkSolutionAssembliesToProject(Project project, ProjectDependencyGraph graph)
        {
            var projectPath = CompilationEngine.OutputDirectoryMap[project.AssemblyName];

            foreach (var projectId in graph.GetProjectsThatThisProjectTransitivelyDependsOn(project.Id))
            {
                var requiredProject = ProgramInfo.Solution.GetProject(projectId);
                var assemblyPath    = CompilationEngine.ProjectAssemblyPathMap[requiredProject.AssemblyName];
                var fileName        = projectPath + Path.DirectorySeparatorChar + requiredProject.AssemblyName + ".dll";

                File.Delete(fileName);
                File.Copy(assemblyPath, fileName);
            }
        }
        /// <summary>
        /// Links the external references to the given P# compilation.
        /// </summary>
        private void LinkExternalAssembliesToProject(Project project, ProjectDependencyGraph graph)
        {
            var projectPath = this.OutputDirectoryMap[project.AssemblyName];

            foreach (var projectId in graph.GetProjectsThatThisProjectTransitivelyDependsOn(project.Id))
            {
                var requiredProject = this.CompilationContext.GetSolution().GetProject(projectId);
                foreach (var reference in requiredProject.MetadataReferences)
                {
                    // if (!(reference is PortableExecutableReference))
                    // {
                    //    continue;
                    // }
                    var fileName = Path.Combine(projectPath, Path.GetFileName(reference.Display));
                    CopyAssembly(reference.Display, fileName);
                }
            }
        }