General

Categories

  • No categories

SEARCH


Writing from my iPad

Posted in: General by Steve on May 26, 2010 | 2 Comments

This is my first post written directly on my iPad. This device has made our lives more interesting and has a lot uses for children. I’ve enjoyed the initial experience with the iPad and I think the rest of my family has as well. I would say the games and coloring style apps have been the most enjoyable, along with the ability to stream movies and videos.

The apps that I have installed on here are:

  • Air Video – stream video from a server directly to the iPad
  • Netflix – mandatory for video
  • Plants vs. Zombies – my wife truly enjoys this game, much to my amusement
  • Flight Control HD – I have a thing for planes
  • RadarScope – Level 2 radar at your fingertips, along with Spotter Network integration make for an awesome experience
  • X-Plane – again, an excellent flight simulator

The one thing I am surprised with is reading books. I thought that it would be different because of the backlit screen and my eyes would hurt, but I haven’t had any problems picking up the iPad to read a nice book on Python.

Overall, I am extremely happy we purchased the iPad.


UPDATE: I forgot to mention GoodReader which is an awesome app to manage documents.

I’ve embarked on a new career

Posted in: General by Steve on April 1, 2010 | No Comments

I have decided that programming is no longer a viable career, so I have decided to being mentoring under Eduard Khil:

Merry Christmas

Posted in: General by Steve on December 25, 2009 | No Comments

I want to wish everyone a Merry Christmas and a prosperous New Year.

Merry Christmas

ASP.NET + StructureMap = Epic Win

Posted in: General by Steve on November 26, 2009 | No Comments

After running into a lot of testing problems with my current architecture in ASP.NET, I decided that it was time to look into an IoC Framework. I have heard the marvels of how it makes code so much more isolated and clean (SOLID), but I couldn’t see my code ever getting to this point. Because this project has a ton of legacy code, there was little incentive to add anything else when it was already so highly coupled. I needed to take a step back and look at it from a different perspective.

I understood how IoC (Inversion of Control) Frameworks worked and knew how this technique is used, but I didn’t know how I could integrate it in my application. Most of my action/service methods were static classes that instantiated new objects to return what I needed.

Here’s an example:

On the member page, there is a list of upcoming conferences that calls this code:

Public Class ConferenceService    

	Public Shared Function GetUpcomingConferences(ByVal DisplayDate As DateTime) As IList(Of ConferenceEntity)
		Using repo As New Repository
			Dim bucket As New RelationPredicateBucket(ConferenceFields.IsActive = True)
            Dim startfilter As New PredicateExpression(ConferenceFields.StartDisplayDate = System.DBNull.Value)
			startfilter.AddWithOr(ConferenceFields.StartDisplayDate <= DisplayDate)
			bucket.PredicateExpression.AddWithAnd(startfilter)         

			Dim endfilter As New PredicateExpression(ConferenceFields.EndDisplayDate = System.DBNull.Value)
			endfilter.AddWithOr(ConferenceFields.EndDisplayDate >= DisplayDate)
			bucket.PredicateExpression.AddWithAnd(endfilter)
			Dim sorter As New SortExpression(ConferenceFields.StartDateTimeUtc Or SortOperator.Ascending)
			Return repo.GetCollection(Of ConferenceEntity)(bucket, sorter).ToList()
		End Using
	End Function

End Class

I am using LLBLGen (Adapter) as my DAL so the Repository class is responsible for calling a new object to create what LLBLGen calls an EntityCollection. This is easy to call because all I have to do is call ConferenceService.GetUpcomingConferences(Date.Now()) to get a list of upcoming conference. This is very hard to test though without using something like Typemock.

In order to start my refactoring to be able to integrate StructureMap, I needed to look at how my ConferenceService was being constructed. There are 5 constructor calls in this method alone. You can imagine how the rest of the application looks like.

Adding and Setting Up StructureMap

