Exemplo n.º 1
0
        private static Link CreateLink(QueryLink source, RenderContext ctx)
        {
            var linkedQuery = ctx.Injector.CreateInstance(source.QueryType);

            source.Setter?.Invoke(linkedQuery);

            var targets =
                from renderer
                in ctx.PaperRendererRegistry.FindPaperRenderers(source.QueryType)
                where renderer.PaperRendererType == typeof(QueryRenderer)
                let argNames = UriUtil.GetArgNames(renderer.PathTemplate)
                               orderby argNames.Length descending
                               select new { renderer, argNames };

            foreach (var target in targets)
            {
                var pathTemplate = target.renderer.PathTemplate;
                var argNames     = target.argNames;

                var pathArgs = QueryPathBuilder.SatisfyArgs(linkedQuery, argNames);

                var isAllArgsSatisfied = !pathArgs.Any(x => x.Value == null);
                if (isAllArgsSatisfied)
                {
                    var href = QueryPathBuilder.BuildPath(ctx, linkedQuery, pathTemplate, pathArgs, null);
                    var link = new Link().CopyFrom(source);
                    link.Href = href;
                    return(link);
                }
            }

            return(null);
        }