Example #1
0
 public RouteData(System.Web.Routing.RouteBase route, System.Web.Routing.IRouteHandler routeHandler)
 {
 }
Example #2
0
        public void ReturnAspNetProxiedRouteInstances(Routes tab, ITabContext context, RoutesInspector routeInspector, IInspectorContext routeInspectorContext, System.Web.Routing.IRouteHandler routeHandler)
        {
            System.Web.Routing.RouteTable.Routes.Clear();
            System.Web.Routing.RouteTable.Routes.Add("Test", new System.Web.Routing.Route("Test", routeHandler));
            System.Web.Routing.RouteTable.Routes.Add("BaseTyped", new RoutesInspectorShould.NewRouteBase());
            System.Web.Routing.RouteTable.Routes.Add("BaseTestTyped", new RoutesInspectorShould.NewConstructorRouteBase("Name"));
            System.Web.Routing.RouteTable.Routes.Add("SubTyped", new RoutesInspectorShould.NewRoute("test", routeHandler));
            System.Web.Routing.RouteTable.Routes.Add("SubTestTyped", new RoutesInspectorShould.NewConstructorRoute("test", routeHandler, "Name"));
            System.Web.Routing.RouteTable.Routes.Ignore("{resource}.axd/{*pathInfo}", new { resource = "Test", pathInfo = "[0-9]" });

            routeInspectorContext.Setup(x => x.ProxyFactory).Returns(new CastleDynamicProxyFactory(routeInspectorContext.Logger, routeInspectorContext.MessageBroker, () => new ExecutionTimer(new Stopwatch()), () => new RuntimePolicy()));
            routeInspector.Setup(routeInspectorContext);

            var model = tab.GetData(context) as List <RouteModel>;

            Assert.NotNull(model);
            Assert.Equal(6, model.Count);
        }
Example #3
0
 public Route(string url, System.Web.Routing.RouteValueDictionary defaults, System.Web.Routing.IRouteHandler routeHandler)
 {
 }
Example #4
0
 public Route(string url, System.Web.Routing.RouteValueDictionary defaults, System.Web.Routing.RouteValueDictionary constraints, System.Web.Routing.RouteValueDictionary dataTokens, System.Web.Routing.IRouteHandler routeHandler)
 {
 }
Example #5
0
 public Route(string url, System.Web.Routing.IRouteHandler routeHandler)
 {
 }
Example #6
0
 public HttpWebRoute(string url, System.Web.Routing.RouteValueDictionary defaults, System.Web.Routing.RouteValueDictionary constraints, System.Web.Routing.RouteValueDictionary dataTokens, System.Web.Routing.IRouteHandler routeHandler) : base(default(string), default(System.Web.Routing.IRouteHandler))
 {
 }
Example #7
0
 public HttpWebRoute(string url, System.Web.Routing.IRouteHandler routeHandler) : base(default(string), default(System.Web.Routing.IRouteHandler))
 {
 }
