Thursday, March 18, 2010

The Conditional Logic Module

Say you want to make your rules conditional , meaning that you want your rules to be executed when certain criteria are valid for a given object. That is implemented at eXpand.ExpressApp.ConditionalLogic.dll assembly.

I have extend ILogicRule interface like

public interface IConditionalLogicRule : ILogicRule

{

    /// <summary>

    /// Criteria to apply when show DetailView or filled ListView

    /// </summary>

    string NormalCriteria { get; set; }

 

    /// <summary>

    /// Criteria to apply when show ListView empty

    /// </summary>

    string EmptyCriteria { get; set; }

}

and create derived classes

1.from LogicAttribute

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

public abstract class ConditionalLogicRuleAttribute:LogicAttribute, IConditionalLogicRule {

    protected ConditionalLogicRuleAttribute(string id, Nesting targetViewNesting, string normalCriteria, string emptyCriteria, ViewType viewType, string viewId) : base(id, targetViewNesting,  viewType, viewId) {

        NormalCriteria = normalCriteria;

        EmptyCriteria = emptyCriteria;

    }

    /// <summary>

    /// Criteria to apply when show DetailView or filled ListView

    /// </summary>

    public string NormalCriteria { get; set; }

    /// <summary>

    /// Criteria to apply when show ListView empty

    /// </summary>

    public string EmptyCriteria { get; set; }

 

}

2.from LogicRuleNodeWrapper

public abstract class ConditionalLogicRuleNodeWrapper : LogicRuleNodeWrapper, IConditionalLogicRule {

    public const string NormalCriteriaAttribute = "NormalCriteria";

    public const string EmptyCriteriaAttribute = "EmptyCriteria";

 

    protected ConditionalLogicRuleNodeWrapper(DictionaryNode ruleNode)

        : base(ruleNode) {

    }

    #region IConditionalLogicRule Members

    public string NormalCriteria {

        get { return Node.GetAttributeValue(NormalCriteriaAttribute); }

        set { Node.SetAttribute(NormalCriteriaAttribute, value); }

    }

 

    public string EmptyCriteria {

        get { return Node.GetAttributeValue(EmptyCriteriaAttribute); }

        set { Node.SetAttribute(EmptyCriteriaAttribute, value); }

    }

    #endregion

}

I did the same for the other require classes so now we have a structure we can inherit if we want to create conditional logic rules.

In the next post I am going to speak how I inherited that structure to refactor AdditionalViewControlsProvider upon it.

Subscribe to XAF feed
Subscribe to community feed

DiggIt!
blog comments powered by Disqus