Exemple #1
0
        /// <summary>
        /// Process all the <code>@include</code> directives in the file.
        /// </summary>
        /// <param name="lines">Source file lines</param>
        /// <returns>An enumerable object containing the lines of the source code after the inclusions</returns>
        private async Task <IEnumerable <string> > ProcessIncludes(string[] lines)
        {
            LinkedList <string> result = new LinkedList <string>();

            foreach (string line in lines)
            {
                if (line.StartsWith("@include"))
                {
                    string includeSrc = await ProcessSingleInclude(line);

                    includeSrc = SiiTextParser.SanitizeSource(includeSrc);

                    foreach (string includeLine in SiiTextParser.SplitSourceToLines(includeSrc))
                    {
                        result.AddLast(includeLine);
                    }
                }
                else
                {
                    result.AddLast(line);
                }
            }

            return(result);
        }
Exemple #2
0
        /// <summary>
        /// Read a Sii text file.
        /// </summary>
        /// <param name="stream">Stream containing the sii text data</param>
        /// <returns>The root Sii object representing the unit</returns>
        public async Task <Object> ReadFromText(Stream stream)
        {
            using (StreamReader sr = new StreamReader(stream)) {
                string content = await sr.ReadToEndAsync();

                if (!content.StartsWith(SII_TEXT_UNIT_SIGNATURE)) // Not a valid text unit
                {
                    throw new InvalidSiiFileException();
                }

                content = SiiTextParser.SanitizeSource(content);
                string[] lines = SiiTextParser.SplitSourceToLines(content).ToArray();
                lines = (await ProcessIncludes(lines)).ToArray();

                return(ObjectDeserializer.ParseObject(lines, 0, lines.Length));
            }
        }