private void BuildWidgets(ParameterGroup parameterGroup, PlaceHolder placeHolder, string panelLabel)
        {
            if (!parameterGroup.ParameterProfiles.Any())
            {
                return;
            }

            var bindings = new Dictionary <string, object>();

            foreach (var parameterProfile in parameterGroup.ParameterProfiles)
            {
                var loadedValue = _parameterValues.FirstOrDefault(p => p.Item1 == parameterProfile.Name);

                object parameterValue = loadedValue != null ? loadedValue.Item2 : parameterProfile.GetDefaultValue();

                bindings.Add(parameterProfile.Name, parameterValue);
            }

            parameterGroup.FormTreeCompiler = FunctionUiHelper.BuildWidgetForParameters(
                parameterGroup.ParameterProfiles,
                bindings,
                placeHolder.ID,
                panelLabel,
                WebManagementChannel.Identifier);

            parameterGroup.Widgets = (IWebUiControl)parameterGroup.FormTreeCompiler.UiControl;

            placeHolder.Controls.Add(parameterGroup.Widgets.BuildWebControl());
        }
Example #2
0
        private void BuildWidgets(ActionInformation action, PlaceHolder placeHolder, bool createEvenIfDisabled)
        {
            if (!action.Enabled && !createEvenIfDisabled)
            {
                return;
            }

            var bindings = new Dictionary <string, object>();

            foreach (var parameterProfile in action.ParameterProfiles)
            {
                var loadedValue = action.ParameterValues.FirstOrDefault(p => p.Item1 == parameterProfile.Name);

                object parameterValue = loadedValue != null ? loadedValue.Item2 : parameterProfile.GetDefaultValue();

                bindings.Add(parameterProfile.Name, parameterValue);
            }

            action.FormTreeCompiler = FunctionUiHelper.BuildWidgetForParameters(
                action.ParameterProfiles,
                bindings,
                "widgets",
                StringResourceSystemFacade.ParseString(action.ConfigurationElement.Label),
                WebManagementChannel.Identifier);

            action.Control            = (IWebUiControl)action.FormTreeCompiler.UiControl;
            action.ControlPlaceHolder = placeHolder;

            var webControl = action.Control.BuildWebControl();

            placeHolder.Controls.Add(webControl);
        }
        private bool ProcessWidgets(bool processPost, bool showValidationErrors = false, bool ignoreValidationErrors = false)
        {
            XElement functionMarkup = XElement.Parse(FunctionMarkupInState);

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

            if (function.ParameterProfiles.All(p => p.WidgetFunction == null))
            {
                plhNoParameters.Visible = true;
                return(true);
            }

            var bindings       = new Dictionary <string, object>();
            var parameterNodes = FunctionMarkupHelper.GetParameterNodes(functionMarkup);

            foreach (var parameterProfile in function.ParameterProfiles)
            {
                object parameterValue;

                XElement parameterNode;

                if (parameterNodes.TryGetValue(parameterProfile.Name, out parameterNode))
                {
                    parameterValue = FunctionMarkupHelper.GetParameterValue(parameterNode, parameterProfile);
                }
                else
                {
                    parameterValue = parameterProfile.GetDefaultValue();
                }

                if (parameterProfile.Type.IsLazyGenericType() && parameterValue != null)
                {
                    parameterValue = parameterProfile.Type.GetProperty("Value").GetGetMethod().Invoke(parameterValue, null);
                }

                bindings.Add(parameterProfile.Name, parameterValue);
            }

            var formTreeCompiler = FunctionUiHelper.BuildWidgetForParameters(
                function.ParameterProfiles.Where(p => !p.HideInSimpleView ||
                                                 (p.IsRequired && (!bindings.ContainsKey(p.Name) || bindings[p.Name] == null))),
                bindings,
                "BasicView",
                "",
                WebManagementChannel.Identifier);

            var webUiControl = (IWebUiControl)formTreeCompiler.UiControl;

            var webControl = webUiControl.BuildWebControl();

            BasicContentPanel.Controls.Add(webControl);

            if (!processPost)
            {
                webUiControl.InitializeViewState();
                return(true);
            }

            // Loading control's post data
            LoadPostBackData(webControl);

            var validationErrors = formTreeCompiler.SaveAndValidateControlProperties();

            if (!ignoreValidationErrors)
            {
                // Validating required parameters
                foreach (var parameterProfile in function.ParameterProfiles)
                {
                    if (!validationErrors.ContainsKey(parameterProfile.Name) &&
                        parameterProfile.IsRequired &&
                        parameterProfile.WidgetFunction != null &&
                        (!bindings.ContainsKey(parameterProfile.Name) || bindings[parameterProfile.Name] == null))
                    {
                        validationErrors.Add(parameterProfile.Name, new Exception(
                                                 StringResourceSystemFacade.GetString("Composite.Management", "Validation.RequiredField")));
                    }
                }


                if (validationErrors.Any())
                {
                    if (showValidationErrors)
                    {
                        ShowServerValidationErrors(formTreeCompiler, validationErrors);
                    }

                    return(false);
                }
            }

            foreach (var parameterProfile in function.ParameterProfiles)
            {
                XElement parameterNode;
                parameterNodes.TryGetValue(parameterProfile.Name, out parameterNode);

                object value = bindings[parameterProfile.Name];

                if (!parameterProfile.IsRequired)
                {
                    object defaultValue = parameterProfile.GetDefaultValue();
                    if (value == defaultValue ||
                        (value != null && value.Equals(defaultValue)) ||
                        (value is XNode && defaultValue is XNode && XElement.DeepEquals(value as XNode, defaultValue as XNode)) ||
                        parameterProfile.WidgetFunction == null)
                    {
                        if (parameterNode != null)
                        {
                            parameterNode.Remove();
                        }
                        continue;
                    }
                }

                FunctionMarkupHelper.SetParameterValue(functionMarkup, parameterProfile, value);
            }

            FunctionMarkupInState = functionMarkup.ToString();

            return(true);
        }