Exemple #1
0
        private static void ParseFile([PathReference] string file)
        {
            // Load up the file.
            string solutionFileText;

            using
            (
                StreamReader sr =
                    new StreamReader
                    (
                        new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read)
                    )
            )
            {
                solutionFileText = sr.ReadToEnd();
            }
            // Cut off unneeded start and end of the file.
            int firstProjectWordIndex =
                solutionFileText.IndexOf(ProjectTag, StringComparison.InvariantCulture);
            int firstGlobalWordIndex =
                solutionFileText.IndexOf(GlobalTag, StringComparison.InvariantCulture);

            solutionFileText =
                solutionFileText.Substring
                (
                    firstProjectWordIndex,
                    firstGlobalWordIndex - firstProjectWordIndex + 2
                );
            // Find starts and ends of each Project section.
            List <int> projectSectionStartIndices = solutionFileText.AllIndexesOf(ProjectTag);
            List <int> projectSectionEndIndices   = solutionFileText.AllIndexesOf(EndProjectTag);

            if (projectSectionStartIndices.Count != projectSectionEndIndices.Count)
            {
                throw new Exception
                      (
                          "Solution file is not properly written: Number of project section" +
                          " start points is not the same as number of end points."
                      );
            }
            // Load up projects.
            for (int i = 0; i < projectSectionStartIndices.Count; i++)
            {
                // Get the text between Project and EndProject tags.
                string projectDescription =
                    solutionFileText.Substring
                    (
                        projectSectionStartIndices[i] + "Project".Length,
                        projectSectionEndIndices[i] - projectSectionStartIndices[i]
                    );
                IProject project = ProjectFactory.Create(projectDescription);
                if (project != null)
                {
                    CodeSolution.Projects.Add(project);
                }
            }
        }
Exemple #2
0
        public static IProject Create([NotNull] string projectFileDescription)
        {
            // Find name of the project and path to the file in the description.
            List <int> quoteIndices = projectFileDescription.AllIndexesOf("\"");
            string     projectName  =
                projectFileDescription.Substring
                (
                    // Name of the project is between third and fourth quotation marks.
                    quoteIndices[2] + 1, quoteIndices[3] - quoteIndices[2] - 1
                );
            string projectPath =
                projectFileDescription.Substring
                (
                    // Path is between fifth and sixth quotation marks.
                    quoteIndices[4] + 1, quoteIndices[5] - quoteIndices[4] - 1
                );

            return
                (ProjectFactory.Create
                 (
                     projectName,
                     Path.Combine(CodeSolution.SolutionFolder, projectPath)
                 ));
        }