Monday, May 07, 2007
Monday, May 07, 2007 6:54:30 PM (SE Asia Standard Time, UTC+07:00) (C#)

Back in March I went to the MSDN Roadshow in London to see presentations on several topics - one of them was LINQ.

In my attempts to keep up with the avalanche of software coming out of Microsoft - I have a short list of beefy books to read, weblogs to keep up with, and videos and Webcasts to watch.

The presentation at the roadshow in March was ok - but I thought for a while about the cost of attending; the time it took to get there - the structured format of the show and my never ending need for utilitarian sources of good information.

Today I came across Mike Champion's very helpful post...

Accelerating Evolution: LINQ News from Mix 2007 which includes a link to a video of Anders' presentation at Mix 2007 .

Anders' presentation is brilliant; fluid and clear - and really demonstrates the LINQ language enhancements well.

What's more I was able to watch it at a time of my choosing, and at my own pace - which makes me wonder a little about the real benefit of the Roadshows (apart from the less than subtle injection of a lot of MS Office 2007 mini-marketing presentations between each of the main items of the event).

Mix 07 on the other hand is a 'whole-n-other' thing.... :-)



| Comments [0] | | #  
Sunday, April 29, 2007
Sunday, April 29, 2007 4:38:34 PM (SE Asia Standard Time, UTC+07:00) (Utilities)

For a while now I've been backing up my important data to a removable 80GB USB drive (two actually - one for on-site storage and one for off-site).  I've been using a utility called SmartSync Pro which I've routinely recommended to friends who want to back up their files to a removable drive.

I finally got round to creating some proper batch files today using Robocopy to perform my backups. Robocopy copy ships with Vista and it's a cool file copy utility. For maintaining an in-sync external drive it's great because by default it will only copy files that have timestamp or filesize changes - so that covers new or updated files. It also has a purge option (/PURGE) that when combined with the empty directory option (/E) will remove any orphaned files from the external drive (both of these options can be combined with the /MIR switch which mirrors the destination drive).

I also needed to stop SQL Server and related services so that database files would be backed up as well  - NET STOP <service_name> for each service is included in the batch file along with a NET START <service_name> after the backup has completed.

The last batch file I created simply clones my regular backup drive to a second removable drive for off-site storage.

Several of the comments and variable declarations in the attached batch files were created by another author (the log file format setting in particular) - a sample I found on the net, and for the life of me I can't find the link back to the original files to give credit to (apologies in advance if you happen to come across this post).

I still use the Vista System Backup - creating a Windows Complete Backup - to backup my OS as an image - but I find Robocopy much more flexible (and fast) for backing up data that will be available on removable media - especially when combined with an on and off-site media strategy.

BatchFiles.zip



| Comments [0] | | #  
Saturday, April 21, 2007
Saturday, April 21, 2007 5:03:44 PM (SE Asia Standard Time, UTC+07:00) (Enterprise)

NOTE - see Part Two of this article here...

I've recently been working on a component for a client that requires several implementations of a base class and interface including internal class dependencies.

I'd also been lurking over a couple of blog entries on the topic of Inversion of Control Containers and the Dependency Injection pattern and trying to work out the best strategy for configuring the base provider class as well as the dependencies, and so for the first time I was thinking - hmmm.. a case for DI and a pluggable architecture.

I'm by no means an 'Alpha Geek' where DI, IoC and pluggable frameworks go, however I've been using EntLib and various providers in .Net for a while now and my curiosity was peeked when Enterprise Library 3.0 shipped with its very own Application Block Software Factory.

A brilliant blog writer by the name of Jeremy D. Miller has posted a series on DI and IoC - such as The Dependency Injection Pattern – What is it and why do I care? and Thoughts on Building Pluggable Frameworks.  I'd been looking at StructureMap and Castle Windsor as possible starting points.

I've also been following the evolution of the Guidance Automation Toolkit and the Guidance Automation Extensions. There's some cool stuff going on here with the software factories released so far.

