示例#1
0
        private bool FindResource(string url, HttpServerContext context, string MimeType)
        {
            var staticPathCon = StaticPathCon.GetInstance();
            var staticResCon  = StaticResCon.GetInstance();

            foreach (var item in staticPathCon.GetFragment())
            {
                string basedir = System.IO.Directory.GetCurrentDirectory();
                string path    = basedir + "\\" + item + "\\" + url;
                if (!File.Exists(path))
                {
                    continue;
                }
                var result = File.ReadAllText(path, System.Text.Encoding.UTF8);
                if (MimeType.Equals("js") || MimeType.Equals("html") || MimeType.Equals("css"))
                {
                    context.Response.Content(result, staticResCon.ParseMimeType(MimeType));
                }
                else
                {
                    context.Response.Image(path, staticResCon.ParseMimeType(MimeType));
                }
                return(true);
            }
            return(false);
        }
示例#2
0
        private bool FilterResource(HttpServerContext httpServerContext)
        {
            var    url          = httpServerContext.Request.Url.ToString();
            string absolutePath = httpServerContext.Request.Url.AbsolutePath;

            if (string.IsNullOrWhiteSpace(absolutePath) || absolutePath.Equals("/"))
            {
                absolutePath = "index.html";
            }
            var staticPathcon = StaticPathCon.GetInstance();
            var staticResCon  = StaticResCon.GetInstance();

            foreach (var item in staticResCon.GetPattern())
            {
                string resName = ".*." + item;
                var    re      = new Regex(item);
                var    Match   = re.Match(absolutePath);
                if (Match.Success)
                {
                    if (FindResource(absolutePath, httpServerContext, item) == false)
                    {
                        new ResourceNotFoundExceptionHandler().HandleException(httpServerContext, new Exception("url"));
                        httpServerContext.Response.NotFountResource(404);
                    }
                    return(true);
                }
            }
            return(false);
        }
示例#3
0
        static void RegisterStaticRule(string s)
        {
            var staticResCon = StaticResCon.GetInstance();

            staticResCon.AddPattern(s);
        }