Пример #1
0
        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;
                        bool         nogzip    = !(Server.ServerConfig.NoGzipFiles.IndexOf(ext) >= 0);
                        bool         cachefile = Server.ServerConfig.CacheFiles.IndexOf(ext) >= 0;
                        if (Debug)
                        {
                            fr = new NoCacheResource(filename, urlname);
                            if (nogzip)
                            {
                                fr.GZIP = true;
                            }
                        }
                        else
                        {
                            if (cachefile)
                            {
                                fr = new FileResource(filename, urlname);
                            }
                            else
                            {
                                fr = new NoCacheResource(filename, urlname);
                                if (nogzip)
                                {
                                    fr.GZIP = true;
                                }
                            }
                        }
                        mResources[urlname] = fr;
                        fr.Load();
                        if (Server.EnableLog(EventArgs.LogType.Info))
                        {
                            Server.BaseServer.Log(EventArgs.LogType.Info, null, "load static resource " + urlname);
                        }
                    }
                }
            }
        }
Пример #2
0
        private FileResource CreateResource(string file, bool cache)
        {
            try
            {
                string ext = System.IO.Path.GetExtension(file).ToLower();
                ext = ext.Substring(1, ext.Length - 1);
                if (mExts.ContainsKey(ext))
                {
                    FileResource fr;
                    string       urlname = "";
                    urlname = GetUrl(file);
                    if (cache)
                    {
                        if (!Debug)
                        {
                            if (mResources.TryGetValue(urlname, out fr))
                            {
                                if (Server.BaseServer.GetRunTime() - fr.CreateTime < 2000)
                                {
                                    return(fr);
                                }
                            }
                        }
                    }
                    bool nogzip    = !(Server.Options.NoGzipFiles.IndexOf(ext) >= 0);
                    bool cachefile = Server.Options.CacheFiles.IndexOf(ext) >= 0;
                    if (Debug)
                    {
                        fr = new NoCacheResource(file, urlname);
                        if (nogzip)
                        {
                            fr.GZIP = true;
                        }
                    }
                    else
                    {
                        FileInfo info = new FileInfo(file);
                        if (cachefile && info.Length < 1024 * Server.Options.CacheFileSize)
                        {
                            fr = new FileResource(file, urlname);
                        }
                        else
                        {
                            fr = new NoCacheResource(file, urlname);
                            if (nogzip)
                            {
                                fr.GZIP = true;
                            }
                        }
                    }

                    fr.Load();
                    fr.CreateTime = Server.BaseServer.GetRunTime();
                    if (cache && mResources.Count < 5000)
                    {
                        mResources[urlname] = fr;
                    }
                    if (Server.EnableLog(EventArgs.LogType.Info))
                    {
                        Server.BaseServer.Log(EventArgs.LogType.Info, null, "update {0} static resource success", urlname);
                    }
                    return(fr);
                }
            }
            catch (Exception e_)
            {
                Server.BaseServer.Error(e_, null, "update {0} resource error {1}", file, e_.Message);
            }
            return(null);
        }