Taswar Bhatti
The synonyms of software simplicity
DD-WRT

This post is more of a geeky type of post about the awesome DD-WRT firmware. And how I set up two wireless router to talk to each other without wires.

So, yesterday the digiturk web tv set-top box arrived, that my wife purchased for Onur (our son, who is only 1 year old now) to watch “Turkish” television, basically the box runs windows CE and has an internet jack that requires you to plug in to get IPTV from the web.

The problem is that our TV is located on the main floor while our office is downstairs in the basement where all internet connection is located, cable modem with the linux version of linksys wireless WRT54GL to provide wireless to our laptop on the main floor.

Now in order for me to provide internet for this new set-top box I need to either pull an ethernet wire all the way up or use the existing cable coax to the TV and move my modem and linksys upstairs, and I was thinking wouldn’t it be great if I can use my old WRT54G (without linux which I was selling on kijiji, and some guy was trying to offer me $20 bucks for it, glad I didnt take his offer) just plug it up there with the set-top box and have it talk to my linux WRT54GL wirelessly to go to the internet.

So that got me thinking and googling for a solution and I found out about WDS (Wireless Distributed System) and how to set it up.

To get started I flashed my v8 CDFF version of my linksys WRT54G with the dd-wrt as listed here

Once I got that running, I had to flash my WRT54GL with the same dd-wrt, you want to have the same version of firmware running on both.

After that I had to follow this techinque of setting it up for my 54GL router to talk to the 54G router, although that cost me  to go to bed around midnight to get it all working, even though I was proud of achieving it, my wife was like “weren’t it suppose to take only half an hour?”

It always that “geek factor” where you say, just half and hour I will be there and half hour turns to 2 hours later 🙂 But I did go to bed smiling that I got it working, and thinking about what I can do next with it, maybe set up VOIP etc, just need to investigate more into DD-WRT.

Now I just need digiturk to enable my service at their end to let my son watch some Turkish TV, it makes me wonder why would you send a box and not enable the serial number to login to your system, but that’s another story or post for bureaucracy in this world of large co-op, how disfunctional they are.

From all of this my lesson learned is, estimation of hacking/software setup stuff always doesn’t take half an hour 🙂

Working Effectively with Legacy Code

When doing unit testing, one always comes to a point where there this “kind of hard” part to test since the part depends on something you might not have control over or depends on the functionality of the dependency to complete.

In “Working Effectively with Legacy Code” by Michael C. Feathers talks about a dependency breaking technique called “Extract and Override” which is also in Roy Osherove book “Art of Unit Testing“.

The basic technique is quite simple and quite powerful as Roy puts it

Extract & Override is a very powerful technique because it lets you deal directly with replacing the dependency without going down the rabbit hole at all (changing dependencies deep inside the call stack). That makes it very quick and clean to perform, almost to the point where it corrupts your good sense of object oriented aesthetics, leading you to code that might even have less interfaces but more virtual methods.” (Art of Unit Testing, pg.50)

In this post I am going to show a simple example of how to use the extract and override method, lets say for example you have an Order Class and it has a dependency call User as shown below

For us to test out the Add method we have a dependency that calls and checks if the user is valid, this basically makes it pretty hard to test, unless you refactor your code to use an interface IUser, pass it in the constructor and mock the user with a Mocking Framework or hand write the stub but lets say you don’t have access to User or some other reason that there will not be a setter for ValidUser on the user object for some reason (security comes to mind). [Although using an interface IUser would be a better design]

This can be one of the reason where some people quit unit testing since it just makes it hard to test but there is a way to test and it is quite simply. The way to do it is actually by extracting the dependency, since to us we don’t really care about the user and we want to test the Add functionality only to see if things are working properly. Let see how we do it

We introduced a virtual method called CheckValidUser so that we can override it. Now for our stub we can simply override the method so that it always returns what we want it to

And finally for our unit testing we can write something like

There are definitely better ways to design this class by using interface IUser, dependency injection frameworks and mocking frameworks to ease the testing, but those methods would be mentioned later in my blog. Hope you enjoyed the read 🙂

Taswar

WCF Error Handling with log4net

WCF Error Handling with log4net

In this blog post I will be going through how to do error handing with WCF by using attributes to log your errors.

There are multiple ways to do error handling in WCF as listed by Pedram Rezaei Blog.

The default way that WCF allows errors message to display is by setting IncludeExceptionDetailInFaults Property to true in web.config or on the service attribute but this is only recommended when you need to debug you development code not in your shipped/release code.

In Web.config file

In the web.config file of the WCF service the includeExceptionDetailFaults attribute set it to true.  With this action every endpoint associated to WCF service will send managed exception information.

