void AppendResourceScriptContents(StringWriter sw, CompositeEntry entry) { if (entry.Assembly == null || entry.Attribute == null || String.IsNullOrEmpty(entry.NameOrPath)) { return; } using (Stream s = entry.Assembly.GetManifestResourceStream(entry.NameOrPath)) { if (s == null) { throw new HttpException(404, "Resource '" + entry.NameOrPath + "' not found"); } if (entry.Attribute.PerformSubstitution) { using (var r = new StreamReader(s)) { new PerformSubstitutionHelper(entry.Assembly).PerformSubstitution(r, sw); } } else { using (var r = new StreamReader(s)) { string line = r.ReadLine(); while (line != null) { sw.WriteLine(line); line = r.ReadLine(); } } } } }
void AppendScriptContents(StringWriter sw, CompositeEntry entry) { if (entry.Assembly != null) { AppendResourceScriptContents(sw, entry); } else { AppendFileScriptContents(sw, entry); } }
void AppendFileScriptContents(StringWriter sw, CompositeEntry entry) { // FIXME: should we limit the script size in any way? if (String.IsNullOrEmpty(entry.NameOrPath)) { return; } string mappedPath; if (!HostingEnvironment.HaveCustomVPP) { // We'll take a shortcut here by bypassing the default VPP layers mappedPath = HostingEnvironment.MapPath(entry.NameOrPath); if (!File.Exists(mappedPath)) { return; } sw.Write(File.ReadAllText(mappedPath)); return; } VirtualPathProvider vpp = HostingEnvironment.VirtualPathProvider; if (!vpp.FileExists(entry.NameOrPath)) { return; } VirtualFile file = vpp.GetFile(entry.NameOrPath); if (file == null) { return; } using (Stream s = file.Open()) { using (var r = new StreamReader(s)) { string line = r.ReadLine(); while (line != null) { sw.WriteLine(line); line = r.ReadLine(); } } } }