Example #1
0
        private static WidgetFunctionRuntimeTreeNode BuildWidgetFunctionRuntimeNode(XElement element)
        {
            XAttribute nameAttribute = element.Attribute(FunctionTreeConfigurationNames.NameAttributeName);

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

            string label             = AttributeValueOrEmpty(element, FunctionTreeConfigurationNames.LabelAttributeName);
            string bindingSourceName = AttributeValueOrEmpty(element, FunctionTreeConfigurationNames.BindingSourceNameAttributeName);

            HelpDefinition helpDefinition = null;
            var            parameters     = new List <BaseParameterRuntimeTreeNode>();

            foreach (XElement childElement in element.Elements())
            {
                if (childElement.Name.LocalName == FunctionTreeConfigurationNames.HelpDefinitionTagName)
                {
                    helpDefinition = HelpDefinition.Deserialize(childElement);
                }
                else 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));
                }
            }

            if (helpDefinition == null)
            {
                helpDefinition = new HelpDefinition("");
            }

            IWidgetFunction widgetFunction = FunctionFacade.GetWidgetFunction(nameAttribute.Value);

            foreach (BaseParameterRuntimeTreeNode parameter in parameters)
            {
                if (widgetFunction.ParameterProfiles.All(pp => pp.Name != parameter.Name))
                {
                    throw new InvalidOperationException(string.Format("The parameter '{0}' is not defined in the function named '{1}' parameter profiles", parameter.Name, widgetFunction.CompositeName()));
                }
            }

            return(new WidgetFunctionRuntimeTreeNode(widgetFunction, label, helpDefinition, bindingSourceName, parameters));
        }
Example #2
0
        /// <exclude />
        public static WidgetFunctionRuntimeTreeNode BuildWidgetFunction(string widgetFunctionName, string label, HelpDefinition helpDefinition, string bindingSourceName)
        {
            IWidgetFunction widgetFunction = FunctionFacade.GetWidgetFunction(widgetFunctionName);

            return(new WidgetFunctionRuntimeTreeNode(widgetFunction, label, helpDefinition, bindingSourceName));
        }
Example #3
0
        /// <exclude />
        public static WidgetFunctionProvider GetDefaultWidgetFunctionProviderByType(Type type, bool required)
        {
            if (type == typeof(string))
            {
                return(StandardWidgetFunctions.TextBoxWidget);
            }
            if (type == typeof(int) || type == typeof(int?))
            {
                return(StandardWidgetFunctions.IntegerTextBoxWidget);
            }
            if (type == typeof(Decimal) || type == typeof(Decimal?))
            {
                return(StandardWidgetFunctions.DecimalTextBoxWidget);
            }
            if (type == typeof(DateTime) || type == typeof(DateTime?))
            {
                return(StandardWidgetFunctions.DateSelectorWidget);
            }
            if (type == typeof(Guid) || type == typeof(Guid?))
            {
                return(StandardWidgetFunctions.GuidTextBoxWidget);
            }
            if (type == typeof(bool) || type == typeof(bool?))
            {
                return(StandardWidgetFunctions.CheckBoxWidget);
            }

            if (type == typeof(DataReference <IImageFile>))
            {
                return(StandardWidgetFunctions.GetImageSelectorWidget(required));
            }
            if (type == typeof(NullableDataReference <IImageFile>))
            {
                return(StandardWidgetFunctions.GetImageSelectorWidget(false));
            }
            if (type == typeof(DataReference <IMediaFile>))
            {
                return(StandardWidgetFunctions.GetMediaFileSelectorWidget(required));
            }
            if (type == typeof(NullableDataReference <IMediaFile>))
            {
                return(StandardWidgetFunctions.GetMediaFileSelectorWidget(false));
            }

            if (type == typeof(XhtmlDocument))
            {
                return(StandardWidgetFunctions.VisualXhtmlDocumentEditorWidget);
            }

            IEnumerable <string> functionNames = FunctionFacade.GetWidgetFunctionNamesByType(type);

            foreach (string functionName in functionNames)
            {
                IWidgetFunction widgetFunction = FunctionFacade.GetWidgetFunction(functionName);
                bool            sameType       = widgetFunction.ReturnType == type;

                if (!sameType &&
                    !required &&
                    type.IsGenericType && type.GetGenericTypeDefinition() == typeof(DataReference <>) &&
                    type.IsAssignableFrom(widgetFunction.ReturnType) &&
                    widgetFunction.ReturnType == typeof(NullableDataReference <>).MakeGenericType(type.GetGenericArguments()))
                {
                    sameType = true;
                }

                if (sameType && !widgetFunction.ParameterProfiles.Any(p => p.IsRequired))
                {
                    return(new WidgetFunctionProvider(widgetFunction));
                }
            }

            if (type.IsLazyGenericType())
            {
                var lazyType = type.GetGenericArguments().First();

                var provider = GetDefaultWidgetFunctionProviderByType(lazyType, required);

                if (provider != null)
                {
                    return(provider);
                }
            }


            return(null);
        }