Snow Leopard: Days 1-2
Thanks to a pre-order from Amazon on August 3, a copy of Snow Leopard arrived on my doorstep August 28. The install was uneventful–typical of Mac OS X installs. I put in the DVD, clicked through a few dialog boxes, went to run a couple of errands. When I got back, I logged in as usual.
So far, I haven’t noticed many differences between Leopard and Snow Leopard. The few of note:
- Hard drive space. Before installing Snow Leopard, I had around 14GB of free space. After installing Snow Leopard (and the latest version of XCode) I have 27GB of free space. It's quite a bit more freed space than the 7GB Apple advertised
- Printing. I have a HP LaserJet 1022. I had to re-install it after upgrading to Snow Leopard and use an Apple driver. It still works just fine.
- Battery Status. Apple added information on battery health. Since my MacBook Pro is closing in on 3 years old, the "Service Battery" message is most likely correct. Apple Support already has a thread about it. Another thing I've noticed which may also be new to Snow Leopard is that I'm getting battery life percentages for my Bluetooth keyboard and mouse as well.
- Character/Keyboard Viewer. A new widget in the upper-right of the screen. I haven't found any particular use for it yet.
- Mail. When I first started it, the app prompted me for some sort of upgrade. Once it was done, the notes from my iPhone showed up under a Reminders item.
- Quicken. I'm still using Quicken 2007 for Mac, so I saw a little prompt about Rosetta when I first launched it. What I really need to do is get out of Quicken 2007 into something else, but that's a subject for another post.
Random SQL Tricks (Part 2)
In my previous random SQL tricks post, I discussed how to generate random alphanumeric strings of any length. A slight variation on that idea that also proved useful in generating test data is the following stored procedure (which generates a varchar consisting entirely of numbers):
CREATE PROCEDURE [dbo].[SpGenerateRandomNumberString] @randomString varchar(15) OUTPUT AS BEGIN SET NOCOUNT ON DECLARE @counter tinyint DECLARE @nextChar char(1) SET @counter = 1 SET @randomString = ''
WHILE @counter <= 15 BEGIN SELECT @nextChar = CHAR(48 + CONVERT(INT, (57-48+1)*RAND()))
SELECT @randomString = @randomString + @nextChar SET @counter = @counter + 1 END END GO
The range in the select for @nextChar maps to ASCII values for the digits 0-9. Unlike the stored procedure from my first post, there’s no if statement to determine whether or not the random value retrieved is allowed because the ASCII range for digits is contiguous. The needs of my application restricted the length of this numeric string to 15 characters. For more general use, the first refactoring would probably add string length as a second parameter, so the numeric string could be a variable length.
A long overdue upgrade
I’m finally running the latest version of WordPress (I’ve been way behind on upgrading). I’d be curious to hear from those of you who visit regularly what you think of the new look. I’d considered a couple others:
I ultimately chose this one for the random post feature that appears in the upper-right of the page.Build Server Debugging
Early in June, I posted about inheriting a continuous integration setup from a former colleague. Since then, I’ve replaced CruiseControl.NET and MSTest with TeamCity and NUnit 2.5.1, added FxCop, NCover, and documentation generation (with Doxygen). This system had been running pretty smoothly, with the exception of an occasional build failure due to SQL execution error. Initially, I thought the problem was due to the build restoring a database for use by some of our integration tests. But when replacing the restore command with a script for database creation didn’t fix the problem, I had to look deeper.
A look at the error logs for SQL Server Express 2005 revealed a number of messages that looked like:
SQL Server has encountered <x> occurrence(s) of cachestore flush ...Most of what I found in my initial searches indicated that these could be ignored. But a bit more googling brought me to this thread of an MSDN SQL Server database forum. The answer by Tom Huleatt that recommended turning off the Auto-Close property seemed the most appropriate. After checking in database script changes that included the following:
ALTER DATABASE <database name> SET AUTO_CLOSE OFFnone of the builds have failed due to SQL execution errors. We’ll see if these results continue.GO
Random SQL Tricks (Part 1)
One of my most recent tasks at work has been generating test data for integration tests of a new application. We don’t have the version of Visual Studio which does it for you, and rather than write an app that did it, I spent the past week hunting for examples that just used Transact-SQL. The initial post that I found the most useful is this one, in which the author provides five different ways of generating random numbers. I use his third method quite often, as you’ll see in this post (and any others I write on this topic).
One of our needs for random test data was alphanumeric strings of varying lengths. Because the content of the text mattered less than the need for text, it didn’t have to resemble actual names (or anything recognizable). The first example I found of a T-SQL stored procedure for generating a random string was in this blog post by XSQL Software. The script does generate random strings, but they include non-alphanumeric characters. To get the sort of random strings I wanted, I took the random number generation method from the first post and the stored procedure mentioned earlier and adapted them to this:
CREATE PROCEDURE [dbo].[SpGenerateRandomString] @sLength tinyint = 10, @randomString varchar(50) OUTPUT AS BEGIN SET NOCOUNT ON DECLARE @counter tinyint DECLARE @nextChar char(1) SET @counter = 1 SET @randomString = ''
WHILE @counter <= @sLength BEGIN SELECT @nextChar = CHAR(48 + CONVERT(INT, (122-48+1)*RAND()))
IF ASCII(@nextChar) not in (58,59,60,61,62,63,64,91,92,93,94,95,96) BEGIN SELECT @randomString = @randomString + @nextChar SET @counter = @counter + 1 END END END
The range in the select for @nextChar is the set of ASCII table values that map to digits, upper-case letters, and lower-case letters (among other things). The “if” branch values in the set are those ASCII table values that map to punctuation, brackets, and other non-alphanumeric characters. Only alphanumeric characters are added to @randomString as a result. Having a stored procedure like this one available makes it much easier to generate test data, especially since it can be called from other stored procedures.
Introducing Doxygen
Last Wednesday evening, I gave a presentation on Doxygen at RockNUG. I didn’t actually bother with slides in order to give as much time as possible to actually demonstrating how the tool worked, so this blog post will fill in some of those gaps.
Doxygen is just one of a number of tools that generate documentation from the comments in source code. In addition to C# “triple-slash” comments, Doxygen can generate documentation from Java, Python, and PHP source. In addition to HTML, Doxygen can provide documentation in XML, LaTeX, and RTF formats.
Getting up to speed quickly is pretty easy with Doxywizard. It will walk you through configuring all the necessary values in wizard or expert mode. When you save the configuration file it generates, the purpose and effect of each setting is thoroughly documented. One thing I will note that may not be readily apparent is that you can run Doxygen against multiple directories with source code to get a single set of documentation. It just requires that the value of your input (INPUT) property contain all of those directories (instead of a single one).
Converting MSTest Assemblies to NUnit
If you wanted to convert existing test assemblies for a Visual Studio solution from using MSTest to NUnit, how would you do it? This post will provide one answer to that question.
I started by changing the type of the test assembly. To do this, I opened the .proj file with a text editor, then used this link to find the MSTest GUID in the file and remove it (the guid will be inside a ProjectTypeGuids XML tag). This should ensure that Visual Studio and/or any third-party test runners can identify it correctly. Once I saved that change, the remaining steps were:
- replace references to Microsoft.VisualStudio.QualityTools.UnitTestFramework with nunit.framework
- change unit test attributes from MSTest to NUnit (you may find a side-by-side comparison helpful)
- delete any code specific to MSTest (this includes TestContext, DeploymentItem, AssemblyInitialize, AssemblyCleanup, etc)
MSBuild Transforms, Batching, Well-Known Metadata and MSTest
Thanks to a comment from Daniel Richardson on my previous MSTest post (and a lot more research, testing, & debugging), I’ve found a more flexible way of calling MSTest from MSBuild. The main drawback of the solution I blogged about earlier was that new test assemblies added to the solution would not be run in MSBuild unless the Exec call to MSTest.exe was updated to include them. But thanks to a combination of MSBuild transforms and batching, this is no longer necessary.
First, I needed to create a list of test assemblies. The solution is structured in a way that makes this relatively simple. All of our test assemblies live in a “Tests” folder, so there’s a root to start from. The assemblies all have the suffix “.Test.dll” too. The following CreateItem task does the rest:
<CreateItem Include="$(TestDir)**bin$(Configuration)*.Test.dll" AdditionalMetadata=“TestContainerPrefix=/testcontainer:"> <Output TaskParameter=“Include” ItemName=“TestAssemblies” /> </CreateItem>
The task above creates a TestAssemblies element, which contains a semicolon-delimited list of paths to every test assembly for the application. Since the MSTest command line needs a space between each test assembly passed to it, the TestAssemblies element can’t be used as-is. Each assembly also requires a “/testcontainer:” prefix. Both of these issues are addressed by the combined use of transforms, batching, and well-known metadata as shown below:
<Exec Command=""$(VS90COMNTOOLS)..IDEmstest.exe” @(TestAssemblies->'%(TestContainerPrefix)%(FullPath)',' ‘) /runconfig:localtestrun.testrunconfig" />
Note the use of %(TestContainerPrefix) above. I defined that metadata element in the CreateItem task. Because it’s part of each item in TestAssemblies, I can refer to it in the transform. The %(FullPath) is well-known item metadata. For each assembly in TestAssemblies, it returns the full path to the file. As for the semi-colon delimiter that appears by default, the last parameter of the transform (the single-quoted space) replaces it.
The end result is a MSTest call that works no matter how many test assemblies are added, with no further editing of the build script.
Here’s a list of the links that I looked at that helped me find this solution:
Detect .NET Framework Version Programmatically
If you need to determine what versions of the .NET Framework are available on a machine programmatically, you’d ideally use a C++ program (since it has no dependencies on .NET). But if you can guarantee that .NET 2.0 will be available, there’s another option. The source code (written by Scott Dorman) is ported from a C++ program. I’m using the library for an application launcher that verifies the right version of the .NET Framework is available (among other prerequisites).
Calling MSTest from MSBuild or The Price of Not Buying TFS
When one of my colleagues left for a new opportunity, I inherited the continuous build setup he built for our project. This has meant spending the past few weeks scrambling to get up to speed on CruiseControl.NET, MSTest and Subversion (among other things). Because we don’t use TFS, creating a build server required us to install Visual Studio 2008 in order to run unit tests as part of the build, along with a number of other third-party tasks to make MSBuild work more like NAnt. So the first time a build failed because of tests that had passed locally, I wasn’t looking forward to figuring out precisely which of these pieces triggered the problem.
After reimplementing unit tests a couple of different ways and still getting the same results (tests passing locally and failing on the build server), we eventually discovered that the problem was a bug in Visual Studio 2008 SP1. Once we installed the hotfix, our unit tests passed on the build server without us having to change them. This hasn’t been the last issue we’ve had with our “TFS-lite” build server.
Build timeouts have proven to be the latest hassle. Instead of the tests passing locally and failing on the build server, they actually passed in both places. But for whatever reason, the test task didn’t really complete and build timed out. Increasing the build timeout didn’t address the issue either. Yesterday, thanks to the Microsoft Build Sidekick editor, we narrowed the problem down to the MSTest task in our build file. The task is the creation of Nati Dobkin, and it made writing the test build target easier (at least until we couldn’t get it to work consistently). So far, I haven’t found (or written) an alternative task, but I did find a blog post that pointed the way to our current solution.
The solution:
<!– MSTest won’t work if the tests weren’t built in the Debug configuration –> <Target Name=“Test:MSTest” Condition=" ‘$(Configuration)’ == ‘Debug’"> <MakeDir Directories="$(TestResultsDir)" /> <MSBuild.ExtensionPack.FileSystem.Folder TaskAction=“RemoveContent” Path="$(TestResultsDir)" />
<Exec Command=""$(VS90COMNTOOLS)..IDEmstest.exe" /testcontainer:$(TestDir)<test assembly directory>bin$(Configuration)<test assembly>.dll /testcontainer:$(TestDir)<test assembly directory>bin$(Configuration)<test assembly>.dll /testcontainer:$(TestDir)<test assembly directory>bin$(Configuration)<test assembly>.dll /runconfig:localtestrun.testrunconfig" />
</Target>
TestDir and TestResultsDir are defined in a property group at the beginning of the MSBuild file. VS90COMNTOOLS is an environment variable created during the install of Visual Studio 2008. Configuration comes from the solution file. Actual test assembly directories and names have been replaced with <test assembly> and <test assembly directory>. The only drawback to the solution so far is that we’ll have to update our MSBuild file if we add a new test assembly.
CruiseControl.NET, MSBuild and Multicore CPUs
When I was trying to debug a continuous build timeout at work recently, I came across this Scott Hanselman post about parallel builds and builds with multicore CPUs using MSBuild. While adding /m to the buildArgs tag in my ccnet.config didn’t solve my timeout problem (putting the same unit tests into a different class did), pooling multiple MSBuild processes will certainly help as our builds get bigger.
The unexpected home of IsHexDigit
I was about to write a method that checked to see if a character was a hexadecimal value when it occurred to me that I should google for it. I was going to name it IsHexDigit, and googling for that revealed this link. I’m not sure why it’s in the System.Uri class, but it’s less code for me to write.
Implementing Mouse Hover in WPF
We’ve spent the past couple of weeks at work giving ourselves a crash course in Windows Presentation Foundation (WPF) and LINQ. I’m working on a code example that will switch the datatemplate in a list item when the mouse hovers over it. Unfortunately, WPF has no MouseHover event like Windows Forms does. The usual googling didn’t cough up a ready-made answer. Some hacking on one example did reveal a half-answer (not ideal, but at least a start).
First, I set the ToolTip property of the element I used to organize my data (in this case, a StackPanel). Next, I added a ToolTipOpening event for the StackPanel. Here’s the code for StackPanel_ToolTipOpening:
private void StackPanel_ToolTipOpening(object sender, ToolTipEventArgs e)
{
e.Handled = true;
ContentPresenter presenter = (ContentPresenter)(((Border)((StackPanel)e.Source).Parent).TemplatedParent);
presenter.ContentTemplate = this.FindResource(“Template2”) as DataTemplate;
}
The result: instead of a tooltip displaying when you hover over a listbox row, the standard datatemplate is replaced with an expanded one that displays more information. This approach definitely has flaws. Beyond being a hack, there’s no way to set how long you can hover before the templates switch.
Switching from an expanded datatemplate back to a standard one involved a bit less work. I added a MouseLeave event to the expanded template. Here’s the code for the event:
private void StackPanel_MouseLeave(object sender, MouseEventArgs e)
{
ContentPresenter presenter = (ContentPresenter)(((Border)((StackPanel)e.Source).Parent).TemplatedParent);
presenter.ContentTemplate = this.FindResource(“ScriptLine”) as DataTemplate;
}
So once the mouse moves out of the listbox item with the expanded template, it switches back to the standard template. Not an ideal solution, but it works.
This link started me down the path to finding a solution (for reference).
Gotta love this April Fool's Day gag from Google
Here’s the e-mail home page.
They’ve got a little announcement, technical specs, even a blog with annoying, cutesy music.
Free Software for Your New Computer
If you’ve bought a new PC or Windows laptop recently, it probably came “bundled” with a bunch of free software. It is a near certainty that the bundled software you got is awful. Most people I know who make their living from computers (the ones who use Windows instead of Mac OS X anyway) reformat the hard drive and install only what they need to avoid this junk. Why this software is on your computer in the first place is another story. This post is about where you can find free software you actually want on your computer.
The Google Pack (http://pack.google.com) is a great place to start adding software you actually need. As of this writing, the pack contains 14 applications. This includes applications like Adobe Acrobat Reader, Firefox, Picasa, Skype, and RealPlayer. The biggest benefit of adding these applications to your new computer via Google Pack is the updater software. You can configure it to automatically update applications when there are new versions.
Open Source Windows is another great source for free software. Unlike the Google Pack offerings, none of the software you’ll find at Open Source Windows is offered by Google. The types of software are broader in many ways as well. They include instant messaging (IM) clients, RSS clients, video playback, sound recording, graphics/photo editing, even games.
So if you’ve got a new Windows machine you need to get running, get rid of the bundled software and pay those sites a visit. It will only cost you a little time, and the quality of the software you’ll get in return makes it a worthwhile investment.
Recommended Listening: Derivative Dangers
If you want to know how long ago the seeds of the current financial crisis were sown, definitely listen to this episode of Fresh Air. Terry Gross' interview of Frank Partnoy reveals not just how derivatives came to be unregulated, but who some of the players were in making it possible. What may disturb you is how many of the people who made the current situation possible are playing key roles in trying to fix it. Partnoy also authored F.I.A.S.C.O.: Blood in the Water on Wall Street. He first wrote this book 12 years ago–before the collapse of the internet and telecom bubbles, before Enron, and the subprime mortgage meltdown that triggered our latest financial calamity.
Sometimes, I really love the web
I’m at the airport to pick up a couple of friends, just back from a week in Spain. Adam asked me last week if I could pick him and his fiancée up from the airport. Somehow, we didn’t exchange a flight number along with the airport and arrival time, so I had no easy way to see if anything changed. Thanks to the web, this was no problem.
A search for Dulles Airport brought up their website. A search for today’s arrivals from Spain revealed the flight number and scheduled arrival time (which turned out to be about 30 minutes later than Adam and I discussed last week). I put the flight number into flightstats.com, and not only did it give me both segments of the return flight, it updated the scheduled arrival time and provided a near real-time map of their flight as it approached.
So instead of showing up way too early, I got to Dulles just a few minutes before Adam called to let me know they’d landed. I was able to do all that (and write this post) with my iPhone 3G.
Alternative PDF Readers
According to an article I got from my boss, there is a flaw in Adobe Acrobat and Adobe Acrobat Readers that will allow hackers to take over your machine if you open a PDF file they send you. The article only mentions Windows XP Service Pack 3 as a vulnerable OS, so it’s unclear whether Vista can be taken over this way as well. Despite how serious this flaw is, a fix for it won’t be available until March 11. Between now and then, you can either swear off the opening of PDFs entirely, or use an alternative PDF reader.
Those of us using Mac OS X (which understands the PDF format natively) need only make sure that Preview or Safari is the default PDF reader.
Las Vegas Sites and Attractions Photo Republished
One of my Las Vegas photos from a trip last year got picked up by a little online travel guide. I originally posted it on Flickr (http://www.flickr.com/photos/scottlaw1/2916736404/).
Microsoft Gets It Wrong Again
According to this story, there’s no direct upgrade from Windows XP to Windows 7. Given all the stories of people “downgrading” from Vista to XP, or not upgrading at all, it seemed obvious to me that Microsoft should make upgrading as smooth as possible. Instead, XP users will have to backup data, re-install programs, and restore data.
Having used the Windows 7 beta on a spare laptop for awhile, I can say it’s a distinct improvement over Vista. It’s just a shame that Microsoft has decided to make the upgrade experience more difficult for XP users.