RuleEditor class

Namespace: CodeEffects.Rule.Mvc
Assembly: CodeEffects.Rule.dll

Provides core functionality for authoring and validating complex business rules in MVC web applications.

Syntax

public class RuleEditor : CodeEffects.Rule.Models.IControl

Properties

  • ClientOnly Type: System.Boolean

    Gets or sets the value indicating whether the Rule Editor should instantiate itself as a pure JavaScript object to be used in client-side web applications. The default value is False.

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

    Gets or sets the collection of reusable rules that will be added to the field context menu in the Rule Editor. Only rules of evaluation type should be added to this collection, which will appear in the menu as if they were regular fields. It's up to the developer to decide which existing evaluation type rules (if any) should be added to the context menu. See the reusable rules topic for details.

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

    Gets or sets the collection of named GetDataSourceDelegate delegates. Each delegate is represented in the collection by an instance of the DataSourceHolder class. See the customizable dynamic sources topic for details.

  • DeleteAction Type: System.String

    Gets or sets the name of the action that deletes a rule by its ID, which it takes as a parameter. The name of the parameter must be id.

    [HttpGet]
    public ActionResult Delete(string id)
    {
    	// Create a new model and store it in the bag
    	ViewBag.Rule = RuleModel.Create(typeof(SourceObjectType));
     
    	// Delete the rule by its ID
    	StorageService.DeleteRule(id);
     
    	ViewBag.Message = "The rule was deleted successfully";
    	return View("Index");
    }
  • DeleteController Type: System.String

    Gets or sets the name of the controller that declares DeleteAction.

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

    Gets or sets a collection of operators that should be excluded from the Rule Editor. Code Effects component is smart enough to include all necessary operators based on data types used by the source object. For example, if your source object doesn't use the System.DateTime type, Code Effects component will exclude all date operators from the client-side data it adds to the markup on page load. This saves bandwidth. But sometimes developers need to explicitly exclude certain operators for existing data types. The following code sample demonstrates how to exclude the string operators startsWith, doesntStartWith, endsWith, and doesntEndWith:

    [HttpGet]
    public ActionResult Index()
    {
    	// Create a new rule model and store it in the bag
    	ViewBag.Rule = RuleModel.Create(typeof(SourceObjectType));
     
    	// Store the excluded operators in the bag as well
    	List<Operator> excludedOperators = new List<Operator>();
    		excludedOperators.Add(
    			new Operator
    			{
    				Type = OperatorType.String,
    				ExcludedOperator =
    					ExcludedOperator.StartsWith |
    					ExcludedOperator.DoesNotStartWith |
    					ExcludedOperator.EndsWith |
    					ExcludedOperator.DoesNotEndWith
    			});
     
    	ViewBag.ExcludedOperators = excludedOperators;
     
    	return View();
    }
    <div>
    	@{
    		Html.CodeEffects().RuleEditor()
    			.Id("ruleEditor")
    			.SaveAction("Save""Test")
    			.DeleteAction("Delete""Test")
    			.LoadAction("Load""Test")
    			.Mode(RuleType.Execution)
    			.ExcludedOperators(ViewBag.ExcludedOperators)
    			.Rule(ViewBag.Rule)
    			.Render();
    	}
    </div>
  • HelpXml Type: System.Xml.XmlDocument

    Gets or sets the XmlDocument object that contains the custom help and validation messages shown in the Help String, as well as all UI labels and values used by the Rule Editor on the client. In Code Effects, this document is called Help XML. A copy of the default English Help XML document used in version 4.x can be found here.

  • HelpXmlFile Type: System.String

    Gets or sets the full path to the XML file that contains the custom Help XML. A copy of the default English Help XML document used in version 4.x can be found here. You can use your own custom Help XML by replacing the built-in document if you'd like to change the default English messages, or if Code Effects component is used in a multilingual project. To do that, first obtain the default XML document by calling RuleEditor.GetHelpXml(), then open the resulting string in any XML editor, edit the messages (but not the node names or document structure), save the file, and load it with Code Effects.

    IMPORTANT! You must use the main Index action to set the path to the custom Help XML file using the ViewBag or your model if you use Code Effects as a client-only component (the ClientOnly property is set to True) and want to set the path programmatically.

  • Id Type: System.String

    Gets or sets the Id of the RuleEditor. The SaveAction's parameter of the RuleModel type must have the same name as the Id of the RuleEditor in order for the built-in MVC form data conversion to work properly.

  • KeepDeclaredOrder Type: System.Boolean

    Gets or sets the value indicating whether the rule editor should alphabetically order fields and actions in menus or keep the order in which they are declared in the source object. The default value is False.

  • LoadAction Type: System.String

    Gets or sets the name of the action that loads a rule by its ID, which it takes as a parameter. The name of the parameter must be id.

    [HttpGet]
    public ActionResult Load(string id)
    {
    	// Load rule from the storage
    	string ruleXml = StorageService.LoadRuleXml(id);
     
    	// Create a new model and store it in the bag
    	ViewBag.Rule = RuleModel.Create(ruleXml, typeof(SourceObjectType));
     
    	ViewBag.Message = "The rule is loaded";
    	return View("Index");
    }
  • LoadController Type: System.String

    Gets or sets the name of the controller that declares LoadAction.

  • Mode Type: CodeEffects.Rule.Common.RuleType

    Gets or sets the current mode of the Rule Editor. The RuleType.Execution value allows rule authors to create both evaluation and execution type rules (in this mode the evaluation type is the default). The RuleType.Evaluation value restricts rule authors to evaluation type rules only. The RuleEditor.Filter value sets Code Effects up for data filtering. The default value is RuleType.Evaluation.

  • RuleModel Type: CodeEffects.Rule.Models.RuleModel

    Gets or sets an instance of the RuleModel, created on the server by a controller's action and passed down to the view as a property of either a ViewBag object or a view model.

  • SaveAction Type: System.String

    Gets or sets the name of the action that saves a rule, extracting the rule's data from the RuleModel, received as the action's parameter. The name of the parameter must match the Id property of the RuleEditor set by the view.

    // "ruleEditor" is the ID of the RuleEditor instance declared in the view.
    // The name of the action parameter must match that ID, even though RuleEditor
    // and RuleModel are two different types. This is MVC's default behavior.
    [HttpPost]
    public ActionResult Save(RuleModel ruleEditor)
    {
    	// At this point the rule model doesn't know
    	// which type to use as its source object.
    	// We need to "bind" the source type to the rule model
    	ruleEditor.BindSource(typeof(SourceObjectType));
     
    	// Add the rule model to the ViewBag object
    	ViewBag.Rule = ruleEditor;
     
    	// Make sure that the Rule Area is not empty and the current rule is valid
    	if(ruleEditor.IsEmpty() || !ruleEditor.IsValid(StorageService.LoadRuleXml))
    	{
    		ViewBag.Message = "The rule is empty or invalid";
    		return View("Index");
    	}
     
    	// Save the rule
    	StorageService.SaveRule(
    		ruleEditor.Id,
    		ruleEditor.GetRuleXml(),
    		ruleEditor.IsLoadedRuleOfEvalType == null ?
    			true : (bool)ruleEditor.IsLoadedRuleOfEvalType);
     
    	ViewBag.Message = "The rule was saved successfully";
    	return View("Index");
    }
  • SaveController Type: System.String

    Gets or sets the name of the controller that declares SaveAction.

  • ShowDescriptionsOnMouseHover Type: System.Boolean

    Gets or sets the value indicating whether the rule editor should display descriptions of actions, fields, in-rule methods, parameters of actions or in-rule methods and reusable rules when the rule author hovers the mouse over those elements in the Rule Editor. Element descriptions are optional. Developers can set them using the Description property of ActionAttribute, FieldAttribute, MethodAttribute, or ParameterAttribute respectively. The default value is True. Setting this property has no effect on rule evaluation.

  • ShowHelpString Type: System.Boolean

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

  • ShowLineDots Type: System.Boolean

    Gets or sets the value indicating whether the rule editor should display a period before each new line in the rule. The default value is False. Setting this property has no effect on rule evaluation.

  • ShowMenuOnElementClicked Type: System.Boolean

    Gets or sets the value indicating whether the rule editor should display the related context menu when the rule author clicks most rule elements. If True, this property allows rule authors to edit rule values, change fields, actions, operators and so on "on the fly", simply by clicking an element and selecting a replacement value from the menu. If there are no suitable items, the rule editor displays the menu for the next element (if any). The default value is True. Setting this property has no effect on rule evaluation.

  • ShowMenuOnRightArrowKey Type: System.Boolean

    Gets or sets the value indicating whether the rule editor should show a context menu that lists the next possible elements of the rule every time the rule author presses the Right Arrow key while browsing the current rule using the keyboard. Setting this value to True eliminates the need to hit the Space Bar to bring up the menu every time the author needs to insert a new rule element. The default value is True. Setting this property has no effect on rule evaluation.

  • ShowToolBar Type: System.Boolean

    Gets or sets the value indicating whether the rule editor should display its Toolbar. The default value is True. Setting this property has no effect on rule evaluation.

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

    Gets or sets the collection of existing rules that will be added to the Rules menu of the Toolbar. Adding rules to the Rules menu allows rule authors to select each rule in order to load it into the Rule Editor for editing or deletion. It's up to the developer which rules (if any) to add to this collection. This property is ignored if the ShowToolBar property is set to False.

