コード例 #1
0
 private void LocateIncludes(HashSet <string> filePaths, Includes includes)
 {
     foreach (string script in includes.Scripts)
     {
         string   scriptPath;
         string[] checkedPaths;
         if (AppContentLocator.Locate(script, out scriptPath, out checkedPaths))
         {
             filePaths.Add(AppContentLocator.ContentRoot.GetAbsolutePath(scriptPath));
         }
         else
         {
             if (CommonContentLocator.Locate(script, out scriptPath, out checkedPaths))
             {
                 filePaths.Add(CommonContentLocator.ContentRoot.GetAbsolutePath(scriptPath));
             }
             else
             {
                 Logger.AddEntry("script specified in app include.js file was not found: {0}\r\nchecked paths:\r\n\t{1}", LogEventType.Warning, script, checkedPaths.ToDelimited(p => p, "\r\n\t"));
             }
         }
     }
 }
コード例 #2
0
        public bool TryRespond(IHttpContext context, out string[] checkedPaths)
        {
            checkedPaths = new string[] { };
            try
            {
                if (Etags.CheckEtags(context))
                {
                    return(true);
                }
                IRequest  request  = context.Request;
                IResponse response = context.Response;
                string    path     = request.Url.AbsolutePath;

                string ext = Path.GetExtension(path);

                string[] split   = path.DelimitSplit("/");
                byte[]   content = new byte[] { };
                bool     handled = AllRequestHandler.HandleRequest(context, out content);

                if (!handled)
                {
                    if (ContentHandlers.ContainsKey(path.ToLowerInvariant()))
                    {
                        handled = ContentHandlers[path.ToLowerInvariant()].HandleRequest(context, out content);
                    }
                    else if (AppContentLocator.Locate(path, out string locatedPath, out checkedPaths))
                    {
                        handled = true;
                        string foundExt = Path.GetExtension(locatedPath);
                        if (FileCachesByExtension.ContainsKey(foundExt))
                        {
                            FileCache cache = FileCachesByExtension[ext];
                            if (ShouldZip(request))
                            {
                                SetGzipContentEncodingHeader(response);
                                content = cache.GetZippedContent(locatedPath);
                            }
                            else
                            {
                                content = cache.GetContent(locatedPath);
                            }
                        }
                        else
                        {
                            content = File.ReadAllBytes(locatedPath);
                        }
                        Etags.SetLastModified(response, request.Url.ToString(), new FileInfo(locatedPath).LastWriteTime);
                    }
                    else if (string.IsNullOrEmpty(ext) && !ShouldIgnore(path) || (AppRoot.FileExists("~/pages{0}.html"._Format(path), out locatedPath)))
                    {
                        content = RenderLayout(response, path);
                        handled = true;
                    }
                }

                if (handled)
                {
                    SetContentType(response, path);
                    SetContentDisposition(response, path);
                    Etags.Set(response, request.Url.ToString(), content);
                    SetResponseHeaders(response, path);
                    SendResponse(response, content);
                    OnResponded(context);
                }
                else
                {
                    OnNotResponded(context);
                }
                return(handled);
            }
コード例 #3
0
        public bool TryRespond(IHttpContext context, out string[] checkedPaths)
        {
            checkedPaths = new string[] { };
            IRequest  request  = context.Request;
            IResponse response = context.Response;
            string    path     = request.Url.AbsolutePath;

            string ext = Path.GetExtension(path);

            path = RemoveBamAppsPrefix(path);

            string[] split   = path.DelimitSplit("/");
            byte[]   content = new byte[] { };
            bool     result  = false;

            string locatedPath;

            if (path.Equals("/upload", StringComparison.InvariantCultureIgnoreCase))
            {
                HandleUpload(context, HttpPostedFile.FromRequest(request));
                string query = request.Url.Query.Length > 0 ? request.Url.Query : string.Empty;
                if (query.StartsWith("?"))
                {
                    query = query.TruncateFront(1);
                }
                content = RenderLayout(response, path, query);
                result  = true;
            }
            else if (string.IsNullOrEmpty(ext) && !ShouldIgnore(path) ||
                     (AppRoot.FileExists("~/pages{0}.html"._Format(path), out locatedPath)))
            {
                content = RenderLayout(response, path);
                result  = true;
            }
            else if (AppContentLocator.Locate(path, out locatedPath, out checkedPaths))
            {
                result = true;
                string foundExt = Path.GetExtension(locatedPath);
                if (FileCachesByExtension.ContainsKey(foundExt))
                {
                    FileCache cache = FileCachesByExtension[ext];
                    if (ShouldZip(request))
                    {
                        SetGzipContentEncodingHeader(response);
                        content = cache.GetZippedContent(locatedPath);
                    }
                    else
                    {
                        content = cache.GetContent(locatedPath);
                    }
                }
                else
                {
                    content = File.ReadAllBytes(locatedPath);
                }
            }

            if (result)
            {
                SetContentType(response, path);
                SetContentDisposition(response, path);
                SendResponse(response, content);
                OnResponded(context);
            }
            else
            {
                OnNotResponded(context);
            }
            return(result);
        }