Featured Post

Deep Fried Bytes Episode 11: Talking Security with Microsoft’s M

Listen To This Episode   Last week Woody and I were at DevLink 2008.  While we were there we recorded several episodes that will be coming out soon.  The first to come out is a great conversation with Joe Stagner about security.  While Joe works for Microsoft, don’t let that fool you because he’s...

Read More

Building an English-Based Rules Engine in .NET with IronRuby Slides and Demo

Posted by Keith Elder | Posted in .Net, C#, CodeMash, IronRuby, Presentations, Speaking | Posted on 19-01-2012

3

As promised at CodeMash to those that attended my session I finally am getting around to getting the slides and demo from my talk posted to my web server. You can download everything at this URL location:

http://keithelder.net/Presentations/RulesEngineWithIronRuby/RulesEngineWithIronRuby.zip 

What you will need to run the demo:

  • Visual Studio 2010

To run the demo you should be able unzip it, open it up in Visual Studio and hit F5.

Once the demo opens you’ll be presented with this.

SNAGHTML29cde5e7

In the middle of the screen you’ll see sample rules for the survey already loaded.

To convert these rules to Ruby script click on the “SurveyRuleSet” option listed under “Rule Sets”. This will load all of the available rules for that rule set.

SNAGHTML29d09da1

Once you have the rules loaded for the SurveyRuleSet you can then click “Convert To Ruby Script” button and the English text in the middle of the page will be converted into Ruby Script.

SNAGHTML29d205e5

Once you have the Ruby script generated click the “Use Script in Survey”.

SNAGHTML29d4666b

This will open a form that has questions and answers.

SNAGHTML29d5267f

Once the form is open just press “Submit” and the rules will fire. You can close the form, change the rules, re-gen the script and then re-run the form to see new rule values run.

When the “Submit” button on the Survey form is called, this is when the IronRuby engine gets invoked.

You can also load the SouthernRuleSet and then load the pre-typed Southern rules to see a “Southern DSL” of the same rules.

In Visual Studio you can open the SurveyRuleSet.cs file and uncomment the other attributes to enable Spanish instead of English (just as an example).

DISCLAIMER

What you should try to take away from this the most are what it is doing and what is possible. We are running something very similar to this in production so this isn’t smoke and mirrors. There are a lot of things that are missing in the demo, but they are completely doable with some additional work. For example grouping isn’t done in this example, other rules like greater than, lesser than etc could all be added to the base ruleset class. Use your imagination and go wild.

Enjoy.

Deep Fried Bytes Episode #63: Multiparadigmatic C# with Ted Neward

Posted by Keith Elder | Posted in C#, Podcast | Posted on 15-02-2011

Tags: ,

0

alt

http://tinyurl.com/deepfried63

In this episode we sit down to discuss Multiparadigmatic C# with Ted Neward.  Yes it is a long word but C# has grown from “just” an object-oriented language into a language that is capable of expressing several different paradigms of software development: object-oriented, functional, and dynamic.

Writing Unit or Integration Tests That Rely on Events Firing

Posted by Keith Elder | Posted in .Net, C# | Posted on 22-10-2010

1

For the past week or so I’ve been working on wrapping the Sonic API to simplify it for developers at my company.  The API itself is pretty much a straight port from Java.  There is nothing C# about the API.  For example no enumerations, no generics, no nothing.  This means when you are using the API you see functions that take a parameter that is just an integer since there are no enumerations for example.  That wouldn’t be so bad if the code was documented in the proper C# way but it isn’t.  So, instead of having 100+ developers at work learn how Sonic works I have been coding up several scenarios that we need to support for the business. 

In my quest to wrap the Sonic API into a more C# centric approach I needed to write some tests obviously to make sure things were working.  Primarily these are integration tests as each test relies upon connecting to a Sonic dev environment. 

If you aren’t familiar with Sonic it is an enterprise messaging platform.  It does pub/sub, supports queues, fault tolerate and so on.  I think the stock market even uses Sonic to route messages so it has a proven track record. 