Methods

  • GetClientInvalidData() Returns: System.String
    Parameters: None

    Returns a JSON string containing an array of rule elements that failed rule validation. Used in Ajax implementations of Code Effects. Certain client methods in the Ajax API consume data supplied by this method. Download any of the demo projects to see Code Effects implemented in an Ajax application.

  • GetClientRuleData() Returns: System.String
    Parameters: None

    Returns a JSON string containing elements of the rule. Used in Ajax implementations of Code Effects. Certain client methods in the Ajax API consume data supplied by this method. Download any of the demo projects to see Code Effects implemented in an Ajax application.

  • GetClientSettings() Returns: System.String
    Parameters: None

    Returns a JSON string containing all client settings that the Rule Editor needs in order to instantiate itself on the page after the page loads in the client. Used in Ajax implementations of Code Effects. Certain client methods in the Ajax API consume data supplied by this method. Download any of the demo projects to see Code Effects implemented in an Ajax application.

  • GetHelpXml() Returns: System.String
    Parameters: None

    Returns the current Help XML document as an XML string. Use this method if you'd like to obtain the default English Help XML used by your copy of Code Effects. You might want to do this if you'd like to use your own UI labels, messages, and values in a multilingual project. A copy of the default Help XML document used in version 4.x can be found here.

  • GetSourceXml() Returns: System.String
    Parameters: None

    Returns a Source XML document. This method can be used to obtain the Source XML in order to edit it manually.

  • LoadClientData(System.String) Returns: System.Void
    Parameters:
    • ruleClientData, System.String - JSON string that contains the current rule. See the Ajax Implementation example for details on how to obtain this string.

    Loads the rule into the server instance of Code Effects for further processing on the server. This method is used by the server-side code to deserialize the client data into the rule source when Code Effects component is used in an Ajax application. Download any of the demo projects to see Code Effects implemented in an Ajax application.

  • Render() Returns: System.Void
    Parameters: None

    Renders an instance of the RuleEditor on the client.

  • ToString() Returns: System.String
    Parameters: None

    Returns a string representation of the current rule.

  • ToString(Dictionary<String,GetDataSourceDelegate>) Returns: System.String
    Parameters:
    • dataSources,
      System.Collections.Generic.Dictionary<System.String, CodeEffects.Rule.Common.GetDataSourceDelegate> - A dictionary of Dynamic Menu Data Sources.

    Returns a string representation of the current rule. Takes a dictionary of data sources in order to get the proper display names if the current rule could use items of those sources as field values or action parameters.

  • ToString(CodeEffects.Rule.Core.GetRuleDelegate) Returns: System.String
    Parameters:
    • ruleDelegate, CodeEffects.Rule.Common.GetRuleDelegate - A delegate that takes a rule ID and returns the XML of that rule.

    Returns a string representation of the current rule. Takes the delegate that returns the Rule XML by rule ID in order to get the proper display names of all reusable rules that the current rule may reference.

  • ToString(CodeEffects.Rule.Core.GetRuleDelegate, Dictionary<String,GetDataSourceDelegate>) Returns: System.String
    Parameters:
    • ruleDelegate, CodeEffects.Rule.Common.GetRuleDelegate - A delegate that takes a rule ID and returns the XML of that rule.
    • dataSources,
      System.Collections.Generic.Dictionary<System.String, CodeEffects.Rule.Common.GetDataSourceDelegate> - A dictionary of Dynamic Menu Data Sources.

    Returns a string representation of the current rule. This overload "combines" the previous two.

    See description of the last ToString() overload of the Asp.RuleEditor for details on how to get the string representation of the current rule using the GetRuleDelegate and dictionary of Dynamic Menu Data Sources.

Post your support requests on Stackoverflow.com. You can also post your comments and product feedback using the form at the bottom of this page.
Comments: 0
Name (optional):
Comment (URLs are allowed and must start with http:// or https://; all tags will be encoded):
Remaining character count: