protected override IEnumerable <ElementAction> OnGetFunctionActions(IFunctionTreeBuilderLeafInfo function)
        {
            string functionName = function.Namespace + "." + function.Name;

            IMetaFunction metaFunction = GetMetaFunction(functionName);

            bool isWidget = !(metaFunction is IFunction);

            if (!isWidget)
            {
                yield return(CreateFunctionTesterAction(functionName));
            }

            yield return(new ElementAction(new ActionHandle(new FunctionInfoActionToken(functionName, isWidget)))
            {
                VisualData = new ActionVisualizedData
                {
                    Label = StringResourceSystemFacade.GetString("Composite.Plugins.AllFunctionsElementProvider", "AllFunctionsElementProvider.ViewFunctionInformation"),
                    ToolTip = StringResourceSystemFacade.GetString("Composite.Plugins.AllFunctionsElementProvider", "AllFunctionsElementProvider.ViewFunctionInformationTooltip"),
                    Disabled = false,
                    Icon = CommonElementIcons.Search,
                    ActionLocation = new ActionLocation
                    {
                        ActionType = ActionType.Other,
                        ActionGroup = PrimaryActionGroup,
                        IsInFolder = false,
                        IsInToolbar = true
                    }
                }
            });
        }
Exemplo n.º 2
0
        /// <exclude />
        public static bool TryGetFunction(out IMetaFunction foundFunction, string name, Type functionType)
        {
            if (functionType == typeof(IFunction))
            {
                if (MetaFunctionProviderRegistry.FunctionNames.Contains(name))
                {
                    foundFunction = GetFunction(name);
                    return(true);
                }

                foundFunction = null;
                return(false);
            }


            if (functionType == typeof(IWidgetFunction))
            {
                if (MetaFunctionProviderRegistry.WidgetFunctionNames.Contains(name))
                {
                    foundFunction = GetWidgetFunction(name);
                    return(true);
                }

                foundFunction = null;
                return(false);
            }

            throw new ArgumentException("Type of function must be IFunction or IWidgetFunction");
        }
Exemplo n.º 3
0
        /// <exclude />
        public static string DescriptionLocalized(this IMetaFunction function)
        {
            if (function.Description != null && function.Description.Contains("${"))
            {
                return(StringResourceSystemFacade.ParseString(function.Description));
            }

            return(function.Description);
        }
Exemplo n.º 4
0
        /// <exclude />
        public static string[] GetParameterNames(XElement functionXElement)
        {
            if (functionXElement.Name != FunctionNodeName && functionXElement.Name != WidgetFunctionNodeName)
            {
                return(new string[0]);
            }

            string        functionName = functionXElement.Attribute("name").Value;
            IMetaFunction function     = (functionXElement.Name == FunctionNodeName)
                ? (IMetaFunction)FunctionFacade.GetFunction(functionName)
                : FunctionFacade.GetWidgetFunction(functionName);

            return(function.ParameterProfiles.Select(parameter => parameter.Name).ToArray());
        }
Exemplo n.º 5
0
        /// <exclude />
        public static bool ValidateParameterProfiles(this IMetaFunction metaFunction)
        {
            List <string> names = new List <string>();

            foreach (ParameterProfile parameterProfile in metaFunction.ParameterProfiles)
            {
                if (names.Contains(parameterProfile.Name))
                {
                    return(false);
                }
                names.Add(parameterProfile.Name);
            }

            return(true);
        }