One of the scenarios I had to cover was I needed to send a message to a queue and then have that message pulled out of the queue on the other side, processed and acknowledged.  In order to do this there is one object that sends a message, and another object that is listening for a message(s).   But how do you write a test that waits on an event to happen?  Well, it turns out we’d done this before in other tests but I couldn’t for the life of me remember how.  So here’s how it works. 

Using an EventWaitHandle we can wait on an event to occur.  First is to create a handle.

   1: EventWaitHandle handle = new ManualResetEvent(false);

Using the handle we can tell it to WaitOne() which blocks the current thread until the WaitHandle receives a signal.

   1: handle.WaitOne();

Then inside our event we simply call handle.Set() (this is the signal). 

Putting all of this together we can write an integration test that sends a message to Sonic and then waits for that message to come through.  Obviously the Sonic piece doesn’t really matter, the important piece here is how to get a test to wait for an event.  Putting it all together it looks like this.

   1: [TestMethod]

   2: public void Can_Send_To_Queue_And_Receive_Message_From_Queue()

   3: {

   4:     EventWaitHandle handle = new ManualResetEvent(false);

   5:     SonicQueueSender sender = new SonicQueueSender(Helpers.SonicQueueArgs);

   6:     string sendMsg = "test";

   7:     sender.SendMessage(sendMsg, SonicDeliveryMode.NonPersistent);

   8:     SonicQueueReceiver consumer = new SonicQueueReceiver(Helpers.SonicQueueArgs);

   9:     string receiveMsg = "";

  10:     consumer.MessageRecieved += (mySender, args) =>

  11:         {

  12:             TextMessage txtMsg = (TextMessage)args.Message;

  13:             receiveMsg = txtMsg.getText();

  14:             handle.Set();

  15:         };

  16:     consumer.StartListener();

  17:     handle.WaitOne();

  18:     Assert.AreEqual(receiveMsg, sendMsg);

  19: }

Hope this helps someone out.

TechEd 2010 .NET From Scratch Slides

Posted by Keith Elder | Posted in .Net, Asp.Net, C#, Mobile Devices, Presentations, Smart Clients, Speaking, SQL Server, TechEd, Visual Studio, WCF, Web Services | Posted on 18-06-2010

0

TechEd 2010 was in New Orleans last week and I had the pleasure of doing a full day pre-conf session at TechEd.  Pre-confs are longer sessions where attendees can get into more details.  This year I did “.NET From Scratch” which was a one day session to introduce developers to the .NET platform. 

This seminar is for anyone who is starting at ground zero with .NET and wants a deep dive into the platform starting from scratch. It is designed for developers experienced in at least one other language, and starts with the basics of . NET and covers Microsoft Visual Studio, writing code in C#, and how to build applications in various technologies of the platform such as Windows, Web, Microsoft Silverlight, and Windows Mobile. If you are new to writing applications on Microsoft .NET, what better way to start your Tech·Ed experience?

As promised to the attendees, the slide decks and demos can be downloaded from the following URL:

http://keithelder.net/presentations/NETFromScratch/NETFromScratch.zip

Remember when learning a new platform as large as .NET the main thing to focus on are your immediate needs.  That may be a language and a framework and possibly web programming.  It is impossible to learn or know everything about a platform as large as .NET but knowing what is possible is half of the battle.  As engineers if we know it is possible it is just a matter of research to figure out how to make it happen. 

A big thank you to those that attended the session and I am truly sorry about how cold it was in the room.  If I’d known in advance I’d brought some firewood and blankets.  Enjoy.

Deep Fried Bytes Episode #50: Behind the Scenes of the .NET Languages with Luca Bolognese

Posted by Keith Elder | Posted in .Net, C#, Podcast | Posted on 06-04-2010

1

 
http://deepfriedbytes.com/podcast/episode-50-behind-the-scenes-of-the-net-languages-with-luca-bolognese/

 

 

Ever wonder how your favorite features from C#, VB.NET and F# get selected, implemented and finally reach your fingers? We did too and we found a great person to get the behind the scenes story from Building 41 in Redmond. In this episode, we sat down with Luca Bolognese, former Group Program Manager at Microsoft, to discuss how the languages team decides which features to include in the .NET languages.  We learn also what is coming in NET 4.  Join us for this episode as we uncover some hints on what may be coming in the .NET future, something you don’t want to miss!