Show Navigation
Next Topic »
Working with Source XML
IMPORTANT Generic methods with generic params cannot be used in Source XML as in-rule methods or rule actions. Use plain .Net class(es) if your source object declares generic methods.
The source object classes topic demonstrates how easy it is to use any existing or newly declared public .NET class as a source object for your business rules, but sometimes you need finer control over your source objects. This is where Source XML plays a major role.
As soon as Rule Editor receives the type of the source object, it reflects and validates it. The result is an XML document known as Source XML. Rule Editor uses that document to hold information about your source object.
You can create such a document manually and pass it to Rule Editor as its source object. There are several reasons why you would want to do this:
- If you want to skip the processing of the same source object on every load of the page.
- If you'd like to display fields, in-rule methods, and actions of your rules in multiple languages.
- If you need almost complete control over the nature of the data Rule Editor sends to the client.
You can create Source XML in one of two ways:
-
If you already have a .NET class that you'd like to use as a template for your Source XML, then simply register Rule Editor on a test web page, set the SourceType property of the RuleEditor class to the type of your template class as shown here, run that page in the debugger, and extract the Source XML into a string variable by calling RuleEditor's GetSourceXml() method. Edit that XML document as needed, validate the result against its schema, and save it in your file system or database. Then reuse it with Rule Editor as shown below.
string sourceXml = ruleEditor.GetSourceXml();
YourStorage.SaveSourceXmlAs("C:\MySourceXml.config", sourceXml);
YourStorage.SaveSourceXmlInDatabase(sourceXml);
-
Another way to generate Source XML is to create it manually from scratch against its schema
IMPORTANT! As of version 3.0, Rule Editor employs schema versioning for rules and source objects by specifying different namespace URLs for different versions.
You can load an existing Source XML document into Rule Editor as its source object by setting the value of either the RuleEditor.SourceXmlFile or RuleEditor.SourceXml property. (See the topic on RuleEditor class for details.)
string sourceXmlString = YourStorage.GetSourceXmlSomehow();
System.Xml.XmlDocument source = new XmlDocument();
source.Load(sourceXmlString);
CodeEffects.Rule.Web.RuleEditor editor = new RuleEditor("divRuleEditor")
{
SourceXml = source
};
Obviously, different source objects use different Source XML documents. In multilingual applications, the use of Source XML is the only way to set different display names for rule fields, in-rule methods and actions based on the user's culture or preference.
Post your questions on
Stackoverflow and become a part of our growing community
Comments:
0
|
|