Exemplo n.º 1
0
        public static Route ToMvcRoute(this PageRoute pageRoute)
        {
            var routePath   = GetRouteUrl(pageRoute);
            var routeValues = RouteValuesHelper.GetRouteValues(pageRoute.Defaults);

            routeValues = MergeEmptyRouteValues(pageRoute, routeValues);
            var mvcRoute = new Route(routePath, routeValues, null);

            return(mvcRoute);
        }
Exemplo n.º 2
0
        public static IEnumerable <string> GetRouteParamters(this PageRoute pageRoute)
        {
            var routePath = pageRoute.RoutePath;

            TemplateParser parser = new TemplateParser();

            var parameters = parser.GetTokens(routePath);

            return(parameters);
        }
Exemplo n.º 3
0
 private static string GetRouteUrl(PageRoute pageRoute)
 {
     var routePath = pageRoute.RoutePath;
     if (!string.IsNullOrEmpty(pageRoute.TrimmedIdentifier))
     {
         if (!string.IsNullOrEmpty(routePath))
         {
             routePath += "/" + pageRoute.TrimmedIdentifier;
         }
         else
         {
             routePath = pageRoute.TrimmedIdentifier;
         }
     }
     return routePath;
 }
Exemplo n.º 4
0
        private static string GetRouteUrl(PageRoute pageRoute)
        {
            var routePath = pageRoute.RoutePath;

            if (!string.IsNullOrEmpty(pageRoute.TrimmedIdentifier))
            {
                if (!string.IsNullOrEmpty(routePath))
                {
                    routePath += "/" + pageRoute.TrimmedIdentifier;
                }
                else
                {
                    routePath = pageRoute.TrimmedIdentifier;
                }
            }
            return(routePath);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 填充默认的URL参数值,保证生产页面链接时不出错
        /// </summary>
        /// <param name="pageRoute"></param>
        /// <param name="routeValues"></param>
        /// <returns></returns>
        private static RouteValueDictionary MergeEmptyRouteValues(this PageRoute pageRoute, RouteValueDictionary routeValues)
        {
            var parameters = pageRoute.GetRouteParamters();

            if (parameters != null)
            {
                foreach (var p in parameters)
                {
                    if (!routeValues.ContainsKey(p))
                    {
                        routeValues[p] = "";
                    }
                }
            }

            return(routeValues);
        }
Exemplo n.º 6
0
        public static string GetVirtualPath(this Page page, PageRoute route)
        {
            var    segment     = page.Name;
            string virtualPath = "";
            var    parent      = page.GetParent();
            var    site        = page.Site;

            if (route != null && !string.IsNullOrEmpty(route.Identifier))
            {
                if ((route.Identifier.StartsWith("#") || route.Identifier == "*") && parent != null)
                {
                    return(parent.LastVersion(site).GetVirtualPaths().First());
                }
                else if (route.Identifier.StartsWith("/"))
                {
                    return(route.Identifier);
                }
                else
                {
                    if (route != null && !string.IsNullOrEmpty(route.Identifier) && !route.Identifier.StartsWith("/"))
                    {
                        segment = route.Identifier;
                    }
                }
            }
            if (parent != null)
            {
                virtualPath = UrlUtility.Combine(parent.LastVersion(site).GetVirtualPaths().First(), segment);
            }
            else
            {
                virtualPath = segment;
            }
            if (!virtualPath.StartsWith("/"))
            {
                virtualPath = "/" + virtualPath;
            }
            return(virtualPath);
        }
Exemplo n.º 7
0
 public static string GetVirtualPath(this Page page, PageRoute route)
 {
     var segment = page.Name;
     string virtualPath = "";
     var parent = page.GetParent();
     var site = page.Site;
     if (route != null && !string.IsNullOrEmpty(route.Identifier))
     {
         if ((route.Identifier.StartsWith("#") || route.Identifier == "*") && parent != null)
         {
             return parent.LastVersion(site).GetVirtualPaths().First();
         }
         else if (route.Identifier.StartsWith("/"))
         {
             return route.Identifier;
         }
         else
         {
             if (route != null && !string.IsNullOrEmpty(route.Identifier) && !route.Identifier.StartsWith("/"))
             {
                 segment = route.Identifier;
             }
         }
     }
     if (parent != null)
     {
         virtualPath = UrlUtility.Combine(parent.LastVersion(site).GetVirtualPaths().First(), segment);
     }
     else
     {
         virtualPath = segment;
     }
     if (!virtualPath.StartsWith("/"))
     {
         virtualPath = "/" + virtualPath;
     }
     return virtualPath;
 }