示例#1
0
        public bool TryParseLine(string line, SolutionFileBuilder sfb, out bool needMoreLines)
        {
            needMoreLines = false;
            if (currentState == State.NotStarted)
            {
                if (line.StartsWith("Project(\""))
                {
                    if (!TryParseProjectDefinitionFirstLine(line))
                    {
                        sfb.SetIsValid(false);
                        return(false);
                    }

                    currentState  = State.WaitForProjectSectionOrEnd;
                    needMoreLines = true;
                    return(true);
                }
            }
            else if (currentState == State.WaitForProjectSectionOrEnd)
            {
                if (line == "EndProject")
                {
                    sfb.AddProjectDefinition(project);
                    Clear();
                    return(true);
                }

                if (sectionParser.TryParseFirstLine(line))
                {
                    currentState  = State.InsideProjectSection;
                    needMoreLines = true;
                    return(true);
                }

                sfb.SetIsValid(false);
            }
            else if (currentState == State.InsideProjectSection)
            {
                if (!sectionParser.ParseNextLine(line))
                {
                    if (sectionParser.LastProcessingStatus == SectionDefinitionLineParser.State.Succeeded)
                    {
                        project.InnerProjectSections[sectionParser.LastSuccessfullyProcessedSection.SectionType] =
                            sectionParser.LastSuccessfullyProcessedSection;
                        currentState  = State.WaitForProjectSectionOrEnd;
                        needMoreLines = true;
                        return(true);
                    }

                    sfb.SetIsValid(false);
                }
                else
                {
                    needMoreLines = true;
                    return(true);
                }
            }

            return(false);
        }
示例#2
0
        public bool TryParse(string solutionFile, out SolutionFile result)
        {
            Validate.IsNotNull(solutionFile, nameof(solutionFile));
            SolutionFileBuilder sfb = new SolutionFileBuilder();

            result = null;
            string[] strArray = solutionFile.Split(new string[2]
            {
                "\n",
                "\r\n"
            },
                                                   StringSplitOptions.RemoveEmptyEntries);
            sfb.SetLineCount(strArray.Length);
            sfb.SetSizeInChars(solutionFile.Length);
            ILineParser lineParser1   = null;
            bool        needMoreLines = false;

            foreach (string str in strArray)
            {
                string line = str.Trim();
                if (lineParser1 == null)
                {
                    foreach (ILineParser lineParser2 in lineParsers)
                    {
                        if (lineParser2.TryParseLine(line, sfb, out needMoreLines))
                        {
                            if (needMoreLines)
                            {
                                lineParser1 = lineParser2;
                            }

                            break;
                        }
                    }
                }
                else if (lineParser1.TryParseLine(line, sfb, out needMoreLines))
                {
                    if (!needMoreLines)
                    {
                        lineParser1 = null;
                    }
                }
                else
                {
                    sfb.SetIsValid(false);
                    break;
                }
            }

            if (needMoreLines)
            {
                sfb.SetIsValid(false);
            }

            result = sfb.Build();
            return(result.IsValid);
        }