public FunctionValueProvider(FunctionRuntimeTreeNode functionFunctionRuntimeNode)
        {
            if (functionFunctionRuntimeNode == null)
            {
                throw new ArgumentNullException("functionFunctionRuntimeNode");
            }

            _functionFunctionRuntimeNode = functionFunctionRuntimeNode;
        }
 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);
                 }
             }
         }
     }
 }
 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);
                 }
             }
         }
     }
 }
    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);
    }
Exemple #5
0
 /// <exclude />
 public FunctionParameterRuntimeTreeNode(string name, FunctionRuntimeTreeNode functionNode)
     : base(name)
 {
     _functionNode = functionNode;
 }
Exemple #6
0
        private static BaseParameterRuntimeTreeNode BuildParameterFunctionRuntimeNode(XElement element)
        {
            XAttribute nameAttribute = element.Attribute(FunctionTreeConfigurationNames.NameAttribute);

            Verify.IsNotNull(nameAttribute, "Missing attribute named '{0}'", FunctionTreeConfigurationNames.NameAttributeName);

            string parameterName = nameAttribute.Value;


            XAttribute valueAttribute = element.Attribute(FunctionTreeConfigurationNames.ValueAttribute);

            if (valueAttribute != null)
            {
                return(new ConstantParameterRuntimeTreeNode(parameterName, valueAttribute));
            }

            if (!element.Elements().Any())
            {
                if (string.IsNullOrWhiteSpace(element.Value))
                {
                    return(new ConstantParameterRuntimeTreeNode(parameterName, (string)null));
                }

                return(new ConstantParameterRuntimeTreeNode(parameterName, element.Value));
            }

            if ((element.Elements().Count() == 1) &&
                (element.Elements().First().Name.LocalName == FunctionTreeConfigurationNames.FunctionTagName))
            {
                XElement childElement = element.Elements().First();

                if (childElement.Name.LocalName != FunctionTreeConfigurationNames.FunctionTagName)
                {
                    throw new InvalidOperationException(string.Format("Missing '{0}' child element (found '{1}')", FunctionTreeConfigurationNames.FunctionTagName, childElement.Name.LocalName));
                }

                FunctionRuntimeTreeNode functionNode = BuildFunctionRuntimeNode(childElement, false);

                return(new FunctionParameterRuntimeTreeNode(parameterName, functionNode));
            }

            if ((element.Elements().Count() == 1) &&
                (element.Elements().First().Name.LocalName != FunctionTreeConfigurationNames.ParamElementTagName))
            {
                return(new XElementParameterRuntimeTreeNode(parameterName, element.Elements().First()));
            }

            if (element.Elements().All(f => f.Name.LocalName == FunctionTreeConfigurationNames.ParamElementTagName))
            {
                var strings = new List <string>();

                foreach (XElement elm in element.Elements())
                {
                    XAttribute attr = elm.Attribute(FunctionTreeConfigurationNames.ValueAttribute);
                    Verify.IsNotNull(attr, "One or more {0} are missing the attribute {1}", FunctionTreeConfigurationNames.ParamElementTagName, FunctionTreeConfigurationNames.ValueAttributeName);

                    strings.Add(attr.Value);
                }

                return(new ConstantParameterRuntimeTreeNode(parameterName, strings));
            }

            if (element.Nodes().Any())
            {
                object value = element.Nodes().All(f => f is XElement) ? element.Elements() : element.Nodes();

                return(new ConstantObjectParameterRuntimeTreeNode(parameterName, value));
            }

            throw new InvalidProgramException("Wrong xml format in parameter '{0}'".FormatWith(parameterName));
        }
    private void BtnAddFunctionCallClicked()
    {
        string selectedFunctionName = this.Request.Form["btnAddFunction"];

        BaseFunctionRuntimeTreeNode functionRuntime;
        if (_state.WidgetFunctionSelection)
        {
            functionRuntime = new WidgetFunctionRuntimeTreeNode(FunctionFacade.GetWidgetFunction(selectedFunctionName));
        }
        else
        {
            functionRuntime = new FunctionRuntimeTreeNode(FunctionFacade.GetFunction(selectedFunctionName));
        }

        XElement function = functionRuntime.Serialize();

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

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

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

        FunctionMarkup.Root.Add(function);

        SaveChanges();
    }
        protected void Page_PreRender(object sender, EventArgs e)
        {
            if(CurrentlySelectedFieldId != Guid.Empty)
            {
                var defaultFunction = StandardFunctions.GetDefaultFunctionByType(this.CurrentlySelectedType);

                btnDefaultValueFunctionMarkup.Attributes["label"] = GetString(btnDefaultValueFunctionMarkup.Value.IsNullOrEmpty() ? "DefaultValueSpecify" : "DefaultValueEdit");
                btnDefaultValueFunctionMarkup.Attributes["url"] =
                    "${root}/content/dialogs/functions/editFunctionCall.aspx?type=" + this.CurrentlySelectedType.FullName +
                    "&dialoglabel=" + HttpUtility.UrlEncode(GetString("DefaultValueDialogLabel"), Encoding.UTF8) + "&multimode=false&functionmarkup=";

                btnTestValueFunctionMarkup.Attributes["label"] = GetString(btnTestValueFunctionMarkup.Value.IsNullOrEmpty() ? "TestValueSpecify" : "TestValueEdit");
                btnTestValueFunctionMarkup.Attributes["url"] =
                    "${root}/content/dialogs/functions/editFunctionCall.aspx?type=" + this.CurrentlySelectedType.FullName +
                    "&dialoglabel=" + HttpUtility.UrlEncode(GetString("TestValueDialogLabel"), Encoding.UTF8) + "&multimode=false&functionmarkup=";

                btnWidgetFunctionMarkup.Attributes["label"] = CurrentlySelectedWidgetText;
                btnWidgetFunctionMarkup.Attributes["url"] =
                    "${root}/content/dialogs/functions/editFunctionCall.aspx?functiontype=widget&type=" + this.CurrentlySelectedWidgetReturnType.FullName +
                    "&dialoglabel=" + HttpUtility.UrlEncode(GetString("WidgetDialogLabel"), Encoding.UTF8) + "&multimode=false&functionmarkup=";

                if (defaultFunction != null)
                {
                    string defaultValue = new FunctionRuntimeTreeNode(defaultFunction).Serialize().ToString();

                    btnDefaultValueFunctionMarkup.DefaultValue = defaultValue;
                    btnTestValueFunctionMarkup.DefaultValue = defaultValue;
                }
            }

            btnDelete.Attributes["isdisabled"] = CurrentlySelectedFieldId == Guid.Empty ? "true" : "false";

            if (nameChanged)
            {
                UpdateFieldsPanel();
            }

            _state.Parameters = this.CurrentFields.ToList();
            SessionStateManager.GetProvider(SessionStateProviderName).SetState(StateId, _state, DateTime.Now.AddDays(7.0));
        }
 /// <exclude />
 public FunctionParameterRuntimeTreeNode(string name, FunctionRuntimeTreeNode functionNode)
     : base(name)
 {
     _functionNode = functionNode;
 }
