private string PreprocessTemplate(string template) { if (options.IncludeResolver == null) { return(template); } Regex includePattern = new Regex("\\{include:([^\\}]+)\\}", RegexOptions.Multiline | RegexOptions.CultureInvariant); return(includePattern.Replace(template, delegate(Match include) { string includedScript = string.Empty; if (include.Groups.Count == 2) { string includePath = include.Groups[1].Value; IStreamSource includeSource = options.IncludeResolver.Resolve(includePath); if (includeSource != null) { Stream includeStream = includeSource.GetStream(); StreamReader reader = new StreamReader(includeStream); includedScript = reader.ReadToEnd(); includeSource.CloseStream(includeStream); } } return includedScript; })); }
private void ProcessIncludeInstruction(string instructionLine, bool skipPreprocessing) { Debug.Assert(_includeStream == null); Debug.Assert(_includeTextReader == null); bool included = false; int beginQuoteIndex = instructionLine.IndexOf('"'); int endQuoteIndex = 0; if (beginQuoteIndex > 0) { endQuoteIndex = instructionLine.IndexOf('"', beginQuoteIndex + 1); } if (endQuoteIndex > 0) { Exception resolveException = null; string includePath = instructionLine.Substring(beginQuoteIndex + 1, endQuoteIndex - beginQuoteIndex - 1); try { _include = _includeResolver.ResolveInclude(_source, includePath); if (_include != null) { _includeStream = _include.GetStream(); if (_includeStream != null) { _includeTextReader = new StreamReader(_includeStream); _includeLineCounter = 0; if (skipPreprocessing) { string includeText = _includeTextReader.ReadToEnd(); _skipPreprocessingWriter.Write(includeText); _include.CloseStream(_includeStream); _includeTextReader = null; _includeStream = null; included = true; } } } } catch (Exception e) { resolveException = e; } if ((included == false) && (_includeTextReader == null)) { RaiseError("Unable to resolve or open included file '" + includePath + "'", resolveException); } } else { RaiseError("Invalid #include instruction."); } }
private string GetMarkup(IStreamSource source) { string markup = null; Stream stream = source.GetStream(); try { StreamReader reader = new StreamReader(stream); markup = reader.ReadToEnd(); } finally { if (stream != null) { source.CloseStream(stream); stream = null; } } return markup; }
private char[] GetBuffer(IStreamSource source) { char[] buffer = null; Stream stream = source.GetStream(); if (stream != null) { StreamReader reader = new StreamReader(stream); string text = reader.ReadToEnd(); buffer = text.ToCharArray(); source.CloseStream(stream); } return(buffer); }
private string GetMarkup(IStreamSource source) { string markup = null; Stream stream = source.GetStream(); try { StreamReader reader = new StreamReader(stream); markup = reader.ReadToEnd(); } finally { if (stream != null) { source.CloseStream(stream); stream = null; } } return(markup); }
private char[] GetBuffer(IStreamSource source) { char[] buffer = null; Stream stream = source.GetStream(); if (stream != null) { StreamReader reader = new StreamReader(stream); string text = reader.ReadToEnd(); buffer = text.ToCharArray(); source.CloseStream(stream); } return buffer; }