First, download StructureMap from the website. I downloaded version 2.5.3. Next was to look how to get StructureMap set up on the web project (found here http://structuremap.sourceforge.net/ConfiguringStructureMap.htm). I had to use for VB and lambdas are tricky so this is how the Bootstrapper was defined:

Imports StructureMap
Imports StructureMap.Configuration.DSL

Public Class Bootstrapper    

	Public Shared Sub BootstrapStructureMap()
		ObjectFactory.Initialize(AddressOf ConfigStructureMap)
	End Sub    

	Private Shared Sub ConfigStructureMap(ByVal x As IInitializationExpression)
		x.AddRegistry(New RepositoryRegistry)
	End Sub    

	Public Class RepositoryRegistry
		Inherits Registry        

		Overrides Protected Sub configure()
			'Will be used later after we refactor
			'ForRequestedType(Of IRepository)().TheDefaultIsConcreteType(Of Repository)().CacheBy(Attributes.InstanceScope.Hybrid)
		End Sub   

	 End Class
 End Class

And then, in our Global.asax, on the Application_Start, call the Bootstrapper.BootstrapStructureMap() method. That is all we need for StructureMap config for now. That will get us started in the right direction.

imageRefactoring

The first refactoring is to Extract an Interface from the Repository class. If you have a refactoring tool such as Refactor Pro! or Resharper, this is made very easy. I called mine, IRepository. This will make the Repository class implement the newly created interface. We can now start on the ConferenceService.

The next refactoring is to create a constructor for the ConferenceService class that takes an IRepository as a parameter. This will help us create Constructor Injection.

After we add the parameter, we can remove the code that uses the concrete Repository object.

 Public Class ConferenceService   

	 Private _repo As IRepository
	 ''' <summary>
	 ''' Initializes a new instance of the ConferenceService class.
	 ''' </summary>
	 ''' <param name="repo"></param>
	 Public Sub New(ByVal repo As IRepository)
		_repo = repo
	 End Sub    

	 Public Function GetUpcomingConferences(ByVal DisplayDate As DateTime) As IList(Of ConferenceEntity)
		 Dim bucket As New RelationPredicateBucket(ConferenceFields.IsActive = True)
		 im startfilter As New PredicateExpression(ConferenceFields.StartDisplayDate = System.DBNull.Value)
		 startfilter.AddWithOr(ConferenceFields.StartDisplayDate <= DisplayDate)
		 bucket.PredicateExpression.AddWithAnd(startfilter)
		 Dim endfilter As New PredicateExpression(ConferenceFields.EndDisplayDate = System.DBNull.Value)
		 endfilter.AddWithOr(ConferenceFields.EndDisplayDate >= DisplayDate)
		 bucket.PredicateExpression.AddWithAnd(endfilter)
		 Dim sorter As New SortExpression(ConferenceFields.StartDateTimeUtc Or SortOperator.Ascending)
		 Return _repo.GetCollection(Of ConferenceEntity)(bucket, sorter).ToList()
	End Function   

 End Class

The next piece of code is back in our Bootstrapper that we have to uncomment.

'ForRequestedType(Of IRepository)().TheDefaultIsConcreteType(Of Repository)().CacheBy(Attributes.InstanceScope.Hybrid)

Now, instead of calling the static method as such:

Dim upcomingConf as IList(Of ConferenceEntity) = ConferenceService.GetUpcomingConferences(Date.Now())

We can call it as such:

Dim upcomingConf as IList(Of ConferenceEntity) = _new ConferenceService(ObjectFactory.GetInstance(Of IRepository)()).GetUpcomingConferences(Date.Now())

This allows us to decouple the concrete Repository object and allows for testing out our method. We’ll be able to write tests now to cover our legacy code, and allow for more flexible code.

Ketchup/Catsup

Posted in: General by Steve on September 27, 2009 | No Comments

Yes ladies and gentlemen, I am still here, albeit very busy.

I thought I would just post to let you know what is going on.  Work has taken over since I was given a deadline of 6 weeks after an estimate of 4 months.  You can assume that I am now knee deep in crap code and worst practices. 

ConnerConner is keeping me busy as always and every day is a new chapter in his life that surprises me.  I would never think that I would ever have this kind of influence on anyone.  It’s amazing.

I have been trying to learn more about ASP.NET MVC but I have not been able to put as much effort into it as I would like.

I realized that this coming Thanksgiving will be the 3 year anniversary of me quitting smoking. 

I have started back on Weightwatchers with Debbie and we are doing well.  I have already lost 25 lbs in 3 months.  I hope to have reached my goal by Christmas, so you might be seeing a new Steve in the future.  I feel great and I really hope to keep it off.  You can follow my progress on my twitter (Thanks to Jason Bock for the idea)

That is all for now, I want to start posting more but Twitter seems to have taken a lot from me since I don’t have much to say here other than little quips here and there. 

~~S

We Landed on the Moon!

Posted in: General by Steve on July 20, 2009 | No Comments

New Blog Layout

Posted in: General by Steve on July 2, 2009 | No Comments

I decided that I should update my blog to be a little more modern and add a little “ZAZZ”.

So here it is, the big bad new blog layout.  I have some new ideas that will be coming out pretty soon, so stay tuned!

Codeapalooza is Almost Here

Posted in: General by Steve on September 4, 2008 | No Comments

codeapaloozaCodeapalooza is coming up this Saturday, September 6, 2008, at IIT of Wheaton at 8:30 AM – 5:00 PM.  This event is FREE so get registered now.  There will be plenty of sessions for you to choose from to attend.  You can view the agenda on the website.

I have set up a place to go afterwards and we will be going to Charlie’s Ale House, which is right next to the venue.  They have room for about 40 people so it’s going to be first come, first served. 

We might also hit up some of the bars in downtown Naperville later if people are willing to stay out a little later.

I’m gauging the interest of a pre-conference event on Friday.  The White Sox are playing the Angels at 7:10 PM and there are plenty of decent seats available.  If anyone is interested in this, leave a comment and I’ll see what I can do to get a group rate.

See you there!

So you think you can Box?

Posted in: General by Steve on August 26, 2008 | 1 Comment

Words…should have sent a poet…

No WMDoDN for Me – Unfortunate

Posted in: General by Steve on May 9, 2008 | No Comments

Due to some unforseen circumstances, I won’t be going to the Western Michigan Day of .NET.  I would have liked to have seen everyone, but it will have to wait until next year.

Or they can all come out to the Chicago ALT.NET conference that is coming together for September ’08.