Edmonton IT Blogger Roll
RSS
 
Going Digital At Home - Part 3 - The Law
One of the things I never took much time to consider was the legality off all this. My opinion has been (and hopefully always will be) that if I purchased something I should be able to do whatever I want with it. If I own DVD and want to use it as a decoration on my Christmas tree I feel I have that right.

Again, I am not a lawyer and this is just a summation of my research on the topic so do your own research for your own area.

DVD Backups
The first debate is if you can backup or convert your DVD's to another format. There are two big points in this debate. The first is if you can make a backup of the media. The second is if you can legally circumvent copy protection. In Canada, the current copyright act does not explicitly state if it is legal or not to do either of these. It is legal to make a backup of computer programs, and you are allowed to copy audio/video for personal use. In the current situation it seems quite legal to backup and defeat copy protection. I think this is great as I PURCHASED a product and would like to use it in the manner I see fit. Of course it is illegal for me to share the backup.

From my understanding, in the United States, it is only partially legal to create a backup (yup partially legal). It seems that making a backup copy is totally fine but if you break copy protection it violates the Digital Millenium Copyright Act as it may be considered that you have circumvented copy protection on the DVD. Circumvention though could be in the eye of the beholder as computer software has to open the DVD and decrypt it for playback, capturing the legally decrypted data and placing it on your hard drive may be totally legal.

Canada is working to reform its copyright act so there may be some big changes to modernize it. From reading over Bill C-32, I see this:

29.22 (1) It is not an infringement of copyright for an individual to reproduce a work or other subject-matter or any substantial part of a work or other subject-matter if
(a) the copy of the work or other subject-matter from which the reproduction is made is not an infringing copy;
(b) the individual legally obtained the copy of the work or other subject-matter from which the reproduction is made, other than by borrowing it or renting it, and owns or is authorized to use the medium or device on which it is reproduced;
(c) the individual, in order to make the reproduction, did not circumvent, as defined in section 41, a technological protection measure, as defined in that section, or cause one to be circumvented;
(d) the individual does not give the reproduction away; and
(e) the reproduction is used only for private purposes.

The issue here becomes circumventing technological protection measures. This is where I don't agree as I purchased it so why should I not be able to do what I want with it in my own home? Frankly, if I can't do what I want with content I buy then I will cease buying it.

DOWNLOADING MEDIA
In Canada, this is technically legal as long as you don't distribute it or profit from it. After playing around with converting my own DVDs (that post is coming up), it may be easier to let someone else do the hard work of properly converting a movie and download it from them.

Modifying Your XBOX
I have an old xbox just collecting dust so I installed Xbox Media Center on it. This is not an MS product, it is a replacement OS created by the community (that is awesome) but does require a lot of work to get it installed (there are lots of tutorials out there on the internet about it though). Is it legal to modify your xbox? From what I see, yes. If you mod your xbox it voids your warranty and violates Microsoft's use policy so it will probably not work online. For me that is fine as I am just using it as a media center hooked up to my TV.

Streaming Media Over Wireless
An interesting potential gotcha is that streaming media over a wireless network may be considered broadcasting. Some media center devices will not stream some content for this very reason (buyer beware for sure). I really think this is a non-issue as most people secure their wireless networks and most neighbors don't have the technical expertise to watch what you are streaming but it could still be an issue.


Posted on 7/6/2010 11:51:45 AM by
Going Digital At Home - Part 2 - Sharing
The next step in providing digital content is being able to share your existing media out to the home. There are several ways to do this.

The first thing I want to talk about though is the codec issue. Video and audio can get quite large and there are many different ways to encode media to shrink its size down. In order to play a video you need the proper codec installed (a codec is a bit of code that properly decodes encoded video). The #1 issue with video playback has typically been that you don't have the right codec installed. Normally when you are missing a codec you go out and download the codec and install it on your computer. When you have a device connected to a T.V. though it may not be possible to add the codec you want (I ran into this with my XBOX 360 for instance).


Simple File Share
Most computers and devices can access file shares quite easily. On your media server just right click and goto sharing and then select the users. There are many tutorials out there on how to share a folder so I wont dig into the basics but there are a few key tricks to it.

Most shares require the user to authenticate upon attempting to access a shared folder so that it can grant or deny access to that share. Now unless you have setup a domain controller for your house, it will not know who you are and want a username and password that has been setup on the computer sharing files. A neat trick is that if you have the same username/password setup on both the client and the server then you will automatically be authenticated. Otherwise it will prompt you for credentials. If you have children then it is adviseable to have a folder for family movies that allows the kids credentials and then a higher rated folder that requires an adults credentials.

