powershell, teamcity comments edit

We have a nice TeamCity build server at work and we somewhat-recently updated it to use a MySQL database instead of XML for the data storage (like for the VCS roots).

We have a number of service accounts we use for interacting with the version control systems and they periodically need their passwords changed. It used to be that we could modify the XML document search-and-replace style, but now it’s hidden in the database somewhere and is less straightforward to update.

Thankfully, TeamCity offers a REST API you can work with, so I decided to play with PowerShell and the Invoke-RestMethod command to automate the drudgery of going through the something-like-50 VCS roots we have defined and updating the passwords for selected accounts.

Here’s the code for a small one-function module:

   Updates the password for a user account in TeamCity associated with VCS root entries.
   Iterates through the VCS roots defined in TeamCity and updates the password associated with the specified user for all VCS roots.
   $credential = Get-Credential
   Update-TeamCityVcsAccount -TeamCityUrl "http://your-teamcity-dash/" -TeamCityCredential $credential -VcsUserName "serviceaccount" -VcsPassword "TheNewPassword"
   This command uses the TeamCity REST API to iterate through the VCS roots and update the password for matching accounts.
function Update-TeamCityVcsAccount
        # The URL to the TeamCity dashboard.

        # The credentials of the TeamCity administrator account to make changes.

        # The username of the VCS user that should be updated.

        # The new password for the VCS user.

        $updated = @()
        $progressActivity = "Updating VCS root passwords for $VcsUserName..."
        $vcsRootsUri = New-Object -TypeName System.Uri -ArgumentList $TeamCityUrl, "/httpAuth/app/rest/vcs-roots"
        $allRoots = Invoke-RestMethod -Uri $vcsRootsUri -Method Get -Credential $credential
        foreach($href in $allRoots.'vcs-roots'.'vcs-root'.href)
            $rootHref = New-Object -TypeName System.Uri -ArgumentList $TeamCityUrl, $href
            $vcsRoot = Invoke-RestMethod -Uri $rootHref -Method Get -Credential $credential
            $currentVcsUserName = $vcsRoot.'vcs-root'.properties.property | Where-Object { $_.name -eq "user" } | Select-Object -ExpandProperty "value"
            if($currentVcsUserName -ne $VcsUserName)

            # secure:svn-password == Subversion Repo
            # secure:tfs-password == TFS Repo
            # Making the assumption all the password fields have this
            # name format...
            $propToChange = $vcsRoot.'vcs-root'.properties.property  | Where-Object { ($_.name -like 'secure:*') -and ($_.name -like '*-password') }  | Select-Object -ExpandProperty "name"
            $propHref = New-Object -TypeName System.Uri -ArgumentList $rootHref, "$href/properties/$propToChange"

            Write-Progress -Activity $progressActivity -Status "VCS root: $href"
            Invoke-RestMethod -Uri $propHref -Method Put -Credential $credential -Body $VcsPassword | Out-Null
            $updated += $propHref;
        Write-Progress -Activity $progressActivity -Completed -Status "VCS roots updated."
        return $updated

Export-ModuleMember -Function Update-TeamCityVcsAccount

Save that as TeamCity.psm1 and then you can do this:

Import-Module .\TeamCity.psm1
$credential = Get-Credential
Update-TeamCityVcsAccount -TeamCityUrl "http://your-teamcity-dash/" -TeamCityCredential $credential -VcsUserName "serviceaccount" -VcsPassword "TheNewPassword"

When you run Get-Credential you’ll be prompted for some credentials. Enter your TeamCity username and password. Fill in the appropriate values for the parameters and you’ll see progress rolling by for the password updates. The return value is the list of VCS root URLs that got updated.

Now that I have a reasonably-working pattern for this, it should be easy enough to use the REST API on TeamCity to automate other common admin tasks we do. Neat!

vs, azure comments edit

I have an MSDN subscription at work which comes with some Azure services like virtual machines. I’m using one of these VMs to explore the VS 14 CTP.

The problem is… port 3389 isn’t open through the firewall at work, so using the default port for Terminal Services doesn’t work for me.

Luckily, you can change the port your VM uses for Terminal Services. Knowing I won’t be hosting a web site here, changing to port 80 makes it easy.

First, open up the VM in the Azure Portal and click the “Settings” button.

Click the Settings button on the VM

Now click the “Endpoints” entry on the list of settings.

Click Endpoints in the settings menu

We want the public port for Terminal Services to be port 80. Click the Terminal Services entry to edit it.

We want TS on port 80

Update the public port to 80 and click the Save button at the top.

Update the public port to 80

Now go back to the main VM dashboard and click the “Connect” button.

Click the Connect button

A small .rdp file will download. If you open it in a text editor it will look like this:

full address:s:yourmachine.cloudapp.net:3389
prompt for credentials:i:1

Change that port at the end to 80.

full address:s:yourmachine.cloudapp.net:80
prompt for credentials:i:1

Save that and double-click the file to start a Terminal Service session. Boom! Done.

autofac, github comments edit

All Autofac documentation has moved to our official documentation site at http://autofac.readthedocs.io/.

