コード例 #1
0
        public ScriptResult ProcessScript(System.IO.Stream stream, IDictionary <string, string> requestParameters)
        {
            StreamReader reader = new StreamReader(stream);
            var          all    = reader.ReadToEnd();
            var          script = _GenerateCScript(all);

            using (var newStream = new MemoryStream(Encoding.UTF8.GetBytes(script)))
            {
                var result = new CscriptProcessor().ProcessScript(newStream, requestParameters);
                return(result);
            }
        }
コード例 #2
0
        public ScriptResult ProcessScript(Stream stream, IDictionary <string, string> requestParameters)
        {
            // read the whole file into a string
            StreamReader reader = new StreamReader(stream);
            string       output = ProcessScript(reader.ReadToEnd());

            // convert the output to a stream
            Stream outputStream = StringToStream(output);

            // use the processor to get the result
            var processor = new CscriptProcessor();

            return(processor.ProcessScript(outputStream, requestParameters));
        }
コード例 #3
0
        public ScriptResult ProcessScript(Stream stream, IDictionary <string, string> requestParameters)
        {
            sb = new StringBuilder();
            CscriptProcessor scriptProcessor = new CscriptProcessor();
            List <String>    inputLines      = new List <String>();

            StreamReader reader = new StreamReader(stream);
            string       line   = null;

            while ((line = reader.ReadLine()) != null)
            {
                inputLines.Add(line);
            }

            String parsedScript = ProcessInput(inputLines);

            stream = createStream(parsedScript);

            ScriptResult result = scriptProcessor.ProcessScript(stream, requestParameters);

            return(result);
        }
コード例 #4
0
        public ScriptResult ProcessScript(string path, IDictionary<string, string> requestParameters)
        {
            // Read in the contents of the file to a flat string
            string fileContents = String.Join(" ", File.ReadAllLines(path));
            int length = fileContents.Length;
            int last = 0;

            // Holds executable csscript code
            List<string> codes = new List<string>();

            for (int i = 0; i < length; i++) {

                // Parse out code blocks
                if (fileContents.ElementAt(i) ==  '{')
                {
                    // Get HTML up to this point
                    string html = fileContents.Substring(last, i - last);
                    codes.Add(_WriteString(html));

                    // Find matching brace and add code
                    int endBrace = _FindMatchingBrace(i, fileContents);
                    string code = fileContents.Substring(i + 1, endBrace - i - 1);
                    codes.Add(code);

                    // Update variables
                    i = endBrace;
                    last = i + 1;
                }

                // Parse out @{}
                if (i < length - 1 && fileContents.Substring(i, 2) == "@{")
                {
                    // Get HTML up to this point
                    string html = fileContents.Substring(last, i - last);
                    codes.Add(_WriteString(html));

                    // Find matching brace and add code
                    i++; // Move past the @
                    int endBrace = _FindMatchingBrace(i, fileContents);
                    string code = fileContents.Substring(i + 1, endBrace - i - 1);
                    codes.Add(_WriteExpression(code));

                    // Update variables
                    i = endBrace;
                    last = i + 1;
                }

            }

            // Get any remaining HTML in the file
            string remaining = fileContents.Substring(last);
            codes.Add(_WriteString(remaining));

            // This is jank.  But... :)
            string fileName = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".csscript.tmp";
            File.WriteAllLines(fileName, codes);

            // Use Cscript processor
            IScriptProcessor sp = new CscriptProcessor();
            ScriptResult result = sp.ProcessScript(fileName, requestParameters);

            // Delete the temp file
            File.Delete(fileName);

            // Return the result
            return result;
        }