Tuesday, October 30, 2012

ESATA, SSD and Virtual Machine Goodness (improved)

About a year ago I posted some details on how I setup my environment for each client: http://ledtalks.posterous.com/esata-virtual-machines-goodness

Today I finally upgraded and bought a few Solid State III 2.5" Drives, the specific one is here: http://www.tigerdirect.com/applications/searchtools/item-details.asp?EdpNo=91218

I have to kick myself for not doing this sooner. Bootup is much faster and opening Visual Studio and debugging my web applications is twice as fast (perceived, I didn't actually time things). I should be getting a new laptop from work soon, but this will hold me off for a while. The other nice thing is I can suspend my VM images extremely quickly and the resume just as fast.

 

Friday, October 28, 2011

Multi-site / Multi-languages with Sitecore

My current client has a number of domains for various regions and some regions will support multiple languages, including Right-to-Left languages such as Arabic. So let's highlight what needs to be done in Sitecore and our code to allow for this requirement.

Web.Config

Screen1

Above you can see that we have 3 sites defined. The .com site has en as the default language, the .co.uk has en-GB and the .ae has ar-EG (arabic egyption). The next section goes over language fallback, but for now notice that .co.uk and .ae have a fallback to english.

Langugage Fallback

Alex Shyba who works for Sitecore has contributed a nice Shared Source module called Partial Language Fallback that allows Sitecore to fallback to a different language for an item or field if there is not a value available within the current language context. Alex goes into more detail about this module on his blog located here: http://sitecoreblog.alexshyba.com/2011/08/partial-language-fallback-module-update.html

Multiple Languages

The client's requirement is that the .ae site should default to arabic but allow the user to choose english if they prefer. We already set the default language to arabic in our web.config above, so we have that covered but now we need the ability to set a site's supported languages.

Screen2
Above I have updated the Website Root template, which is the root template of each site item in my solution. We have added a Site_Languages treelist field that has the System/Languages as the source. This allows for the content authors to select which languages they want supported for each site.

Screen3

Changing Languages

Now that the backend is setup, we can create a control that can be used in the site's footer to appear when 2 or more languages for the site is available and allow the user to select a different language.

LanguageContext.ascx

Screen4

Our frontend code above is simply building out a dropdown list that is bound to the languages and it is adding a "selected" tag to the language that matches the current context.

LanguageContext.ascx.cs

Screen5
The ManageLanguages function is in charge of binding the repeater to the available languages and it only shows the repeater if there are 2 or more languages available. So in our .com and .co.uk sites this control will not be displayed but it will show up on the .ae site.

If the request is a PostBack, then it will set the language context for the user and then redirect to the original url to ensure the page and any controls loaded before this point are aware of the context change.

site.js

Screen6
Then the last piece is simply to wire up the select box to submit the form on value change.

Right-to-Left Support

Still in proof of concept mode on this one but what I have so far to support right to left languages is to check to see if the current language context is right to left and if it is then swap out the style sheet with a different one. I will post an update if this approach changes after our UI developers take a look at it.

Screen7

Friday, October 7, 2011

eSATA + Virtual Machines = Goodness

I am not sure if it is the norm or not, but I like to create a virtual machine image for each project I work on. Being a consultant, I am usually on a few projects at a time and at very least need to refer back to past projects. Having a development environment on a virtual machine for each client makes it easy to stay organized and keep things isolated from one another.

The base image that I use to clone has a base install with the necessary IIS components, SQL Server 2008 and Visual Studio 2010 with the settings just how I like them along with the plug-ins such as ReSharper in place. I also have my AHK script in place as well, because your AHK scripts on your host machine will not work when in your VM (they do work when you are remoted into a server however).

My disk space was getting pretty tight this week because I started a new client and I duplicated an existing clients environment so I can test out upgrading to Sitecore 6.5 while still keeping the 6.4 in place. So today I went out and bought a BlacX SATA HDD eSATA + USB 2.0 Docking Station and a 500 GB drive. I could have gone larger or even gone with a solid state drive but I didn't want to shell out a lot just yet because I wasn't sure how performance would be. I tried to run my VMs from a MyBook back in 2006 and it just wasn't possible and I was a bit pesimistic.

Well after a day of developing, I can officially say, I like it a lot. It is actually a bit more responsive than when the image was on my host machine's hard drive. I imagine this is due to the fact that the host and VM do not have to compete for attention from a single drive.

I will probably end up getting a second docking station for the office so I just have to carry the small 2.5 mobile hard drive with me when commuting to/from work. The one downside to this is, I won't be able to code on the train because I will not have access to the external drive. I figure I can catch up on non-development tasks during my commute or if I need, I could keep a copy of one of my images on my laptop too and only use it when commuting (I will just need to remember to get latest/check-in to ensure the external image and local image are in synch).

Friday, September 16, 2011

Web.Config Transformations when Debugging

I am a big fan of the Web.Config Transformations that got introduced with a while back. Prior to them being inherently supported one could accomplish the same thing with part of the Enterprise Library, and prior to that one could leverage a custom MSBuild Task or the XMLPoke Task to get your web.config updated based on the environment it was targeting.

Having your configuration elements managed with a transform file makes it a bit easier to manage and keep track of your settings that could change based on environment or settings. Without this each developer on your team might need to create host entries and keep their folder structure the same to ensure the settings work for each of their machines. Another option is each team member just has their own configuration files with their specific settings that they need but when source control is introduced this can get tricky because one developer might be overwriting another's settings.

Unfortunately, VS.Net doesn't do any transforming when you are developing and just debugging your local environment. But there are some steps you can do to make this happen if you want.

  • First, create the configurations you want in VS.Net, assuming the default debug and release are not enough for what you are trying to accomplish.
  • Right click on you web.config and select Add Config Transforms - this will create a dependant transformation config for each of your configurations defined.
  • Now you can rename your web.config to web.base.config.
  • Add a web.config to your project. It doesn't matter what is in it because it will get overwritten every time we do a build but we want it part of the project so VS.Net doesn't give us the "Your Project isn't configured for Debugging" pop-up.
  • Edit your .csproj Project File and add the following TransformXml task to the AfterBuild target. Here you can see I will be transforming the web.base.config file using the web.[configuration].config and it will save it as web.config.

Screen1

For aesthetics, I renamed my transformation files to just web.[configuration].config instead of web.base.[configuration].config and updated the project file like below:

Screen2
So the transformation files are nested under the web.base.config and the web.config doesn't have any transformation files because it is the output not the input. Below you can see the setup I have so far for the Ergo project where my web.config would look quite different depending on if I am using Ektron or NHibernate as my data repository.

Screen3

Thursday, September 8, 2011

Unit Testing with an InMemory Database and NBuilder

I am throwing a lot of cycles to my Ergo project lately. I will go into more detail of the Ergo project later when it starts to take more shape and get some legs but one thing it is allowing me to do is get back to a true TDD project. A couple of cool things I have introduced to my unit tests are NBuilder and leveraging Fluent NHibernate and SQLite InMemory to make testing the NHibernate layer a bit easier.

When using NHibernate you generally only need to test 3 things:

  • The Properties are being persisted
  • Cascading works as expected
  • Queries return the correct results

By using an in memory SQLite database we can do this testing while keeping our unit tests nice and speedy. Below is my InMemoryDatabaseTest class that my unit tests can inherit from to test our NHibernate layer.

Screen1

Now that we have our InMemoryDatabaseTest class setup, we can structure our unit tests like below. One nifty class I found today that you will see in the screenshot is the Builder class. This is from http://nbuilder.org/ and http://code.google.com/p/nbuilder/. So instead of having to create a new Page instance and populate it with a bunch of dummy data I can just use 1 line of code to new up a Page which I can then persist to the InMemory database and then use it to Assert against when I query.

Screen2

Sunday, September 4, 2011

Dev Magic Fake Framework Released

I have been playing around with this framework this weekend and it is really cool. It allows you to work in a particular layer of your application without having to make sure all the plumbing and the other layers are in place. I will post a more detailed blog entry in a few days but I wanted to get this out there now to get the word out.

http://mohamedradwan.wordpress.com/2011/09/03/dev-magic-fake-video-tutorial/

Wednesday, August 24, 2011

On her good side

Doing a Life / Relationships tag today because I have done way too much development and documentation review to want to do anything else technical. I think if you were to ask my wife or any of her friends, they would say I am one of the better husbands in the world - of course I think if you asked any of my friends I think the term they would use is 'whipped'. Be that as it may, once in a while I will post a couple of things I have done in the past that got good reception in case there are some readers out there that want some ideas to earn some extra brownie points from their significant other. Life should be about more than just coding and work so make sure you put some effort into your relationships too, it makes work that much more enjoyable having that balance in place.

So here are a few good ideas for you. Feel free to steal them entirely and take all the credit - I promise not to tell.

Compliment Stones

Screen1

I actually got this idea from RedEnvelope a few years ago. I think it is a great idea but some of the sayings are a little cheesy or at least a little impersonal since they really aren't your words. What I did was take some nice polished stones; we actually already had some from a vase in one of our rooms but feel free to get some from a craft store. You can then get some clear Avery labels and print out your own sayings. If I recall I had some mushy ones, some funny ones and some risqué ones but be creative and make sure to put a some sayings on couple that would only make sense to the two of you to make it even more personal. You can then place them in a small gift box or container with all the messages face down or place them in a nice velvet pouch with a drawstring. Then write up a little note with some instructions such as "each morning or when you need a little pick me up, pick up a stone, read it and then put it back".

Fortune Cookies

Screen2
Another spin on the idea that I did last year was Fortune Cookie messages. My wife loves fortune cookies, I don't even think she likes the taste of them but loves the surprise of the messages. I found this metal fortune cookie set standing in line at Borders where they have all the compulsive shopping items. It also came with a bunch of tear-away pre-written message but I just printed out my own messages on clear labels and stuck them to the strips and whited out the other side. I couldn't find the actual kit online anywhere but I found the container which is all you need here. I gave her a message every day for a month and then it just turned into a once in a while thing. You can also use them for apologizing if needed.

Scavenger Hunt

Working for a consulting company, I am lucky to not have to travel as much as I used to but there are certainly times when I have had to head out for an extended time. When I had to go to London for 2 weeks for VW Credit back in 2007, I bought a few trinkets and gifts for my wife and the kids and I hid them around the house. I then hid clues to those hiding spots throughout the house. Then each day when I would call them to say goodnight I would give them a clue to where they would find a clue to one of their gifts. This took a lot of planning and you end up running out of hiding spots if you are gone for too many nights but I think it was worth it because after the greeting hugs at the airport one of the first things my son said to me was "Hey, Dad when do you have to go out of town again so we can have another scavenger hunt".