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 (); } } } } }
protected internal override string GetUrl(ScriptManager scriptManager, bool zip) { if (scriptManager == null) { // .NET emulation... throw new NullReferenceException(".NET emulation"); } var url = new StringBuilder(COMPOSITE_SCRIPT_REFERENCE_PREFIX); string path; string name; CompositeEntry entry; List <CompositeEntry> entries = null; WebResourceAttribute wra; foreach (ScriptReference sr in Scripts) { if (sr == null) { continue; } name = sr.Name; if (!String.IsNullOrEmpty(name)) { Assembly assembly = sr.ResolvedAssembly; name = GetScriptName(name, sr.IsDebugMode(scriptManager), null, assembly, out wra); path = scriptManager.ScriptPath; if (sr.IgnoreScriptPath || String.IsNullOrEmpty(path)) { entry = new CompositeEntry { Assembly = assembly, NameOrPath = name, Attribute = wra }; } else { AssemblyName an = assembly.GetName(); entry = new CompositeEntry { NameOrPath = String.Concat(VirtualPathUtility.AppendTrailingSlash(path), an.Name, '/', an.Version, '/', name), Attribute = wra }; } } else if (!String.IsNullOrEmpty((path = sr.Path))) { bool notFound = false; name = GetScriptName(path, sr.IsDebugMode(scriptManager), scriptManager.EnableScriptLocalization ? ResourceUICultures : null, null, out wra); if (!HostingEnvironment.HaveCustomVPP) { notFound = !File.Exists(HostingEnvironment.MapPath(name)); } else { notFound = !HostingEnvironment.VirtualPathProvider.FileExists(name); } if (notFound) { throw new HttpException("Web resource '" + name + "' was not found."); } entry = new CompositeEntry { NameOrPath = name }; } else { entry = null; } if (entry != null) { if (entries == null) { entries = new List <CompositeEntry> (); } entries.Add(entry); url.Append(entry.GetHashCode().ToString("x")); entry = null; } } if (entries == null || entries.Count == 0) { return(String.Empty); } string ret = ScriptResourceHandler.GetResourceUrl(ThisAssembly, url.ToString(), NotifyScriptLoaded); entriesCache.InsertOrUpdate((uint)ret.GetHashCode(), ret, entries, entries); return(ret); }
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 (); } } } }
void AppendScriptContents (StringWriter sw, CompositeEntry entry) { if (entry.Assembly != null) AppendResourceScriptContents (sw, entry); else AppendFileScriptContents (sw, entry); }
protected internal override string GetUrl (ScriptManager scriptManager, bool zip) { if (scriptManager == null) // .NET emulation... throw new NullReferenceException (".NET emulation"); var url = new StringBuilder (COMPOSITE_SCRIPT_REFERENCE_PREFIX); string path; string name; CompositeEntry entry; List <CompositeEntry> entries = null; WebResourceAttribute wra; foreach (ScriptReference sr in Scripts) { if (sr == null) continue; name = sr.Name; if (!String.IsNullOrEmpty (name)) { Assembly assembly = sr.ResolvedAssembly; name = GetScriptName (name, sr.IsDebugMode (scriptManager), null, assembly, out wra); path = scriptManager.ScriptPath; if (sr.IgnoreScriptPath || String.IsNullOrEmpty (path)) { entry = new CompositeEntry { Assembly = assembly, NameOrPath = name, Attribute = wra }; } else { AssemblyName an = assembly.GetName (); entry = new CompositeEntry { NameOrPath = String.Concat (VirtualPathUtility.AppendTrailingSlash (path), an.Name, '/', an.Version, '/', name), Attribute = wra }; } } else if (!String.IsNullOrEmpty ((path = sr.Path))) { bool notFound = false; name = GetScriptName (path, sr.IsDebugMode (scriptManager), scriptManager.EnableScriptLocalization ? ResourceUICultures : null, null, out wra); if (!HostingEnvironment.HaveCustomVPP) notFound = !File.Exists (HostingEnvironment.MapPath (name)); else notFound = !HostingEnvironment.VirtualPathProvider.FileExists (name); if (notFound) throw new HttpException ("Web resource '" + name + "' was not found."); entry = new CompositeEntry { NameOrPath = name }; } else entry = null; if (entry != null) { if (entries == null) entries = new List <CompositeEntry> (); entries.Add (entry); url.Append (entry.GetHashCode ().ToString ("x")); entry = null; } } if (entries == null || entries.Count == 0) return String.Empty; string ret = ScriptResourceHandler.GetResourceUrl (ThisAssembly, url.ToString (), NotifyScriptLoaded); entriesCache.InsertOrUpdate ((uint)ret.GetHashCode (), ret, entries, entries); return ret; }