Пример #1
0
        private static FunctionRuntimeTreeNode BuildFunctionRuntimeNode(XElement element, bool ignoreUnusedParameters)
        {
            XAttribute nameAttribute = element.Attribute(FunctionTreeConfigurationNames.NameAttributeName);

            if (nameAttribute == null)
            {
                throw new InvalidOperationException(string.Format("Missing attribute named '{0}'", FunctionTreeConfigurationNames.NameAttributeName));
            }

            var parameters = new List <BaseParameterRuntimeTreeNode>();

            foreach (XElement childElement in element.Elements())
            {
                if (childElement.Name.LocalName == FunctionTreeConfigurationNames.ParamTagName)
                {
                    BaseParameterRuntimeTreeNode parameterTreeNode = BuildParameterFunctionRuntimeNode(childElement);

                    parameters.Add(parameterTreeNode);
                }
                else
                {
                    throw new InvalidOperationException(string.Format("Only '{0}' tags allowed inside '{1}' tags", FunctionTreeConfigurationNames.ParamTagName, FunctionTreeConfigurationNames.FunctionTagName));
                }
            }


            IFunction function = FunctionFacade.GetFunction(nameAttribute.Value);


            if (FunctionInitializedCorrectly(function))
            {
                for (int index = parameters.Count - 1; index >= 0; index--)
                {
                    BaseParameterRuntimeTreeNode parameter = parameters[index];
                    if (function.ParameterProfiles.All(pp => pp.Name != parameter.Name))
                    {
                        string message = "The parameter '{0}' is not defined in the function named '{1}' parameter profiles"
                                         .FormatWith(parameter.Name, function.CompositeName());

                        if (ignoreUnusedParameters)
                        {
                            Log.LogWarning(typeof(FunctionTreeBuilder).Name, message);

                            parameters.RemoveAt(index);
                            continue;
                        }

                        throw new InvalidOperationException(message);
                    }
                }
            }

            return(new FunctionRuntimeTreeNode(function, parameters));
        }
Пример #2
0
        /// <exclude />
        public static FunctionRuntimeTreeNode BuildFunction(string functionName, Dictionary <string, string> parameters)
        {
            var functionParams = new List <BaseParameterRuntimeTreeNode>();

            foreach (var parameter in parameters)
            {
                functionParams.Add(new ConstantParameterRuntimeTreeNode(parameter.Key, parameter.Value));
            }

            IFunction function = FunctionFacade.GetFunction(functionName);

            return(new FunctionRuntimeTreeNode(function, functionParams));
        }
 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);
                 }
             }
         }
     }
 }