Control Class

Assembly: CodeEffects.Rule.Editor.dll
Namespace: CodeEffects.Rule.Editor

Summary

Provides the core server-side functionality of the Rule Editor for authoring, managing, and validating complex business rules in web applications.

Syntax

public class Control

Constructors

The constructors combine the same five optional parameters: the ID of the editor, the evaluation mode, a type resolver, a rule resolver, and a source provider. A parameter you leave out keeps its default. Every constructor sets these defaults: ShowToolBar, ShowHelpString, ShowMenuOnRightArrowKey, ShowMenuOnElementClicked, ShowDescriptionsOnMouseHover, and RuleNameIsRequired are true; UseHighestZindex, ShowLineDots, and KeepDeclaredOrder are false; ExcludedOperators, ContextMenuRules, InlineRules, and DataSources are empty collections; ToolBarRules is null.

Properties

  • ContextMenuRules

    Type: System.Collections.Generic.ICollection<MenuItem>

    Gets or sets the collection of reusable rules that can be added to the field menus in the Rule Editor. Only rules of the evaluation type should be included in this collection. Such rules appear in the field menu as regular fields of the System.Bool type. It is up to the developer to determine which existing evaluation-type rules, if any, should be made available in the context menu. An Adaptive Source ignores this property: its ISourceProvider returns reusable rules from GetFieldsAndMethods as fields with IsRule set and resolves them with GetReusableRule. This property is optional. The default value is an empty collection of type List<MenuItem>.

  • DataSources

    Type: System.Collections.Generic.ICollection<DataSourceHolder>

    Gets or sets the collection of named GetDataSourceDelegate delegates. Each delegate in the collection is represented by an instance of the DataSourceHolder class. See the Customizable Dynamic Data Sources topic for details. This property is optional. The default value is an empty collection of type List<DataSourceHolder>.

  • EvaluationMode

    Type: CodeEffects.Rule.Common.Models.EvaluationMode

    Gets or sets the current mode of the Rule Editor, which defines what kind of rules rule authors can create.

    The Evaluation value limits the editor to evaluation type rules. The Execution value allows both evaluation and execution type rules (in this mode, the evaluation type is the default). The Loop and Ruleset values select the other modes of the editor. The Filter value is deprecated. See the Understanding Modes topic for details.

    When you load a rule with LoadRuleData, the editor changes this value from Evaluation to Execution for a rule of execution type and from Execution to Evaluation for a rule of evaluation type. The default value is Evaluation.

  • ExcludedOperators

    Type: System.Collections.Generic.ICollection<Operator>

    Gets or sets the collection of operators that should be excluded from menus of the Rule Editor. The Rule Editor automatically includes only the operators required for the data types used by the source object. For example, if the source object does not contain any members of the System.DateTime type, the Rule Editor will automatically exclude all date operators from the client-side settings. However, developers may occasionally need to explicitly exclude certain operators for existing data types. The following code example demonstrates how to exclude the string operators startsWith, doesntStartWith, endsWith, and doesntEndWith:

      control.ExcludedOperators.Add(
      	new CodeEffects.Rule.Common.Models.Operator
      	{
      		Type = CodeEffects.Rule.Common.Models.OperatorType.String,
      		ExcludedOperator =
      			ExcludedOperator.StartsWith |
      			ExcludedOperator.DoesNotStartWith |
      			ExcludedOperator.EndsWith |
      			ExcludedOperator.DoesNotEndWith
      	});
    

    This property is optional. The default value is an empty collection of type List<Operator>.

  • GetRuleDelegate

    Type: CodeEffects.Rule.Common.Models.GetRuleDelegate

    Deprecated. This property will be removed in one of the future versions. Use RuleResolver instead.

  • HelpXml

    Type: System.Xml.XmlDocument

    Gets or sets the XmlDocument object that contains custom help, warning, and validation messages used in the Help String, as well as all UI labels and values displayed by the Rule Editor in the Rule Area. In Code Effects, this document is referred to as Help XML. It plays a key role in providing multilingual support.

    By default, the editor uses the English version of the Help XML document compiled into the CodeEffects.Rule.Editor.dll assembly. You can load this default document by calling the GetDefaultHelpXml() method in debugger mode, save its OuterXml string, and use it as a template for translation into other languages or to modify the default English version as needed.

    For more information, see the Help XML and Multilingual Support topic.

  • HelpXmlFile

    Type: System.String

    Gets or sets the full path to the XML file that contains the customized Help XML document.

  • ID

    Type: System.String

    Gets or sets the ID of the HTML element that hosts the Rule Editor on the client.

  • InlineRules

    Type: System.Collections.Generic.ICollection<MenuItem>

    Gets or sets the collection of rules that a rule of execution type can execute from its THEN and ELSE sections. The editor lists them under the Execute... item of the actions menu ("... and execute Rule Name"). This collection should contain only rules of execution type; the editor does not enforce it. The Rule Engine runs an executed rule in place and in order, and discards its result. The editor ignores this property in the Evaluation mode and for an Adaptive Source, whose provider supplies the rules with GetInlineRules. This property is optional. The default value is an empty collection of type List<MenuItem>.

  • IsAdaptiveSource

    Type: System.Boolean

    Gets a value indicating whether the editor uses an Adaptive Source. It is true after you set SourceProvider to an instance of ISourceProvider and false when you set it back to null.

  • IsEmpty

    Type: System.Boolean

    Gets a value indicating whether the Rule Area is empty (contains no rule elements).

  • IsValid

    Type: System.Boolean

    Gets a value indicating whether the submitted rule has passed automatic validation. The Rule Editor performs automatic validation each time a rule is submitted. If validation fails, the Rule Area highlights all invalid rule elements, and rule authors can hover the mouse pointer over each invalid element to view a description of the corresponding validation issue. If enabled, the Help String displays a relevant error message. The default English descriptions and messages can be customized by modifying the Help XML document.

  • KeepDeclaredOrder

    Type: System.Boolean

    Gets or sets a value indicating whether the Rule Editor should alphabetically order fields, in-rule methods, and rule actions in menus, or retain the order in which they are declared in the source object. The default value is false.

  • Rule

    Type: CodeEffects.Rule.Editor.Models.RuleModel

    Gets the instance of the rule that is currently loaded in the Rule Editor. The property has no public setter; the editor sets it when you load a rule with one of the Load... methods.

  • RuleGetter

    Type: CodeEffects.Rule.Common.Models.GetRuleDelegate

    Deprecated. This property will be removed in one of the future versions. Use RuleResolver instead.

  • RuleNameIsRequired

    Type: System.Boolean

    Gets or sets the value indicating whether Rule Editor should require each rule to have a name when the rule author uses Toolbar to save or update a rule. The default value is true. This property is ignored if the ShowToolBar is set to false. Value of this property has no effect on rule evaluation.

  • RuleResolver

    Type: CodeEffects.Rule.Common.Models.GetRuleDelegate

    Delegate used to request missing rules — rules that are referenced but not included in the current rule set. This property is optional.

    Remarks

    In some cases, such as rules that use reference-typed collections and arrays, the editor creates separate rule nodes in RuleXML for each referenced collection because its ElementType is essentially another source object for the rule. Those rule nodes are included in the resulting RuleXML of the main rule, so the RuleResolver delegate is not needed in that scenario.

    However, if, for instance, you use the reusable rules feature and do not manually add to the main Rule XML all reusable rules referenced by the main rule before loading it into the editor, you need a RuleResolver delegate. The editor calls this delegate whenever it needs a referenced reusable rule, allowing your code to query rule storage and return the requested rule.

  • ShowDescriptionsOnMouseHover

    Type: System.Boolean

    Gets or sets a value indicating whether the Rule Editor should display descriptions of rule actions, fields, in-rule methods, parameters of actions or in-rule methods, and reusable rules when the rule author hovers the mouse pointer over those elements in the Rule Area.

    Element descriptions are optional and can be defined using the Description property of the ActionAttribute, FieldAttribute, MethodAttribute, or ParameterAttribute.

    The default value is true. The value of this property has no effect on rule evaluation.

  • ShowHelpString

    Type: System.Boolean

    Gets or sets a value indicating whether the Rule Editor should display the Help String located between the Toolbar and the Rule Area. The default value is true. The value of this property has no effect on rule evaluation.

  • ShowLineDots

    Type: System.Boolean

    Gets or sets a value indicating whether the Rule Editor should display a • character before each new line in the Rule Area. The default value is false. The value of this property has no effect on rule evaluation.

  • ShowMenuOnElementClicked

    Type: System.Boolean

    Gets or sets a value indicating whether the Rule Editor should display the related context menu when the rule author clicks elements of the current rule. If set to true, this property allows rule authors to edit rule values and modify fields, actions, operators, and other rule elements on the fly by clicking an element and selecting a replacement value from the context menu. If no suitable items are available, the Rule Editor displays the menu for the next applicable element (if any). The default value is true. The value of this property has no effect on rule evaluation.

  • ShowMenuOnRightArrowKey

    Type: System.Boolean

    Gets or sets a value indicating whether the Rule Editor should display a context menu listing the next possible rule elements each time the rule author presses the Right Arrow key while navigating the current rule using the keyboard. When set to true, this property eliminates the need to press the Spacebar to open the menu whenever a new rule element needs to be inserted. The default value is true. The value of this property has no effect on rule evaluation.

  • SourceLabelsXml

    Type: System.Xml.XmlDocument

    Gets or sets the source labels document: the display names and descriptions of the source object's fields, in-rule methods, actions, parameters and enumeration values in another language. Each label names its member by identity, never by its display name: a field by its property path, a method or action by its name and parameters, an enumeration value by its type and number. The editor shows the labels wherever people read the source (the menus, the rule's text, the descriptions and the Help String), while the Rule XML keeps naming members by their declared names, so a rule saved in one language opens in any other. A member the document leaves out keeps the source's own name. It takes precedence over SourceLabelsXmlFile.

    Get a document to translate from Xml.GetSourceLabelsDocument(..). For more information, see the Help XML and Multilingual Support topic.

  • SourceLabelsXmlFile

    Type: System.String

    Gets or sets the full physical path to the file that holds the source labels document. It is ignored when SourceLabelsXml is set. A file that is not well-formed XML throws a MalformedXmlException with the control number CE10261.

  • ShowToolBar

    Type: System.Boolean

    Gets or sets a value indicating whether the Rule Editor should display its Toolbar. The default value is true. Setting this property to false also sets RuleNameIsRequired to false, because a rule cannot be named without the Toolbar. The value of this property has no effect on rule evaluation.

  • SourceAssembly

    Type: System.String

    Deprecated. This property is obsolete and will be removed in a future major version. Instead, use the SourceTypeName property and set it to the source object's AssemblyQualifiedName. The getter always returns null.

  • SourceProvider

    Type: CodeEffects.Rule.Editor.Models.ISourceProvider

    Gets or sets the provider the editor lists the elements of an Adaptive Source from: the fields, in-rule methods, setters, actions, reusable rules, enumerations, and data sources of the source object. Setting it to a provider switches the editor to the Adaptive Source model, and the editor then ignores SourceType, SourceTypeName, SourceXml, SourceXmlFile, ContextMenuRules, and InlineRules. Setting it to null switches the model back. The default value is null.

      var editor = new Control("divEditor");
      editor.SourceProvider = new MySourceProvider();
    
  • SourceType

    Type: System.Type

    Gets or sets the type of the source object. This property is required in Reflection and FlexSource source models and optional in Adaptive Source if no value is set for any of the SourceXml, SourceTypeName, or SourceXmlFile properties.

      private Control GetEditor()
      {
      	var ce = new Control("divClientEditorContainerId");
    
      	ce.SourceType = typeof(MySourceObject);
      	ce.EvaluationMode = CodeEffects.Rule.Common.Models.EvaluationMode.Execution;
      	ce.ShowHelpString = true;
      	ce.ShowToolBar = true;
      	ce.ShowLineDots = true;
    
      	return ce;
      }
    
  • SourceTypeName

    Type: System.String

    Gets or sets the assembly-qualified name of the source object type. This property is required in Reflection and FlexSource source models and optional in Adaptive Source if no value is set for any of the SourceXml, SourceType, or SourceXmlFile properties. You can obtain the assembly-qualified name of the source object type by executing:

      sourceObjectInstance.GetType().AssemblyQualifiedName;
    
  • SourceXml

    Type: System.Xml.XmlDocument

    Gets or sets the XmlDocument that defines the structure of the source object. In Code Effects, this document is referred to as Source XML. You can obtain the string representation of the Source XML at any time by calling the GetSourceXml() method of the instance of the Control class.

  • SourceXmlFile

    Type: System.String

    Gets or sets the full path to the custom XML file that defines the source object. In Code Effects, this document is referred to as Source XML. You can obtain the string representation of the Source XML at any time by calling the GetSourceXml() method of the instance of the Control class and use it as a template for source object customization in dynamic scenarios.

  • ToolBarRules

    Type: System.Collections.Generic.ICollection<MenuItem>

    Gets or sets the collection of existing rules that can be added to the Rules menu of the Toolbar, if it is displayed. Adding rules to the Rules menu allows rule authors to select, load, edit, or delete existing rules directly within the Rule Editor. It is up to the developer to determine which rules, if any, should be included in this collection. This property is ignored if the ShowToolBar property is set to false. The default value is null.

    Collection item

  • TypeResolver

    Type: CodeEffects.Rule.Common.Models.GetTypeDelegate

    Gets or sets the delegate used to resolve .NET types by their assembly-qualified or alias names in the editor and during rule evaluation. Assign this property when your application uses custom type aliases or requires custom type resolution logic. This property is optional. See the main Type Handling and Aliasing article for details.

  • UseHighestZindex

    Type: System.Boolean

    Gets or sets a value indicating whether the Rule Editor should calculate and apply the highest zIndex for its pop-up elements such as menus, date pickers, and similar controls. Set this property to true only if your script dynamically adds other DOM elements that could potentially obscure the editor’s controls and menus. The default value is false.

