Esempio n. 1
0
        private void Read(TextReader reader)
        {
            const string HeaderPrefix = "Microsoft Visual Studio Solution File, Format Version";

            string line;
            int    curLineNum  = 0;
            bool   globalFound = false;
            bool   productRead = false;

            while ((line = reader.ReadLine()) != null)
            {
                curLineNum++;
                line = line.Trim();
                if (line.StartsWith(HeaderPrefix, StringComparison.Ordinal))
                {
                    if (line.Length <= HeaderPrefix.Length)
                    {
                        throw new InvalidSolutionFormatException(
                                  curLineNum,
                                  LocalizableStrings.FileHeaderMissingVersionError);
                    }

                    FormatVersion     = line.Substring(HeaderPrefix.Length).Trim();
                    _prefixBlankLines = curLineNum - 1;
                }
                if (line.StartsWith("# ", StringComparison.Ordinal))
                {
                    if (!productRead)
                    {
                        productRead        = true;
                        ProductDescription = line.Substring(2);
                    }
                }
                else if (line.StartsWith("Project", StringComparison.Ordinal))
                {
                    SlnProject p = new SlnProject();
                    p.Read(reader, line, ref curLineNum);
                    _projects.Add(p);
                }
                else if (line == "Global")
                {
                    if (globalFound)
                    {
                        throw new InvalidSolutionFormatException(
                                  curLineNum,
                                  LocalizableStrings.GlobalSectionMoreThanOnceError);
                    }
                    globalFound = true;
                    while ((line = reader.ReadLine()) != null)
                    {
                        curLineNum++;
                        line = line.Trim();
                        if (line == "EndGlobal")
                        {
                            break;
                        }
                        else if (line.StartsWith("GlobalSection", StringComparison.Ordinal))
                        {
                            var sec = new SlnSection();
                            sec.Read(reader, line, ref curLineNum);
                            _sections.Add(sec);
                        }
                        else // Ignore text that's out of place
                        {
                            continue;
                        }
                    }
                    if (line == null)
                    {
                        throw new InvalidSolutionFormatException(
                                  curLineNum,
                                  LocalizableStrings.GlobalSectionNotClosedError);
                    }
                }
                else if (line.IndexOf('=') != -1)
                {
                    _metadata.ReadLine(line, curLineNum);
                }
            }
            if (FormatVersion == null)
            {
                throw new InvalidSolutionFormatException(LocalizableStrings.FileHeaderMissingError);
            }
        }
Esempio n. 2
0
        public void Read(TextReader reader)
        {
            string line;
            int    curLineNum  = 0;
            bool   globalFound = false;
            bool   productRead = false;

            while ((line = reader.ReadLine()) != null)
            {
                curLineNum++;
                line = line.Trim();
                if (line.StartsWith("Microsoft Visual Studio Solution File", StringComparison.Ordinal))
                {
                    int i = line.LastIndexOf(' ');
                    if (i == -1)
                    {
                        throw new InvalidSolutionFormatException(curLineNum);
                    }
                    FormatVersion    = line.Substring(i + 1);
                    prefixBlankLines = curLineNum - 1;
                }
                if (line.StartsWith("# ", StringComparison.Ordinal))
                {
                    if (!productRead)
                    {
                        productRead        = true;
                        ProductDescription = line.Substring(2);
                    }
                }
                else if (line.StartsWith("Project", StringComparison.Ordinal))
                {
                    SlnProject p = new SlnProject();
                    p.Read(reader, line, ref curLineNum);
                    projects.Add(p);
                }
                else if (line == "Global")
                {
                    if (globalFound)
                    {
                        throw new InvalidSolutionFormatException(curLineNum, "Global section specified more than once");
                    }
                    globalFound = true;
                    while ((line = reader.ReadLine()) != null)
                    {
                        curLineNum++;
                        line = line.Trim();
                        if (line == "EndGlobal")
                        {
                            break;
                        }
                        else if (line.StartsWith("GlobalSection", StringComparison.Ordinal))
                        {
                            var sec = new SlnSection();
                            sec.Read(reader, line, ref curLineNum);
                            sections.Add(sec);
                        }
                        else // Ignore text that's out of place
                        {
                            continue;
                        }
                    }
                    if (line == null)
                    {
                        throw new InvalidSolutionFormatException(curLineNum, "Global section not closed");
                    }
                }
                else if (line.IndexOf('=') != -1)
                {
                    metadata.ReadLine(line, curLineNum);
                }
            }
            if (FormatVersion == null)
            {
                throw new InvalidSolutionFormatException(curLineNum, "File header is missing");
            }
        }