Пример #1
0
 /// <summary>
 /// Registers all routes discovered by specified <see cref="IRoutingStrategy"/> in the RouteTable.
 /// </summary>
 /// <param name="strategy">A strategy that provides list of routes.</param>
 /// <param name="table">A table of DotVVM routes by specified name.</param>
 public static void AutoDiscoverRoutes(this DotvvmRouteTable table, IRoutingStrategy strategy)
 {
     foreach (var route in strategy.GetRoutes())
     {
         table.Add(route.RouteName, route);
     }
 }
Пример #2
0
        public void AddGroup(string groupName,
                             string urlPrefix,
                             string virtualPathPrefix,
                             Action <DotvvmRouteTable> content,
                             Func <IServiceProvider, IDotvvmPresenter>?presenterFactory = null)
        {
            ThrowIfFrozen();
            if (string.IsNullOrEmpty(groupName))
            {
                throw new ArgumentNullException("Name of the group cannot be null or empty!");
            }
            if (routeTableGroups.ContainsKey(groupName))
            {
                throw new InvalidOperationException($"The group with name '{groupName}' has already been registered!");
            }
            urlPrefix         = CombinePath(group?.UrlPrefix, urlPrefix);
            virtualPathPrefix = CombinePath(group?.VirtualPathPrefix, virtualPathPrefix);

            var newGroup = new DotvvmRouteTable(configuration);

            newGroup.group = new RouteTableGroup(
                groupName,
                routeNamePrefix: group?.RouteNamePrefix + groupName + "_",
                urlPrefix,
                virtualPathPrefix,
                addToParentRouteTable: Add,
                presenterFactory);

            content(newGroup);
            routeTableGroups.Add(groupName, newGroup);
        }
Пример #3
0
 public void WriteJson(JsonWriter writer, DotvvmRouteTable value, JsonSerializer serializer)
 {
     writer.WriteStartObject();
     foreach (var route in value)
     {
         writer.WritePropertyName(route.RouteName);
         new JObject()
         {
             ["url"]           = route.Url,
             ["virtualPath"]   = route.VirtualPath,
             ["defaultValues"] = JObject.FromObject(route.DefaultValues)
         }.WriteTo(writer);
     }
     writer.WriteEndObject();
 }
Пример #4
0
        /// <summary>
        /// Adds a group of routes
        /// </summary>
        /// <param name="groupName">Name of the group</param>
        /// <param name="urlPrefix">Url prefix of added routes</param>
        /// <param name="virtualPathPrefix">Virtual path prefix of added routes</param>
        /// <param name="content">Contains routes to be added</param>
        public void AddGroup(string groupName, string urlPrefix, string virtualPathPrefix, Action <DotvvmRouteTable> content)
        {
            if (groupName == null || groupName == "")
            {
                throw new ArgumentNullException("Name of the group cannot be null or empty!");
            }
            if (routeTableGroups.ContainsKey(groupName))
            {
                throw new InvalidOperationException($"The group with name '{groupName}' has already been registered!");
            }
            urlPrefix         = group?.UrlPrefix + ((urlPrefix == null || urlPrefix == "") ? "" : urlPrefix + "/");
            virtualPathPrefix = group?.VirtualPathPrefix + ((virtualPathPrefix == null || virtualPathPrefix == "") ? "" : virtualPathPrefix + "/");
            var newGroup = new DotvvmRouteTable(configuration);

            newGroup.group = new RouteTableGroup(groupName, group?.RouteNamePrefix + groupName + "_", urlPrefix, virtualPathPrefix, Add);

            content(newGroup);
            routeTableGroups.Add(groupName, newGroup);
        }
Пример #5
0
 public static void AutoRegisterRoutes(this DotvvmRouteTable routeTable, DotvvmConfiguration config, Func <string, IEnumerable <string> > getRouteList, string path = "/", string pattern = "*.dothtml") =>
 routeTable.AutoDiscoverRoutes(new CustomListRoutingStrategy(config, getRouteList, path, pattern));
Пример #6
0
 public static void AutoRegisterRoutes(this DotvvmRouteTable routeTable, DotvvmConfiguration configuration, string path = "", string pattern = "*.dothtml") =>
 routeTable.AutoRegisterRoutes(configuration, null, path, pattern);
Пример #7
0
        /// <summary>
        /// Adds collection of routes defined by <see cref="IRoutingStrategy"/> to RouteTable.
        /// </summary>
        /// <param name="table"></param>
        /// <param name="strategy">Object that provides list of routes.</param>
        public static void RegisterRoutingStrategy(this DotvvmRouteTable table, IRoutingStrategy strategy)
        {
            var routes = new List <RouteInfo>(strategy.GetRoutes() ?? new List <RouteInfo>());

            routes.ForEach(r => table.Add(r.RouteName, r.RouteUrl, r.VirtualPath, r.DefaultObject));
        }