So... while StrctureMap looks like an excellent choice (although I should stress I'm really not qualified at this stage to compare the two) - I decided to try it the Microsoft way first using GAX and the Application Block Software Factory ... and here are the results - a Foo Application Block sample app (Zip)

There aren't any QuickStart sample apps for an Application Block using the software factory (at least not yet) and the docs supplied are clear but very brief and so a little digging was required. Tom Hollander has posted three video tutorials on getting started with this software factory - Enterprise Library: The Videos. The first two demonstrate the creation of providers for existing application blocks. The third one takes you through the creation of a custom application block. As an aside - the Configuration namespace in .Net 2.0 is large and daunting at first - but there's some powerful stuff in there. It helps a lot if you're familiar with the most common classes in the configuration namespace, ideally having created at least one configuration section using the ConfigurationSection base class.

I also wanted a simple App.config ready to go with my new block and configuration settings including custom settings for a provider. While Tom's video demonstrates this - the screen width was too narrow to see some of the settings he'd used including the most important reference to the section handler type.

After watching the videos and trying it out - a couple of hours later I'd got the hang of it and can now produce a custom application block, base provider and configuration classes in about five minutes; not a bad return.

The only dependencies in the new custom block are the Microsoft.Practices.EnterpriseLibrary.Common and Microsoft.Practices.ObjectBuilder namespaces - so if you're already using Entlib - these shouldn't worry you - and if you're nervous about getting into bed with GAX and GAT too soon - then with one custom application block in the bag - you can use this as a template for other projects without GAX. Creating new providers within the project is very straightforward.

One mistake I made that caused me to get hung-up for a few minutes - was a typo in the type declaration in the App.config settings file for my first concrete provider (CoolFooProvider) - if you make this mistake you'll get the following exception at runtime - "The [Assembler] attribute is not set in the configuration object type Foo.Configuration.FooProviderData." (for your base provider data class). Since this is the base type for concrete provider data class it's not decorated with the [Assembler] attribute; it's never meant to be 'assembled'. The application block couldn't find my concrete implementation (because of the config typo) and so fell back to trying to assemble the base class. Check your config file carefully if you see this message.

I also didn't like the default name of the ApplicationBlockSettings class that was created by the software factory - but this is a simple search and replace in files from VS - in this case renaming ApplicationBlockSettings to FooSettings. This is important though since this is the class that handles the section - and the one that you'll need to reference in your App.config section definition.

And very lastly - I prefer my section definition names to be camel cased (and so do the authors of the main EntLib blocks) and so a quick change to...

"public const string SectionName = "foo"" in FooSettings was in order.

My objective in the exercise was to see how quickly I could create configurable providers for the base and interface definitions for the component - including the correct settings for App.config since I did not want to depend on the designer for configuration setting creation. Like most things - it's quick and easy once you know how. Here's the link again to a working demo of a custom application block - Foo application block (Zip).

The next step in the project will be to create two new provider bases and interfaces for the nested dependencies (this is the main design goal of the block - otherwise I'd be using a simple FactoryClass to create the component). The constructor for the parent provider will simply call ProviderFactory for the nested providers based on one of the string settings in the parent provider, and of course the App.config will contain another list of possible provider entries for the child providers. If you've made it to your first custom Application Block then this next step is a breeze.

If I were more knowledgeable about StructureMap and the Castle Windows Container - I'd make some comparison comments - but I'm not (yet) so I wont. I've read enough so far to know that I'm in good shape for the first step in the process which is a good object configuration and creation strategy.

Containers are next....



| Comments [0] | | #  
Tuesday, April 03, 2007
Tuesday, April 03, 2007 3:46:04 AM (SE Asia Standard Time, UTC+07:00) (WPF)

For a while now I’ve wanted to build a small application that would take a set of images and generate a set of previews, thumbnails and metadata xml ‘sidecar’ files that I could upload to my blog (I have a gallery viewing ASP.Net control that reads the directory structure and displays the gallery - and yes I have rendered image on the fly using an HTTP handler and GDI.Net in the past – but I prefer to upload my photo albums as pre-generated packages). 

I figured this was a chance to crack the covers of my WPF book and build my first small WPF application.  I got there in the end – and I learned a LOT about WPF in the process. 

I used the WPF SDK Photo Viewer Demo as a starting point. This was just enough to get me going with a ListBox control and some special formatting using control templates, but there was still a long way to go. 

Here’s what I’ve learned from this relatively small exercise. 

  1. WPF window controls have a minimum width and minimum height property. As silly as this may sound, it took me a few minutes before I realised these existed; however they were important since I wanted my XAML layout to be liquid with a fixed right hand panel and canvas, and an expandable listbox. Setting a minimum width prevented the liquid layout from shrinking too far (like a good'ol CSS liquid design).

  2. I learned how to use the Grid, StackPanel, Canvas and DockPanel controls. You really have to crack these first before you can do anything useful in WPF – especially if you were expecting a fast start like Windows Forms will give you when it comes to dropping controls onto a form. Expression Blend helps – but I switched to XAML source to tweak the layout regularly. What’s more I could only get control events to ‘wire-up’ in my code behind files when I placed the event handler name in Expression Blend. Double clicking on the control in VS 2005 will not create the event handler in code for you. No doubt when Visual Studio Orcas is released this will change.

  3. Watch out for BitmapEffects in a list – or on any other element that occupies a large area of the window (like GroupBox controls). Here’s a couple of good links on performance in WPF: Maximizing Performance in WPF and Optimizing WPF Application Performance and specific to the BitmapEffect -Bitmap Effects Overview. Bitmap Effects render in software and the delay in maximizing the window and scrolling the ListBox was dramatic when BitmapEffects were attached to the list and other large window controls.

  4. Triggers in a ControlTemplate are awesome – but I wanted to apply a BorderBrush to a border that surrounded a ListBoxItem for the IsFocused trigger – and the Border control does not have a property trigger for IsFocused. Here’s how you do it from the ControlTemplate for the ListBoxItem:
     
    <Trigger Property="IsFocused" Value="True"> <Setter TargetName="ItemBorder" Property="Border.BorderBrush" Value="#FF8877BB"/> </Trigger>

    Once you’ve defined the triggers – you can set the property of any named control in the XAML control tree by setting the TargetName. It took me ages to work this out. I just named the Border that I’d placed around the template ‘ItemBorder’ and then set the trigger setter as followsJust to be clear, this is a trigger defined in the ControlTemplate for the ListBoxItem - but it is changing the property of another named control in the XAML mark-up; the Border control named ItemBorder. Way cool

  5. When viewing Thumbnails – don’t use the Thumbnail property of the BitmapImage or BitmapSource – it may not be oriented the same way as the full image if you have rotated the image (depending on the software you’ve used to rotate the image). Instead use the DecodePixelWidth of the BitmapImage when you open the file and give it a decent size for thumbnails. I kept the Zoom feature of the SDK sample app – but modified it to give my ListItemControl template a rectangular shape. Having larger resolution thumbnails to back up the Zoom feature meant that this was now a useful method for selecting images without necessarily having to open a larger preview window.

  6. The world of binding – I learned a lot about binding including binding property values of one control to the values of another (the Zoom effect). I also learned something very useful from this blog post on how to get the PlacementTarget for a context menu click from this entry… Binding ContextMenu to its logical Parent.

  7. Although there’s a ton of glassy button effects out there – I found this link very helpful in getting an animated glassy effect for my apps buttons – Creating a Glass Button: The Complete Tutorial. A great intro to Storyboards and Animations.

And here’s the result..(click on the image for a larger version).

My First WPF App



| Comments [0] | | #  
Sunday, March 25, 2007
Sunday, March 25, 2007 12:35:21 AM (SE Asia Standard Time, UTC+07:00) (ASP.Net)

Discovered Mike Ormond's blog after the MSDN Roadshow - which in turn led me to this definitive article on ASP.Net Viewstate from Dave Reed. Mandatory reading.



| Comments [0] | | #  
Wednesday, February 07, 2007
Wednesday, February 07, 2007 10:44:13 AM (SE Asia Standard Time, UTC+07:00) (ASP.Net)

Having recently moved my DasBlog tech blog from one domain to another I wanted an easy way to redirect all the traffic from the old domain, to the new one.

My shared hosting provider doesn’t provide directory level redirects (although this can be done in IIS) – only domain level.

There are also plenty of examples out there for how to redirect a single page – typically Default.aspx. What I wanted was true SEO friendly Url for Url permanent HTTP 301 redirection for every page and service in the blog.

Since the blogging engine and directory contents were the same all I needed to replace was the name portion of the domain name for the incoming Urls, redirecting them to the same resource, but on the new domain.

So I knocked to together an HTTP Handler that looks like this.

namespace DotBits.Handlers
{
   public class RedirectHandler : IHttpHandler
  
{
      public void ProcessRequest(HttpContext context)
     {
        context.Response.Status = "301 Moved Permanently";
        string url = context.Request.Url.ToString().Replace("dotbits", "58bits");
        context.Response.AddHeader("Location", url);
      }

      public bool IsReusable
     {
        get { return false; }
     } 
   }
}

And then a reference to the handler with the correct path statement in the Web.config file.

<system.web>
   <
httpHandlers>
     <
add verb="*" path="blog/*.*" type="DotBits.Handlers.RedirectHandler"/>
   </
httpHandlers>
</system.web
>

Presto. Works for all registered ASP.Net resource types; .aspx, .asmx, .axd etc.



| Comments [0] | | #  
Monday, February 05, 2007
Monday, February 05, 2007 12:42:28 AM (SE Asia Standard Time, UTC+07:00) (Hardware | Other Tech)

I’m not a hard core gamer, or a hardware freak per se, but in my quest to build a small form factor (SFF) PC that will last a few years before having to upgrade I decided to push the envelope on SFF PCs. I have three boxes on the go at the moment including an older Shuttle SD31P. Space is an issue, and I’ve always liked the idea of being able to grab my main box – put it in a  carry-on luggage bag and fly off knowing that my ‘office’ is in the bag (for longer journeys of course).

In December I purchased a Shuttle SD37P2 Barebones SFF (Intel 975X Express chipset). This is a very cool box. The real hard-core iron guys will complain that the audio card is slightly below spec (Realtek ALC882 high definition audio codec for eight channels of 24-bit/192 KHz), and network controller from Broadcom uses a little more CPU resource than it should at full Gigabit bandwidth. I can’t say that I notice. The auido is great, and this is a workstation class PC not a datacentre server with a NIC at full throttle 24/7 and so I’m happy on both counts.

SD37P3

 

I then thought for a while about what to do in the video card department – knowing that DirectX 10 cards are on the way. The choice was to buy an economy card now knowing I would replace it in a month or two – or go for the only DirectX 10 card on the market at the moment. I waited until January before buying the video card – having decided to ‘go for it’ and buy an NVidia GeForce 8800 series card. The longer and more powerful GTX version won’t fit in the SD37P2 and even if it did the power requirements exceed the PSU spec. So the GTS was the one. Cool Card – dual slot PCI-E card with good thermal control. I purchased the Asus version (comes with a few extra connectors and some sampler games – including Ghost Recon Advanced War Fighter).

Asus GeForce 8800GTS

 

Then came Memory – courtesy of Corsair two sets of twinned 2GB XMS2 modules for a total of 4GB.

Xms2_module

 

And then the CPU. If I’d really wanted a ‘boastable’ box I would have bought the Core 2 Extreme X6800 CPU – but I just couldn’t justify the serious bucks required for this CPU. I’m not an over-clocker and for the 0.3 GHz trimmed off the clock speed – the Intel Core 2 Duo E6700 hit the sweet spot. Looking forward to trying out the Virtualization Technology and running my first VPC image soon.

E6700

There are 681 million transistors in this thing. Err.. that’s a lot. Incredible.

With all the bits coming together nicely the only thing missing was the OS. This was going to be a Vista box – but so close to retail launch, and with Vista RTM already in the hands of Microsoft’s corporate customers there seemed little point in installing the the RC1 image I’d previously tested. Somehow a Windows Vista Universal Key and DVD arrived as if by magic; with 26 days left to activate as I write, and yes – I’ll be buying my Windows Vista Ultimate license pronto… :-)

After a couple of test runs with Windows Vista Ultimate 64bit edition I decided that I just wasn’t going to be able to build a stable production machine on a 64bit OS. Not least of which Cisco show no sign of updating there VPN client for 64bit use and have only just released a 32bit beta version of the VPN Client for Vista.

A few hours on and I had a fully functional production box with all the usual tools and utils, VS 2005, SQL Server 2005 and everything else I need to work. The amazing thing is that it does exactly that – works! And does it ever – the machine is incredibly fast. Despite risking it with the VS 2005 SP1 Patch Beta for Vista, the SQL Server 2005 SP2 CTP patch for Vista, the Cisco Client Beta for Vista, Cute FTP Pro 8, FeeDemon, EditPad Pro etc. etc. etc.; it all works! Tortoise SVN misbehaved for the sum total of about 2 hours before the benevolent Stefan Küng posted a fix to the nightly build directory of Tortoise SVN (Stefan deserves a medal for his work on Tortoise SVN).

The number of major and minor improvements in Vista is incredible. Everything from a disk checking utility that actually works and provides a decent report, to the ‘not one’ but ‘three clocks’ and timezones that you can configure for the taskbar clock. The list is huge – and the best site for all the goodies in Vista that I’ve discovered so far is definitely Paul Thurrott's SuperSite for Windows.

So with everything up and running – and real work being performed on my new machine – the only thing left were the video drivers from NVidia followed by activation to get Aero Glass. NVidia must have been scrambling to get the 8800 series Vista drivers out because they showed up on their site on exactly the same day of the official retail launch of Vista. I’d expected something there from the November RTM. And these are still listed as Beta drivers.

About an hour ago I installed the NVidia drivers and a funny thing happened – I got Aero Glass as a bonus. :-). I still have 26 days to activate Vista – and from everything I’ve read you don’t get Aero Glass goodies until you fork over the bucks. Thank you NVidia – two in one!

Aero Glass is just so cool (lurking Gnome, KDE or OSX users – pah – I scoff in your general direction). Aero Glass is the slickest OS UI that I’ve ever seen – and fun too!  I’ve been flip 3Ding for an hour now – and I’m not bored yet (sad I know). I love the blurred transparent background effect on the window frames of apps that have the focus…

Here’s a shot of Windows Media Player 11 on top of BlogJet 2.0.

Aeroeffect01

Here’s the effect…

Aeroeffect02

So cool….

And for the Windows Experience Index braggers out there – I’m a 5.4 all in.

WEI

:-)



