Exemplo n.º 1
0
        public new IHttpHandler GetHttpHandler(RequestContext requestContext)
        {
            //run the onredirection action. For example, this can be used to log that the redirection ocurred,
            //or add additional route data at redirection-time.
            if (OnRedirectAction != null)
            {
                OnRedirectAction(requestContext, this);
            }

            var requestRouteValues = requestContext.RouteData.Values;

            var routeValues = AdditionalRouteValues.Merge(requestRouteValues);

            var vpd = TargetRoute.GetVirtualPath(requestContext, routeValues);

            if (vpd != null)
            {
                string targetUrl = "~/" + vpd.VirtualPath;

                //add query strings
                var qsHelper    = requestContext.HttpContext.Request.QueryString;
                var queryString = String.Join("&", qsHelper.AllKeys.Select(i => HttpUtility.UrlEncode(i) + "=" + HttpUtility.UrlEncode(qsHelper[i])));
                if (!string.IsNullOrWhiteSpace(queryString))
                {
                    targetUrl += "?" + queryString;
                }

                return(new RedirectHttpHandler(targetUrl, Permanent, isReusable: false));
            }
            return(new DelegateHttpHandler(rc => rc.HttpContext.Response.StatusCode = 404, requestContext.RouteData, false));
        }
Exemplo n.º 2
0
        public IHttpHandler GetHttpHandler(RequestContext requestContext)
        {
            //run the onredirection action. For example, this can be used to log that the redirection ocurred.
            if (OnRedirectAction != null)
            {
                OnRedirectAction(requestContext, this);
            }

            var requestRouteValues = requestContext.RouteData.Values;

            var mergedRouteValues = AdditionalRouteValues != null?AdditionalRouteValues.Merge(requestRouteValues) : new RouteValueDictionary();

            var vpd = TargetRoute.GetVirtualPath(requestContext, mergedRouteValues);

            if (vpd != null)
            {
                string targetUrl = "~/" + vpd.VirtualPath;

                //add query strings
                var qsHelper = requestContext.HttpContext.Request.QueryString;
                if (qsHelper != null)
                {
                    var queryString = String.Join("&", qsHelper.AllKeys.Select(key => key + "=" + qsHelper[key]));
                    if (!string.IsNullOrWhiteSpace(queryString))
                    {
                        targetUrl += "?" + queryString;
                    }
                }

                return(new RedirectHttpHandler(targetUrl, Permanent, isReusable: false));
            }
            return(new DelegateHttpHandler(rc => rc.HttpContext.Response.StatusCode = 404, requestContext.RouteData, false));
        }
Exemplo n.º 3
0
        private async Task <TargetRoute> ExtendManualRoute(TargetRoute r, DateTime time, Coordinate from, Coordinate to)
        {
            var startPoint = r.GetStartPoint();
            var endPoint   = r.GetLastPoint();
            var endTime    = time.Date.Add(endPoint.GetTime());

            var startRoute = (await GetAutoRoutes(time, from, startPoint.Coordinate, true))?.FirstOrDefault();
            var endRoute   = (await GetAutoRoutes(time.Date.Add(endPoint.GetTime()), endPoint.Coordinate, to, true))?.FirstOrDefault();

            if (startRoute == null || endRoute == null)
            {
                return(null);
            }

            var startRouteEndTime = startRoute.GetLastPoint().GetTime();

            if (startRouteEndTime > startPoint.GetTime())
            {
                return(null);
            }

            return(new TargetRoute
            {
                TravelTime = (int)(endRoute.GetLastPoint().GetTime() - time.TimeOfDay).TotalSeconds,
                Routes = startRoute.Routes.Concat(r.Routes).Concat(endRoute.Routes).ToList()
            });
        }
Exemplo n.º 4
0
        public IHttpHandler GetHttpHandler(RequestContext requestContext)
        {
            var requestRouteValues = requestContext.RouteData.Values;
            var routeValues        = AdditionalRouteValues.Merge(requestRouteValues);
            var vpd = TargetRoute.GetVirtualPath(requestContext, routeValues);

            if (vpd == null)
            {
                return(new DelegateHttpHandler(rc => rc.HttpContext.Response.StatusCode = 404, requestContext.RouteData, false));
            }

            var targetUrl = "~/" + vpd.VirtualPath;

            if (!IncludeQueryStringInRedirect)
            {
                return(new RedirectHttpHandler(targetUrl, Permanent, isReusable: false));
            }

            var qs          = new StringBuilder("?");
            var queryString = requestContext.HttpContext.Request.QueryString;

            foreach (var key in queryString.AllKeys.Where(key => !requestRouteValues.ContainsKey(key)))
            {
                qs.AppendFormat("{0}={1}&", key, queryString[key]);
            }

            targetUrl += qs.ToString(0, qs.Length - 1);

            return(new RedirectHttpHandler(targetUrl, Permanent, isReusable: false));
        }
        public IHttpHandler GetHttpHandler(RequestContext requestContext)
        {
            var requestRouteValues = requestContext.RouteData.Values;

            var routeValues = requestRouteValues.Merge(AdditionalRouteValuesFunc(requestContext));

            var vpd = TargetRoute.GetVirtualPath(requestContext, routeValues);

            if (vpd != null)
            {
                string targetUrl = "~/" + vpd.VirtualPath;
                return(new RedirectHttpHandler(targetUrl, Permanent, false));
            }
            return(new DelegateHttpHandler(rc => rc.HttpContext.Response.StatusCode = 404, requestContext.RouteData, false));
        }
Exemplo n.º 6
0
 private TargetRoute Convert(TargetRoute r)
 {
     r.Routes = r.Routes.Where(t => t.Points.Count > 1).ToList();
     return(r);
 }