Welcome to tankete.com Sign in | Join | Help

José Lema

Inside the Community Server development team

Shared Posts


Badges



  • www.flickr.com
    This is a Flickr badge showing public photos from tankete. Make your own badge here.
Merlin: Let There Be Code!

This is part six of a series on Merlin. I recommend you read from the beginning.

So after all this thinking, planning, and testing, I was finally going to get my hands dirty! Recalling the pseudo-code that I'd written just a couple of nights earlier, I decided to flush out some of the remaining objects. That said, I did choose to skip the Context object for now since I wasn't too sure about how it would play out. Here's what I was left with:

public abstract class Condition
{
    public abstract bool Evaluate();
}

public abstract class Action
{
    public abstract void Execute();
}

public class Rule
{
    ...
    public void Run()
    {
        if (condition.Evaluate())
            action.Execute();
    }
}

Since I was going to start with the "engine" in the middle, saving the UI for last, I decided to "fake it" for the time being. And since I wanted to keep it simple, I only created a couple of conditions and a single action, none of which were overly complex. My communityserver.config file ended up looking something like this:

...
<CSModules>
    <add name="Merlin - My First Rule" type="JoseLema.Merlin.MerlinModule, JoseLema.Merlin">
        <rule name="My First Rule">
            <condition type="JoseLema.Merlin.TrueCondition, JoseLema.Merlin" />
            <action type="JoseLema.Merlin.NullAction, JoseLema.Merlin" />
        </rule>
    </add>
    <add name="Merlin - My Second Rule" type="JoseLema.Merlin.MerlinModule, JoseLema.Merlin">
        <rule name="My Second Rule">
            <condition type="JoseLema.Merlin.FalseCondition, JoseLema.Merlin" />
            <action type="JoseLema.Merlin.NullAction, JoseLema.Merlin" />
        </rule>
    </add>
</CSModules>
...

As you might imagine, the implementation for these new rule parts was trivial:

public class TrueCondition : Condition
{
    public override bool Evaluate()
    {
        return true;
    }
}

public class FalseCondition : Condition
{
    public override bool Evaluate()
    {
        return false;
    }
}

public class NullAction : Action
{
    public override void Execute()
    {
        // Do Nothing
    }
}

With a note to myself about hiding these simple rule parts from the UI, I was ready to begin the task of parsing...   (continued)

Posted: Friday, September 22, 2006 1:30 PM by Jose
Filed under: ,

Comments

Community Server Daily News said:

news of the day a grab bag for what's happening in Community Server Telligent's Dan Hounshell describes
# September 25, 2006 4:28 PM

Daily News Faq List said:

Telligent's Dan Hounshell describes Jose Lema's recent writing as "A Developing Cliff-hanger." In last

# November 22, 2006 11:15 AM

Community Server Bits said:

Telligent's Dan Hounshell describes Jose Lema's recent writing as "A Developing Cliff-hanger." In last

# March 12, 2007 11:21 AM
New Comments to this post are disabled