| Comments [0] | | #  
Monday, January 29, 2007
Monday, January 29, 2007 2:03:03 PM (SE Asia Standard Time, UTC+07:00) (SQL Server)

The following MS link - http://support.microsoft.com/kb/274188/ - will help you to troubleshoot and fix orphaned logins in a database, re-joining the database username to the SQL Server Login.

However if you've moved a database from one machine (A) to another (B) using the attach database method and B doesn't have the logins available to be fixed in the first place - then you need to create the required SQL Server logins first. MS have a great helper script that will extract the Login name, SID, default database and password as well as create a script that can be run on the new machine B to re-create all the required logs (and SIDs). You won't need to fixed any orphaned users since the user information in the newly attached DB and SQL Servers login information will now match.

http://support.microsoft.com/kb/246133/- How to transfer logins and passwords between instances of SQL Server.

A huge time saver and makes moving a DB using the attach method a breeze.



| Comments [0] | | #  
Sunday, January 28, 2007
Sunday, January 28, 2007 6:19:35 PM (SE Asia Standard Time, UTC+07:00) (Other Tech)

OK – so the post below gushed over True Image. That was until I spent a weekend kicking the tires on Vista RTM (more soon….)

Firstly, on Vista 64Bit – True Image was broken; corrupt images and failed restores. Not sure about 32Bit Vista yet – however having discovered the new Vista Image format and full backup and recovery options – I’ve switched (I also postponed the Vista 64Bit install until Cisco kindly update their VPN client). I’ve run several complete Vista image backups – nuked the drives and restored flawlessly each time. Before my Vista box goes into production I need to be super confident that I have good recovery options.

