Class MacroRuleTree
- Namespace
- CMS.MacroEngine
- Assembly
- CMS.MacroEngine.dll
Represents a structure of of boolean expressions.
public class MacroRuleTree
- Inheritance
-
objectMacroRuleTree
- Extension Methods
Properties
Children
Gets or sets the child rules.
public List<MacroRuleTree> Children { get; set; }
Property Value
- List<MacroRuleTree>
HasPreviousSibling
Returns true if group has a previous sibling node.
public bool HasPreviousSibling { get; }
Property Value
- bool
IDPath
Returns IDPath of the group.
public string IDPath { get; }
Property Value
- string
IsLeaf
Returns true if group is a leaf (expression).
public bool IsLeaf { get; }
Property Value
- bool
Level
Returns level of the group.
public int Level { get; }
Property Value
- int
Operator
Gets or sets operator of the rule.
public string Operator { get; set; }
Property Value
- string
Parameters
Gets or sets the parameters of the rule (null for internal nodes).
public StringSafeDictionary<MacroRuleParameter> Parameters { get; set; }
Property Value
Parent
Gets or sets the parent.
public MacroRuleTree Parent { get; set; }
Property Value
Position
Gets or sets the relative position of the rule within the parent group.
public int Position { get; set; }
Property Value
- int
RuleCondition
Gets or sets the associated rule K# condition.
public string RuleCondition { get; set; }
Property Value
- string
RuleName
Gets or sets the associated rule name.
public string RuleName { get; set; }
Property Value
- string
RuleParameters
Gets or sets the associated rule parameters xml definition.
public string RuleParameters { get; set; }
Property Value
- string
RuleText
Gets or sets the associated rule text.
public string RuleText { get; set; }
Property Value
- string
Methods
Accept(Action<MacroRuleTree>)
Accepts an action that gets executed on the whole tree structure.
public void Accept(Action<MacroRuleTree> visitorAction)
Parameters
visitorAction
Action<MacroRuleTree>
AddRule(MacroRuleInfo, int)
Adds a new rule as a child of current node. Inserts the rule to the specified position.
public MacroRuleTree AddRule(MacroRuleInfo ruleInfo, int position)
Parameters
ruleInfo
MacroRuleInfoRule to add
position
intPosition of the rule within the group
Returns
AutoIndent()
Performs the autoindentation of the expression (according to priority of 'or' and 'and' operators).
public void AutoIndent()
GetCondition()
Returns the condition in K# representing this rule.
public string GetCondition()
Returns
- string
GetParameterText(string, bool, string, string, Func<object, object>)
Processes the text of parameter (handles multivalue parameters separated with new line).
public static string GetParameterText(string paramText, bool includingMarkup, string cssClass = null, string valueType = "text", Func<object, object> valueTransformation = null)
Parameters
paramText
stringParameter text
includingMarkup
boolIf true, rule is formatted using HTML markup
cssClass
stringClass which will be used (used only when includingMarkup is true), can be null
valueType
stringType of the parameter text value
valueTransformation
Func<object, object>Transformation function which is used to further modify the displayed parameter value
Returns
- string
GetRoot()
Returns the root of the rule tree.
public MacroRuleTree GetRoot()
Returns
GetRuleCondition(string, bool)
Returns rule as a human readable sentence. If the expression is Rule(...) method than it uses XML for the rule, otherwise returns expression as it is.
public static string GetRuleCondition(string ruleExpression, bool throwOnError = false)
Parameters
ruleExpression
stringRule expression to render.
throwOnError
boolIf true, the process throws an exception in case of parsing error.
Returns
- string
GetRuleText(MacroRuleTree, bool, Func<object, object>)
Returns rule as a human readable sentence.
public static string GetRuleText(MacroRuleTree rule, bool includingMarkup = false, Func<object, object> valueTransformation = null)
Parameters
rule
MacroRuleTreeRule to render
includingMarkup
boolIf true, rule is formatted using HTML markup
valueTransformation
Func<object, object>Transformation function which is used to further modify the displayed parameter value
Returns
- string
GetRuleText(string, bool, bool, Func<object, object>)
Returns rule as a human readable sentence. If the expression is Rule(...) method than it uses XML for the rule, otherwise returns expression as it is.
public static string GetRuleText(string ruleExpression, bool includingMarkup = true, bool throwOnError = false, Func<object, object> valueTransformation = null)
Parameters
ruleExpression
stringRule expression to render.
includingMarkup
boolIf true, rule is formatted using HTML markup
throwOnError
boolIf true, the exception is thrown in case of error in parsing the expression
valueTransformation
Func<object, object>Transformation function which is used to further modify the displayed parameter value
Returns
- string
GetXML()
Returns xml of the rule designer (to store the layout and parameters).
public virtual string GetXML()
Returns
- string
GetXMLInternal()
Returns xml of the rule designer (to store the layout and parameters).
protected string GetXMLInternal()
Returns
- string
Indent()
Indents the node with one level.
public void Indent()
LoadFromXml(string)
Loads MacroRuleTree from xml definition.
public virtual void LoadFromXml(string xml)
Parameters
xml
stringXML to build the designer from
MoveNode(string, string, int)
Moves the group to given location.
public void MoveNode(string sourcePath, string targetPath, int targetPos)
Parameters
sourcePath
stringPosition path of the source
targetPath
stringPosition path of the target
targetPos
intPosition within the target
RemoveBrackets(MacroRuleTree)
Removes brackets which are not needed.
public static void RemoveBrackets(MacroRuleTree node)
Parameters
node
MacroRuleTreeNode to process
RemoveNode(int, bool)
Adds given group as a new child.
public void RemoveNode(int position, bool removeParent = true)
Parameters
position
intRelative position within the children collection
removeParent
boolIf true, parent group will be removed if we removed last item within the group
ResetPositions()
Sets correct positions according to current state.
public void ResetPositions()
SetParameterValue(string, MacroRuleParameter)
Sets the parameter value.
public void SetParameterValue(string paramName, MacroRuleParameter parameter)
Parameters
paramName
stringName of the parameter
parameter
MacroRuleParameterParameter value
Unindent()
Unindents the node with one level.
public void Unindent()
ValidateParameters()
Returns list of rules which contain required parameters with empty value.
public string ValidateParameters()
Returns
- string