Monday, March 15, 2010

The Logic Module

Xaf architecture and especially the model part is great. What it really teach us is how to parameterized our logic/behavior/code and store that parameter in the model in the form of attributes on already existing nodes or on rule nodes see Xaf Validation system or ConditionalEditorState system. eXpand has provided a similar architecture through its ModelArtifactState module.

But after you start using such “ruling” modules for some times the most “logical” question will come into your mind.

How I could define a uniform way of describing a behavior in terms of an interface and apply a ruling system upon it.

The above problem exactly is address by logic module. What it does ? First look at ILogicRule interface

public interface ILogicRule

{

    string ID { get; set; }

    string ExecutionContextGroup { get; set; }

    ViewType ViewType { get; set; }

    Nesting Nesting { get; set; }

    string Description { get; set; }

    ITypeInfo TypeInfo { get; set; }

    string ViewId { get; set; }

    int Index { get; set; }

}

So given the properties of the above interface the logic system expects you to provide

1. A LogicAttribute derived class so you can apply it above your domain object classes

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)]

public abstract class LogicAttribute : Attribute, ILogicRule

{

    protected LogicAttribute(string id,Nesting targetViewNesting, ViewType viewType,string viewId)

    {

        ViewId = viewId;

        ID=id;

        ViewType = viewType;

        Nesting = targetViewNesting;  

    }

    string ILogicRule.ExecutionContextGroup { get; set; }

    public ViewType ViewType { get; set; }

    public Nesting Nesting { get; set; }

    public string ID { get; set; }

    public string Description { get; set; }

    ITypeInfo ILogicRule.TypeInfo { get; set; }

    public string ViewId { get; set; }

    public int Index { get; set; }

}

2.A LogicRule derived class

public abstract class LogicRule : ILogicRule

{

    readonly ILogicRule _logicRule;

 

    protected LogicRule(ILogicRule logicRule){

        _logicRule = logicRule;

    }

 

    public string ID {

        get { return _logicRule.ID; }

        set { _logicRule.ID = value; }

    }

 

    public string ExecutionContextGroup {

        get { return _logicRule.ExecutionContextGroup; }

        set { _logicRule.ExecutionContextGroup = value; }

    }

 

    public ViewType ViewType {

        get { return _logicRule.ViewType; }

        set { _logicRule.ViewType = value; }

    }

 

    public Nesting Nesting {

        get { return _logicRule.Nesting; }

        set { _logicRule.Nesting = value; }

    }

 

    public string Description {

        get { return _logicRule.Description; }

        set { _logicRule.Description = value; }

    }

 

    public ITypeInfo TypeInfo {

        get { return _logicRule.TypeInfo; }

        set { _logicRule.TypeInfo = value; }

    }

 

    public string ViewId {

        get { return _logicRule.ViewId; }

        set { _logicRule.ViewId = value; }

    }

    public int Index

    {

        get { return _logicRule.Index; }

        set { _logicRule.Index = value; }

    }

 

}

3.a LogicRuleNodeWrapper, derived class so you can control the model

image

image

4.A LogicRulePermission derived class so you can control your behavior from the xaf security system

image

as you see all expected classes should implement the same interface such achieving polymorphism ..

So given that you have provided the above classes then Rule Logic system will attach to the events defined by the following contexts

[Flags]

public enum ExecutionContext

{

    All=0,

    ViewChanging=2,

    ObjectChanged=4,

    ObjectSpaceReloaded=8,

    CurrentObjectChanged=16,

    ViewControlsCreated=32,

    ViewActivated=64,

    ViewControlAdding=128,

    TemplateViewChanged=256

}

and for the rule that are valid according to the ExecutionContextGroup and all other properties defined at I LogicRule interface it will provide a method within a controller to override and place your own logic for that spesific rule.

public override void ExecuteRule(LogicRuleInfo<IActionStateRule> logicRuleInfo, ExecutionContext executionContext) {

    //put your logic here

}

In the next post I ll speak about how I extended the logic module to create the conditional logic module. The logic module is exposed by eXpand.ExpressApp.Logic.dll assembly

Subscribe to XAF feed
Subscribe to community feed

DiggIt!
blog comments powered by Disqus