private Solution CreateSolution(SolutionDocument document)
        {
            var solution = new Solution()
            {
                Version = document.FileVersion,
                VisualStudioVersion = document.VisualStudioVersion
            };

            if (document.Info.Any())
            {
                solution.Headers = new List<NameValue>();
                foreach (var info in document.Info)
                    solution.Headers.Add(new NameValue { Name = info.Key, Value = info.Value });
            }

            var ignored = new[] { "ProjectConfigurationPlatforms", "NestedProjects" };

            foreach (var globalSection in document.GlobalSections.Where(p => !ignored.Contains(p.Name)))
            {
                if (!globalSection.Info.Any())
                    continue;

                var sectionItem = new NameValueItem { Name = globalSection.Name, When = globalSection.When };

                foreach (var item in globalSection.Info)
                    sectionItem.AddItem(item.Key, item.Value);

                solution.Sections.Add(sectionItem);
            }
            
            return solution;
        }
        private List<SolutionProject> CreateProjects(SolutionDocument solution)
        {
            var projects = solution.Projects
                .Where(p => p.TypeId != FolderTypeId)
                .Select(ConvertTo)
                .ToList();

            var configurations = solution.GlobalSections.FirstOrDefault(gs => gs.Name == "ProjectConfigurationPlatforms");
            if (configurations == null)
                return projects;

            foreach (var project in projects)
            {
                CreateProjectConfiguration(configurations, project);

                var documentProject = solution.Projects.First(p => p.Id == project.Id);
                if (documentProject.Section == null || documentProject.Section.Name != "ProjectDependencies")
                    continue;

                foreach (var info in documentProject.Section.Info)
                    project.AddDependency(solution.Projects.First(p => p.Id == info.Value).Name);
            }

            return projects;
        }
        private List <SolutionProject> CreateProjects(SolutionDocument solution)
        {
            var projects = solution.Projects
                           .Where(p => p.TypeId != FolderTypeId)
                           .Select(ConvertTo)
                           .ToList();

            var configurations = solution.GlobalSections.FirstOrDefault(gs => gs.Name == "ProjectConfigurationPlatforms");

            if (configurations == null)
            {
                return(projects);
            }

            foreach (var project in projects)
            {
                CreateProjectConfiguration(configurations, project);

                var documentProject = solution.Projects.First(p => p.Id == project.Id);
                if (documentProject.Section == null || documentProject.Section.Name != "ProjectDependencies")
                {
                    continue;
                }

                foreach (var info in documentProject.Section.Info)
                {
                    project.AddDependency(solution.Projects.First(p => p.Id == info.Value).Name);
                }
            }

            return(projects);
        }
示例#4
0
        private void ParseProjects(SolutionDocument document)
        {
            while (Tokenizer.TokenEquals("Project"))
            {
                var project = new Project();

                ExpectToken("(");
                project.TypeId = ReadString();
                ExpectToken(")");

                ExpectToken("=");

                project.Name = ReadString();
                ExpectToken(",");
                project.Folder = ReadString();
                ExpectToken(",");
                project.Id = ReadString();

                document.Projects.Add(project);
                ReadNextToken();

                if (Tokenizer.TokenEquals("ProjectSection"))
                {
                    ParseProjectSection(project);
                }

                ExpectToken("EndProject");
                ReadNextToken();
            }
        }
示例#5
0
        public SolutionDocument Execute()
        {
            var document = new SolutionDocument();

            ParseHeader(document);
            ParseProjects(document);
            ParseGlobals(document);

            return(document);
        }
