Tuesday, April 24, 2007

Enterprise Library 3.0 Policy Injection

A couple posts ago, I wrote about Enterprise Library 3.0. I blogged about the two new blocks, Validation and Policy injection, then I discussed the validation block. Today I am going to talk about the policy injection block a bit.

The policy injection block is Patterns and Practices way of dealing with crosscutting concerns and aspect oriented programming (AOP). I want to make clear that the Policy Injection block is NOT an AOP framework. One of the first questions asked is "What is a crosscutting concern?". A concern is a feature of the application. Concerns that implement features of an object within the application like business logic is a core concern. Crosscutting concerns are features that are common across different objects, like logging and instrumentation. Policy Injection separates the core concerns from the crosscutting concerns.

So lets say I have a business class Called Foo with a method A. Every time method A is called I want to log the time it was called and who executed the call and what data was given to the method parameters and what was returned. Well using policy injection I can apply a policy to the method that automatically executes before and after execution of A. This policy will handle all the logging of required data using the logging block of course.

How does it work? Well that is the interesting part. You see, when a client wants to consume Foo the client needs to call policy factory to get the Foo object. the factory then decides if the class has policies and if so it really creates a Proxy to Foo. The Proxy of Foo looks to the client just like the object Foo, however when the client calls A the proxy can fire all pre and post handlers of the policy, the logging information needed, along with calling A on Foo.

So that is policy injection in a nutshell. As you can see it is a very powerful tool. One problem however, is it makes the code a little more difficult to read. When reading a class a method will be tagged as having a policy, but there is no information on what that policy is. The developer is required to do some hunting to understand it all.

Monday, April 23, 2007

Archos 604

Last week I bought an Archos 604 personal video player. I really wanted a music and video player I could travel with. Many people told me I should look at the video IPod , but to be honest the screen on it was way to small.

So I was narrowed my choices between the Archos 604, the 604 wifi, and the Cowon A2. There were a lot of features that all three of the players supported. They include the ability to play movies, and music, record off tv, browse photo slide shows, and read PDFs. Although the Archos supported a few more media types that the Cowon. All the players sported a 30gb drive. This is a little small by today's standards but large enough for my needs.

The reason I ended up picking the Archos players over the Cowon because I new for sure all my music and video would play on the player. I am not saying my music wouldn't play on the Cowon but I couldn't find all the file types I needed listed on their website.

So now I had to pick between the wifi version and the non wifi version. On the surface the wifi version jumped out at me. The unit could browse the internet and also act as a go between your tv and computer streaming media back and forth. These options sounded cool until I though a little more about it. First why would I need to browse the internet? I have a cell phone that can do that and I rarely use it. Plus on airplane you are not allowed to use your wifi. So I started thinking about the media streaming and decided I don't need that. I can already stream video and music through my XBox 360. Also; while reading reviews for both players I found the the screen on the wifi version did not have as dark of blacks.

After about a week of use, I have been satisfied. I use it with yahoo music anywhere, and have any song I could possible want. I haven't found a online video store that I like yet, but I have been recording TV programs and DVDs to the device. Playback is good, and with some trial and error I even got good sound levels.

Friday, April 13, 2007


At work during lunch we have been playing Sheepshead. It is an interesting card game that most of us learned while growing up playing with out parents and grandparents.

Sheepshead is a trick taking game, played with a 32 card Deck. The cards are all suits 7 through Ace. Although there are many variations to the game the most common way to play is five handed with Jack of diamonds as the pickers partner.

What makes Sheepshead so fun is the game strategy. Know what cards to play and when to play them. In most trick games, the idae is to take tricks, but in Sheepshead the idea is to get points. To win a hand the picker and partner needs 61 points out of 120 total points. Points are won by winning tricks with the following cards:
Aces = 11
tens = 10
Kings = 4
queens = 3
Jacks = 2
every other card = 0.
What makes this more complex is cards that tend to have power to take tricks, usually are lower in points. for example, the most powerful card in the game is the Queen of Clubs, but it is worth only three points.
there are 4 suits in the game, Trump, Clubs, Spades, and Hearts.
There are 14 trump cards, and 6 cards of the other suits. The power cards are the trump cards and suits are all about the same. So the rankings are as follows:
QC, QS, QH, QD, JC, JS, JH, JD, AD, 10D, KD, 9D, 8D, 7D
For all other suits it goes...
A, 10, K, 9, 8, 7
Fail cards rank in power by type only, suit does not play a part in fail card rankings.

So the play goes as follows, each player is dealt 6 cards, with 2 cards going in the blind. The cards can be dealt anyway the dealer chooses as long as the bottom cards are not dealt to the blind. Usually cards are dealt two, or three at a time. Once the deal is complete, the person on to the left of the dealer gets first choice at the blind. If that person does not pick the next person has the chance. This goes on until the cards are picked or the dealer passes the pick. If this happens them commonly a leaster is played. I will not discuss leasters in this post. So once the cards are picked, the person who picks must now win 61 points to win the hand. Also the player holding the Jack of Diamonds is the pickers partner. At the start of the game no one knows who the picker's partner is. Once this is done the player to the left of the dealer leads. Everyone else must follow suit unless they don't hold that suit. The player who wins the trick always leads the next trick. The game is played until all tricks are won. Then the points of tricks are added up to determine if the picker won.

