Exemplo n.º 1
0
        private async Task HandleHttpStatusException(RequestContext context, HttpStatusException ex)
        {
            HttpStatusException fault = null;

            var vPath = new VirtualPath("~/errors/" + ex.Status.Code);
            var view  = _viewRegistry.GetView(vPath) ??
                        _viewRegistry.GetView(new VirtualPath("~/errors/default"));

            if (view != null)
            {
                try
                {
                    context.Response.Status = ex.Status;
                    context.Response.AddHeader("Content-Type", "text/html");
                    context.Response.AddHeader("Content-Encoding", "utf-8");
                    await view.Render(context.Response.Body, new ViewResult(vPath.ToString(), ex));

                    return;
                }
                catch (Exception exRendering)
                {
                    fault = new HttpStatusException(new AggregateException(ex, exRendering));
                    context.Response.Status = Status.InternalServerError;
                }
            }
            else
            {
                await DumpException(context, fault ?? ex);
            }
        }
Exemplo n.º 2
0
        public void VirtualPath_WithSpecialPoundSequence_ReplacesSequenceWithEncodedPoundSign()
        {
            //arrange
            var vp = new VirtualPath("/foo%7B:#:%7Dbar/");

            //assert
            Assert.AreEqual("/foo%23bar/", vp.ToString());
        }
Exemplo n.º 3
0
        public void VirtualPath_WithFragment_SetsFragmentPropertyWithFragment()
        {
            //arrange
            var vp = new VirtualPath("/foo#bar");

            //assert
            Assert.AreEqual("/foo#bar", vp.ToString());
            Assert.AreEqual("#bar", vp.ToFullyQualifiedUrl(new Blog {
                Host = "localhost"
            }).Fragment);
        }
Exemplo n.º 4
0
        public void EditIcon_WithSubfolderAndApp_ReturnsAppRootAndIgnoresSubfolder()
        {
            //arrange
            var routeData = new RouteData();

            routeData.Values.Add("subfolder", "sub");
            BlogUrlHelper helper = SetupUrlHelper("/Subtext.Web", routeData);

            //act
            VirtualPath url = helper.EditIconUrl();

            //assert
            Assert.AreEqual("/Subtext.Web/images/icons/edit.gif", url.ToString());
        }
Exemplo n.º 5
0
        public void AppRootUrl_WithSubfolder_ReturnsAppRootAndIgnoresSubfolder()
        {
            //arrange
            var routeData = new RouteData();

            routeData.Values.Add("subfolder", "sub");
            BlogUrlHelper helper = SetupUrlHelper("/", routeData);

            //act
            VirtualPath url = helper.AppRoot();

            //assert
            Assert.AreEqual("/", url.ToString());
        }
Exemplo n.º 6
0
        public void TagCloudUrl_WithSubfolderAndApp_ReturnsTagCloudUrl()
        {
            //arrange
            var routeData = new RouteData();

            routeData.Values.Add("subfolder", "sub");
            BlogUrlHelper helper = SetupUrlHelper("/Subtext.Web", routeData);

            //act
            VirtualPath url = helper.TagCloudUrl();

            //assert
            Assert.AreEqual("/Subtext.Web/sub/tags/default.aspx", url.ToString());
        }
Exemplo n.º 7
0
        public void TagUrl_CorrectlyEncodesPoundCharacter()
        {
            //arrange
            var routeData = new RouteData();

            routeData.Values.Add("subfolder", "sub");
            BlogUrlHelper helper = SetupUrlHelper("/Subtext.Web", routeData);

            //act
            VirtualPath url = helper.TagUrl("C#");

            //assert
            Assert.AreEqual("/Subtext.Web/sub/tags/C%23/default.aspx", url.ToString());
        }
Exemplo n.º 8
0
        public void CustomCssUrl_WithSubfolderAndApp_ReturnsFullyQualifiedUrl()
        {
            //arrange
            var routeData = new RouteData();

            routeData.Values.Add("subfolder", "sub");
            BlogUrlHelper helper = SetupUrlHelper("/Subtext.Web", routeData);

            //act
            VirtualPath url = helper.CustomCssUrl();

            //assert
            Assert.AreEqual("/Subtext.Web/sub/customcss.aspx", url.ToString());
        }
