Cowboy No More

Search

June 30th, 12:49am 5 comments

Simulating "Publish to folder" Functionality in Visual Studio 2010

Visual Studio has a handy "publish" feature for web sites. One piece that's really handy is the ability to publish to a folder -- just right click the project, choose Publish, click a few buttons, and you're all set.

But what if you want to automate this in a build server like Hudson, CruiseControl.NET, or TeamCity? It turns out that this can be triggered using MSBuild like so:

msbuild /t:Build;PipelinePreDeployCopyAllFilesToOneFolder /p:Configuration=Release;_PackageTempDir=C:\temp\somelocation MyProject.csproj

Basically, we're hooking into the main action used by the Publish functionality, PipelinePreDeployCopyAllFilesToOneFolder. Be aware that this wipes out the temp directory, so if you need your files to coexist with others then you'll have to follow this with a copy operation.
Posted
May 20th, 1:16am 0 comments

This Linux thing... it's going places.

I've been doing some C programming for my Distributed Systems class. Good times. More interesting is that I've been using Linux. Now I've played with Linux on and off for the past 15 years or so, every time giving up at some juncture where the reward for my efforts doesn't seem worth it.  Even when I owned a Mac for 4 years I rarely descended to the command line... why?

Somehow, this time it's all started to click for me. Is it the new version of Ubuntu making everything so usable?  Was it forcing myself to learn how to get around emacs?  Or because our assignments required writing Makefiles?  Did Google make the OS irrelevant?

All I know is that I just wrote a perl script. For fun. Stand back, I know regular expressions!

Posted
April 27th, 1:16am 1 comment

A maze of twisty little passages, all alike

So I want to use Regular Expressions in a C project for my Distributed Systems class.  If I were a Unix guru, I'd fire up emacs or vi and just add an include for <regex.h>.  But I'm a Windows guy who will give up Visual Studio when it's pried from my... well, when it's upgraded to something else.  Anyway, Microsoft's C implementation doesn't include this. 

Since the target system is Linux, I had to find a port.  This one seems like it will fit the bill.  So it's from 1997, who cares?  If it works, it works.  Except, of course, that the executable won't run.  The ancient INFO-ZIP self-extracting archive gives a message saying that the zip file is incomplete and that its final bytes perhaps reside on another floppy disk.  And I start feeling a little old.

Amazingly, I managed to find an answer for this on a reference for another language, BBC Basic.  Apparently the file is corrupted -- the last byte is missing. So I had to download a Hex editor and add a zero to the end of the file.  Amazingly, that allowed it to extract.  Somehow that made me feel even older.

Now if you'll excuse me, I have to go find a copy of Jumpman to play for a few minutes.

Posted
April 6th, 3:48pm 0 comments

stinky build scripts

I'm new to the world of build scripts.  So my first build script, while functional, is a complete piece of crap that I'm already afraid to touch in a few weeks' time.  Automation for the people: Remove the smell from your build scripts gets to the heart of the problems I'm having.  This is one of the best pieces I've read on the topic of maintaining build scripts.
Posted
March 25th, 10:53am 0 comments

holy crap I love lambdas (ok, delegates :-)

I pity the poor Java coders, really I do.  (Of course at night I am one, but that's another matter.)

Teardown logic in test code can be a pain point, as described by Gerard Meszaros in his book xUnit Test Patterns.

Suppose you have code like this:

teardown1();
teardown2();
teardown3();

If teardown1() fails, then teardown2() and teardown3() are not executed.

So you might write something like this...


try {
    teardown1();
}
finally {
    try {
        teardown2();
    }
    finally {
        teardown3();
    }
}

Which doesn't scale at all when you have a lot of teardown code.

Enter lambdas -- specifically, Action<T>.  This guy gives you a quick syntax for defining a method that returns void.  So now you can aggregate your teardowns in a list, then call each of them one at a time.

// Behold a beauteous delegated teardown.
List<Action> tearDowns = new List<Action>
                             {
                                 () => teardown1(),
                                 () => teardown2(),
                                 () => teardown3()
                             };

foreach (var teardownAction in tearDowns)
{
    try
    {
         teardownAction();
    }
    finally
    {
    }
}

Actually, since the methods being called are themselves all void in this example, you can just use them like so:


 // Behold a beauteous delegated teardown.
 List<Action> tearDowns = new List<Action>
                              {
                                  teardown1,
                                  teardown2,
                                  teardown3
                              };
 
 foreach (var teardownAction in tearDowns)
 {
     try
     {
         teardownAction();
     }
    finally 
    {
    }
 }
 
 

Now when we want to add a teardown, instead of hunting through a nasty indented set of existing ones we can just tack another lambda onto the end of the list.  And with the time you save, you can write a blog post about it. :-)

