Ejemplo n.º 1
0
        private IList <CodeFile> GenerateCodeFileList()
        {
            var res      = new List <CodeFile>();
            var solution = ApplicationObject.Solution;

            if (solution != null)
            {
                VSLogger.Write(string.Format("Getting files from solution... {0}", solution.FullName));
                VSLogger.Write(string.Format(" top level project count {0} / {1}", solution.Count,
                                             solution.Projects.Count));

                if (solution.Count == 0) //unexpected..strange solution, fallback to parsing the solution files
                {
                    if (string.IsNullOrEmpty(solution.FullName))
                    {
                        return(res);
                    }

                    VSLogger.Write("Error getting projects from solution, using manual parsing as fallback");
                    return(new SolutionParser().ParseSln(solution.FullName, FilePassesFilter));
                }

                var totalFiles = 0;
                foreach (Project project in solution.Projects)
                {
                    VSLogger.Write(string.Format(" - Project {0}", project.UniqueName));

                    if (project.ProjectItems == null)
                    {
                        continue; // project not loaded atm
                    }
                    foreach (var item in project.ProjectItems)
                    {
                        var projectItem = item as ProjectItem;
                        foreach (var subItem in GetProjectItems(projectItem))
                        {
                            VSLogger.Write(string.Format("  - {0}", subItem.Name));
                            res.Add(CreateCodeFileFromItem(subItem));
                            totalFiles++;
                        }
                    }
                }
                VSLogger.Write(string.Format("Done with getting files from solution (total files: {0})", totalFiles));
            }
            else
            {
                VSLogger.Write(string.Format("Unexpected: Solution null..."));
            }
            return(res.Distinct(new FilePathComparer()).ToList()); //the same file can be included from multiple projects
        }
Ejemplo n.º 2
0
        public static string GetCodeFileContents(CodeFile codeFile)
        {
            var contents = "";

            try
            {
                var fileName = codeFile.FilePath;
                if (File.Exists(fileName)) //can not exist if using svn templates
                {
                    contents = File.ReadAllText(fileName);
                }
            }
            catch (Exception e)
            {
                //gulp
                VSLogger.Error(string.Format("Unable to read file contents of file {0}", codeFile.FilePath), e);
            }

            return(contents);
        }
Ejemplo n.º 3
0
        public IList <CodeFile> ParseSln(string slnPath, Predicate <string> fileFilter)
        {
            slnPath = Path.GetFullPath(slnPath);

            var files = new List <CodeFile>();

            foreach (var projPath in GetProjectPaths(slnPath))
            {
                var projectName = Path.GetFileNameWithoutExtension(projPath);
                VSLogger.Write(string.Format(" parsing project {0}", projectName));
                var filePaths = GetFilePaths(projPath, fileFilter).ToList();
                VSLogger.Write(string.Format(" - {0} files", filePaths.Count));
                foreach (var file in filePaths)
                {
                    files.Add(new CodeFile {
                        FilePath = file, ProjectName = projectName
                    });
                }
            }
            VSLogger.Write(string.Format("- total {0} files", files.Count));
            return(files);
        }