示例#1
0
    public XElement GetDefaultMarkup(Field field)
    {
        var result = new XElement("Field", new XAttribute("name", field.Name));

        string functionName = (string)field.FunctionNode.Attribute("name");

        IFunction function;

        if (functionName != null &&
            FunctionFacade.TryGetFunction(out function, functionName))
        {
            if (function.ParameterProfiles.Any(p => p.Name == "Name" && p.IsRequired))
            {
                result.Add(new XElement(Namespaces.Function10 + "param",
                                        new XAttribute("name", "Name"),
                                        new XAttribute("value", StringResourceSystemFacade.ParseString(field.Label))));
            }
            if (function.ParameterProfiles.Any(p => p.Name == "Label"))
            {
                result.Add(new XElement(Namespaces.Function10 + "param",
                                        new XAttribute("name", "Label"),
                                        new XAttribute("value", StringResourceSystemFacade.ParseString(field.Label))));
            }
        }
        return(result);
    }
        private object TryExecuteFunction(XElement functionNode)
        {
            try
            {
                var tree = FunctionFacade.BuildTree(functionNode);

                using (new FakeHttpContext())
                {
                    if (_page != null)
                    {
                        PageRenderer.CurrentPage = _page;
                        C1PageRoute.PageUrlData  = new PageUrlData(_page);
                    }
                    PageRenderer.RenderingReason = RenderingReason.BuildSearchIndex;

                    return(tree.GetValue(new FunctionContextContainer
                    {
                        SuppressXhtmlExceptions = false
                    }));
                }
            }
            catch (Exception)
            {
                return(null);
            }
        }
示例#3
0
        private void ValidateFunctionName(object sender, ConditionalEventArgs e)
        {
            IInlineFunction function = this.GetBinding <IInlineFunction>("NewFunction");

            bool exists = FunctionFacade.FunctionExists(function.Namespace, function.Name);

            if (exists)
            {
                string errorMessage = StringResourceSystemFacade.GetString("Composite.Plugins.MethodBasedFunctionProviderElementProvider", "AddFunction.NameAlreadyUsed");
                errorMessage = string.Format(errorMessage, FunctionFacade.GetFunctionCompositionName(function.Namespace, function.Name));
                ShowFieldMessage("NewFunction.Name", errorMessage);
                e.Result = false;
                return;
            }

            ValidationResults validationResults = ValidationFacade.Validate <IInlineFunction>(function);

            if (!validationResults.IsValid)
            {
                foreach (ValidationResult result in validationResults)
                {
                    this.ShowFieldMessage(string.Format("{0}.{1}", "NewFunction", result.Key), result.Message);
                }

                e.Result = false;
                return;
            }

            e.Result = true;
        }
        private bool BasicViewApplicable(ICollection <XElement> functionCallsEvaluated)
        {
            // Basic view is enabled if
            // - Only one function is being edited
            // - here's no parameters defined as function calls
            // - And there no required parameters without widgets

            if (MultiMode || IsWidgetSelection || functionCallsEvaluated.Count != 1)
            {
                return(false);
            }

            var functionMarkup = functionCallsEvaluated.Single();

            if (functionMarkup
                .Elements()
                .Any(childElement => childElement.Elements().Any(e => e.Name.LocalName == "function")))
            {
                return(false);
            }

            string functionName = (string)functionMarkup.Attribute("name");
            var    function     = FunctionFacade.GetFunction(functionName);

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

            return(!function.ParameterProfiles.Any(p => p.IsRequired && p.WidgetFunction == null && !p.IsInjectedValue));
        }
示例#5
0
        public void ProcessRequest(HttpContext context)
        {
            // Get the name of the function to execute by copying the current file name
            // (without the .ashx extension)
            string functionName = Path.GetFileNameWithoutExtension(context.Request.Path);
            // Locate the data culture to use - like en-US or nl-NL
            CultureInfo dataCulture = GetCurrentDataCulture(context);

            using (DataScope dataScope = new DataScope(DataScopeIdentifier.Public, dataCulture))
            {
                // Grab a function object to execute
                IFunction function = FunctionFacade.GetFunction(functionName);

                // Execute the function, passing all query string parameters as input parameters
                object functionResult = FunctionFacade.Execute <object>(function, context.Request.QueryString);

                // output result
                if (functionResult != null)
                {
                    context.Response.Write(functionResult.ToString());
                    if (functionResult is XNode && function.ReturnType != typeof(Composite.Core.Xml.XhtmlDocument))
                    {
                        context.Response.ContentType = "text/xml";
                    }
                }
            }
        }
