Esempio n. 1
0
 public static LinkTransformationBuilder AddQueryStringValues(this LinkTransformationBuilder builder, IDictionary <string, string> values)
 {
     return(builder.Add(ctx =>
     {
         var queryString = String.Join("&", values.Select(v => $"{v.Key}={v.Value?.ToString()}"));
         return string.Concat("?", queryString);
     }));
 }
Esempio n. 2
0
 public static LinkTransformationBuilder AddVirtualPath(this LinkTransformationBuilder builder, Func <LinkTransformationContext, string> getPath)
 {
     return(builder.Add(ctx =>
     {
         var path = getPath(ctx);
         if (!path.StartsWith("/"))
         {
             path = String.Concat("/", path);
         }
         return path;
     }));
 }
Esempio n. 3
0
        public static LinkTransformationBuilder AddRoutePath(this LinkTransformationBuilder builder)
        {
            return(builder.Add(ctx =>
            {
                if (string.IsNullOrEmpty(ctx.LinkSpec.RouteName))
                {
                    throw new InvalidOperationException($"Invalid route specified in link specification.");
                }

                var path = ctx.LinkGenerator.GetPathByRouteValues(ctx.HttpContext, ctx.LinkSpec.RouteName, ctx.LinkSpec.RouteValues);

                if (string.IsNullOrEmpty(path))
                {
                    throw new InvalidOperationException($"Invalid path when adding route '{ctx.LinkSpec.RouteName}'. RouteValues: {string.Join(",", ctx.ActionContext.RouteData.Values.Select(x => string.Concat(x.Key, "=", x.Value)))}");
                }

                return path;
            }));
        }
        public static LinkTransformationBuilder AddRoutePath(this LinkTransformationBuilder builder)
        {
            return(builder.Add(ctx =>
            {
                if (string.IsNullOrEmpty(ctx.LinkSpec.RouteName))
                {
                    throw new InvalidOperationException($"Invalid route specified in link specification.");
                }

                var valuesDictionary = GetValuesDictionary(ctx.LinkSpec.RouteValues);
                var virtualPathContext = new VirtualPathContext(ctx.HttpContext, ctx.RouteValues, valuesDictionary, ctx.LinkSpec.RouteName);
                var virtualPathData = ctx.Router.GetVirtualPath(virtualPathContext);
                if (virtualPathData == null)
                {
                    throw new InvalidOperationException($"Invalid virtualPathData when adding route '{ctx.LinkSpec.RouteName}'. RouteValues: {String.Join(",", valuesDictionary.Select(x => String.Concat(x.Key,"=",x.Value)))}");
                }
                return virtualPathData.VirtualPath;
            }));
        }
Esempio n. 5
0
 public static LinkTransformationBuilder AddFragment(this LinkTransformationBuilder builder, Func <LinkTransformationContext, string> getFragment)
 {
     return(builder.Add(ctx => string.Concat("#", getFragment(ctx))));
 }
Esempio n. 6
0
 public static LinkTransformationBuilder AddHost(this LinkTransformationBuilder builder)
 {
     return(builder.Add(ctx => ctx.HttpContext.Request.Host.ToUriComponent()));
 }
Esempio n. 7
0
 public static LinkTransformationBuilder AddProtocol(this LinkTransformationBuilder builder)
 {
     return(builder.Add(ctx => String.Concat(ctx.HttpContext.Request.Scheme, "://")));
 }