示例#6
0
        private void ParseGlobals(SolutionDocument document)
        {
            if (Tokenizer.TokenEquals("Global"))
            {
                ReadNextToken();

                while (Tokenizer.TokenEquals("GlobalSection"))
                {
                    ParseGlobalSection(document);
                }
            }
        }
        public void WriteDocument(SolutionDocument document, string output)
        {
            Solution result = CreateSolution(document);

            var folders = document.Projects
                          .Where(p => p.TypeId == FolderTypeId)
                          .Select(p => new SolutionFolder {
                Id = p.Id, Name = p.Name
            })
                          .ToList();

            var nestingPairs = document.GlobalSections
                               .Where(gs => gs.Name == "NestedProjects")
                               .SelectMany(gs => gs.Info)
                               .ToList();

            var nestedFolders = (

                from np in nestingPairs

                join f in folders
                on np.Value equals f.Id

                let folder = folders.FirstOrDefault(p => p.Id == np.Key)
                             let parent = folders.FirstOrDefault(p => p.Id == np.Value)

                                          where folder != null

                                          select new { Folder = folder, Parent = parent }
                )
                                .ToList();

            foreach (var nesting in nestedFolders.Where(nf => nf.Parent != null))
            {
                nesting.Parent.Folders.Add(nesting.Folder);
            }

            var parentedFolders = nestedFolders.Select(nf => nf.Folder).ToList();

            result.Items.Folders.AddRange(folders.Except(parentedFolders));

            var projects = CreateProjects(document);

            BuildFolderHeirarchy(folders, nestingPairs, projects);
            WriteSolutionFolders(document, folders);

            result.Items.Projects.AddRange(projects.OrderBy(p => p.Name).ToList());
            Sort(result.Items);

            result.SaveAsXml(output);
        }
        private Solution CreateSolution(SolutionDocument document)
        {
            var solution = new Solution()
            {
                Version             = document.FileVersion,
                VisualStudioVersion = document.VisualStudioVersion
            };

            if (document.Info.Any())
            {
                solution.Headers = new List <NameValue>();
                foreach (var info in document.Info)
                {
                    solution.Headers.Add(new NameValue {
                        Name = info.Key, Value = info.Value
                    });
                }
            }

            var ignored = new[] { "ProjectConfigurationPlatforms", "NestedProjects" };

            foreach (var globalSection in document.GlobalSections.Where(p => !ignored.Contains(p.Name)))
            {
                if (!globalSection.Info.Any())
                {
                    continue;
                }

                var sectionItem = new NameValueItem {
                    Name = globalSection.Name, When = globalSection.When
                };

                foreach (var item in globalSection.Info)
                {
                    sectionItem.AddItem(item.Key, item.Value);
                }

                solution.Sections.Add(sectionItem);
            }

            return(solution);
        }
        private void WriteSolutionFolders(SolutionDocument document, List <SolutionFolder> folders)
        {
            foreach (var folder in folders)
            {
                var documentProject = document.Projects.First(p => p.Id == folder.Id);
                if (documentProject.Section == null)
                {
                    continue;
                }

                foreach (var info in documentProject.Section.Info)
                {
                    folder.AddConfiguration(
                        documentProject.Section.Name,
                        documentProject.Section.When,
                        info.Key,
                        info.Value
                        );
                }
            }
        }
示例#10
0
        private void ParseHeader(SolutionDocument document)
        {
            _tokenizer.SetSkip(false, TokenType.WhiteSpace);

            string header = ReadUntil(TokenType.Version, "");

            document.FileVersion = Decimal.Parse(Tokenizer.Current.Value);

            if (header != "Microsoft Visual Studio Solution File, Format Version ")
            {
                throw new Exception("Solution Header missing");
            }

            ReadUntil(TokenType.InLineComment);
            document.VisualStudioVersion = ReadString().Replace("# ", "");

            _tokenizer.SetSkip(true, TokenType.WhiteSpace);
            ReadNextToken();

            while (!Tokenizer.IsNextToken("Project") && Tokenizer.Current.Type != TokenType.NewLine)
            {
                ReadNameValuePair(document.Info);
            }
        }
示例#11
0
        public void WriteDocument(SolutionDocument document, string output)
        {
            Solution result = CreateSolution(document);

            var folders = document.Projects
                .Where(p => p.TypeId == FolderTypeId)
                .Select(p => new SolutionFolder { Id = p.Id, Name = p.Name })
                .ToList();

            var nestingPairs = document.GlobalSections
                .Where(gs => gs.Name == "NestedProjects")
                .SelectMany(gs => gs.Info)
                .ToList();

            var nestedFolders = (

                from np in nestingPairs

                join f in folders
                  on np.Value equals f.Id

                let folder = folders.FirstOrDefault(p => p.Id == np.Key)
                let parent = folders.FirstOrDefault(p => p.Id == np.Value)

                where folder != null

                select new { Folder = folder, Parent = parent }
            )
            .ToList();

            foreach (var nesting in nestedFolders.Where(nf => nf.Parent != null))
                nesting.Parent.Folders.Add(nesting.Folder);
            
            var parentedFolders = nestedFolders.Select(nf => nf.Folder).ToList();
            result.Items.Folders.AddRange(folders.Except(parentedFolders));

            var projects = CreateProjects(document);
            
            BuildFolderHeirarchy(folders, nestingPairs, projects);
            WriteSolutionFolders(document, folders);

            result.Items.Projects.AddRange(projects.OrderBy(p => p.Name).ToList());
            Sort(result.Items);

            result.SaveAsXml(output);
        }
示例#12
0
        private void WriteSolutionFolders(SolutionDocument document, List<SolutionFolder> folders)
        {
            foreach (var folder in folders)
            {
                var documentProject = document.Projects.First(p => p.Id == folder.Id);
                if (documentProject.Section == null)
                    continue;

                foreach (var info in documentProject.Section.Info)
                {
                    folder.AddConfiguration(
                        documentProject.Section.Name,
                        documentProject.Section.When,
                        info.Key,
                        info.Value
                    );
                }
            }
        }
示例#13
0
        private void ParseGlobalSection(SolutionDocument document)
        {
            var global = ParseSection <GlobalSection>("EndGlobalSection");

            document.GlobalSections.Add(global);
        }