The other debate is what type of access the share should have. I typically have shared folders that are read only and one folder that allows write so that new content can be dropped in from any computer and then sorted into the proper readonly folder.

The cons with this is that you need credentials, not all devices work over a file share, not all devices can play all types of media (due to the codec issue). For instance my xbox 360 does not access fileshares so this technique does not work)

Windows Media Sharing
I believe that starting with Windows Media Player 10 is an included service that allows you to share media out that is added to your Media Player library. I think that this solution works pretty good for the scenario where a user has one computer running a client operating system (i.e. XP/Vista/Windows 7) with their media and share it out. I have not tried it as I have a hatred for the bloatware that is Windows Media Player but it may just work for you.

From my quick read it does appear to overcome the codec issue via transcoding. This means that the media player on your computer converts the video on the fly to a format the remote device knows how to play. Again I have not tried this but I leave it up to you to experiment.

Windows Media Center & Media Center Extenders
Media Center is a chunk of software that ships with some editions of Vista and Win7. It allows you to access all your media, photos, and more via a client. The XBOX 360 ships with just such a client so I tried it out. It was horrible. It could not play a lot of the videos I had (due to codec issues), it was slow to navigate, and I found the video was choppy a lot of the time. Granted, I tried this a few years ago and they have probably made improvements but I have moved on to other technologies. I also don't believe that you can have Media Center on a computer running a server OS (but again, I could be wrong)

Transcoding Server
I have found the best thing for me has been using a transcoding server called TVersity. The app converts video on the fly and streams it out to my devices just fine. The really nice feature is that you can also add internet feeds to the TVersity library. What this means is that I can take a show that published a feed and have my computer download that data, transcode it, and stream it to my xbox 360. I can now watch internet TV... on my TV! There is a lot of neat stuff you can do in this area.

The biggest issue I have found with TVersity is that the service will not respond sometimes and requires me to restart the service. Friends of mine have had no problems but I have had the issue on two separate installs now.

Network Considerations
For all of these solutions you will need to have the appropriate exceptions in your firewall to allow the services that share media to be accessible. Bandwidth can also be an issue with wireless networks. I currently have my server connected to the router via regular cat 5 cable but the devices I consume media on are wireless. This works fairly well but media sharing is a bandwidth intensive operation so the quality of wireless signal you get may have an effect on streaming. If you can use a hardwire connection then I would recommend it as it is much more reliable than wireless.
Posted on 6/25/2010 9:49:33 AM by
Making the most of Brownfield Application Development – Winnipeg Edition

On Friday July 23rd I’ll be in Winnipeg giving a one day seminar on the nuances of Brownfield Application Development and how to get the most out of it. More about the day can be found here. I recently did the seminar at the PrairieDevCon and it was a blast. The day is filled chocka-block with content and ideas that pertain directly to Brownfield codebases and will work in Greenfield situations.

Registration can be found here and until July 2nd the session is available at a discount. Hope to see you there!

Posted on 6/23/2010 4:22:41 PM by
Induction Into the Android Army – the Aftermath
Thanks to all who attended my “Induction into the Android Army” talk this afternoon at the monthly Edmonton Java User’s Group meeting.  I’d say it was a good turn out, especially when one considers that this is only the second monthly meeting for EJUG.  It was a pretty basic talk, and didn’t dive to deeply [...]
Posted on 6/15/2010 5:27:10 PM by
Android at the Edmonton Java User Group
Just a heads up for those interested:  On Tuesday, June 15th the Edmonton Java User’s Group is having it’s monthly meeting at noon at the Canadian Western Bank Building.  The speaker is none other than yours truly.  I’ll be giving a brief introduction to application development to Android, using my trusty G1 and IntelliJ. It’s [...]
Posted on 6/11/2010 9:51:42 PM by
Visual Studio Project files and coupling

The way that we’re told to use Visual Studio is that we create a solution file and add into it one or more project files. Each project file then gets filled with different development artefacts. When you build inside of Visual Studio each project represents a compiled distributable file (exe, dll, etc). Many people carry this practice over into their build scripts. You might be one of them. I’m here to tell you why you’re wrong to be doing this.

Let’s say you’re starting a project. You open Visual Studio, select File | New Project and get things rolling. In a few minutes you have a Solution that contains a few Projects. Maybe you have one for the UI, one for the business logic and one for the data access layer. All is good. A few months later, after adding many artefacts to the different projects, something triggers the need to split the artefacts into one assembly from one DLL into two DLLs.

