Month: July 2008

Separate the ‘what’ and the ‘how’ with xsd.exe

In case you’ve not come across it there’s an extremely useful command line utility in the Visual Studio tools, the XML Schema Definition Tool xsd.exe. It’s particularly important in separating the ‘what’, the system requirements, and the ‘how’, the system architecture.

An example of using it would be defining your application’s FooStatus XSD using Altova’s XMLSpy and then generating your FooStatus class. The class can be generated with the following command line:
C:\>xsd FooStatus.xsd /classes.

This is a painless way of quickly getting a usable business object. The best part of using xsd? The process is completely reversible. If you want to start by generating your class and then create a schema from it you can. Take a look at what else xsd can do for you when you’ve a spare moment – it’ll save you a lot of effort!

Advertisements

Robocopy

If you’ve a large piece of un-branched code you’re working on but you can’t check in to source control then you’ll be worried about losing your changes. You need a backup. Here’s a way of mirroring your working copy.
Robocopy came as part of the Windows Server 2003 Resource Kit Tools. Robocopy can perform mirrors of any directory tree and can monitor that tree for changes, mirroring only the changed files. I’ve set up mine as a scheduled task (Run: robocopy /JOB:SVNBACKUP) (cf: Managed File Transfer, RoboCopy, Sheduled Tasks). A useful Microsoft Robocopy GUI for learning the Robocopy switches is available. When you first create the destination directory with robocopy use the /CREATE switch (see the Robocopy Help file) to minimise directory fragmentation.

The following is my current job file:
::
:: Source Directory :
::
/SD:C:\svn\ :: Source Directory.
::
:: Destination Directory :
::
/DD:G:\svn\ :: Destination Directory.
::
:: Exclude These Directories :
::
/XD :: eXclude Directories matching these names
.svn
bin
obj
::
:: Copy options :
::
/S :: copy Subdirectories, but not empty ones.
/E :: copy subdirectories, including Empty ones.
/MON:1 :: MONitor source; run again when more than n changes seen.
/MOT:5 :: MOnitor source; run again in m minutes Time, if changed.
/PURGE :: delete dest files/dirs that no longer exist in source.
/MIR :: MIRror a directory tree (equivalent to /E plus /PURGE).
::
:: Retry Options :
::
/R:10 :: number of Retries on failed copies: default 1 million.
/W:30 :: Wait time between retries: default is 30 seconds.
::
:: Logging Options :
::
/V :: produce Verbose output, showing skipped files.
/NDL :: No Directory List - don't log directory names.
/NFL :: No File List - don't log file names.
/NP :: No Progress - don't display % copied.
/LOG+:C:\Documents and Settings\Placeholder\Application Data\Microsoft Robocopy GUI\Logs\robocopy.log :: output status to LOG file (append to existing log).
/TEE :: output to console window, as well as the log file.

Watir, WatirMaker & FireWatir

I didn’t want to have to work through browser screens while I was debugging my controls, constantly searching for postcodes etc., so I’ve started using Watir (pronounced ‘Water’) to create and run browser automation scripts.

Watir

Watir installation is simple. Running a script is even easier:

C:\>ruby myScript.rb

An example script for your project might be:

#requires
require 'watir'

#includes
include Watir

browser = IE.new

browser.goto( 'http://localhost:3112/' )

browser.text_field( :id, /username$/ ).set( 'memberuser1' )
browser.text_field( :id, /password$/ ).set( 'password1' )
browser.button( :id, /submit$/ ).click

Watir Maker

WatirMaker lets you easily record Watir scripts as you click through a session in the browser:

C:\>ruby WatirMaker.rb > myScript.rb

It provides you with a basic script quickly and easily and then you can modify it (the Watir cheatsheet is handy).

FireWatir

FireWatir is Watir for Firefox. Once you’ve installed the JSSh extension and started Firefox with the -jssh switch you can run your modified scripts. The only changes that should be required to your scripts are at the start:

#requires
require 'firewatir'

#includes
include FireWatir

browser = Firefox.new

Important tools for development time and you can port the scripts straight into your UAT environment, too.