示例#6
0
        private void GetFunctionCode(string copyFromFunctionName, out string markupTemplate, out string code)
        {
            IFunction function = FunctionFacade.GetFunction(copyFromFunctionName);

            if (function is FunctionWrapper)
            {
                function = (function as FunctionWrapper).InnerFunction;
            }

            var    razorFunction = (UserControlBasedFunction)function;
            string filePath      = PathUtil.Resolve(razorFunction.VirtualPath);
            string codeFilePath  = filePath + ".cs";

            Verify.That(C1File.Exists(codeFilePath), "Codebehind file not found: {0}", codeFilePath);

            markupTemplate = C1File.ReadAllText(filePath);
            code           = C1File.ReadAllText(codeFilePath);

            const string quote             = "\"";
            string       codeFileReference = quote + Path.GetFileName(codeFilePath) + quote;

            int codeReferenceOffset = markupTemplate.IndexOf(codeFileReference, StringComparison.OrdinalIgnoreCase);

            Verify.That(codeReferenceOffset > 0, "Failed to find codebehind file reference '{0}'".FormatWith(codeFileReference));

            markupTemplate = markupTemplate.Replace(codeFileReference,
                                                    quote + Marker_CodeFile + quote,
                                                    StringComparison.OrdinalIgnoreCase);
        }
示例#7
0
        public static IEnumerable GetOptions(string optionsDescriptorSerialized)
        {
            XElement optionsDescriptor = XElement.Parse(optionsDescriptorSerialized);

            string              keyFieldName    = optionsDescriptor.Attribute("KeyFieldName").Value;
            string              labelFieldName  = optionsDescriptor.Attribute("LabelFieldName").Value;
            XElement            treeNodeElement = optionsDescriptor.Element("TreeNode").Elements().First();
            BaseRuntimeTreeNode runtimeTreeNode = FunctionFacade.BuildTree(treeNodeElement);

            IEnumerable optionsSource = runtimeTreeNode.GetValue <IEnumerable>();

            if (optionsSource is IEnumerable <XElement> )
            {
                IEnumerable <XElement> optionElements = (IEnumerable <XElement>)optionsSource;
                foreach (XElement optionElement in optionElements)
                {
                    yield return(new
                    {
                        Key = optionElement.Attribute(keyFieldName).Value,
                        Label = optionElement.Attribute(labelFieldName).Value
                    });
                }
            }
            else if (optionsSource is IDictionary)
            {
                IDictionary optionsDictionary = (IDictionary)optionsSource;
                foreach (var optionKey in optionsDictionary.Keys)
                {
                    yield return(new { Key = optionKey, Label = optionsDictionary[optionKey] });
                }
            }
            else if (string.IsNullOrEmpty(keyFieldName) == false || string.IsNullOrEmpty(labelFieldName))
            {
                foreach (object optionObject in optionsSource)
                {
                    if (optionObject != null)
                    {
                        Type objectType = optionObject.GetType();

                        string key = (string.IsNullOrEmpty(keyFieldName) ?
                                      optionObject.ToString() :
                                      objectType.GetProperty(keyFieldName).GetValue(optionObject, null).ToString());

                        string label = (string.IsNullOrEmpty(labelFieldName) ?
                                        optionObject.ToString() :
                                        objectType.GetProperty(labelFieldName).GetValue(optionObject, null).ToString());

                        yield return(new { Key = key, Label = label });
                    }
                }
            }
            else
            {
                foreach (var option in optionsSource)
                {
                    yield return(new { Key = option, Label = option });
                }
            }
        }
        public void ProcessRequest(HttpContext context)
        {
            var functionName = (string)context.Request.RequestContext.RouteData.Values["function"];

            var dataCulture = GetCurrentDataCulture(context);

            using (var data = new DataConnection())
            {
                if (!data.Get <IFunctionRoute>().Any())
                {
                    context.Response.StatusCode = (int)HttpStatusCode.NotFound;

                    return;
                }
            }

            IFunction function;

            if (!FunctionFacade.TryGetFunction(out function, functionName))
            {
                context.Response.StatusCode = (int)HttpStatusCode.NotFound;

                return;
            }

            using (var dataScope = new DataScope(DataScopeIdentifier.Public, dataCulture))
            {
                var functionResult = FunctionFacade.Execute <object>(function, context.Request.QueryString);
                if (functionResult == null)
                {
                    context.Response.StatusCode = (int)HttpStatusCode.BadRequest;

                    return;
                }

                var xhtmlDocument = functionResult as XhtmlDocument;
                if (xhtmlDocument != null)
                {
                    PageRenderer.ExecuteEmbeddedFunctions(xhtmlDocument.Root, new FunctionContextContainer());
                    PageRenderer.NormalizeXhtmlDocument(xhtmlDocument);

                    var xhtml = xhtmlDocument.ToString();

                    xhtml = PageUrlHelper.ChangeRenderingPageUrlsToPublic(functionResult.ToString());
                    xhtml = MediaUrlHelper.ChangeInternalMediaUrlsToPublic(xhtml);

                    context.Response.Write(xhtml);
                }
                else
                {
                    context.Response.Write(functionResult.ToString());

                    if (functionResult is XNode && function.ReturnType != typeof(XhtmlDocument))
                    {
                        context.Response.ContentType = "text/xml";
                    }
                }
            }
        }
