Exemple #1
0
        /// <summary>
        /// Transforms the osq script into an osb script.
        /// </summary>
        /// <returns>The osb script.</returns>
        public string Encode()
        {
            if(ExecutionContext == null) {
                throw new InvalidOperationException("ExecutionContext must not be null");
            }

            if(Parser == null) {
                throw new InvalidOperationException("Parser must not be null");
            }

            scriptNodes = new List<ConvertedNode>();

            var output = new StringBuilder();

            using(var bufferingReader = new BufferingTextReaderWrapper(Parser.InputReader))
            using(var myReader = new LocatedTextReaderWrapper(bufferingReader, Parser.InputReader.Location.Clone())) { // Sorry we have to do this...
                var parser = new Parser.Parser(Parser, myReader);

                NodeBase node;

                while((node = parser.ReadNode()) != null) {
                    string curOutput = node.Execute(ExecutionContext);

                    output.Append(curOutput);

                    var converted = new ConvertedNode {
                        Node = node,
                        NodeOutput = curOutput,
                        OriginalScript = bufferingReader.BufferedText
                    };

                    scriptNodes.Add(converted);

                    bufferingReader.ClearBuffer();
                }
            }

            return output.ToString();
        }