Exemplo n.º 6
0
        private void AddFunction(string providerName, IMetaFunction function)
        {
            string compositeName = function.CompositeName();

            _functionByNameDictionary.Add(compositeName, function);


            List <string> functionNamesByProviderNameList;

            if (_functionNamesByProviderName.TryGetValue(providerName, out functionNamesByProviderNameList) == false)
            {
                functionNamesByProviderNameList = new List <string>();
                _functionNamesByProviderName.Add(providerName, functionNamesByProviderNameList);
            }

            functionNamesByProviderNameList.Add(compositeName);


            List <string> functionNamesByType;

            if (_functionNamesByTypeDictionary.TryGetValue(function.ReturnType, out functionNamesByType) == false)
            {
                functionNamesByType = new List <string>();
                _functionNamesByTypeDictionary.Add(function.ReturnType, functionNamesByType);
            }

            functionNamesByType.Add(compositeName);

            if (function is IDowncastableFunction && ((IDowncastableFunction)function).ReturnValueIsDowncastable)
            {
                List <string> downcastableFunctionNamesByType;
                if (_downcastableFunctionNamesByTypeDictionary.TryGetValue(function.ReturnType, out downcastableFunctionNamesByType) == false)
                {
                    downcastableFunctionNamesByType = new List <string>();
                    _downcastableFunctionNamesByTypeDictionary.Add(function.ReturnType, downcastableFunctionNamesByType);
                }
                downcastableFunctionNamesByType.Add(compositeName);
            }
        }
