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
        internal void Read(TextReader reader, string line, ref int curLineNum)
        {
            Line = curLineNum;

            int n = 0;

            FindNext(curLineNum, line, ref n, '(');
            n++;
            FindNext(curLineNum, line, ref n, '"');
            int n2 = n + 1;

            FindNext(curLineNum, line, ref n2, '"');
            TypeGuid = line.Substring(n + 1, n2 - n - 1);

            n = n2 + 1;
            FindNext(curLineNum, line, ref n, ')');
            FindNext(curLineNum, line, ref n, '=');

            FindNext(curLineNum, line, ref n, '"');
            n2 = n + 1;
            FindNext(curLineNum, line, ref n2, '"');
            Name = line.Substring(n + 1, n2 - n - 1);

            n = n2 + 1;
            FindNext(curLineNum, line, ref n, ',');
            FindNext(curLineNum, line, ref n, '"');
            n2 = n + 1;
            FindNext(curLineNum, line, ref n2, '"');
            FilePath = line.Substring(n + 1, n2 - n - 1);

            n = n2 + 1;
            FindNext(curLineNum, line, ref n, ',');
            FindNext(curLineNum, line, ref n, '"');
            n2 = n + 1;
            FindNext(curLineNum, line, ref n2, '"');
            Id = line.Substring(n + 1, n2 - n - 1);

            while ((line = reader.ReadLine()) != null)
            {
                curLineNum++;
                line = line.Trim();
                if (line == "EndProject")
                {
                    return;
                }
                if (line.StartsWith("ProjectSection", StringComparison.Ordinal))
                {
                    if (_sections == null)
                    {
                        _sections = new SlnSectionCollection();
                    }
                    var sec = new SlnSection();
                    _sections.Add(sec);
                    sec.Read(reader, line, ref curLineNum);
                }
            }

            throw new InvalidSolutionFormatException(
                      curLineNum,
                      LocalizableStrings.ProjectSectionNotClosedError);
        }
Esempio n. 3
0
 internal SlnPropertySetCollection(SlnSection parentSection)
 {
     _parentSection = parentSection;
 }