private FileResource CreateResource(string file) { try { string ext = System.IO.Path.GetExtension(file).ToLower(); ext = ext.Substring(1, ext.Length - 1); if (mExts.ContainsKey(ext)) { string urlname = GetUrl(file); FileResource fr; if (!Debug) { if (mResources.TryGetValue(urlname, out fr)) { if (Server.BaseServer.GetRunTime() - fr.CreateTime < 2000) { return(fr); } } } if (Debug) { fr = new NoGzipResource(file, urlname); } else { if ("jpg;jpeg;png;gif;png;ico".IndexOf(ext) >= 0) { fr = new NoGzipResource(file, urlname); } else { fr = new FileResource(file, urlname); } } mResources[urlname] = fr; fr.CreateTime = Server.BaseServer.GetRunTime(); fr.Load(); Server.BaseServer.Log(EventArgs.LogType.Info, null, "load static resource " + urlname); return(fr); } } catch (Exception e_) { Server.BaseServer.Error(e_, null, "load " + file + " resource error"); } return(null); }
public void LoadManifestResource(System.Reflection.Assembly assembly) { string[] files = assembly.GetManifestResourceNames(); string tmpFolder = "_tempview"; if (!System.IO.Directory.Exists(tmpFolder)) { Directory.CreateDirectory(tmpFolder); } foreach (string item in files) { int offset = item.IndexOf(".views"); if (offset > 0) { string url = GetResourceUrl(item.Substring(offset + 6, item.Length - offset - 6)); string ext = System.IO.Path.GetExtension(item).ToLower(); ext = ext.Substring(1, ext.Length - 1); if (mExts.ContainsKey(ext)) { string urlname = url; string filename = tmpFolder + System.IO.Path.DirectorySeparatorChar + item; SaveTempFile(assembly, item, filename); FileResource fr; if (Debug) { fr = new NoGzipResource(filename, urlname); } else { if ("jpg;jpeg;png;gif;png".IndexOf(ext) >= 0) { fr = new NoGzipResource(filename, urlname); } else { fr = new FileResource(filename, urlname); } } mResources[urlname] = fr; fr.Load(); Server.BaseServer.Log(EventArgs.LogType.Info, null, "load static resource " + urlname); } } } }