If the picker and partner got 61+ points the picker is awarded 2 point to his score, and the partner is awarded 1 point. All the other players will be minus 1 point. If the picker and partner does not get 61 points then the picker is minus 2 points, the partner is minus 1 point and all other players are plus one point.

If the picker and partner get 91+ points then they schneidered the opposition. If this happens all points won and lost are doubled. If the picker and partner no trick the opposition then points won and lost are tripled. This work in reverse also, so if the picker and partner does not get 30+ points then they lose double, and if no tricked they lose triple.

So as I said the game is easy it is the strategy that is tough. I will from time to time discuss hand strategy that comes up while playing at sheepshed.

Sunday, April 08, 2007

Enterprise Library 3.0

Enterprise Libary 3.0

Last week Enterprise Library 3.0 was released.

Enterprise library is a package of eight application blocks. The blocks include Caching, Cryptography, Data Access, Exception Handling, Logging, Security, Validation, and Policy Injection. These blocks are small frameworks that implement enterprise patterns that help make developing enterprise applications easier. The Enterprise Library also includes a set of core functions, including configuration, instrumentation, and object builder services. These functions are used by all other application blocks.

Of all the new blocks the two that jump out at me are Validation, and Policy Injection. They are new to version 3.0.

Validation Block
Validation has many applications. For example, you can use it to prevent the injection of malicious data by checking to see if a string is too long or if it contains illegal characters. You can also use validation to enforce business rules and to provide responses to user input. It is often important to validate data several times within the same application. For example, you may need to validate data at the UI layer to give immediate feedback when a user enters an invalid data value, and again at the service interface layer for security

The Validation Application Block is designed to allow you to easily validate objects. In many situations, you can validate an object with a single line of code. The following example shows how to associate a validator with an object and how to validate that object.
using Microsoft.Practices.EnterpriseLibrary.Validation;
using Microsoft.Practices.EnterpriseLibrary.Validation.Validators;
public class Customer
[StringLengthValidator(0, 20)]
public string CustomerName;

public Customer(string customerName)
this.CustomerName = customerName;

public class MyExample
public static void Main()
Customer myCustomer = new Customer("A name that is too long");
ValidationResults r = Validation.Validate(myCustomer);
if (!r.IsValid)
throw new InvalidOperationException("Validation error found.");

Because the StringLengthValidator attribute is applied, the Validation Block checks that the length of the customer name is between 0 and 20 characters. The application creates a new Customer object and validates it using the Validation Block fa├žade. In this case, the customer name is illegal because it is too long. The application throws an exception that notifies you of the error.

The Validation Application Block has the following benefits:

  • It helps maintain consistent validation practices.
  • It includes validators for validating most standard .NET data types.
  • It allows you to create validation rules with configuration, with attributes, and with code.
  • It allows you to associate multiple rule sets with the same class and with members of that class.
  • It can be integrated with ASP.NET, Windows Forms, and Windows Communications Foundation (WCF).
I will talk about the policy injection block in another post. I have not used it yet and really don't have much knowledge of it.

Friday, April 06, 2007

Interview Questions

At work, we have been discussing the role of FizzBuzz question during the interview process. We started the discussion in reference to the following blog posts.

Post 1.
Post 2.

I thought I would add my two cents to the mix.

While I think a candidate for a developer position should be able to solve FizzBuzz questions, I don't think FizzBuzz questions are fare during an interview.

I think what is more beneficial is to ask a candidate about their past work projects. Get them to white board, and ask the candidate questions that will show if he/she really understood the business problem and the solution. Question them about why they did A, or if they thought about using B… and so on.

As developers we do have resources (Google, Msdn, Blogs, ...) that we can use to do our jobs, so why would we expect interviewees to know something that could be easily looked up. It is impossible to memorize everything and to judge someone by how fast they come up with an answer to a question is foolish. I know a co-worker even stated that when asked questions like this, usually the first thing he does is try to figure out if it is a trick question and he looks at the problem from a lot of different ways until he decided the easy basic answer is right. It takes him some time to do this but I think this process is better than someone just taking answering the question with the easy basic answer.

So there are my thoughts to it all.

Tuesday, April 03, 2007

Brewers Rock the House

Opening Day
Yesterday was opening day and the Milwaukee Brewers won 7-1.

Ben Sheets threw a two hit nine inning gem. Rickie Weeks got the first hit of the year and also scored the first run. Bill Hall collected the first RBI and HR of the season. He also had a web gem in center field robbing a sure hit in the gap on a diving catch.

Some thoughts about the Brewers.
1. I think they will win 87 games this year
2. I think 3H Hall, Hardy, and Hart are going to have solid production this year.
3. Estrada is going to open eyes here in MKE. Who new a catcher could swing a bat. He is going to be a solid addition to a lineup that at time last year struggled to hit in key situations.
4. Sheets looks healthy and throwing well.
5. Weeks' defense has improved
6. Fielder's deserves more credit on his defense. He made a couple nice plays yesterday.
7. Jenkins walk up to the plate music is Crazy Bitch by Buchcherry. Interesting only because the lyrics must be censored out and only the music is played.
8. Jenkins could have a good year if he only faces righties.

That is it for now. Go Brewers.