Exemplo n.º 9
0
        public void AdminRssUrl_WithFeednameAndSubfolderAndApp_ReturnsAdminRssUrl()
        {
            //arrange
            var routeData = new RouteData();

            routeData.Values.Add("subfolder", "sub");
            BlogUrlHelper helper = SetupUrlHelper("/Subtext.Web", routeData);

            //act
            VirtualPath url = helper.AdminRssUrl("Referrers");

            //assert
            Assert.AreEqual("/Subtext.Web/sub/admin/ReferrersRss.axd", url.ToString());
        }
Exemplo n.º 10
0
        /// <summary>
        ///  Gets a view.
        /// </summary>
        /// <param name="pathToView"></param>
        /// <returns></returns>
        public IView GetView(VirtualPath pathToView)
        {
            var extendedPaths =
                from extension in _viewEngines.Keys
                select new VirtualPath(pathToView.ToString() + "." + extension);
            var allPaths = new[] { pathToView }.Concat(extendedPaths);
            var views =
                from path in allPaths
                let engine = this.GetViewEngine(path)
                             where engine != null
                             let view = engine.GetView(path, _resolver)
                                        where view != null
                                        select view;

            return(views.FirstOrDefault());
        }
Exemplo n.º 11
0
        internal static IEnumerable <IFileSystemOperation> MoveDirectoryOperations(string src, string dst)
        {
            EnsureDirectoryExists(src);
            EnsureDirectoryNotExists(dst);

            List <IFileSystemOperation> operations = new List <IFileSystemOperation>();

            FileWalker fileWalker = new FileWalker(src);

            operations.Add(Factory.CreateDirectoryCreate(dst));

            VirtualPath srcRootPath = new VirtualPath(src);
            VirtualPath dstRootPath = new VirtualPath(dst);

            EnsurePathExists(dstRootPath.Parent, operations);

            foreach (var dir in fileWalker.Directories.Reverse().Skip(1))
            {
                VirtualPath srcDirPath = new VirtualPath(dir);
                VirtualPath dstDirPath = new VirtualPath(
                    dstRootPath.Parts,
                    srcDirPath.Parts.Skip(srcRootPath.Parts.Count()));

                operations.Add(Factory.CreateDirectoryCreate(dstDirPath.ToString()));
            }
            foreach (var file in fileWalker.Files)
            {
                VirtualPath srcFilePath = new VirtualPath(file);
                VirtualPath dstFilePath = new VirtualPath(
                    dstRootPath.Parts,
                    srcFilePath.Parts.Skip(srcRootPath.Parts.Count()));

                operations.Add(Factory.CreateFileMove(file, dstFilePath.ToString()));
            }
            foreach (var dir in fileWalker.Directories)
            {
                operations.Add(Factory.CreateDirectoryDelete(dir));
            }

            return(operations);
        }
Exemplo n.º 12
0
        /// <summary>
        ///  Registers a directory of views, or a single view file,
        ///  within the filespace of the ASP.NET hosting environment.
        /// </summary>
        /// <param name="feature">
        ///  The feature in which the files are to be registered.
        /// </param>
        /// <param name="path">
        ///  The virtual path to the view(s) to be registered.
        /// </param>

        public static void AddViews(this Feature feature, VirtualPath path)
        {
            feature.AddViews(path, HostingEnvironment.MapPath(path.ToString()));
        }
Exemplo n.º 13
0
 public static void FromWebApplication(this IStaticFilesExpression expr, VirtualPath path)
 {
     expr.FromDirectory(HostingEnvironment.MapPath(path.ToString()));
 }
Exemplo n.º 14
0
        public void VirtualPath_WithSpecialPoundSequence_ReplacesSequenceWithEncodedPoundSign()
        {
            //arrange
            var vp = new VirtualPath("/foo%7B:#:%7Dbar/");

            //assert
            Assert.AreEqual("/foo%23bar/", vp.ToString());
        }
Exemplo n.º 15
0
        public void VirtualPath_WithFragment_SetsFragmentPropertyWithFragment()
        {
            //arrange
            var vp = new VirtualPath("/foo#bar");

            //assert
            Assert.AreEqual("/foo#bar", vp.ToString());
            Assert.AreEqual("#bar", vp.ToFullyQualifiedUrl(new Blog {Host = "localhost"}).Fragment);
        }