示例#9
0
        public object GetResult()
        {
            IFunction function = FunctionFacade.GetFunction(this.name);

            FunctionRuntimeTreeNode functionNode = new FunctionRuntimeTreeNode(function, this.Producers);

            return(functionNode);
        }
示例#10
0
 /// <summary>
 /// Executes all cacheable (not dynamic) functions and returns <value>True</value>
 /// if all of the functions were cacheable.
 /// </summary>
 /// <param name="element"></param>
 /// <param name="functionContext"></param>
 /// <returns></returns>
 internal static bool ExecuteCacheableFunctions(XElement element, FunctionContextContainer functionContext)
 {
     return(ExecuteFunctionsRec(element, functionContext, name =>
     {
         var function = FunctionFacade.GetFunction(name);
         return !(function is IDynamicFunction df && df.PreventFunctionOutputCaching);
     }));
 }
示例#11
0
        /// <exclude />
        public static IMetaFunction GetFunction(XElement functionNode)
        {
            string functionName = functionNode.Attribute("name").Value;

            if (functionNode.Name == WidgetFunctionNodeName)
            {
                return(FunctionFacade.GetWidgetFunction(functionName));
            }

            return(FunctionFacade.GetFunction(functionName));
        }
示例#12
0
        /// <summary>
        /// Executes the function.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="parameters">The parameters.</param>
        /// <param name="functionContextContainer">The function context container</param>
        /// <returns></returns>
        public static object ExecuteFunction(string name, IDictionary <string, object> parameters, FunctionContextContainer functionContextContainer)
        {
            IFunction function;

            if (!FunctionFacade.TryGetFunction(out function, name))
            {
                throw new InvalidOperationException("Failed to load function '{0}'".FormatWith(name));
            }

            functionContextContainer = functionContextContainer ?? new FunctionContextContainer();

            return(FunctionFacade.Execute <object>(function, parameters, functionContextContainer));
        }
        /// <exclude />
        public static FormTreeCompiler BuildWidgetForParameters(IEnumerable <ParameterProfile> parameterProfiles, Dictionary <string, object> bindings, string uniqueName, string panelLabel, IFormChannelIdentifier channelIdentifier)
        {
            XNamespace stdControlLibSpace = Namespaces.BindingFormsStdUiControls10;

            var bindingsDeclaration = new XElement(Namespaces.BindingForms10 + "bindings");
            var widgetPlaceholder   = new XElement(stdControlLibSpace + "FieldGroup", new XAttribute("Label", panelLabel));

            var bindingsValidationRules = new Dictionary <string, List <ClientValidationRule> >();

            foreach (ParameterProfile parameterProfile in parameterProfiles.Where(f => f.WidgetFunction != null))
            {
                IWidgetFunction widgetFunction = parameterProfile.WidgetFunction;

                Type bindingType = widgetFunction != null && parameterProfile.Type.IsLazyGenericType() ?
                                   widgetFunction.ReturnType : parameterProfile.Type;

                bindingsDeclaration.Add(
                    new XElement(Namespaces.BindingForms10 + "binding",
                                 new XAttribute("optional", true),
                                 new XAttribute("name", parameterProfile.Name),
                                 new XAttribute("type", bindingType.AssemblyQualifiedName)));

                var      context  = new FunctionContextContainer();
                XElement uiMarkup = FunctionFacade.GetWidgetMarkup(widgetFunction, parameterProfile.Type, parameterProfile.WidgetFunctionParameters, parameterProfile.Label, parameterProfile.HelpDefinition, parameterProfile.Name, context);

                widgetPlaceholder.Add(uiMarkup);

                if (!bindings.ContainsKey(parameterProfile.Name))
                {
                    bindings.Add(parameterProfile.Name, "");
                }

                if (parameterProfile.IsRequired)
                {
                    bindingsValidationRules.Add(parameterProfile.Name, new List <ClientValidationRule> {
                        new NotNullClientValidationRule()
                    });
                }
            }

            FormDefinition widgetFormDefinition = BuildFormDefinition(bindingsDeclaration, widgetPlaceholder, bindings);

            var compiler = new FormTreeCompiler();

            using (XmlReader reader = widgetFormDefinition.FormMarkup)
            {
                compiler.Compile(reader, channelIdentifier, widgetFormDefinition.Bindings, false, "WidgetParameterSetters" + uniqueName, bindingsValidationRules);
            }

            return(compiler);
        }