You set off to make this happen. Obviously you need to add a new Project to your Solution, modify some references, and shift some files from one Project into another. Say you’re stuck using an exclusive locking source control system (like VSS…shudder). You *must* have exclusive access to all the files necessary including:

  • the sln so you can add the new project
  • at least one existing cs/vb/fsproj which you’ll be removing existing code artefacts from
  • any cs/vb/fs files that will be moved
  • any cs/vb/fs files that reference the ones moving (using statements will need updating when you change the namespacing on the files being moved)
  • possibly some resx files that need to be moved
  • possibly config files that need to be changed or moved
  • any automated tests that make use of the moving cs/vb/fs files

It’s a pretty damn big list of files that you will need to exclusively lock during this process. Chances are you will need to push all of your co-workers out of the development environment so that you can gain access to all of those files. Essentially you are, at this point, halting the development process so that you can do nothing more than split one DLL into two. That in quite inefficient in the short term and it’s completely unsustainable in the long term.

I can hear you now, “Well I use <git/mercurial/svn/etc> so we won’t have those issues”. Really? Think it through for a second. Go ahead, I’ll wait.

With the volume of changes that I listed above, you’ll likely want to be working in some kind of isolation, whether that is local or central. So yes, you can protect yourself from blocking the ongoing development of your co-workers by properly using those version control systems. But remember, you do have to integrate your changes with their work at some point. How are you going to do that? You’ve moved and modified a significant number of files. You will have to merge your changes into a branch (or the trunk) locally or otherwise. Trust me, this will be a merge conflict nightmare. And it won’t be a pain just for you. What about the co-worker that has local changes outstanding when you commit your merged modification? They’re going to end up with a massive piece of merge work on their plate as well. So instead of being blocked while you do the work, you’re actually creating a block for them immediately after you have completed your work. Again, the easiest way to achieve the changes would be to prevent any other developers from working in the code while modifications are occurring. Doesn’t that sound an awful lot like exclusive locking?

Now, I know you’re thinking “Pfft..that doesn’t happen often”. This is where you’re wrong. When you started that application development cycle (remember File | New Project?) you likely didn’t have all of the information necessary to determine what your deployables requirements were. Since you didn’t have all of that information, chances were good, right from the outset, that you were going to be doing the wrong thing. With that being the case, it means that chances were good that you were going to have to make changes like the one described above. To me that indicates that you are, by deciding to tie your Visual Studio Projects to your deployables, accepting that you will undertake this overhead.

People, possibly you, accept this overhead on every software project they participate in. This is where you’re wrong. There is a way to avoid all of this, but people shrug it off as “not mainstream” and “colouring outside the lines”. The thing is it works, so ignore it at your own peril.

There is a lot of talk in some development circles about decoupling code. It’s generally accepted that tightly coupled code is harder to modify, extend and maintain. When you say that a Visual Studio Project is the equivalent of a deployable, you have tightly coupled your deployment and development structures. Like code, and as the example above shows, it makes it hard to modify, extend and maintain your deployment. So why not decouple the Visual Studio Project structure from the deployables requirements?

