private XElement ExecuteInnerFunctions(FunctionContextContainer contextContainer)
        {
            XElement resultRoot = new XElement(_element);
            int      loopCount  = 0;

            while (true)
            {
                XName functionXName = Namespaces.Function10 + FunctionTreeConfigurationNames.FunctionTagName;
                IEnumerable <XElement> nestedFunctionCalls = resultRoot.Descendants(functionXName).Where(f => !f.Ancestors(functionXName).Any());
                var evaluatedListOfInnerFunctions          = nestedFunctionCalls.ToList();

                if (!evaluatedListOfInnerFunctions.Any())
                {
                    break;
                }

                if (loopCount++ > 1000)
                {
                    throw new InvalidOperationException("One or more function seems to be returning markup generating endless recursion. The following markup seems to generate the problem: " + evaluatedListOfInnerFunctions.First().ToString());
                }

                var functionCallResults = new object[evaluatedListOfInnerFunctions.Count];


                for (int i = 0; i < evaluatedListOfInnerFunctions.Count; i++)
                {
                    XElement functionCallDefinition = evaluatedListOfInnerFunctions[i];

                    BaseRuntimeTreeNode runtimeTreeNode = FunctionTreeBuilder.Build(functionCallDefinition);

                    functionCallResults[i] = runtimeTreeNode.GetValue(contextContainer);
                }
                ;

                for (int i = 0; i < evaluatedListOfInnerFunctions.Count; i++)
                {
                    object embedableResult = contextContainer.MakeXEmbedable(functionCallResults[i]);

                    if (embedableResult is XAttribute)
                    {
                        evaluatedListOfInnerFunctions[i].Parent.Add(embedableResult);
                        evaluatedListOfInnerFunctions[i].Remove();
                    }
                    else
                    {
                        evaluatedListOfInnerFunctions[i].ReplaceWith(embedableResult);
                    }
                }
            }

            return(resultRoot);
        }
 private void Initialize()
 {
     if (_functionFunctionRuntimeNode == null)
     {
         lock (_lock)
         {
             if (_functionFunctionRuntimeNode == null)
             {
                 if (_serializedFunction == null)
                 {
                     IFunction function = FunctionFacade.GetFunction(_functionName);
                     _functionFunctionRuntimeNode = new FunctionRuntimeTreeNode(function, _parameters);
                 }
                 else
                 {
                     _functionFunctionRuntimeNode = (FunctionRuntimeTreeNode)FunctionTreeBuilder.Build(_serializedFunction);
                 }
             }
         }
     }
 }
Beispiel #3
0
 /// <exclude />
 public static BaseRuntimeTreeNode BuildTree(XElement element)
 {
     return(FunctionTreeBuilder.Build(element));
 }