Exemple #10
0
        /// <summary>
        /// Executes the function. Note that all the XhtmlParameters will have all the nested &gt;f:function /&lt; lazily evaluated
        /// </summary>
        private static object ExecuteFunction(IFunction function, IDictionary<string, object> parameters, FunctionContextContainer functionContextContainer )
        {
            List<BaseParameterRuntimeTreeNode> parameterNodes = new List<BaseParameterRuntimeTreeNode>();

            if (parameters != null)
            {
                foreach (KeyValuePair<string, object> kvp in parameters)
                {
                    var value = kvp.Value;
                    if (value is XhtmlDocument)
                    {
                        parameterNodes.Add(new LazyParameterRuntimeTreeNode(kvp.Key,
                            () => ExecuteNestedFunctions(value as XhtmlDocument, functionContextContainer)));
                    }
                    else
                    {
                        parameterNodes.Add(new ConstantObjectParameterRuntimeTreeNode(kvp.Key, kvp.Value));
                    }
                }
            }

            var treeNode = new FunctionRuntimeTreeNode(function, parameterNodes);

            return treeNode.GetValue(functionContextContainer);
        }
        public FunctionValueProvider(FunctionRuntimeTreeNode functionFunctionRuntimeNode)
        {
            if (functionFunctionRuntimeNode == null) throw new ArgumentNullException("functionFunctionRuntimeNode");

            _functionFunctionRuntimeNode = functionFunctionRuntimeNode;
        }