It’s not that hard to do. You’ll need to write a build script that doesn’t reference the cs/vb/fsproj files at all. The .NET Framework kindly provides configurable compiler access for us. The different language command line compilers (vbc.exe/csc.exe/fsc.exe) allow you to pass in code files, references, resources, etc. By using this capability, you can build any number of assemblies that you want simply by passing a listing of artefacts into the compiler. To make it even easier, most build scripting tools provide built in capability to do this. NAnt and MSBuild both provide (for C#) <csc> tasks that can accept wild carded lists of code files. This means you can end up with something like this coming out of a solution-project structure that has only one project in it:

<csc output="MyApp.DAL.dll" target="library" debug="${debug}">
<sources>
<include name="MyApp.Core/DAL/**/*.cs"/>
</sources>
<references>
<include name="log4net.dll"/>
</references>
</csc>

<csc output="MyApp.Core.dll" target="library" debug="${debug}">
<sources>
<include name="MyApp.Core/Business/**/*.cs"/>
</sources>
<references>
<include name="log4net.dll"/>
<include name="MyApp.DAL.dll"/>
</references>
</csc>

<csc output="MyApp.UI.exe" target="winexe" debug="${debug}">
<sources>
<include name="MyApp.Core/**/*.cs"/>
<exclude name="MyApp.Core/DAL/*.cs"/>
<exclude name="MyApp.Core/Business/*.cs"/>
</sources>
<references>
<include name="log4net.dll"/>
<include name="MyApp.DAL.dll"/>
<include name="MyApp.Core.dll"/>
</references>
</csc>

Likewise, we could consolidate code from multiple projects (really file paths is what the build script sees them as) into one deployable.

<csc output="MyApp.UI.exe" target="winexe" debug="${debug}">
<sources>
<include name="MyApp.DAL/**/*.cs"/>
<include name="MyApp.Business/**/*.cs"/>
<exclude name="MyApp.UI/**/*.cs"/>
</sources>
<references>
<include name="log4net.dll"/>
</references>
</csc>

Now, when it comes time to change to meet new deployables needs, you just need to modify your build script. Modify the inputs for the different compiler calls and/or add new compilations simply by editing one file. While you’re doing this the rest of your co-workers can continue doing what they need to provide value to the business. When it comes time for you to commit the changes to how things are getting compiled, you only have to worry about merging one file. Because the build script is far less volatile than the code files in your solution-project structure, that merge should be relatively painless.

Another way to look at this is that we are now able to configure and use Visual Studio and the solution-project structure in a way that is optimal for developers to write and edit code. And, in turn, we configure and use the build script in a way that allows developers to be efficient and effective at compiling and deploying code. This is the decoupling that we really should have in our process and ecosystem to allow us to react quickly to change, whether it comes from the business or our own design decisions.

Posted on 6/9/2010 9:39:40 AM by
Rotating text using Graphics.DrawString

Recently I needed to create a custom WinForms label-like control that allowed for the text to be displayed in a rotated fashion. Our needs were only for four rotation locations; 0 degrees (the default label position), 90, 180 and 270 degrees. There were other complicating factors, but for this post we’ll only concentrate on this component of the control.

To rotate text using the Graphics.DrawString method you only have to do a couple of things. First you have to use the Graphics.TranslateTransform method, then the Graphics.RotateTransform method, and followed by the Graphics.DrawString. Here’s what it looks like.

using (var brush = new SolidBrush(ForeColor))
{
var stringFormat = new StringFormat
{
Alignment = StringAlignment.Near,
LineAlignment = StringAlignment.Near
};
e.Graphics.TranslateTransform(transformCoordinate.X, transformCoordinate.Y);
e.Graphics.RotateTransform(rotationDegrees);
e.Graphics.DrawString(Text, Font, brush, DisplayRectangle, stringFormat);
}

What you see are the three steps that I outlined above. Let’s start at the bottom and work our way up. The code exists inside of a UserControl’s overridden OnPaint event. The DrawString method makes use of some of the properties on the control, like Text and Font. It also uses the DisplayRectangle property to set the boundaries for the drawing to be the same size as the control. This is one of the keys to making the rotations work. The other key is to provide the DrawString with the StringFormat settings. By setting them to be StringAlignment.Near for both the Alignment and LineAlignment, you are declaring that the text’s location should be based in the top left of the DisplayRectangle’s area.

Graphics.RotateTransform is how you set the rotation value. In the case of our control, we would be putting in a value from the list of 0, 90, 180, and 270. As you might expect the rotations are clockwise with 0 starting with the text in the ‘normal’ location.

Graphics.TranslateTransform is where the last piece of magic occurs. It is here that you set where the top right corner of the text drawing area will be located in the DisplayRectangle’s area. Here are some images that will help clarify the situation.

0degrees

When you need the text to appear the same as “Text Area” does in the above image (rotated 0 degrees), you need to set the TranslateTransform X and Y parameters to be those that are designated by the “X” in the image. In this case, it’s X=0 and Y = 0.

90degrees

The picture above shows you what you should be displayed when you are rotating the text “Text Area” 90 degrees. Again, you need to set the TranslateTransform, but this time the values are slightly different. The Y parameter is still 0, but the X parameter equals the height of the text. You can get this value by using the following line of code:

var textSize = TextRenderer.MeasureText(Text, Font);
textSize.Height;

180degrees

To render the text upside down we set the rotation to 180 degrees and then, again, determine the location of the TranslateTransform X and Y coordinates. Like we did for the last rotation, we will need to retrieve the text size to set these values. For this situation Y will be the text height and X will be the text width.

270degrees

The final step is to make the rotation work for 270 degrees. Like all the others, we need to set the X and Y coordinates for the TranslateTransform method call. Here the Y value will be the text width and the X value will be 0.

This is simply the first step of many to making a control that will allow rotation of the text and locating it in one of 9 locations in a 3x3 grid representation of the control’s DisplayRectangle. More on that in another blog post though.

Posted on 6/9/2010 6:06:17 AM by
PrairieDevCon 2010 wrapup

Friday past brought the end to the first incarnation of the PrairieDevCon in Regina. The conference had a great buzz of people, interest, conversations and learning about it. It really was a blast to be at it. Thanks to everyone who attended in whatever capacity since it was you that made this event so much fun and productive to be at.

Here are the materials from the sessions that I presented. There isn’t anything for the panel discussion since it was all off the cuff. If you weren’t there you didn’t get to add or absorb….sorry.

Intro To Aspect Oriented Programming: Slides, Code
ORM Fundamentals: Slides

Thanks again everyone and I hope to get invited back to do this all again next year.

Posted on 6/6/2010 2:31:05 PM by
Prairie Dev Con Materials
It was a blast presenting at the first Prarie Dev Con. It was great to have so many attendees with a willingness and want to learn new things. As promised, here are the session materials:

Hands On TDD

Silverlight & WCF In The Real World
Posted on 6/6/2010 12:16:32 PM by
The Tulips are Lovely this Time of Year
  You have to love spring time in Alberta.  The tulips have such a contrast against the snow at 21:30 on a Saturday evening:
Posted on 5/30/2010 10:44:13 AM by
TFS Integration for Source Control in Blend 4, and why it might not be working for you

Since I haven't written here in a while, I thought I'd toss out this quick tip while it's on my mind.

Working with Expression Blend for WPF or Silverlight can be gratifying.  Sketchflow in particular is a great way to rapidly develop clickable prototypes.  Of course, especially if you're working on a Blend project as a team, you'll want to be using version control with a source repository.  Turns out that Blend 4 has TFS 2010 integration built in (and it can be enabled for Blend 3 via patches for both Blend and TFS 2008).

However, if you're working in Blend, you may find the path to that a little convoluted.

See, you can't actually initially add a project to source control from within Blend. 

At first, I had created the project in Blend, and then when we got to the point where wanted to work on it as a team, we used the Source Control Explorer in Visual Studio 2010 to map the path and check the files into TFS source control.  However, there was no integration with Blend, which was painful, as files would have to be manually checked out through Visual Studio and then manually checked back in.  More painfully, new files added to the project would not be picked up and would have to be manually added. 

This frustrated me enough (and made me start worrying about potentially sticky bad-merging scenarios) to see if the Internet knew of any way to make Blend behave the same way as Visual Studio does with regards to source controlled projects... only to find that it's supposed to already be a part of Blend 4.  So why wasn't it working?

After a little poking and prodding, I finally realised that although the files were in source control, the solution and project files were not BOUND to source control.

This is not something you can accomplish via Blend.  However, if you close Blend, open the solution in Visual Studio, go to File > Source Control > Change Source Control..., select each item listed and click Bind, since the containing folder is already mapped to a source repository folder and the solution and project files are in source control it'll pick up the correct binding.  Save and close Visual Studio, and then open the solution in Blend again, and voila!  Blend is now aware of TFS!  You can check files in and out manually from the Projects pane, files will automatically be checked out when you edit them in Blend, and new files added to the project will automatically be added to source control, just like in Visual Studio.

This is one of those things that seems really self-evident after you recognize it, but you might be like me and not recognize it right away.  So here it is blogged for the benefit of your Google search results.

Posted on 5/28/2010 11:03:00 AM by
Gotta Love JetBrains
Gotta love companies that “get it”. Late last night I was hacking away on some Android stuff using IntelliJ 9.0.2 (on Ubuntu 10.04). For reasons unknown to me, none of my breakpoints seemed to be working. In fact, IntelliJ just didn’t seem to be working. I narrowed it down to the breakpoints I was setting [...]
Posted on 5/22/2010 9:22:29 PM by
Going Digital At Home - Part 1
We have a lot of disparate sources of media around our home. DVDs, CDs, VHS, downloaded content, mp3s, etc. I find it to become more and more of a hastle running around finding the media I want, and then finding the device that can play that. Plus with 3 kids running around it is inevitable that their (and sometimes my) optical media gets scratched or damaged.

To that end I have decided to try and go completely digital in our home and felt that documenting it may be of help to others.

Infastructure:
Wireless network (802.11g)
3 televisions
2 original xboxes
1 xbox 360
1 server (more on this later)
multiple client laptops

Goal:
-Have all media centralized
-Have a backup of all media (if I had to do this all over again I would cry)
-Have different media available from different terminals (kids television should not be able to watch adult shows)

Requirements:
The first step here was to get a central computer that will store all the media. This computer should have the following:
-Lots of storage
-A DVD and or Blue Ray player
-Have some sort of hard drive redundancy
-Enough CPU power to convert videos on the fly (A Pentium III 700Mhz is the bare minimum you would want)
-Enough techincal knowhow to install an operating system, install software, and install hardware into a computer.

To do this I took an old server I had (but a desktop would work just fine) and installed two 2TB drives into it (at the time of writing they cost only $150 each). I also installed Windows Server 2008 R2 onto it but any OS of choice should do.

The biggest difference between my setup and the average user is that my media server has a builtin SATA raid card which I configured to mirror the drives (so I only have 2GB of storage but when (not if, when) one fails I can plunk in another and be on my way). If you don't have hardware RAID and don't want to purchase it you can actually setup a raid in software. Setting up a software raid can be a bit tricky but I found a great article about it. The only thing I would change is to give more than 10GB to windows / programs (at least 40GB nowdways I would think). Trust me in that running out of room on a partition is one of the most annoying things to happen to a person.

Once you have the system setup and running I like to make sure that the drives are actually redundant. I have never ever found that a mirror is not actually working after I set it up but I just like to make sure. To do this I take each hard drive out and slave it into another computer and ensure that they both have the same data on it (just a quick check to make sure that the folder structures are copied to each). Once that is done I put them both back in and ensure the mirror is functioning (sometimes it may detect they are out of sync and need to resync the array). The other way to do this is to remove one drive from the server, turn it on, make sure it works, then repeat with the other drive. This process will require a resync of the array which is time consuming. It took at least 15 hours to resync my 2TB array.

That is about it for now. In the future we will talk about software on the server, ripping DVDs and CDs, and how to watch/listen to this stuff on you TVs and computers effectively.



Posted on 5/4/2010 9:48:31 AM by
WPF ISO Date Format Converter
This is a little piece of code I put together for an application. The code is no longer being used but I didn't want to lose it.
 
 
public sealed class IsoDateValueConverter : IValueConverter {
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
if (value != null && value is DateTime) {
var date = (DateTime)value;
return date.ToString(SystemInformation.DateTime.IsoShortDateFormat);
}
return string.Empty;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
if (culture == null) {
throw new ArgumentNullException("culture");
}
if (value != null && value is string) {
return DateTime.ParseExact((string)value, SystemInformation.DateTime.IsoShortDateFormat, CultureInfo.InvariantCulture);
}
return null;
}
}
 
