ISourceProvider Interface
Assembly: CodeEffects.Rule.Editor.dll
Namespace: CodeEffects.Rule.Editor.Models
Summary
Supplies the source elements of an Adaptive Source: a source object whose fields, methods, actions, enumerations, and data sources come from the host application instead of from a .NET type or a Source XML document. Its methods return ISourceElements, and it also supplies SourceObjectDisplayName, GetInlineRules, and GetSource.
Syntax
public interface ISourceProvider
Properties
SourceObjectDisplayName
Type: System.String
Gets the name people see for the source object, or null to use its class name. It is a label only. Changing it never changes the identity of the source, and the Rule Repository records a change as a label change, not as a new version.
SourceObjectTypeOrAliasName
Type: System.String
Gets the full type name or the alias name of the source object. It identifies the source wherever the source is stored, the Rule Repository included, so it must not change. Required.
Methods
GetAction
Returns: CodeEffects.Rule.Editor.Client.Function
Returns the metadata of a rule action referenced by a rule. The editor calls this method when it needs to resolve an action used by an execution type rule.
Parameters
- methodName (
System.String) - The "combined" name of the action (see Remarks below). It must match the Function.Value of the returned metadata.
GetDataSource
Returns: CodeEffects.Rule.Editor.Client.DataSource
Returns the Dynamic Menu Data Source with this name. A data source can be loaded from any place your application can reach, such as a database, an API, a configuration file, or a cache.
Parameters
- dataSourceName (
System.String) - The "combined" name of the data source (see Remarks below). It must match the DataSource.Name of the returned metadata.
GetEnum
Returns: CodeEffects.Rule.Editor.Client.Enum
Returns the metadata of an enumeration used by a field, a method parameter, or a method return value, with its members. An Adaptive Source does not make the editor reflect enumeration types, so your provider supplies them when the editor asks.
Parameters
- enumName (
System.String) - The "combined" name of the enumeration (see Remarks below). It must match the Enum.Name of the returned metadata.
GetField
Returns: CodeEffects.Rule.Editor.Client.Field
Returns the field with this name. The editor calls this method when it needs to resolve a field by name, usually while it loads or updates a stored Rule XML.
Parameters
- fieldName (
System.String) - The "combined" name of the field (see Remarks below). It must match the Field.Value of the returned metadata.
GetFieldsAndMethods
Returns: CodeEffects.Rule.Editor.Models.ISourceElements
Returns the fields and in-rule methods available in the condition section of the rule at the point the context describes. A reusable rule is offered here as a field with IsRule set.
Parameters
GetInlineRules
Returns: System.Collections.Generic.ICollection<CodeEffects.Rule.Editor.Models.MenuItem>
Returns the rules that a rule of this source can execute from its THEN and ELSE sections, listed by the Execute... item of the actions menu ("... and execute Rule Name"), or null for none. They should be rules of execution type; the editor does not enforce it. The editor calls this method whenever it sends its menus, including when it loads a stored rule, so an executed rule is shown by its name. It ignores the list in the Evaluation mode, an item without an ID, and the SourceName of every item. This is the Adaptive Source's counterpart of Control.InlineRules, which an Adaptive Source ignores.
Parameters
GetMethod
Returns: CodeEffects.Rule.Editor.Client.Function
Returns the in-rule method with this name. The editor calls this method when it needs to resolve an in-rule method by name.
Parameters
- methodName (
System.String) - The "combined" name of the method (see Remarks below). It must match the Function.Value of the returned metadata.
GetReusableRule
Returns: CodeEffects.Rule.Editor.Client.Field
Returns the reusable rule with this ID, as a field. The editor exposes a reusable rule as a Boolean field.
Parameters
- ruleID (
System.String) - The string value of the rule's GUID ID.
GetSetter
Returns: CodeEffects.Rule.Editor.Client.Field
Returns the settable field with this name. The editor calls this method when it needs to resolve a field used as a value setter in an execution type rule.
Parameters
- fieldName (
System.String) - The "combined" name of the setter (see Remarks below). It must match the Field.Value of the returned metadata.
GetSettersAndActions
Returns: CodeEffects.Rule.Editor.Models.ISourceElements
Returns the setters (fields) and actions (methods) available in the execution section of the rule at the point the context describes.
Parameters
GetSource
Returns: CodeEffects.Rule.Editor.Models.Source
Returns the whole source: every field, in-rule method, action, enumeration (with its members), and data source the provider can ever offer, whatever the context. The Rule Repository stores and versions an Adaptive Source from this result and indexes which rules use which of its members. The editor itself never calls this method. Control.GetSourceXml(ISourceProvider) writes the result as a Source XML document.
Parameters
ISourceProvider is the main implementation point of an Adaptive Source. To use an Adaptive Source, create a class that implements this interface and assign its instance to the Control.SourceProvider property, or pass it to a Control constructor:
var editor = new Control("divEditor");
editor.SourceProvider = new SourceProvider(typeof(YourSourceObject));
Setting SourceProvider tells the editor to use the Adaptive Source model. From that point on, the editor asks your provider for the rule metadata as the rule author creates, loads, or updates rules.
The provider has two main responsibilities:
- Generate dynamic menus based on the current rule context.
- Resolve existing rule elements referenced by Rule XML.
This allows the editor to work without loading the entire source object into the browser.
IMPORTANT! The Value properties of fields and methods, as well as the Name property of enumerations and data sources supplied by an Adaptive Source provider, use combined names. A combined name is in dot notation and consists of the source object's class name (or its alias name) followed by the declared name of the member.
The static methods of the Source class build fields, methods, data sources, and enumerations from a .NET type with combined names already in place. A provider whose model is a class can implement GetSource and the lookup methods on top of them.
Combined Name Example
// Source object
public class MySource
{
public int UserID { get; set; }
}
// Metadata of the UserID property
var field = new Field { Value = "MySource.UserID", DisplayName = "User ID" };