示例#14
0
        protected override IEnumerable <IFunctionTreeBuilderLeafInfo> OnGetFunctionInfos(SearchToken searchToken)
        {
            var functions = FunctionFacade.GetFunctionsByProvider(_functionProviderName);

            if (searchToken != null && !string.IsNullOrEmpty(searchToken.Keyword))
            {
                string keyword = searchToken.Keyword.ToLowerInvariant();

                functions = functions.Where(f => f.Namespace.IndexOf(keyword, StringComparison.OrdinalIgnoreCase) > 0 ||
                                            f.Name.IndexOf(keyword, StringComparison.OrdinalIgnoreCase) > 0);
            }

            return(functions.Select(f => new RazorFunctionTreeBuilderLeafInfo(f)));
        }
        private void prepareFunctionObject_codeActivity_ExecuteCode(object sender, EventArgs e)
        {
            DataTypeDescriptor dataTypeDescriptor = GetDataTypeDescriptor();

            var function = DataFacade.BuildNew <IVisualFunction>();

            function.Id              = Guid.NewGuid();
            function.Name            = FunctionFacade.BuildUniqueFunctionName(dataTypeDescriptor.Namespace, string.Format("{0}Rendering", dataTypeDescriptor.Name));
            function.Namespace       = dataTypeDescriptor.Namespace;
            function.TypeManagerName = dataTypeDescriptor.TypeManagerTypeName;
            function.Description     = "";

            this.UpdateBinding("Function", function);
        }
示例#16
0
        private void LoadParameterProfiles(ActionInformation action)
        {
            XElement functionNode = action.ConfigurationElement.FunctionNode;

            string functionName = (string)functionNode.Attribute("name");

            IFunction function = FunctionFacade.GetFunction(functionName);

            Verify.IsNotNull(function, "Failed to get C1 function '{0}'", functionName);

            List <string> predefinedParameterNames = functionNode.Elements().Select(el => (string)el.Attribute("name")).ToList();

            action.ParameterProfiles = function.ParameterProfiles.Where(p => !predefinedParameterNames.Contains(p.Name)).ToArray();
        }
        private IMetaFunction GetMetaFunction(string metaFunctionName)
        {
            switch (_providerType)
            {
            case FunctionsProviderType:
                return(FunctionFacade.GetFunction(metaFunctionName));

            case WidgetFunctionsProviderType:
                return(FunctionFacade.GetWidgetFunction(metaFunctionName));

            default:
                throw new NotImplementedException();
            }
        }