The new Backup and Restore Center in Windows Visa is excellent; boot from the Vista install CD, enter your language and time information, and then choose repair Vista on the next screen. If there’s nothing to repair (i.e. an empty drive) you will still be allowed to move onto the next screen where you can choose your repair options – including a full recovery. No need to install the OS first. The Vista image will recreate all drive partition information and restore the machine to the state it was in during your last backup. Can be used in the same way Ghost and True Image are to upgrade or replace a drive.

Lots of good things in Vista – and this is certainly one of them.



| Comments [0] | | #  
Monday, January 15, 2007
Monday, January 15, 2007 2:45:11 PM (SE Asia Standard Time, UTC+07:00) (Utilities)

I’ve been a loyal follower of Norton Ghost for many years. I’ve used it regularly in the past to copy, clone, and restore drive images. I’ve always used a dedicated drive image tool to create my own system restore points. The last DOS version of Ghost running from my boot CD with USB support to store the image was the zenith of Ghost usage for me I think. Feature bloat and a really terrible recovery CD in the latest version forced me to begin a search for an alternative.

Powerquest’s Drive Image Pro is long gone thanks to their acquisition however - happily I found exactly what I was looking for at Acronis True Image. Thank you Acronis. What an excellent piece of software. For starters the imaging tool is cool – well designed, easy to use and FAST. I can do a full image of my OS disk in about 15 minutes (a 14GB image file from 28GB of data). But the really amazing part is their recover CD. It takes only a couple of minutes to prepare, boots VERY fast, and runs True Image nicely – allowing me to browse for the backup image wherever it’s located, on another disk, or on my USB drive. The Ghost recovery CD takes nearly 10 minutes to boot – using a PE version of Windows (I think). The simplicity of True Image combined with their excellent recovery CD was the killer blow to Ghost, and I’m now an Acronis True Image convert.

For interest – I use True Image to create recovery images of my OS partition (my C: drive) and another very cool tool called SmartSync Pro to sync my data volume (my D: drive) with an external USB drive. I run backups (syncs) to the USB drive every day and also keep a fortnightly drive on rotation, locked in a safe at a friends office for off-site storage. The Robocopy console app is also a good way to kick-start the backup of a data volume and can also be used to mirror or sync data – but I liked the UI in SmartSync Pro enough to pay the asking 35.00 USD for the product.

Between the two – Acronis True Image 10 and SmartSync Pro, I’m pretty much covered on the system backup and data recovery front.



| Comments [0] | | #