protected void editElem_OnAfterDefinitionUpdate(object sender, EventArgs e)
 {
     // Set the form definition to the FieldEditor
     if (EditedObject != null)
     {
         MacroRuleInfo rule = ((MacroRuleInfo)EditedObject);
         rule.MacroRuleParameters = editElem.FormDefinition;
         MacroRuleInfoProvider.SetMacroRuleInfo(rule);
     }
 }
示例#2
0
    private void ShowMacroWarning(object sender, EventArgs e)
    {
        MacroRuleInfo info = Control.EditedObject as MacroRuleInfo;

        if (info != null)
        {
            string macroName = info.MacroRuleName;
            if (!MacroRuleMetadataContainer.IsTranslatorAvailable(macroName))
            {
                Control.ShowWarning(CoreServices.Localization.GetString("om.configuration.macro.slow"));
            }
        }
    }
    private void EditForm_OnAfterDataLoad(object sender, EventArgs e)
    {
        MacroRuleInfo info = Control.EditedObject as MacroRuleInfo;

        if (info != null)
        {
            string macroName = info.MacroRuleName;
            if (!MacroRuleMetadataContainer.IsTranslatorAvailable(macroName))
            {
                Control.ShowWarning(Control.GetString("om.configuration.macro.slow"));
            }
        }
    }
    private void ShowMacroWarning(object sender, EventArgs e)
    {
        MacroRuleInfo info = Control.EditedObject as MacroRuleInfo;

        if (info != null)
        {
            string macroName = info.MacroRuleName;
            if (!MacroRuleMetadataContainer.IsTranslatorAvailable(macroName))
            {
                var text = string.Format(Service.Resolve <ILocalizationService>().GetString("om.configuration.macro.slow"), DocumentationHelper.GetDocumentationTopicUrl("om_macro_performance"));
                Control.ShowWarning(text);
            }
        }
    }
    /// <summary>
    /// Initializes inner controls.
    /// </summary>
    /// <param name="forceReload">Indicates if form with parameters should be reloaded</param>
    private void InitializeControl(bool forceReload = false)
    {
        // Init rule selector
        uniSelector.Value = mSelectedRuleName;

        MacroRuleInfo mri = MacroRuleInfoProvider.GetMacroRuleInfo(mSelectedRuleName);

        if (mri != null)
        {
            // Show rule description
            ltlDescription.Text       = mri.MacroRuleDescription;
            txtErrorMsg.Value         = string.Empty;
            txtErrorMsg.WatermarkText = String.IsNullOrEmpty(DefaultErrorMessage) ? ResHelper.GetString("basicform.invalidinput") : DefaultErrorMessage;

            // Prepare form for rule parameters
            FormInfo fi = new FormInfo(mri.MacroRuleParameters);
            formProperties.FormInformation = fi;
            DataRow data = fi.GetDataRow();
            formProperties.DataRow = data;

            fi.LoadDefaultValues(formProperties.DataRow, FormResolveTypeEnum.AllFields);
            if ((mMacroRule != null) && (mMacroRuleTree != null) && mMacroRuleTree.RuleName.EqualsCSafe(mSelectedRuleName, true))
            {
                // Set params from rule given by Value property
                foreach (DictionaryEntry entry in mMacroRuleTree.Parameters)
                {
                    string             paramName = ValidationHelper.GetString(entry.Key, String.Empty);
                    MacroRuleParameter param     = entry.Value as MacroRuleParameter;

                    if ((param != null) && data.Table.Columns.Contains(paramName))
                    {
                        data[paramName] = param.Value;
                    }
                }

                txtErrorMsg.Value = mMacroRule.ErrorMessage;
            }

            if (forceReload)
            {
                // Reload params
                formProperties.ReloadData();
            }

            mParamsInitialized = true;
        }
    }
    /// <summary>
    /// Adds a clause according to selected item.
    /// </summary>
    private void AddClause()
    {
        MacroRuleInfo rule = MacroRuleInfo.Provider.Get(ValidationHelper.GetInteger(lstRules.SelectedValue, 0));

        if (rule != null)
        {
            List <MacroRuleTree> selected = GetSelected();
            if (selected.Count == 1)
            {
                MacroRuleTree item = selected[0];
                if (item?.Parent != null)
                {
                    item.Parent.AddRule(rule, item.Position + 1);
                    return;
                }
            }

            // Add the rule at the root level, when no selected item
            RuleTree.AddRule(rule, RuleTree.Children.Count);
        }
    }
    /// <summary>
    /// Creates new <see cref="FieldMacroRule"/> object based on inputs.
    /// </summary>
    private FieldMacroRule CreateMacroRule()
    {
        if (!IsValid())
        {
            return(null);
        }

        MacroRuleTree  main = null;
        FieldMacroRule fmr  = null;

        MacroRuleInfo mri = MacroRuleInfoProvider.GetMacroRuleInfo(mSelectedRuleName);

        if (mri != null)
        {
            main = new MacroRuleTree();

            MacroRuleTree childern = new MacroRuleTree()
            {
                RuleText      = mri.MacroRuleText,
                RuleName      = mri.MacroRuleName,
                RuleCondition = mri.MacroRuleCondition,
                Parent        = main
            };
            main.Children.Add(childern);

            foreach (string paramName in formProperties.Fields)
            {
                // Load value from the form control
                FormEngineUserControl ctrl = formProperties.FieldControls[paramName];
                if (ctrl != null)
                {
                    // Convert value to EN culture
                    var dataType = ctrl.FieldInfo.DataType;

                    var convertedValue = DataTypeManager.ConvertToSystemType(TypeEnum.Field, dataType, ctrl.Value);

                    string value       = ValidationHelper.GetString(convertedValue, "", CultureHelper.EnglishCulture);
                    string displayName = ctrl.ValueDisplayName;

                    if (String.IsNullOrEmpty(displayName))
                    {
                        displayName = value;
                    }

                    MacroRuleParameter param = new MacroRuleParameter
                    {
                        Value     = value,
                        Text      = displayName,
                        ValueType = dataType
                    };

                    childern.Parameters.Add(paramName, param);
                }
            }

            string macroRule = string.Format("Rule(\"{0}\", \"{1}\")", MacroElement.EscapeSpecialChars(main.GetCondition()), MacroElement.EscapeSpecialChars(main.GetXML()));

            if (!MacroSecurityProcessor.IsSimpleMacro(macroRule))
            {
                // Sign complex macros
                macroRule = MacroSecurityProcessor.AddMacroSecurityParams(macroRule, MacroIdentityOption.FromUserInfo(MembershipContext.AuthenticatedUser));
            }

            fmr              = new FieldMacroRule();
            fmr.MacroRule    = string.Format("{{%{0}%}}", macroRule);
            fmr.ErrorMessage = txtErrorMsg.Text;
        }

        return(fmr);
    }