Posted on 4/29/2010 4:33:12 PM by
Passing Parameters to a target in MSBuild

On our current project we are using MSBuild to build our application. This is my first time using MSBuild other than just tinkering and I have found it.... challenging to say the least. A lot of my challenges are lack of knowledge but the other half is the language itself.

The most recent challenge I wanted to write about was calling a target multiple times. Our scenario is this: We have to generate a batch file for each environment we are going to install in with environment specific settings. The issue I had was that for each environment we had that we were copying and pasting the steps and changing values for each environments. While this worked, as the number of environments grew the size of the build task grew and got harder to modify as requirements changed.

Ideally what we would have is a task that would generate a batch file based on a set of parameters that we could just call out to so I built this:

  <Target Name="BuildBatchFile ">
<Copy SourceFiles="install.bat"
DestinationFiles="MyApp.Setup\Release\install.$(BATCHENV).bat"
ContinueOnError="false"
SkipUnchangedFiles="false" />
<FileUpdate Files="MyApp.Setup\Release\install.$(BATCHENV).bat"
Regex="{ENV}"
ReplacementText="$(ENV)" />
<FileUpdate Files="MyApp.Setup\Release\install.$(BATCHENV).bat"
Regex="{VDIR}"
ReplacementText="$(VDIR)" />
<FileUpdate Files="MyApp.Setup\Release\install.$(BATCHENV).bat"
Regex="{INSTALLDIR}"
ReplacementText="$(INSTALLDIR)" />
</Target>