Example #8
0
        /// <summary>
        /// Processa a requisição.
        /// </summary>
        /// <returns></returns>
        public async override Task <object> Handle()
        {
            var context     = new Microsoft.Owin.OwinContext(Environment);
            var wr          = new HttpWorkerRequestWrapper(context);
            var httpContext = new System.Web.HttpContext(wr);

            httpContext.User            = System.Threading.Thread.CurrentPrincipal;
            httpContext.Request.Browser = new System.Web.HttpBrowserCapabilities()
            {
                Capabilities = new System.Collections.Hashtable()
            };
            System.Web.HttpContext.Current = httpContext;
            System.Web.HttpContextBase httpContextBase = null;
            httpContextBase = new System.Web.HttpContextWrapper(httpContext);
            httpContext.Request.Form.HasKeys();
            HttpContext.Current = new HttpContext(context, httpContextBase.Request, httpContextBase.Response);
            var route = base.GetRoute(httpContextBase);

            context.Response.Headers.Add("Server", new[] {
                "Colosoft 1.0"
            });
            if (_application != null)
            {
                _application.OnBeginRequest(context, EventArgs.Empty);
            }
            if (_application != null)
            {
                _application.OnAuthenticateRequest(context, EventArgs.Empty);
            }
            httpContext.User = System.Threading.Thread.CurrentPrincipal;
            System.Web.Routing.IRouteHandler routeHandler = null;
            if (route != null)
            {
                routeHandler = route.RouteHandler;
                if (routeHandler == null)
                {
                    throw new InvalidOperationException("NoRouteHandler");
                }
            }
            if (route != null && !(routeHandler is System.Web.Routing.StopRoutingHandler))
            {
                var requestContext = new System.Web.Routing.RequestContext(httpContextBase, route);
                var httpHandler    = route.RouteHandler.GetHttpHandler(requestContext);
                if (httpHandler == null)
                {
                    throw new InvalidOperationException(string.Format("NoHttpHandler {0}", routeHandler.GetType()));
                }
                try
                {
                    if (httpHandler is System.Web.IHttpAsyncHandler)
                    {
                        var asyncHandler = (System.Web.IHttpAsyncHandler)httpHandler;
                        await Task.Factory.FromAsync <System.Web.HttpContext>(asyncHandler.BeginProcessRequest, asyncHandler.EndProcessRequest, httpContext, null);
                    }
                    else
                    {
                        httpHandler.ProcessRequest(httpContext);
                    }
                }
                catch (Exception ex)
                {
                    if (!FinishRequest(wr, httpContext, ex))
                    {
                        wr.SendStatus(400, "Bad Request");
                        wr.SendKnownResponseHeader(12, "text/html; charset=utf-8");
                        byte[] data = Encoding.ASCII.GetBytes("<html><body>Bad Request </ br>" + ex.ToString() + "</body></html>");
                        wr.SendResponseFromMemory(data, data.Length);
                        wr.FlushResponse(true);
                    }
                }
                if (httpContextBase.Response.StatusCode == 401)
                {
                    httpContextBase.Response.Redirect(string.Format("/login?returnurl={0}", context.Request.Uri.AbsolutePath));
                }
            }
            else
            {
                var path = this.RequestPath;
                if (System.Web.Hosting.HostingEnvironment.VirtualPathProvider.FileExists(path))
                {
                    var file  = System.Web.Hosting.HostingEnvironment.VirtualPathProvider.GetFile(path);
                    var index = path.LastIndexOf('.');
                    if (index >= 0)
                    {
                        var extension   = path.Substring(index);
                        var contentType = Colosoft.Web.ExtendedHtmlUtility.TranslateContentType(extension);
                        if (!string.IsNullOrEmpty(contentType))
                        {
                            httpContextBase.Response.ContentType = contentType;
                        }
                    }
                    var      cacheControl        = httpContextBase.Request.Headers["Cache-Control"];
                    var      ifModifiedSince     = httpContextBase.Request.Headers["If-Modified-Since"];
                    DateTime ifModifiedSinceDate = DateTime.Now;
                    if (!string.IsNullOrEmpty(ifModifiedSince) && DateTime.TryParseExact(ifModifiedSince, "ddd,' 'dd' 'MMM' 'yyyy' 'HH':'mm':'ss' GMT'", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AssumeUniversal | System.Globalization.DateTimeStyles.AdjustToUniversal, out ifModifiedSinceDate))
                    {
                        if (file is Web.Hosting.IPhysicalFileInfo && ((Web.Hosting.IPhysicalFileInfo)file).LastWriteTimeUtc.ToString("yyyy/MM/dd HH:mm:ss") == ifModifiedSinceDate.ToString("yyyy/MM/dd HH:mm:ss"))
                        {
                            httpContextBase.Response.StatusCode = 304;
                            httpContextBase.Response.Flush();
                            if (_application != null)
                            {
                                _application.OnEndRequest(context, EventArgs.Empty);
                            }
                            return(await Task.FromResult <object>(null));
                        }
                    }
                    httpContextBase.Response.AddHeader("Age", "25000");
                    httpContextBase.Response.AddHeader("Cache-Control", "max-age=10000, public");
                    httpContextBase.Response.AddHeader("Date", string.Format(System.Globalization.CultureInfo.InvariantCulture, HTTP_DATEFORMAT, DateTimeOffset.UtcNow));
                    httpContextBase.Response.AddHeader("Expires", string.Format(System.Globalization.CultureInfo.InvariantCulture, HTTP_DATEFORMAT, DateTimeOffset.UtcNow.AddYears(1)));
                    httpContextBase.Response.AddHeader("Vary", "*");
                    if (file is Web.Hosting.IPhysicalFileInfo)
                    {
                        var physicalFile = (Web.Hosting.IPhysicalFileInfo)file;
                        httpContextBase.Response.AddHeader("Content-Length", physicalFile.ContentLength.ToString());
                        httpContextBase.Response.AddHeader("Last-Modified", string.Format(System.Globalization.CultureInfo.InvariantCulture, HTTP_DATEFORMAT, physicalFile.LastWriteTimeUtc));
                    }
                    httpContextBase.Response.Flush();
                    if (file != null)
                    {
                        System.IO.Stream outstream = httpContextBase.Response.OutputStream;
                        var    read   = 0;
                        byte[] buffer = new byte[81920];
                        using (var inputStream = file.Open())
                        {
                            while ((read = inputStream.Read(buffer, 0, buffer.Length)) > 0)
                            {
                                outstream.Write(buffer, 0, read);
                            }
                        }
                        outstream.Flush();
                    }
                }
                else
                {
                    httpContextBase.Response.StatusCode = 404;
                    var virtualPath = "~/Views/404.html";
                    if (System.Web.Hosting.HostingEnvironment.VirtualPathProvider.FileExists(virtualPath))
                    {
                        var virtualFile = System.Web.Hosting.HostingEnvironment.VirtualPathProvider.GetFile(virtualPath);
                        using (var stream = virtualFile.Open())
                        {
                            var reader = new System.IO.StreamReader(stream, httpContextBase.Response.ContentEncoding);
                            var writer = new System.IO.StreamWriter(httpContextBase.Response.OutputStream, httpContextBase.Response.ContentEncoding);
                            writer.Write(reader.ReadToEnd());
                            writer.Flush();
                        }
                    }
                }
            }
            httpContextBase.Response.Flush();
            if (_application != null)
            {
                _application.OnEndRequest(context, EventArgs.Empty);
            }
            return(Task.FromResult <object>(null));
        }
Example #9
0
        public void PublishMessageWhenExecuted([Frozen] IExecutionTimer timer, IAlternateMethodContext context, System.Web.Routing.IRouteHandler handler)
        {
            context.Setup(c => c.Arguments).Returns(new object[] { (System.Web.HttpContextBase)null, new System.Web.Routing.Route("Test", handler), (string)null, (System.Web.Routing.RouteValueDictionary)null, System.Web.Routing.RouteDirection.IncomingRequest });
            context.Setup(c => c.ReturnValue).Returns(true);
            context.Setup(c => c.InvocationTarget).Returns(new System.Web.Routing.Route("Test", null));

            var impl = new RouteConstraint.Match();

            impl.NewImplementation(context);

            timer.Verify(t => t.Time(It.IsAny <Action>()));
            context.MessageBroker.Verify(mb => mb.Publish(It.IsAny <RouteConstraint.Match.Message>()));
        }