private bool TryGetDsInfo(CallNode callNode, TexlBinding binding, out IExternalDataSource dsInfo)
        {
            Contracts.AssertValueOrNull(callNode);
            Contracts.AssertValue(binding);

            dsInfo = null;
            if (callNode == null || !binding.IsDelegatable(callNode) || !binding.GetType(callNode).IsTable)
            {
                return(false);
            }

            var callInfo = binding.GetInfo(callNode);

            if (callInfo == null)
            {
                return(false);
            }

            var function = callInfo.Function;

            if (function == null)
            {
                return(false);
            }

            bool success = function.TryGetDataSource(callNode, binding, out var external);

            dsInfo = (IExternalDataSource)external;
            return(success);
        }
Exemplo n.º 2
0
        // Verifies if given callnode can be server delegatable or not.
        // Return true if
        //        - Arg0 is delegatable ds and supports filter operation.
        //        - All predicates to filter are delegatable if each firstname/binary/unary/dottedname/call node in each predicate satisfies delegation criteria set by delegation strategy for each node.
        public override bool IsServerDelegatable(CallNode callNode, TexlBinding binding)
        {
            Contracts.AssertValue(callNode);
            Contracts.AssertValue(binding);

            if (!CheckArgsCount(callNode, binding))
            {
                return(false);
            }

            IExternalDataSource dataSource;
            FilterOpMetadata    metadata           = null;
            IDelegationMetadata delegationMetadata = null;

            if (TryGetEntityMetadata(callNode, binding, out delegationMetadata))
            {
                if (!binding.Document.Properties.EnabledFeatures.IsEnhancedDelegationEnabled ||
                    !TryGetValidDataSourceForDelegation(callNode, binding, DelegationCapability.ArrayLookup, out _))
                {
                    SuggestDelegationHint(callNode, binding);
                    return(false);
                }

                metadata = delegationMetadata.FilterDelegationMetadata.VerifyValue();
            }
            else
            {
                if (!TryGetValidDataSourceForDelegation(callNode, binding, FunctionDelegationCapability, out dataSource))
                {
                    return(false);
                }

                metadata = dataSource.DelegationMetadata.FilterDelegationMetadata;
            }

            TexlNode[] args = callNode.Args.Children.VerifyValue();
            if (args.Length > 2 && binding.IsDelegatable(args[2]))
            {
                SuggestDelegationHint(args[2], binding);
                return(false);
            }

            if (args.Length < 2)
            {
                return(false);
            }

            return(IsValidDelegatableFilterPredicateNode(args[1], binding, metadata));
        }