示例#18
0
        protected override IFunctionTreeBuilderLeafInfo OnIsEntityOwner(EntityToken entityToken)
        {
            if (entityToken is FileBasedFunctionEntityToken && entityToken.Source == _functionProviderName)
            {
                string functionFullName = entityToken.Id;

                IFunction function = FunctionFacade.GetFunctionsByProvider(_functionProviderName)
                                     .FirstOrDefault(func => func.Namespace + "." + func.Name == functionFullName);

                return(function == null ? null : new RazorFunctionTreeBuilderLeafInfo(function));
            }

            return(null);
        }
        public IEnumerable <ElementAction> GetActions(EntityToken entityToken)
        {
            string fullName = FavoriteFunctionWrapper.GetFunctionNameFromEntityToken(entityToken);

            if (!String.IsNullOrEmpty(fullName))
            {
                IFunction function;

                if (FunctionFacade.TryGetFunction(out function, fullName))
                {
                    yield return(createAction(fullName));
                }
            }
        }
示例#20
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());
        }
        private string GetFunctionCode(string copyFromFunction)
        {
            IFunction function = FunctionFacade.GetFunction(copyFromFunction);

            if (function is FunctionWrapper)
            {
                function = (function as FunctionWrapper).InnerFunction;
            }

            var    razorFunction = (RazorBasedFunction)function;
            string filePath      = PathUtil.Resolve(razorFunction.VirtualPath);

            return(C1File.ReadAllText(filePath));
        }
        public static void SetDefaultValues(IModelInstance instance)
        {
            var def = GetFormByName(instance.Name);

            foreach (var field in instance.Fields)
            {
                if (!def.DefaultValues.TryGetValue(field.Name, out var defaultValueSetter))
                {
                    continue;
                }

                var runtimeTree = FunctionFacade.BuildTree(defaultValueSetter);

                field.Value = runtimeTree.GetValue();
            }
        }
示例#23
0
        private void initalizeStateCodeActivity_Initialize_ExecuteCode(object sender, EventArgs e)
        {
            List <NamedFunctionCall> namedFunctionCalls = new List <NamedFunctionCall>();

            if (Payload != "")
            {
                IFunction function = FunctionFacade.GetFunction(Payload);

                BaseRuntimeTreeNode baseRuntimeTreeNode = FunctionFacade.BuildTree(function, new Dictionary <string, object>());

                NamedFunctionCall namedFunctionCall = new NamedFunctionCall("", (BaseFunctionRuntimeTreeNode)baseRuntimeTreeNode);

                namedFunctionCalls.Add(namedFunctionCall);

                string layoutLabel = string.Format(StringResourceSystemFacade.GetString("Composite.Plugins.AllFunctionsElementProvider", "FunctionTesterWorkflow.Layout.Label"), function.Name);
                this.Bindings.Add("LayoutLabel", layoutLabel);
            }

            this.Bindings.Add("FunctionCalls", namedFunctionCalls);
            this.Bindings.Add("Parameters", new List <ManagedParameterDefinition>());
            this.Bindings.Add("PageId", PageManager.GetChildrenIDs(Guid.Empty).FirstOrDefault());

            if (UserSettings.ActiveLocaleCultureInfo != null)
            {
                List <KeyValuePair <string, string> > activeCulturesDictionary = UserSettings.ActiveLocaleCultureInfos.Select(f => new KeyValuePair <string, string>(f.Name, DataLocalizationFacade.GetCultureTitle(f))).ToList();
                this.Bindings.Add("ActiveCultureName", UserSettings.ActiveLocaleCultureInfo.Name);
                this.Bindings.Add("ActiveCulturesList", activeCulturesDictionary);
            }

            this.Bindings.Add("PageDataScopeName", DataScopeIdentifier.AdministratedName);
            this.Bindings.Add("PageDataScopeList", new Dictionary <string, string>
            {
                { DataScopeIdentifier.AdministratedName, StringResourceSystemFacade.GetString("Composite.Plugins.AllFunctionsElementProvider", "FunctionTesterWorkflow.AdminitrativeScope.Label") },
                { DataScopeIdentifier.PublicName, StringResourceSystemFacade.GetString("Composite.Plugins.AllFunctionsElementProvider", "FunctionTesterWorkflow.PublicScope.Label") }
            });


            Guid stateId = Guid.NewGuid();
            var  state   = new FunctionCallDesignerState {
                WorkflowId = WorkflowInstanceId, ConsoleIdInternal = GetCurrentConsoleId()
            };

            SessionStateManager.DefaultProvider.AddState <IFunctionCallEditorState>(stateId, state, DateTime.Now.AddDays(7.0));

            this.Bindings.Add("SessionStateProvider", SessionStateManager.DefaultProviderName);
            this.Bindings.Add("SessionStateId", stateId);
        }
