Multiple Rule 'Sets'

Topics: Developer Forum
Mar 30, 2007 at 2:28 PM
Edited Mar 30, 2007 at 2:30 PM
Hi Simon,

Just started taking a look at your framework and it's looking pretty good so far:)

A question...a client of mine operates as an application provider as in they distribute client winforms applications out to users at a variety of companies and all those users talk to single farm of servers over web services. The issue arises because the companies all have seperate rule sets (although there are some common rules in there) now this is less of a problem from a client application point of view since they could distribute with the appropriate set of rules....more of a problem with the server since that would interact with data from\and would perhaps need to server side validate data from the different companies...

Hope some of the above rambling makes sense! :)

Any thoughts on how best to manage this?

Thanks,

- Andrew
Apr 1, 2007 at 4:47 AM
Edited Apr 1, 2007 at 4:53 AM
Andrew

Unfortunately that is difficult. I will go though a few options

Adding and removing rules at runtime
It is possible to add and remove rules at runtime with code. So you could defining the rules for each company in separate XML files. Then, when each request comes in, apply the rules, for the company in question, using the ConfigurationService. After a request you would clear out the rules for the type. The problem with this approach is that to stop different groups of rules interfering with each other, on other threads, you would have to do some thread locking during the period of each validation. While this bottleneck may be satisfactory depending on the frequency of requests the purist in me cringes from such an ugly solution.

Using inheritance and property copying
Having a base class and then a class for each company that inherits from that base class would allow you to apply rules in any way you like. At run time you would have to cast/convert from the base class to the appropriate child class based on the company. The child class would have the validation rules. The casting could be done either with reflection, if you prefer smaller amount of generic code, or through copying individual properties, if you prefer performance.

Though the use of a rule set
I have been toying with the idea of functionality that allows the grouping of rules or, as you described, a “rule set”. This would allow a rule to have string(s) that identify what rule set(s) it exists in. Then code would need to be added allow validation based on a rule set. As you can see this is only conceptual at the moment. If you feel it would be a good feature feel free to raise an issue as a feature request. Or you could code it up yourself ;)

Hope all that makes sense and sorry about the essay.

Regards Simon
Apr 2, 2007 at 12:00 PM
Edited Sep 25, 2007 at 1:27 PM
Andrew

I had a think about the RuleSet functionality and decided it was a good idea. A first cut of this functionality is now checked in.
Apr 2, 2007 at 1:41 PM
I would rather an essay than a one liner! Thanks for taking the time out to respond.

The rule set thing would be most useful I think, means I could have a set of Universal rules plus sets for each company. I can get away without this functionality initially although I will need it in the next few months so I'll put a feature request in:)

Thanks for your help...

- Andrew
Apr 2, 2007 at 2:14 PM

SimonCropp wrote:
Andrew

I had a think about the RuleSet functionality and decided it was a good idea. A first cut of this functionality is not checked in.


Excellent!! :)

I've got roughly a month to implement a validation mechanism and plug in the rules, how does that fit with your ETA for this functionality? Not trying to pin you down or anything (!!) just trying to get a handle when roughly that might be.

Thanks,

- Andrew
Apr 2, 2007 at 11:09 PM
The initial source is already checked in. http://www.codeplex.com/ValidationFramework/SourceControl/ListDownloadableCommits.aspx
I would appreciate some feedback on it if you have time.
I still need to write some more unit tests and doco.
Should have the next release out by the 17th.
Apr 4, 2007 at 7:58 AM
Edited Apr 4, 2007 at 7:59 AM
Morning Simon,

Downloaded source yesterday thanks, will give it a bash today, I'll let you know how I get on!

Do you have a more real world example XML rules file that you could get to me? Particularly something with some custom rules in there.

Thanks,

- Andrew
Apr 4, 2007 at 8:25 AM
Do you have any code examples of this Rule Set mechanism? Thx!
Apr 4, 2007 at 10:53 AM
Morning Simon,

A question...I have an XML that looks like this...

<?xml version="1.0" encoding="utf-8" ?>
<validationMapping xmlns="urn:validationFramework-validationDefinition-1.5">
<class typeName="Property.Common.Entities.Policy, Property.Common.Entities">
<property name="PolicyNumber">
<rule typeName="RequiredStringRuleConfigReader"/>
</property>
</class>
</validationMapping>

In ConfigurationService.Process methods things are failing at...

if (classData.Methods.Length > 0) // classData.Methods is null since I have no method validation

I can comment out the ProcessMethods call in AddValidated documents for now to get me going.

Looks like a bug?

Thanks,

- Andrew
Apr 4, 2007 at 1:30 PM
Re. something like this...

IList<ValidationResult> results = propertyValidationManager.GetResultsInErrorForProperty("StartDate");

Is it possible to get a list of all property errors in one hit?

Thanks,

- Andrew

P.S. Apologies for all the questions!
Apr 4, 2007 at 3:59 PM
Last one today I promise:)

We have a document containing entities in the following structure...

Assessment (which is the Root Entity and contains a member called AssessmentType)
Assessment-->Policy (1 to 1)

Some property values in Policy are mandatory depending on the AssessmentType.

I am not able to navigate backwards from Policy to Assessment to pick up this information:(

Any thoughts on how I might achieve this? (Apart from providing a link backwards, that is possible but it's not in code I have access to at present!)

Thanks,

- Andrew



Apr 5, 2007 at 5:57 AM
This discussion has been copied to Work Item 9383. You may wish to continue further discussion there.
Apr 5, 2007 at 6:22 AM
1. Using Xml to add rules.
I just checked in a sample of how to do this for a CustomRule
Validation\SamplesLibrary\Configuration\CustomRuleConfigReaderSample.cs

2. RuleSet Sample
Checked in a sample. Start the SampleApp project and click the ruleSet button. Or have a look at
Validation\SampleApp\RuleSetForm.cs

3. ConfiguationService problem
Correct. That is a bug. I have checked in a fix and added that case to the unit tests.

4. Get a list of all property errors in one hit
have a look at PropertyValidationManager.ValidatorResultsInError

5. Policy / Assessment problem
If policy needs to be aware of its Assessment to perform validation you will need to add a link. I will have a think on this. There may be some other solutions.
Apr 5, 2007 at 7:56 AM
Thanks for the information and fix!

I have started implementing some rules this morning and all looking good so far:)

Have a good Easter holiday!

- Andrew
Apr 5, 2007 at 1:25 PM
Good luck
And Happy Easter to you too.