예제 #1
0
        public static SliceSection Parse(IList <string> lines, int lineStart)
        {
            var section = new SliceSection
            {
                Lines = new List <string>()
            };

            for (var pos = lineStart; pos < lines.Count; pos++)
            {
                var  line = lines[pos].Trim();
                Type foundType;
                Enum.TryParse(line, out foundType);

                if (foundType != Type.None && section.SectionType == Type.None)
                {
                    section.StartLine   = pos;
                    section.SectionType = foundType;
                }
                else if (foundType != Type.None && section.SectionType != Type.None)
                {
                    break;
                }
                else if (section.SectionType != Type.None && line.Length > 0)
                {
                    section.Lines.Add(line);
                    section.EndLine = pos;
                }
            }

            return(section.SectionType != Type.None ? section : null);
        }
예제 #2
0
        public static SliceSection Parse(IList<string> lines, int lineStart)
        {
            var section = new SliceSection
            {
                Lines = new List<string>()
            };

            for (var pos = lineStart; pos < lines.Count; pos++)
            {
                var line = lines[pos].Trim();
                Type foundType;
                Enum.TryParse(line, out foundType);

                if (foundType != Type.None && section.SectionType == Type.None)
                {
                    section.StartLine = pos;
                    section.SectionType = foundType;
                }
                else if (foundType != Type.None && section.SectionType != Type.None)
                {
                    break;
                }
                else if (section.SectionType != Type.None && line.Length > 0)
                {
                    section.Lines.Add(line);
                    section.EndLine = pos;
                }
            }

            return section.SectionType != Type.None ? section : null;
        }
예제 #3
0
        public void Write(SliceSection section, StringBuilder sb)
        {
            if (section.SectionType == SliceSection.Type.FROM)
            {
                foreach (var line in section.Lines)
                {
                    sb.Append("FROM ").AppendLine(line);
                }
            }

            if (section.SectionType == SliceSection.Type.RUN)
            {
                var text = string.Join($" && {"\\"} {Environment.NewLine}", section.Lines);
                sb.Append("RUN ");
                sb.AppendLine(text);
            }
        }
예제 #4
0
        public void Write(SliceSection section, StringBuilder sb)
        {
            if (section.SectionType == SliceSection.Type.OS)
            {
                foreach (var line in section.Lines)
                {
                    sb.AppendLine("# " + line);
                }
            }

            if (section.SectionType == SliceSection.Type.RUN)
            {
                foreach (var line in section.Lines)
                {
                    sb.AppendLine(line);
                }
            }
        }
예제 #5
0
파일: Slice.cs 프로젝트: curabuild-alex/cb
        public Slice(SemName semName, IList <string> lines)
        {
            SemName    = semName;
            SemVersion = new SemVersion(semName.VersionPart, semName.PreReleasePart);
            Sections   = new List <SliceSection>();
            OsList     = new List <string>();

            int          lineStart = 0;
            SliceSection section;

            while ((section = SliceSection.Parse(lines, lineStart)) != null)
            {
                lineStart = section.EndLine > lineStart ? section.EndLine : lineStart + 1;
                Sections.Add(section);
            }

            foreach (var s in Sections.Where(s => s.SectionType == SliceSection.Type.OS))
            {
                foreach (var line in s.Lines.Where(l => !l.StartsWith("#")))
                {
                    OsList.Add(new SemName(line.Trim()).NamePart.ToLower());
                }
            }
        }