示例#24
0
        public IEnumerable <ElementAction> Provide(EntityToken entityToken)
        {
            var functionName = entityToken.Id;

            if (!functionName.Contains("."))
            {
                yield break;
            }

            IFunction function;

            if (!FunctionFacade.TryGetFunction(out function, functionName))
            {
                yield break;
            }

            var message = (string)null;
            var icon    = (string)null;

            using (var data = new DataConnection())
            {
                var route = data.Get <IFunctionRoute>().SingleOrDefault(r => r.Function == functionName);
                if (route == null)
                {
                    message = "Enable Function Route";
                    icon    = "accept";
                }
                else
                {
                    message = "Disable Function Route";
                    icon    = "delete";
                }
            }

            var actionToken = new ToggleFunctionRouteActionToken(functionName);

            yield return(new ElementAction(new ActionHandle(actionToken))
            {
                VisualData = new ActionVisualizedData
                {
                    Label = message,
                    ToolTip = message,
                    Icon = new ResourceHandle("Composite.Icons", icon),
                    ActionLocation = ActionLocation.OtherPrimaryActionLocation
                }
            });
        }
        private void LoadParameterProfiles()
        {
            string elementName = (string)_fieldXml.Attribute("name");

            Verify.ArgumentNotNullOrEmpty(elementName, "Missing element name");

            var allElements = FormBuilderConfiguration.GetFieldMap();

            Verify.That(allElements.ContainsKey(elementName), "Undeclared form element 'elementName'");

            var element = allElements[elementName];

            string functionName = (string)element.FunctionNode.Attribute("name");

            IFunction function = FunctionFacade.GetFunction(functionName);

            Verify.IsNotNull(function, "Failed to get C1 function '{0}'", functionName);

            List <string> predefinedParameterNames = element.FunctionNode.Elements().Select(el => (string)el.Attribute("name")).ToList();

            _fieldConfiguration = element;
            _parameterProfiles  = function.ParameterProfiles.Where(p => !predefinedParameterNames.Contains(p.Name)).ToArray();

            _standardParameters = new ParameterGroup {
                ParameterProfiles = _parameterProfiles.Where(p =>
                                                             !_fieldConfiguration.DescriptionParameters.Contains(p.Name) &&
                                                             !_fieldConfiguration.ValidationParameters.Contains(p.Name) &&
                                                             !_fieldConfiguration.AdvancedParameters.Contains(p.Name)).ToArray()
            };

            _descriptionParameters = new ParameterGroup
            {
                ParameterProfiles = _parameterProfiles.Where(p => _fieldConfiguration.DescriptionParameters.Contains(p.Name)).ToArray()
            };

            _validationParameters = new ParameterGroup
            {
                ParameterProfiles = _parameterProfiles.Where(p => _fieldConfiguration.ValidationParameters.Contains(p.Name)).ToArray()
            };

            _advancedParameters = new ParameterGroup {
                ParameterProfiles = _parameterProfiles.Where(p => _fieldConfiguration.AdvancedParameters.Contains(p.Name)).ToArray()
            };
        }
        private void ProcessFunctionCall(XElement functionNode)
        {
            var functionName = functionNode.GetAttributeValue("name");

            if (functionName == null)
            {
                return;
            }

            IFunction function;

            try
            {
                function = FunctionFacade.GetFunction(functionName);
                if (function == null)
                {
                    return;
                }
            }
            catch
            {
                return;
            }

            foreach (var paramElement in functionNode.Elements())
            {
                var parameterName = paramElement.GetAttributeValue("name");
                if (parameterName == null)
                {
                    continue;
                }

                var profile = function.ParameterProfiles.FirstOrDefault(p => p.Name == parameterName);
                if (profile != null)
                {
                    if (profile.Type == typeof(XhtmlDocument))
                    {
                        ProcessElement(paramElement);
                    }

                    // TODO: handle the other parameter types
                }
            }
        }