Exemplo n.º 7
0
        /// <exclude />
        public static bool IsNamespaceCorrectFormat(this IMetaFunction metaFunction)
        {
            if (metaFunction.Namespace == "")
            {
                return(true);
            }

            if (metaFunction.Namespace.StartsWith(".") ||
                metaFunction.Namespace.EndsWith("."))
            {
                return(false);
            }

            string[] splits = metaFunction.Namespace.Split('.');
            foreach (string split in splits)
            {
                if (split == "")
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 8
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string functionName = Request.QueryString["Name"];
        bool   isWidget     = bool.Parse(Request.QueryString["IsWidget"] ?? "false");

        this.PageLabel = functionName;

        IMetaFunction function = isWidget ? FunctionFacade.GetWidgetFunction(functionName)
                                           : (IMetaFunction)FunctionFacade.GetFunction(functionName);

        var      functionDescriptors = new XElement("ul", new XAttribute("id", "functionList"));
        XElement descriptionElement  = null;
        XElement parametersTable     = null;

        XNamespace functionNamespace = FunctionTreeConfigurationNames.NamespaceName;
        var        codeElement       = new XElement(functionNamespace + (isWidget ? "widgetfunction" : "function"),
                                                    new XAttribute("name", functionName),
                                                    new XAttribute(XNamespace.Xmlns + "f", FunctionTreeConfigurationNames.NamespaceName));


        if (!string.IsNullOrEmpty(function.Description))
        {
            descriptionElement = new XElement("div",
                                              new XAttribute("class", "description"),
                                              StringResourceSystemFacade.ParseString(function.Description));
        }



        if (function.ParameterProfiles.Any())
        {
            parametersTable = new XElement("table", new XAttribute("class", "parameters"));
            foreach (ParameterProfile parameterProfile in function.ParameterProfiles)
            {
                string helpText = parameterProfile.HelpDefinition.GetLocalized().HelpText;

                if (!string.IsNullOrEmpty(helpText))
                {
                    helpText = string.Format(" {0}", helpText);
                }

                var parameterRow = new XElement("tr",
                                                new XAttribute("title", parameterProfile.LabelLocalized),
                                                new XElement("td",
                                                             new XAttribute("class", string.Format("requiredInfo required{0}", parameterProfile.IsRequired))),
                                                new XElement("td",
                                                             new XAttribute("class", "name"),
                                                             parameterProfile.Name),
                                                new XElement("td",
                                                             new XAttribute("class", "type"),
                                                             new XElement("span",
                                                                          new XAttribute("class", "typeinfo"),
                                                                          parameterProfile.Type.GetShortLabel())),
                                                new XElement("td",
                                                             new XAttribute("class", "description"),
                                                             helpText
                                                             )
                                                );
                parametersTable.Add(parameterRow);



                var codeParameter = new XElement(functionNamespace + "param", new XAttribute("name", parameterProfile.Name));

                string value = parameterProfile.IsRequired ? "[Required Value]" : "[Optional Value]";

                if (parameterProfile.Type.IsPrimitive || parameterProfile.Type == typeof(string) || parameterProfile.Type == typeof(Guid))
                {
                    codeParameter.Add(new XAttribute("value", value));
                }
                else
                {
                    codeParameter.Add(value);
                }

                codeParameter.Add(new XAttribute(XNamespace.Xmlns + "f", FunctionTreeConfigurationNames.NamespaceName));

                codeElement.Add(codeParameter);
            }
        }


        var functionDescriptor = new XElement("li",
                                              new XElement("div",
                                                           new XAttribute("class", "header"),
                                                           functionName,
                                                           new XElement("span",
                                                                        new XAttribute("class", "typeinfo"),
                                                                        " ← " + function.ReturnType.GetShortLabel())),
                                              descriptionElement,
                                              parametersTable
                                              );

        functionDescriptors.Add(functionDescriptor);

        var hans = new XElement("div", functionDescriptors);

        hans.Add(new XElement("div", new XAttribute("style", "padding-left: 45px"),
                              new XElement("div", new XAttribute("style", "font-weight: bold"), "Function Markup"),
                              new XElement("div", new XAttribute("style", "padding-left: 10px"), new XElement("pre", codeElement.ToString(SaveOptions.OmitDuplicateNamespaces)))
                              ));

        functionInfoPlaceholder.Controls.Add(new LiteralControl(hans.ToString(SaveOptions.DisableFormatting)));
    }
Exemplo n.º 9
0
    private void AddFunctionCall(string functionName, out IMetaFunction metaFunction)
    {
        BaseFunctionRuntimeTreeNode functionRuntime;

        if (_state.WidgetFunctionSelection)
        {
            IWidgetFunction widgetFunction = FunctionFacade.GetWidgetFunction(functionName);
            functionRuntime = new WidgetFunctionRuntimeTreeNode(widgetFunction);

            metaFunction = widgetFunction;
        }
        else
        {
            IFunction functionInfo = FunctionFacade.GetFunction(functionName);
            functionRuntime = new FunctionRuntimeTreeNode(functionInfo);

            metaFunction = functionInfo;
        }

        XElement function = functionRuntime.Serialize();

        if (!_state.WidgetFunctionSelection && _state.AllowLocalFunctionNameEditing)
        {
            string localName = functionName;
            int pointOffset = localName.LastIndexOf(".", StringComparison.Ordinal);
            if (pointOffset > 0 && pointOffset < localName.Length - 1)
            {
                localName = localName.Substring(pointOffset + 1);
            }
            string uniqueLocalName = localName;
            int retry = 1;
            while (FunctionMarkup.Descendants().Attributes("localname").Any(a => a.Value == uniqueLocalName))
            {
                uniqueLocalName = string.Format("{0}{1}", localName, ++retry);
            }

            function.Add(new XAttribute("localname", uniqueLocalName));
        }

        function.Add(new XAttribute("handle", Guid.NewGuid()));

        FunctionMarkup.Root.Add(function);
    }
Exemplo n.º 10
0
        internal EntityToken CreateEntityToken(IMetaFunction function)
        {
            string id = StringExtensionMethods.CreateNamespace(function.Namespace, function.Name, '.');

            return new StandardWidgetFunctionProviderEntityToken(_providerName, id );
        }
Exemplo n.º 11
0
        internal EntityToken CreateEntityToken(IMetaFunction function)
        {
            string id = StringExtensionMethods.CreateNamespace(function.Namespace, function.Name, '.');

            return(new StandardWidgetFunctionProviderEntityToken(_providerName, id));
        }
        protected override IEnumerable <IFunctionTreeBuilderLeafInfo> OnGetFunctionInfos(SearchToken searchToken)
        {
            var castedSearchToken = (AllFunctionsElementProviderSearchToken)searchToken;

            string loweredKeyword = null;

            if (searchToken != null)
            {
                loweredKeyword = (searchToken.Keyword ?? string.Empty).ToLowerInvariant();
            }

            foreach (string metaFunctionName in this.MetaFunctionNames.OrderBy(f => f))
            {
                IMetaFunction metaFunction = this.GetMetaFunction(metaFunctionName);

                if (castedSearchToken == null)
                {
                    yield return
                        (new AllFunctionsTreeBuilderLeafInfo
                    {
                        Name = metaFunction.Name,
                        Namespace = metaFunction.Namespace,
                        EntityToken = metaFunction.EntityToken
                    });

                    continue;
                }

                if (!string.IsNullOrEmpty(loweredKeyword))
                {
                    if (!metaFunction.CompositeName().ToLowerInvariant().Contains(loweredKeyword))
                    {
                        continue;
                    }
                }

                bool shouldBeIncluded = true;

                if (!string.IsNullOrEmpty(castedSearchToken.AcceptableTypes) &&
                    castedSearchToken.AcceptableTypes != "__None__")
                {
                    shouldBeIncluded = false;

                    foreach (string typeKey in castedSearchToken.AcceptableTypes.Split(';'))
                    {
                        Type type = TypeManager.GetType(typeKey);

                        // MAW: Negate that string is an IEnumerable - thats just plain stupid.
                        if (type == typeof(IEnumerable) && metaFunction.ReturnType == typeof(String))
                        {
                            continue;
                        }

                        if (type.IsAssignableFrom(metaFunction.ReturnType) ||
                            (metaFunction is IDowncastableFunction &&
                             (metaFunction as IDowncastableFunction).ReturnValueIsDowncastable &&
                             metaFunction.ReturnType.IsAssignableFrom(type)))
                        {
                            shouldBeIncluded = true;
                            break;
                        }


                        if (metaFunction is IWidgetFunction &&
                            metaFunction.ReturnType.IsAssignableFrom(type))
                        {
                            shouldBeIncluded = true;
                            break;
                        }
                    }
                }

                if (shouldBeIncluded)
                {
                    yield return
                        (new AllFunctionsTreeBuilderLeafInfo
                    {
                        Name = metaFunction.Name,
                        Namespace = metaFunction.Namespace,
                        EntityToken = metaFunction.EntityToken
                    });
                }
            }
        }
Exemplo n.º 13
0
        private void AddFunction(string providerName, IMetaFunction function)
        {
            string compositeName = function.CompositeName();

            _functionByNameDictionary.Add(compositeName, function);

            List<string> functionNamesByProviderNameList;
            if (_functionNamesByProviderName.TryGetValue(providerName, out functionNamesByProviderNameList) == false)
            {
                functionNamesByProviderNameList = new List<string>();
                _functionNamesByProviderName.Add(providerName, functionNamesByProviderNameList);
            }

            functionNamesByProviderNameList.Add(compositeName);

            List<string> functionNamesByType;
            if (_functionNamesByTypeDictionary.TryGetValue(function.ReturnType, out functionNamesByType) == false)
            {
                functionNamesByType = new List<string>();
                _functionNamesByTypeDictionary.Add(function.ReturnType, functionNamesByType);
            }

            functionNamesByType.Add(compositeName);

            if (function is IDowncastableFunction && ((IDowncastableFunction)function).ReturnValueIsDowncastable)
            {
                List<string> downcastableFunctionNamesByType;
                if (_downcastableFunctionNamesByTypeDictionary.TryGetValue(function.ReturnType, out downcastableFunctionNamesByType) == false)
                {
                    downcastableFunctionNamesByType = new List<string>();
                    _downcastableFunctionNamesByTypeDictionary.Add(function.ReturnType, downcastableFunctionNamesByType);
                }
                downcastableFunctionNamesByType.Add(compositeName);
            }
        }
Exemplo n.º 14
0
 /// <exclude />
 public static string CompositeName(this IMetaFunction metaFunction)
 {
     return(CompositeName(metaFunction.Namespace, metaFunction.Name));
 }