Posted
March 24th, 10:20am 0 comments

Two things that make me happy.

1. Command prompts are (by default) the same width in characters as 1928 IBM punch cards.  This is by design.  (Learned that from Code.)
2. You can define extension methods on interfaces in C#.  And since classes can implement multiple interfaces, this makes it possible to pretend to have multiple inheritance (without any of that pesky state coming along for the ride).
Posted
March 19th, 12:05pm 0 comments

Varisimilitude

After installing Resharper I've become "var" happy.  It's nice not having to declare your types knowing that it's inferred from the assignment.

Today, after a bungled branch/merge session involving unversioned code, a class went missing.  I thought "well, at least I have my TDD unit test to inform me of my specifications!"

And then I saw some var statements.  So I have no idea what return type I was supposed to emit.

I'm gonna chalk this up as an "edge case" and keep on trucking, but if it happens again... bang zoom, to the moon!

Posted
March 18th, 8:37pm 0 comments

Stupid gits

I just discovered that the #1 result on a search for "Git vs. Mercurial" is a one page mini-screed.  Strange that it's so popular considering that plenty of people would like to know which one is better for their jobs without having to install and run both.  What is the Internet coming to?
Posted
March 13th, 11:32pm 0 comments

The Agile Home

I just discussed with my wife the possibility of redoing our (nonexistent) family to-do system with Scrum.  It seems straightforward enough:
  • Have a first sprint meeting
    • Determine how many hours we actually each have per week to accomplish stuff
    • Create a prioritized backlog of things we need to do
    • Do T-Shirt sizing on each item
    • Choose the most important things to do in our sprint
    • Place items on 3x5 cards and place on a Scrum board
  • Every day have a daily stand-up to discuss what we did yesterday, what we're doing today and what's getting in our way of our tasks
  • As we complete items, move them to "To Be Verified" on the scrum board, and write on the card how long it took
  • Every week have a sprint meeting
    • Move all verified items to done (if they can be verified)
    • Quick retrospective: what went well? what didn't? how do we fix what didn't work?  how were our estimates?
    • Take the next hunk of items off the backlog and move them to the board
She actually liked the idea.  As a proud technophobe, she really liked that everything could be done with paper and pencil instead of sitting in front of a computer screen.

If we actually do this, I'm going to log our progress here.  It seems like the appropriate spot.

Filed under agile agilehome
Posted
March 5th, 4:07pm 0 comments

LINQ-to-SQL-Via-T4-Is-Wicked-Pissah

Seriously.  I don't know how I ever used LINQ-to-SQL before I found the L2S T4 Generator.  It actually makes the thing usable.

Today I had to turn off optimistic concurrency checks.  I've been getting spurious errors as a result of some datetime fields that is well-documented on the Internet.  Instead of trying to find and fix each one, I've decided that this application really doesn't need to protect users from each other.  If two people happen to be updating the exact same thing, no worries.  The last one wins. 

If I wanted to do this with the L2S designer, I'd have to click on each column, then go to the properties window and change the desired concurrency level. Instead, I can add the following to the T4 template:

var options = new {
    DbmlFileName = Host.TemplateFile.Replace(".tt",".dbml"), // Which DBML file to operate on (same filename as template)
    SerializeDataContractSP1 = false, // Emit SP1 DataContract serializer attributes
    FilePerEntity = true, // Put each class into a separate file
    StoredProcedureConcurrency = false, // Table updates via an SP require @@rowcount to be returned to enable concurrency
    DisableOptimisticConcurrencyChecks = true, // Remove any UpdateCheck statements, so the last run statement wins.
};

// ... //

if (options.DisableOptimisticConcurrencyChecks) {
    #>, UpdateCheck=UpdateCheck.Never<#
}
else {
    if (column.UpdateCheck != UpdateCheck.Always) {#>, UpdateCheck=UpdateCheck.<#=column.UpdateCheck.ToString()#><#}
}

And my generated code now has "UpdateCheck.Never" set on every single column, so my updates are all performed against the primary key ONLY. 

Ahhhhhhhhhhh.

The disadvantage to this technique is that it is quite a bit more opaque.  The designer still says "Always" instead of "Never" as the T4 template is completely disconnected from it.  I've left a text file in the same folder to explain my changes to the template in hopes of helping out the poor future maintainer.

 

Posted