So this copies my template install.bat to install.[ENVIRONMENT[.bat and then does all the string replacements on it.

The issue is how to invoke this task with different sets of data. My first thought was this:

<CallTarget Targets="BuildConfigFile" />

Unfortunately, there is no way to pass parameters to a target. The only way to do that is to call MSBuild and set the parameters passed to MSBuild (this does feel wrong but I am not sure of a better way to do it so far)

<Target Name="BuildDeploymentPackage">
<MSBuild Projects="$(MSBuildProjectFile)"
Targets="BuildBatchFile "
Properties="BATCHENV=ALPHA;ENV=ALPHA;VDIR=PASIPrep;INSTALLDIR=C:\inetpub\wwwroot\MyApp;" />
<MSBuild Projects="$(MSBuildProjectFile)"
Targets="BuildBatchFile "
Properties="BATCHENV=SYST;ENV=SYST;VDIR=MyApp;INSTALLDIR=C:\inetpub\wwwroot\MyApp;" />
<MSBuild Projects="$(MSBuildProjectFile)"
Targets="BuildBatchFile " 
Properties="BATCHENV=TRAINING;ENV=TEST;VDIR=MyApp;INSTALLDIR=C:\inetpub\wwwroot\MyApp.TEST;" />
</Target>

The above target calls MSBuild to call its own build file and run the BuildBatchFile target with a set of parameters.

Hope this helps (or someone shows me a better way to do it)!

 

 

 

Posted on 4/29/2010 2:28:51 PM by
Testing Your Configuration
One common issue of team development is sharing configuration files. If a developer is testing something out and changes a value and then accidentally checks that file in it affects all developers.

There are a few approaches to solving this issue:
1) Be very careful and disciplined.
+Simple
-SImple to forget
2) Have a web.config.template under source control that developers copy to web.config and not include in source control.
+Prevents checkins of web.config files that affect other people
-Developers need to manually update their config files if a new value is added/removed/or the default updated
3) Have a build script task to generate a config file on demand.
+Changes are easily propagated through the script
-If a developer mucks with the build script and checks it in then we have the same problem (but less likely to happen)
4) What we are trying. Unit test the configuration to make sure it is correct.
+web.config is under source control
+changes are caught by a test. If it is meant to be distributed to all developers then the test should be updated as well
-have to write a test for the configuration (not a big minus in my opinion)
-If you have different config settings for the test project than the actual project then this will not work