Since moving from Google Code to GitHub we’ve had documentation spread all over, some of which was getting pretty stale from not being maintained. We wanted to get control over that and set a good stage going forward, so we consolidated everything to our site on Read the Docs.

Doing this provides a lot of benefit:

  • Documentation is searchable.
  • You can get the docs in multiple formats (online, PDF, epub).
  • Docs are readable on a mobile browser.
  • We can start versioning the documentation.
  • We can update docs in one spot, inside the source tree, and not worry about wikis all spread out getting stale.

As part of this, you will see some changes to our wikis:

  • All of the pages in our GitHub wiki have been removed except for the release notes pages. We’ll only be maintaining release notes in the wiki. If you want docs, you need to go to the doc site. This may break some links in things like StackOverflow answers, but the other choice was to keep a bunch of placeholder redirect pages in place, which would be just painful to maintain. Instead we ripped the bandage off.
  • All of the pages in the Google Code wiki have been cleared out and replaced with some text pointing to the new documentation location. There are a substantially larger number of articles and answers linking to the old wiki and that wiki doesn’t change anymore so putting some pseudo-redirects in there was a simple one-time effort.

Apologies if this causes some issue with broken links.

It’s taken a long time to get here, but we think this will provide a better documentation experience for everyone now and going forward.

personal, tv, costumes, halloween comments edit

For Halloween this year I went as the Tenth Doctor from Doctor Who (originally played by David Tennant).

David Tennant as the Tenth Doctor

I make my costume every year (well, pretty much every year) and I enjoy sewing so it was fun to take this on. However, I don’t normally post “behind-the-scenes” stuff and there are folks who don’t really realize what goes into making a costume so I figured this year I’d do it. Oh, and if you want to see the pictures in a larger format, I have an annotated photo album on Google Photos.

Before doing anything else, I did some research. The Making My Tennant Suit blog was the best resource I found for info on the suit, the fabrics, and so forth. It has a really good fabric comparison showing different fabrics and sources that match/approximate the fabric from the suit. I also gathered a few pictures from the web to help me pick the right pieces.

I was due for some new glasses, so I picked some out that both look good on me (IMHO) and are close to the ones seen in the show.

My new Tennant-style glasses

I went to Jo-Ann Fabrics and searched for a pattern. None were exact, but I found that Vogue pattern 8890 was pretty close. I figured I could take “View A” jacket from the pattern, change it from a two-button jacket to four buttons, and add a custom breast pocket. The “View D” pants could be done unmodified.

Vogue Pattern 8890

The pattern was actually pretty ambitious. Given that it wasn’t a “costume pattern,” it was fully lined with all the extra stuff you’d find if you bought a suit - nicely finished pockets, extra give/pleats in the lining for movement… Definitely the most complex thing I’ve taken on to date.

The fabric I picked was ordered online from Hancock Fabrics. It’s item #3859071 “Brown and Teal Pinstripe Suiting.” I got it on sale half-off so I bought something like eight yards so I wouldn’t run out if I made a mistake or had to lengthen the pants/sleeves on the suit.

My Tenth Doctor fabric from Hancock

This particular fabric was a little challenging to work with because it was somewhat light and stretchy. When you work with cotton or wool, it’s not really stretchy so you can cut and pin it without worrying about it moving on you or changing shape. With this, I had to be really careful about pinning it, making sure I wasn’t stretching it while it was getting cut, and so on.

The buttons I used were some pretty standard tortoise shell ones off the shelf.

The buttons I used on the suit

Thread was Coats & Clark #8960. It was the perfect brown to match the fabric so hems and seams were nice and hidden. I think I went through three of these spools of thread.

Coats & Clark #8960

The pocket insides, waistband lining, and other strong internals was all done with some off-the-shelf brown cotton twill. You don’t really see this from the outside, but it is a nice shade to offset the suiting. Not that I had a lot of choice; there was only one color of brown twill available when I went shopping and I wasn’t feeling too picky.

My cotton twill

After I got all the materials together, I got down to work. I ironed the pattern (yes, ironed the pattern - on low heat, to make it easy to cut out and all flat), cut it out, and pinned the pattern to the fabric. There were something like 15 pieces to the pants and 30 pieces to the jacket.

Pinning the pattern

I did the pants first (though I didn’t get any pictures of the making of the pants). Normally I’ve found Vogue patterns run a little small, so I took my measurements and did the pants the next size up. This pattern seemed to run pretty true to size, so I had to take the pants in when they were done. I haven’t yet figured out how to fit a pattern on myself before it’s finished.

Doing the pants first helped me figure out that I needed to make the jacket true to size.

The first part of the jacket to be done is the main body outside. In this picture you can see I’ve replaced the breast pocket from the pattern with one of my own design so it matches the Tenth Doctor. I did that without a pattern, sort of taking an average measurement on width/height of pockets on other garments and fudging something together. This custom pocket is about 5.5” wide and 6” tall.

The outside jacket body