In Attribute

Another way is setting the IncludeExceptionDatailInFaults property to true using the ServiceBehaviorAttribute.

That is fine and dandy but it is definitely not recommended for production server, you don’t want an stack trace to show up when someone is viewing it on the webpage for this service.

The IErrorHandler interface

The basic form of error logging in WCF is to use the IErrorHandler interface, which enables developers to customize the default exception reporting and propagation, and provides for a hook for custom logging.

Another thing to note is we need to implement the IServiceBehavior also since installing our own custom implementation of IErrorHandler requires adding it to the desired dispatcher. Since we need to treat the extensions as custom service behaviors in order for it to work.

Rather than just calling Log4Net I create a class called Logger which decouples log4net so that one can use any logging framework by using a dependency injection framework. (Code not listed)

Back to building our own ErrorHandler, ServiceBehavior with Attribute, the code is listed below

Now one can just add an attribute to the WCF service code to log our error message to log4net or whatever logging framework that you may be using.

There is also another way by using the web.config and adding the error logging to all the services listed by Stever B in his blog, but I find that does not give me the flexibility that I wanted, I may want to log some but not others etc.

Hope you enjoy this post.

realprogrammers

Today is my first post to my blog, since its my birthday today so I thought I would start today. One of the things that I know in life is that, one has to keep learning and I would like to say is

As a pragmatic programmer, one should always invest regularly.”

The Pragmatic Programmer by Andrew Hunt and David Thomas  is a must read book. It also comes with tips of all the chapters in a card form bounded at the end of the book.  One can stick those tips in your cubicle or office (if you are lucky) just to act smart in front of other developers 🙂

Here are some good excerpt from the book

  • Invest regularly. Just as in financial investing, you must invest in your knowledge portfolio regularly. Even if it’s just a small amount, the habit itself is as important as the sums. A few sample goals are listed in the next section.
  • Diversify. The more different things you know, the more valuable you are. As a baseline, you need to know the ins and outs of the particular technology you are working with currently. But don’t stop there. The face of computing changes rapidly—hot technology today may well be close to useless (or at least not in demand) tomorrow. The more technologies you are comfortable with, the better you will be able to adjust to change.
  • Manage risk. Technology exists along a spectrum from risky, potentially high-reward to low-risk, low-reward standards. It’s not a good idea to invest all of your money in high-risk stocks that might collapse suddenly, nor should you invest all of it conservatively and miss out on possible opportunities. Don’t put all your technical eggs in one basket.
  • Buy low, sell high. Learning an emerging technology before it becomes popular can be just as hard as finding an undervalued stock, but the payoff can be just as rewarding. Learning Java when it first came out may have been risky, but it paid off handsomely for the early adopters who are now at the top of that field.
  • Review and rebalance. This is a very dynamic industry. That hot technology you started investigating last month might be stone cold by now. Maybe you need to brush up on that database technology that you haven’t used in a while. Or perhaps you could be better positioned for that new job opening if you tried out that other language….

 

Now that you have some guidelines on what and when to add to your knowledge portfolio, what’s the best way to go about acquiring intellectual capital with which to fund your portfolio? Here are a few suggestions.

  • Learn at least one new language every year. Different languages solve the same problems in different ways. By learning several different approaches, you can help broaden your thinking and avoid getting stuck in a rut. Additionally, learning many languages is far easier now, thanks to the wealth of freely available software on the Internet (see page 267).
  • Read a technical book each quarter. Bookstores are full of technical books on interesting topics related to your current project. Once you’re in the habit, read a book a month. After you’ve mastered the technologies you’re currently using, branch out and study some that don’t relate to your project.
  • Read nontechnical books, too. It is important to remember that computers are used by people—people whose needs you are trying to satisfy. Don’t forget the human side of the equation.
  • Take classes. Look for interesting courses at your local community college or university, or perhaps at the next trade show that comes to town.
  • Participate in local user groups. Don’t just go and listen, but actively participate. Isolation can be deadly to your career; find out what people are working on outside of your company.
  • Experiment with different environments. If you’ve worked only in Windows, play with Unix at home (the freely available Linux is perfect for this). If you’ve used only makefiles and an editor, try an IDE, and vice versa.
  • Stay current. Subscribe to trade magazines and other journals (see page 262 for recommendations). Choose some that cover technology different from that of your current project.
  • Get wired. Want to know the ins and outs of a new language or other technology? Newsgroups are a great way to find out what experiences other people are having with it, the particular jargon they use, and so on. Surf the Web for papers, commercial sites, and any other sources of information you can find.

 

Go ahead and purchase this book at amazon since its defintely worth it and would defintely enlighten you on your craft.

UA-4524639-2