示例#8
0
    protected void EditForm_OnBeforeSave(object sender, EventArgs e)
    {
        MacroRuleInfo info = Control.EditedObject as MacroRuleInfo;

        if (info != null)
        {
            // Generate automatic fields when present in UserText
            FormEngineUserControl control = Control.FieldControls["MacroRuleText"];
            if (control != null)
            {
                string userText = ValidationHelper.GetString(control.Value, String.Empty);
                if (!string.IsNullOrEmpty(userText))
                {
                    Regex           regex = RegexHelper.GetRegex("\\{[-_a-zA-Z0-9]*\\}");
                    MatchCollection match = regex.Matches(userText);
                    if (match.Count > 0)
                    {
                        FormInfo fi = new FormInfo(info.MacroRuleParameters);
                        foreach (Match m in match)
                        {
                            foreach (Capture c in m.Captures)
                            {
                                string        name = c.Value.Substring(1, c.Value.Length - 2).ToLowerCSafe();
                                FormFieldInfo ffi  = fi.GetFormField(name);
                                if (ffi == null)
                                {
                                    ffi           = new FormFieldInfo();
                                    ffi.Name      = name;
                                    ffi.DataType  = FieldDataType.Text;
                                    ffi.Size      = 100;
                                    ffi.FieldType = FormFieldControlTypeEnum.CustomUserControl;
                                    ffi.SetPropertyValue(FormFieldPropertyEnum.FieldCaption, "select operation");
                                    ffi.AllowEmpty = true;
                                    switch (name)
                                    {
                                    case "_is":
                                        ffi.SetPropertyValue(FormFieldPropertyEnum.DefaultValue, ";is");
                                        ffi.Settings["controlname"] = "MacroNegationOperator";
                                        ffi.Settings["EditText"]    = "false";
                                        ffi.Settings["Options"]     = ";is\r\n!;is not";
                                        break;

                                    case "_was":
                                        ffi.SetPropertyValue(FormFieldPropertyEnum.DefaultValue, ";was");
                                        ffi.Settings["controlname"] = "MacroNegationOperator";
                                        ffi.Settings["EditText"]    = "false";
                                        ffi.Settings["Options"]     = ";was\r\n!;was not";
                                        break;

                                    case "_will":
                                        ffi.SetPropertyValue(FormFieldPropertyEnum.DefaultValue, ";will");
                                        ffi.Settings["controlname"] = "MacroNegationOperator";
                                        ffi.Settings["EditText"]    = "false";
                                        ffi.Settings["Options"]     = ";will\r\n!;will not";
                                        break;

                                    case "_has":
                                        ffi.SetPropertyValue(FormFieldPropertyEnum.DefaultValue, ";has");
                                        ffi.Settings["controlname"] = "MacroNegationOperator";
                                        ffi.Settings["EditText"]    = "false";
                                        ffi.Settings["Options"]     = ";has\r\n!;does not have";
                                        break;

                                    case "_perfectum":
                                        ffi.SetPropertyValue(FormFieldPropertyEnum.DefaultValue, ";has");
                                        ffi.Settings["controlname"] = "MacroNegationOperator";
                                        ffi.Settings["EditText"]    = "false";
                                        ffi.Settings["Options"]     = ";has\r\n!;has not";
                                        break;

                                    case "_any":
                                        ffi.SetPropertyValue(FormFieldPropertyEnum.DefaultValue, "false;any");
                                        ffi.Settings["controlname"] = "macro_any-all_bool_selector";
                                        ffi.Settings["EditText"]    = "false";
                                        ffi.Settings["Options"]     = "false;any\r\ntrue;all";
                                        break;

                                    default:
                                        ffi.FieldType = FormFieldControlTypeEnum.TextBoxControl;
                                        ffi.Size      = 1000;
                                        ffi.SetPropertyValue(FormFieldPropertyEnum.FieldCaption, "enter text");
                                        break;
                                    }

                                    fi.AddFormItem(ffi);
                                }
                            }
                        }
                        info.MacroRuleParameters = fi.GetXmlDefinition();
                    }
                }
            }
        }

        Control.EditedObject.SetValue("MacroRuleIsCustom", !SystemContext.DevelopmentMode);
    }