Methods

  • FillSource

    Returns: System.Void

    Fills a Source with the elements of one ISourceElements set. The method copies the cache ID and the fields, puts the methods in Source.Functions for the Conditions section or in Source.Actions for the Executions section, and then asks the SourceProvider for every enumeration and data source the elements use and adds them. It is public so you can generate the JSON of a source yourself; SourceProvider must be set before you call it.

    Parameters

  • GetAdaptiveData

    Returns: System.String

    Returns a JSON string with the source elements of an Adaptive Source for one section of a rule at the point the context describes: the fields and in-rule methods of a condition, or the setters and actions of an execution, with the enumerations and data sources they use. Hosts that send the editor its menus on demand call this method from the endpoint the editor requests them from. The method asks the SourceProvider for the elements, adds the rules from GetInlineRules for modes other than Evaluation, and orders the elements by display name unless KeepDeclaredOrder is true. Throws a SourceException if SourceProvider is not set. The returned JSON is safe to write into an inline <script> block, as the result of GetEditorData is.

    Parameters

  • GetClientInvalidData

    Returns: System.String

    Deprecated. This method will be removed in one of the future versions. Use GetInvalidData() instead.

    Parameters

    • None.
  • GetClientRuleData

    Returns: System.String

    Deprecated. This method will be removed in one of the future versions. Use GetRuleData() instead.

    Parameters

    • None.
  • GetClientSettings

    Returns: System.String

    Deprecated. This method will be removed in one of the future versions. Use GetEditorData() instead.

    Parameters

    • None.
  • GetDefaultHelpXml

    Returns: System.Xml.XmlDocument

    Returns the default Help XML document compiled into the CodeEffects.Rule.Editor.dll assembly. Use it as a template for translating the editor's messages and labels, or for changing the default English ones.

    Parameters

    • None.
  • GetEditorData

    Returns: System.String

    Returns a JSON string containing the source object member information required by the Rule Editor to complete its initialization during page load. Pass the returned JSON to the editor’s loadSettings() method of the Client-Side API to load the source object data when initializing the editor for the first time.

    Parameters

    • None.

    Remarks

    The returned JSON is safe to write into an inline <script> block: the characters < and > are escaped as \u003c and \u003e, so a name that contains markup cannot end the script block. The escapes parse back to the same values.

    This code examples demonstrate how to initialize the editor on the client using the data from the server endpoint:

      // Server endpoint
    
      api.MapGet("/api/settings", () =>
      {
      	var settings = new MySettings();
      	var editor = new Control("divEditor");
      	editor.SourceType = typeof(MySourceObject);
    
      	// Get UI settings for the editor (Help String, UI labels, etc)
      	settings.EditorData = editor.GetGlobalData();
    
      	// Get the source data for the editor
      	settings.SourceData = editor.GetEditorData();
    
      	return Results.Ok(settings);
      });
    
      // Client-side js
    
      // Declare the editor as a global var
      var editor = null;
    
      async function settings()
      {
      	const res = await fetch('/api/settings', { headers: { 'Accept': 'application/json' } });
      	const settings = await res.json();
      	// Init and clear the editor
      	editor = $rule.init(settings.editorData);
      	editor.clear();
      	// Attach rule action handlers
      	// All code examples above show implementation of these action methods
      	editor.setCallbacks(load, remove, save);
      	// Load the source data into the editor
      	editor.loadSettings(settings.sourceData);
      };
    
      // Call the settings() function when the page loads to init the editor
      settings();
    

    Refer to the Code Effects Client-Side API topic and the Code Effects demo project repos for implementation details.

  • GetGlobalData

    Returns: System.String

    Returns a JSON string containing the current environment information, UI messages and labels, mode details, and other data required by the Rule Editor to complete its initialization after the page is loaded. Pass the returned string to the $rule.init() global method of the Client-Side API before initializing the Rule Editor.

    Parameters

    • None.

    Remarks

    The returned JSON is safe to write into an inline <script> block: the characters < and > are escaped as \u003c and \u003e, so a name that contains markup cannot end the script block. The escapes parse back to the same values.

  • GetInitialSettings

    Returns: System.String

    Deprecated. This method will be removed in one of the future versions. Use GetGlobalData() instead.

    Parameters

    • None.
  • GetInvalidData

    Returns: System.String

    Returns a JSON string containing an array of rule elements that failed validation.

    Parameters

    • None.

    Remarks

    The returned JSON is safe to write into an inline <script> block: the characters < and > are escaped as \u003c and \u003e. The method returns null if the rule is empty or valid.

    The following C# example demonstrates an ASP.NET endpoint that saves a rule. Note the use of both the IsValid property and the GetInvalidData() method to return invalid rule elements to the client:

      api.MapPost("/api/save", ([FromBody] string rule) =>
      {
      	// Using the Reflection source model
      	var editor = new Control("divEditor");
      	editor.SourceType = typeof(MySourceObject);
    
      	editor.LoadRuleData(rule);
      	var response = new MyResponse(); // See our demo projects for implementation details
    
      	if(editor.IsEmpty) { response.IsRuleEmpty = true; }
      	else if(!editor.IsValid)
      	{
      		response.IsRuleValid = false;
    
      		// Load invalid elements from the editor
      		response.ClientInvalidData = editor.GetInvalidData();
      	}
      	else
      	{
      		// See our demo projects for the rule storage implementation details
      		MyStorage[editor.Rule.ID] = new Rule
      		{
      			Eval = editor.Rule.IsEvalType.HasValue && editor.Rule.IsEvalType.Value,
      			Name = editor.Rule.Name,
      			RuleXml = editor.GetRuleXml()
      		};
      		// Using the Output value to send rule ID back to client
      		response.Output = editor.Rule.ID;
      	}
      	return Results.Ok(response);
      });
    

    The following JavaScript excerpt demonstrates how the client calls the /api/save endpoint and handles the response, including invalid rule elements if the rule is invalid:

      // The "rule" is supplied by the editor
      async function save(rule)
      {
      	const response = await fetch(
      		'/api/save',
      		{
      			method: 'POST',
      			headers:
      			{
      				'Content-Type': 'application/json'
      			},
      			body: JSON.stringify(rule)
      		});
    
      	const data = await response.json();
    
      	if (data.isRuleEmpty)
      	{
      		alert("The rule is empty");
      	}
      	else if (!data.isRuleValid)
      	{
      		editor.loadInvalids(data.clientInvalidData);
      		alert("The rule is invalid");
      	}
      	else
      	{
      		// Server returns the new rule ID using the Output property.
      		// You are free to use any value for that. The editor needs this ID.
      		editor.saved(data.output);
      		alert("The rule was saved successfully");
      	}
      };
    

    Refer to the Code Effects Client-Side API topic and the Code Effects demo project repos for implementation details.

  • GetRuleData

    Returns: System.String

    Returns a JSON string containing an array of rule elements used to load the rule into the Rule Area, or null if the rule is empty. With an Adaptive Source, the string also carries the source elements the rule uses, so the editor can display a stored rule. Pass it to the loadRule() method of the Client-Side API.

    Parameters

    • None.

    Remarks

    The returned JSON is safe to write into an inline <script> block: the characters < and > are escaped as \u003c and \u003e, so a name that contains markup cannot end the script block. The escapes parse back to the same values.

    The following C# example demonstrates an ASP.NET endpoint that receives a rule ID and returns the data required to load that rule on the client:

      api.MapGet("/api/load/{ruleId}", (string ruleId) =>
      {
      	MyStorage.TryGetValue(ruleId, out var ruleXml);
    
      	var editor = new Control("divEditor");
      	editor.SourceType = typeof(MySourceObject);
      	editor.LoadRuleXml(ruleXml);
    
      	// Returns the rule data to the client
      	return Results.Ok(editor.GetRuleData());
      });
    

    This JavaScript excerpt shows how the client calls the /api/load endpoint and loads the rule into the editor:

      // The ruleId is supplied by the editor
      async function load(ruleId)
      {
      	const res = await fetch(`/api/load/${encodeURIComponent(ruleId)}`);
      	const data = await res.json();
      	editor.loadRule(data); // Load the rule
      };
    

    Refer to the Code Effects Client-Side API topic and the Code Effects demo project repos for implementation details.

  • GetRuleXml

    Returns: System.String

    Returns a string containing the Rule XML document of the rule currently loaded in the Rule Editor, or null if the rule is empty. Throws a RuleException if no rule has been loaded into the editor yet. Check the IsValid property to ensure that the current rule is valid before calling this method; otherwise, an InvalidRuleException will be thrown. Use the returned string to store the rule in a database as a varchar(max) or XML type or in a file system as an XML or txt file. This is the same string you pass to all evaluation classes to evaluate the rule. You can also use this string to load the rule into the Rule Editor for editing or deletion.

    Parameters

    • None.
  • GetSourceXml

    Returns: System.String

    Returns a string containing the Source XML document the editor uses. Use this method to obtain the Source XML for manual editing or as a template for creating other sources in dynamic scenarios. It returns null if the editor uses an Adaptive Source; use the static overload that takes an ISourceProvider instead.

    Parameters

    • None.
  • GetSourceXml (static)

    Returns: System.String

    Returns the Source XML document of an Adaptive Source as a string: everything the provider's GetSource() lists, enumerations with their members, in the format a type's document has. The editor itself only sees an Adaptive Source one context at a time. This method gives the whole source, which is what lets the Rule Repository store, version, and index it. It needs no Control instance.

    Parameters

  • GetSourceXml (static)

    Returns: System.String

    Returns the Source XML document of a source object type as a string: the document an instance of this class uses when its SourceType is set to that type. It needs no Control instance. Throws a SourceException if the type is null.

    Parameters

    • sourceType (System.Type) - The type of the source object.
    • typeResolver (CodeEffects.Rule.Common.Models.GetTypeDelegate) - Optional. Loads types the source names by alias or from assemblies the application does not load by name, as the TypeResolver property does. The default value is null.

    Example

      string sourceXml = Control.GetSourceXml(typeof(MySourceObject));
    
  • LoadClientData

    Returns: System.Void

    Deprecated. This method will be removed in one of the future versions. Use LoadRuleData() instead.

    Parameters

    • ruleClientData (System.String) - A JSON string containing the current rule returned by the client’s $rule.extract() method.
  • LoadHelpXml

    Returns: System.Xml.XmlDocument

    Returns the Help XML document the editor uses and keeps it in the HelpXml property. It returns HelpXml if it is set, otherwise loads the file in HelpXmlFile, and otherwise returns the default document. Throws a MalformedXmlException if the file cannot be loaded or is malformed. The path in HelpXmlFile must be a full physical path.

    Parameters

    • None.
  • LoadRuleData

    Returns: System.Void

    Loads the rule into the instance of the Rule Editor for further processing on the server.

    Parameters

    • ruleClientData (System.String) - A JSON string containing the current rule returned by the client’s $rule.extract() method. See the Client-Side API for details.

    Remarks

    Loading the rule can change EvaluationMode to match the type of the rule. The method does nothing if the string is null or empty.

  • LoadRuleFile

    Returns: System.Void

    Loads the XML file containing the Rule XML into the instance of the Rule Editor.

    Parameters

    • ruleXmlFileFullPath (System.String) - The full path to the file containing the XML rule document.
  • LoadRuleFile

    Returns: System.Void

    Deprecated. This overload will be removed in a future version. Set Control.RuleResolver to GetRuleDelegate and call the overload that takes only the full path of the Rule XML file.

    Parameters

  • LoadRuleXml

    Returns: System.Void

    Loads the XML string containing the Rule XML document into the instance of the Rule Editor.

    Parameters

    • ruleXml (System.String) - The rule XML document as a string.

    With an Adaptive Source, the editor takes the source elements the rule uses from the SourceProvider.

  • LoadRuleXml

    Returns: System.Void

    Deprecated. This overload will be removed in a future version. Set Control.RuleResolver to GetRuleDelegate and call the overload that takes only the Rule XML.

    Parameters

  • ToString

    Returns: System.String

    Returns the string representation of the current rule, written in the language of the editor's Help XML. Returns an empty string if the rule is empty. With an Adaptive Source, the method takes the source elements from the loaded rule.

    Parameters

    • None.
  • ToString

    Returns: System.String

    Returns the string representation of the current rule. Accepts a dictionary of dynamic menu data sources to retrieve the correct display names when the rule references items from those sources. Throws a SourceException if the editor uses an Adaptive Source; use the parameterless overload then.

    Parameters

    • dataSources (System.Collections.Generic.Dictionary<System.String, CodeEffects.Rule.Editor.Models.GetDataSourceDelegate>) - A dictionary of dynamic menu data sources.

    Example

      using System.Collections.Generic;
      using CodeEffects.Rule.Common.Attributes;
      using CodeEffects.Rule.Editor;
      using CodeEffects.Rule.Editor.Client;
      using CodeEffects.Rule.Editor.Models;
    
      [Data("Education", typeof(Utility), "GetSchools")]
      public class Test
      {
      	public string GetRuleDefinition(string ruleId)
      	{
      		var editor = new Control("divEditorContainerId");
      		editor.SourceType = typeof(Test);
      		editor.LoadRuleXml(MyStorage.GetRuleByID(ruleId));
    
      		var sources = new Dictionary<string, GetDataSourceDelegate>();
      		sources.Add("Education", Utility.GetSchools);
    
      		return editor.ToString(sources);
      	}
      }
    
      public class Utility
      {
      	public static List<DataSourceItem> GetSchools()
      	{
      		var schools = new List<DataSourceItem>();
      		schools.Add(new DataSourceItem(1, "School # 1"));
      		schools.Add(new DataSourceItem(2, "School # 2"));
      		return schools;
      	}
      }
    
  • ToString

    Returns: System.String

    Deprecated. This overload will be removed in a future version. Set Control.RuleResolver to GetRuleDelegate and call the parameterless overload.

    Parameters

  • ToString

    Returns: System.String

    Deprecated. This overload will be removed in a future version. Set Control.RuleResolver to GetRuleDelegate and call the overload that takes only the data sources dictionary.

    Parameters

    • ruleDelegate (CodeEffects.Rule.Common.Models.GetRuleDelegate) - Sets the RuleResolver property.
    • dataSources (System.Collections.Generic.Dictionary<System.String, CodeEffects.Rule.Editor.Models.GetDataSourceDelegate>) - A dictionary of dynamic menu data sources.

Example

The following example creates an editor for a source object type and returns everything the client needs to start it:

var editor = new Control("divEditor", CodeEffects.Rule.Common.Models.EvaluationMode.Execution);
editor.SourceType = typeof(MySourceObject);

string globalData = editor.GetGlobalData(); // pass to $rule.init() on the client
string editorData = editor.GetEditorData(); // pass to loadSettings() on the client

Ask on Stack Overflow - Yes, it's still active
Ask in GitHub Discussions

p102

l097 --

l102

p101

×