Below is one of top classes of winservice/remote rule application server.
Methods of this top class must handle exception and be rock-stable.
Instead of handling exception in every overloaded method "Rule"
I can pass anonymous method into one/major and handle exception there.
Here's sample :
using System;
using System.Collections.Generic;
using System.Text;
namespace BusinessRules.Reactor
{
/// <summary>
/// Control panel is central dispatcher and Rules-Runner
/// </summary>
public class ControlPanel
{
public Result Rule(int EnityType, string ReferenceID, int ruleid)
{
BasicProperties p = new BasicProperties();
p.ReferenceID = ReferenceID;
Result res = Rule(p, delegate() {return Storage.getRule(Storage.GetEntityID(EnityType, ReferenceID), ruleid); });
return res;
}
public Result Rule(RuleProperties RuleProperties ,int EnityType, string ReferenceID,int ruleid){
return Rule(RuleProperties, delegate() {
return
Storage.getRule(Storage.GetEntityID(EnityType, ReferenceID),
ruleid);});
}
public Result Rule(RuleProperties RuleProperties, int ruleid) {
return Rule(RuleProperties, delegate() { return Storage.getRule(ruleid); });
}
public delegate ConcreteRule GetRule();
public Result Rule(RuleProperties RuleProperties, GetRule rule_get){
Result res= new Result();
try
{
ConcreteRule rule = rule_get();
rule.Init((BasicProperties)RuleProperties);
rule.ApplyRule();
res = rule.Result;
}catch (AssertionException aex){
res.ExeptionHappend = aex.ToString();
res.Status = enResultStatus.Collision;
res.Description = aex.Message;
} catch ( Exception ex) {
res.ExeptionHappend = ex.ToString();
res.Status = enResultStatus.UnhandledException;
res.Description = ex.Message;
}
return res;
}
}
}