In order to test a config file though we need to be able to load that config file! In our case we are testing a web.config and nunit is expecting a app.test.dll.config file. The easy way around this was to copy the web.config from our application to the proper folder and name with a pre-build event:

copy $(SolutionDir)\App.Service\web.config $(ProjectDir)\bin\App.Test.dll.config /y

Now my tests use that config file to assert that the settings are proper. The big downside to this approach is that it will overwrite the app.config file that you may already have for your test which may not be desirable.

Alternatives:
1) Parse the XML of the config file you want to test and verify
2) Load and unload and external config file in a test (I started with this and could not get it to work)

Posted on 4/16/2010 12:38:37 PM by
Quick Update to HistoricalBuildings
I just uploaded an update to HistoricalBuildings.  The list of historical buildings used to be sorted alphabetically, by name.  Now they are sorted by the distance from your current location (assuming the GPS can figure that out).
Posted on 4/10/2010 1:36:37 PM by
YEG OpenData and their Historical Buildings on your Android phone
Well, for the brave, criminally insane, curious, or otherwise bored I have a alpha version of Historical Buildings – download the APK if you want to try it out.  This is just, at this time, the application just shows a simple list of historical buildings in Edmonton (according to the City of Edmonton’s Open Data [...]
Posted on 4/8/2010 11:36:24 PM by
Where do you start building skills from?

In the past I’ve had to take development teams and build their skills. It was part of what I was hired to do. “Build an app, and at the same time make our developers better.” I’m back at it again and today I had a chat with someone online about where do you need to start.

First you need to know what your goals are. Usually I find that management is, by asking me to make their developers “better”, looking to increase quality, decrease development time and increase maintainability. All of these are pretty vague and there’s certainly no one day course for each one, let alone all of them. So where do you start then?

One of the first lessons I learned while at basic officer training was that before getting my section/platoon/company working on a task I needed to know what their skills (special or otherwise) were. The lesson was all about resource management. I’m starting a new project complete with a new (to me) development team and once again I’m being asked to make them “better". I could go into a meeting room right now and tell them all how they should be doing TDD, BDD, DDD, SOLID, etc. Some (most I hope) of you will agree that these are practices that can make you a better developer. It would be far more prudent of me to walk into that room and ask instead of state though. I should take the lessons of my Drill Sergeant and initially put effort (and not much will be needed) into evaluating what skills (special or otherwise) the team has. That knowledge is going to set the foundation for how I will approach making these developers “better”.

One of the questions raised in the conversation I was having today was “When we talk about things that we can throw at developers to learn, something like DDD is (sic) beneficial. By the time someone reads the ‘blue book’ they should know quite a bit. Where would you place it (sic) relative to SOLID or the other good practices?” This raised the question of what knowledge in what order when dealing with under trained developers.

For me the whole idea revolves around one thing building on another. Yes you could dive straight into DDD, but wouldn’t it be easier if you understood something about SOLID, or OO Fundamentals? So what is my preferred order then? Depending on what the developers skills are I may start in different places, but usually the order would be something like this.

  1. Tooling. Understanding and being effective inside Visual Studio and other tools that are used every day.
  2. OO Fundamentals. Abstraction, Encapsulation, Polymorphism and Inheritance.
  3. DRY. Simple code reuse techniques.
  4. SRP. Single Responsibility is the foundation (in my mind) for all that follows.
  5. OLID. The rest of SOLID.
  6. Coupling. Why developers should care and how they can deal with it effectively.
  7. Application Layers. How to use logical layering to build more flexible applications
  8. TDD. With the foundation for good design acquired, developers are ready to learn how to apply those design skills.
  9. DDD. How to think about business and translate it into code.
  10. Frameworks. With the foundations built through this list, I feel developers are ready to understand how to use tools such as nHibernate, StructureMap, log4net and others.

I made the mistake that most developers have; jumping straight into frameworks. While it didn’t set my career back, I did need to take a step back and put concerted effort into building my way back up to frameworks again. The best part? With all of the fundamental and foundational knowledge, learning almost any framework is quite simple.

You can’t expect to blast into a room full of developers and expect them to follow this (or any list on this topic) to achieve overnight success. It’s going to take time. Time, effort and commitment. At least the transition from one learning topic to the other will be logical and smooth.

Posted on 4/8/2010 1:00:00 AM by
Android, MapView, and your Google apiKey: Part 1
Thanks to the MapView, it’s drop dead easy to put Google Maps into your application.  There are lots of posts out there how to do it.  Interestingly (to me anyway), when I did a quick search of the Android developers mailing list, I was surprised to see that a lot of people had the same [...]
Posted on 4/7/2010 9:52:38 PM by
MVP in C# For 2010
I guess I forgot to mention this:  On April 1, 2010, I received an e-mail from Microsoft that my MVP in C# was renewed for the third year.  This makes me a happy, because with Resharper 5 (and therefore Visual Studio 2010) and Windows Mobile 7, I’m hoping that this will be an exciting year [...]
Posted on 4/5/2010 8:15:12 PM by
Me, Android, and YEG OpenData
Not that long ago, the City of Edmonton announced it’s Open Data Catalogue. I noticed that one of the data catalogues was a list of historical buildings in the city. Yeah, I know that some people in other cities might consider this a pretty weak list. I mean, the oldest building in Edmonton isn’t even [...]
Posted on 4/4/2010 2:52:35 PM by
Staying Secure
I have started to realize that there are a few things I do that most average users do not to stay secure.

  1. I use a password manager (Roboform) that integrates with my browser. This tool makes me remember one master password and then allows me to fill in login forms on websites with only needing to know one master password. This has let me use unique passwords on all the sites I login to. I see looking through my list of sites that I have 45 accounts on various sites and there is no way that I could remember 45 unique passwords.
  2. I use encrypted pop/smtp/imap so as not to divulge my password. Most of the world still seems to use unauthenticated POP3 for some reason
  3. I use the NoScript add on for Firefox that allows me to control if scripts run on a page or not
  4. I use the ForceTLS add on for Firefox so that if I visit a http site that it will redirect me to an https site (unfortunately you have to setup this list on your own)
  5. I never upgrade an OS. I always reinstall. Call me paranoid but it is hard for anything bad to survive a wipe and reinstall
  6. I run the Secunia Personal Software Inspector that checks for security issues in third party apps and allows me to easily download updates
  7.  I run Microsoft Security Essentials. A free, lightweight, and (from what I have read) accurate virus scanner. It reminds me of how all antivirus software starts out so lets hope MS does not bloat it up.
Posted on 3/24/2010 9:29:25 PM by
Fun in SoCal
Just sitting here at Legoland in Carlsbad, CA waiting for my kids to get off Coastersaurus. Just thought I’d make a mention about my presentation on SOLID to the Inland Empire .NET User Group. This is my third year in a row as their March speaker. I’m glad to say that for the third year [...]
Posted on 3/19/2010 4:43:19 PM by
Winnipeg Code Camp and DevTeach Toronto

It’s been a hectic couple of weeks speaking at Winnipeg Code Camp, the Winnipeg .NET User Group and DevTeach Toronto. All the events were a blast to do. To those who attended, thanks for the great questions and conversations.

Session material is available as follows:

Introduction to Dependency Inversion and Inversion of Control Containers – Slide deck, Dimecasts
ORM Fundamentals – Slide deck
Software Craftsmanship – Slide deck

Posted on 3/14/2010 1:28:22 PM by
Copyright 2010 igloocoder.com Consulting Inc.