示例#27
0
        private object GetValue(FunctionContextContainer functionContextContainer, out Type returnType)
        {
            string functionName = Name;

            IFunction function;

            if (!FunctionFacade.TryGetFunction(out function, functionName))
            {
                throw new InvalidOperationException("Invalid function name '{0}'".FormatWith(functionName));
            }

            returnType = function.ReturnType;

            IDictionary <string, object> parameters = parseParameters(functionContextContainer);

            VerifyParameterMatch(function, parameters);

            return(ExecuteFunction(function, parameters, functionContextContainer));
        }
        internal void GetProviderAndFunction <FunctionType>(
            FileBasedFunctionEntityToken entityToken,
            out FileBasedFunctionProvider <FunctionType> provider,
            out FileBasedFunction <FunctionType> function) where FunctionType : FileBasedFunction <FunctionType>
        {
            string functionProviderName = entityToken.FunctionProviderName;

            provider = (FileBasedFunctionProvider <FunctionType>)FunctionProviderPluginFacade.GetFunctionProvider(functionProviderName);
            IFunction func = FunctionFacade.GetFunction(entityToken.FunctionName);

            Verify.IsNotNull(func, "Failed to get function '{0}'", entityToken.FunctionName);

            if (func is FunctionWrapper)
            {
                func = (func as FunctionWrapper).InnerFunction;
            }

            function = (FileBasedFunction <FunctionType>)func;
        }
示例#29
0
        public void Pack(PackageCreator pc)
        {
            IFunction function = null;

            if (FunctionFacade.TryGetFunction(out function, this.Id))
            {
                var innerFunction         = function.GetProperty <IFunction>("InnerFunction");
                var innerFunctionTypeName = innerFunction.GetType().Name;

                switch (innerFunctionTypeName)
                {
                case "MethodBasedFunction":
                    PackCSharpFunction(pc);
                    break;

                case "LazyInitializedInlineFunction":
                case "InlineFunction":
                    PackInlineFunction(pc);
                    break;

                case "RazorBasedFunction":
                    PackRazorFunction(pc, innerFunction);
                    break;

                case "UserControlBasedFunction":
                    PackUserControlFunction(pc, innerFunction);
                    break;

                case "VisualFunction`1":
                    PackVisualFunction(pc);
                    break;

                case "XsltXmlFunction":
                    PackXsltFunction(pc);
                    break;
                }
            }
            else
            {
                throw new InvalidOperationException(string.Format("Function '{0}' does not exists", this.Name));
            }
        }
示例#30
0
        private void initializeCodeActivity_ExecuteCode(object sender, EventArgs e)
        {
            BaseFunctionFolderElementEntityToken token = (BaseFunctionFolderElementEntityToken)this.EntityToken;
            string @namespace = token.FunctionNamespace ?? UserSettings.LastSpecifiedNamespace;

            this.Bindings.Add(Binding_Name, string.Empty);
            this.Bindings.Add(Binding_Namespace, @namespace);

            var functionProvider = GetFunctionProvider <UserControlFunctionProvider>();
            var copyOfOptions    = new List <KeyValuePair <string, string> >();

            copyOfOptions.Add(new KeyValuePair <string, string>(string.Empty, GetText("AddNewUserControlFunction.LabelCopyFromEmptyOption")));
            foreach (string functionName in FunctionFacade.GetFunctionNamesByProvider(functionProvider.Name))
            {
                copyOfOptions.Add(new KeyValuePair <string, string>(functionName, functionName));
            }

            this.Bindings.Add(Binding_CopyFromFunctionName, string.Empty);
            this.Bindings.Add(Binding_CopyFromOptions, copyOfOptions);
        }