After the body of the jacket was done, it was time to sew the arms in. Putting arms in a jacket is always a real pain because the fabric at the top part of the arm is larger than the arm hole on the jacket body. They do that so you can move around, but it means you have to be really careful about putting the arm in and evenly distributing the extra fabric or you’ll get gathers along the seam where the fabric folds over onto itself. This is a particular problem with stretchy fabric, which likes to move around a lot. I had to rip out and redo a couple of areas to remove the gathering, but I got the arms in.

The right sleeve sewn in

Here’s the jacket with both sleeves sewn in but the lining not yet put in. The white stuff you see on the collar is interfacing - a sort of mesh-like fabric that you attach to make other fabric less flexible. You have interfacing in collars and cuffs, for example. I used “fusible interfacing” which is basically iron-on to attach. This pattern called for “hair canvas” interfacing, which is really expensive and much harder to work with. If I was making this as a suit and not as a costume, I probably would have tried to work with the hair canvas.

Both sleeves in, but no lining

With the outside done, it was time to do the lining. The first bit of lining was the inside front - the part with the inside pocket. Here’s the inside of the right front. You can see in the image a diagonal line where the collar is intended to fold over. You can also see a small, thin rectangle where the inside pocket will eventually go.

The inside right front, minus the inside pocket

Here’s the inside right front after getting the inside pocket in. You can see a small loop hanging down off the top of the pocket that will be used to button the pocket closed. The pattern called for 2” of ribbon (I used bias tape) for the loop, but that turned out to be too small to fold around the button that will be later attached below the pocket. If I were to do it again, I’d use 3” or 3.5” of ribbon. You can always move the button down a bit, but I had to sew my button right on the pocket welt (the twill “lip” lining the pocket).

The inside right front, this time with the inside pocket

Here’s what the lining looks like fully assembled - both inside front pieces, the back, and the sleeves. If you’ve never lined a coat before, it’s sort of like making a second copy of the coat, just inside-out. Then you take the lining, put it in the jacket, and sew along the edges. Basically.

In the picture on the left you see the inside pocket as you’ll view it when wearing the jacket; on the right is the other side - that brown square is the other inside pocket.

The lining, fully assembled

Once you put the lining in, you have to attach it. The back was able to be machine-sewn in, but the sleeves required hand sewing. Here you see I have the sleeve lining pinned in place so I can hand sew it in.

Sleeve lining pinned in place

Here’s the same sleeve lining after the hand sewing. I also have the sleeve buttons attached, so this sleeve is done.

The sleeve with the lining and buttons attached

Once the lining is in, the last thing to happen is the front buttons. Here’s the jacket entirely finished. You can see in the photo the white marks around the button holes on the front where I was sketching out the button locations.

Finished jacket with button hole markings

I did a little cleanup on the markings and here’s how it turned out.

First time wearing the complete jacket

And, once the whole costume was on, here’s how it looked. I think it turned out pretty well.

Travis as the Tenth Doctor

For those interested: The shoes are unbleached white Converse Chuck Taylors. The shirt is one I already had; any old white dress shirt will do. The sonic screwdriver is the toy version that’s been out for a while. The tie is a maroon polka dot tie by Chevalier.

I don’t know how much time it took exactly, but I know that I watch TV/Netflix while I’m working and I made it through three seasons of Kyle XY, the Jekyll miniseries, a couple of movies, and half a season of The Blacklist… and I wasn’t watching something the whole time. So… it took a while.

As far as cost, that’s another thing I didn’t really keep track of, but roughly (guessing on a few of these)…

  • Shoes: $45
  • Tie: $15
  • Pinstripe Suiting: $50
  • Lining: $10
  • Interfacing: $10
  • Felt (for the collar): $5
  • Twill: $10
  • Thread, buttons, zipper, notions: $30

So… uh… $175? Give or take. It’s not cheap. Even if you take out the cost for the shoes and tie, which I can wear elsewhere, you’re still looking at over $100. Plus the time.

This definitely increases my admiration and respect for folks who do this on a convention circuit.

Again, if you want to see the pictures in a larger format, I have an annotated photo album on Google Photos.

testing, culture comments edit

One of the projects I work on has some dynamic culture-aware currency formatting stuff and we, of course, have tests around that.

I’m in the process of moving our build from Windows Server 2008R2 to Windows Server 2012 and I found that a lot of our tests are failing. I didn’t change any of the code, just updated a couple of lines of build script. What gives?

It appears Windows Server 2012 has different culture settings installed than the previous platforms. Per the documentation, “Windows versions or service packs can change the available cultures” and it appears I’m getting hit by that.

I cobbled together a quick program to do some testing using LINQPad.

var nfi = CultureInfo.CreateSpecificCulture("as-IN").NumberFormat;

The results were the same on Windows 7 and Windows Server 2008R2 but different on Windows Server 2012:

Item Windows 7 Windows 2008R2 Windows 2012
CurrencyNegativePattern 12 12 12
CurrencyPositivePattern 1 1 2

Notice the positive pattern is different? Yeah. That’s not the only culture or item that differs across the installed cultures.

So… now I have to figure out a way to craft our tests to be a little more… dynamic(?)… about the expected value vs. the actual value.