21
Oct

There’s a great TFS Auto Shelve Visual Studio tool that will magically autoshelve your pending changes every X minutes. It’s very handy, but what if you wanted to extend it with more features? Here’s a little code snippet to help you get started that will shelve your pending changes for a specific workspace.

using System.Linq;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;

var tfsUrl = "http://myserver:8080/whatever";
string userName = "MyName";
string workspaceName = "MyWorkspace";

TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(tfsUrl);
VersionControlServer vcs = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));

var workspace = vcs.GetWorkspace(
    workspaceName,              // workspaceName
    userName);                  // workspaceOwner

// Query for Latest Pending Changes
var pendingSets = vcs.QueryPendingSets(
    new[] { "$/" },             // items
    RecursionType.Full,         // recursion
    workspaceName,              // queryWorkspaceName
    userName);                  // queryUserName
var latestPendingChanges = pendingSets.First().PendingChanges;

if (latestPendingChanges.Length > 0)
{
    // Create and Save a Shelve set
    var shelveset = new Shelveset(
        vcs,
        "My Shelveset",             // shelveset name
        workspace.OwnerName);       // shelveset owner
    workspace.Shelve(
        shelveset,                  // shelveset
        latestPendingChanges,       // changes
        ShelvingOptions.Replace);   // options
}

Remember that you may need to add the name of your project collection as a folder to the end of your TFS url.

10
Oct

Twin Cities Code Camp was this weekend and I was lucky enough to attend on Sunday.  It was great, but there are a few things that people really should do before they ever give a presentation.

  1. Reset your IDE back to “factory defaults” and disable all add-ons.  This includes themes and colors.  There is nothing worse than trying to read a color scheme that does not play well with a projector.
  2. Have at least a few PowerPoint slides… always.  Purchase a clicker.
  3. Give your monitor a reasonable resolution and ensure your font size is set appropriately.  Avoid zooming in excessively due to your failure to comply with this rule.
  4. Do not live code.  Unless it’s very, very tiny snippets.  It’s not fun watching people type away, and you will make mistakes.  Use snippets if you want the illusion of building out the system.
  5. Run through it at least once in final form as it will be presented to everyone who attends.
20
Sep

Why CouchDB and Cloudant?

After playing around with a little project that required a lot of “document” retrieval from a database, I decided to try one of the hosted NoSQL options that are out there.  I decided to try Cloudant, a cloud-based CouchDB host that has add-ons for both Heroku and AppHarbor.

Why Cloudant?  I was looking for something in the cloud, free and not constrained by too much of a size issue.  The choice between MongoDB and CouchDB came down to what would be less of a hassle. Cloudant is officially supported by AppHarbor, so that was my ultimate choice.  At this point, you should create yourself a free Cloudant account.

Interacting with the Database

It is very easy to interact with the database as CouchDB is REST based, so standard HTTP calls can be made to perform CRUD operations.  Divan is a popular .NET wrapper that will be used instead of hand crafting the calls to the CouchDB server. To get started, a reference to the Divan project will be needed in the website project.

  1. From Visual Studio 2010, choose “File” -> “Add” -> “Existing Project” from the menu bar.
  2. In the “Add Existing Project” dialog box navigate to the location of the Divan “src” folder and open Divan.csproj.
  3. Upgrade the Divan project to .NET Framework 4.0 by right-clicking on the Divan project in Solution Explorer and choosing Properties.  From here change the “Application” tab’s “Target Framework” option from .NET Framework 3.5 to .NET Framework 4.0.
  4. Remove the Newtonsoft.Json reference under the “References” folder because we will need to upgrade the Json.NET reference from .NET 3.5 to .NET 4.0, so both our website project and Divan project are in sync. (This won’t be that important until Part 2)
  5. Using either the internet or NuGet to reference Json.NET 4.0.x (or later).
    • In NuGet, this can be done by right-clicking on “References” and selecting “Manage NuGet Packages”.
    • Select the “Online” tab and search for “Json.NET”.
    • Once “Json.NET” is located. Select it from the list and click the “Install” button.
  6. Finally, right-click the website’s “References” and under “Projects” add the Divan project.

With project setup complete, it is now time to create and query a Cloudant database. In order to do this, a CouchServer object will be created to store the server connection information and perform a call to create/get a database.  For this example, the trivial example of a database called “people” that stores “firstName” and “lastName” will be used. Ensure that the Divan namespace is resolved in the file that you are creating this code (right-click “Resolve” on the squiggly lines under CouchServer).

CouchServer server = new CouchServer("INSERTUSERNAME.cloudant.com", 5984, "INSERTUSERNAME", "INSERTPASSWORD");
ICouchDatabase database = server.GetDatabase("people");

In the above example, remember to insert your username and password.  After digging in Cloudant’s FAQ, it can be found that Cloudant runs their servers on port 5984. The final interesting thing to note with the above code sample is that the GetDatabase call will create the database if a database with that name is not found on the server.

With the database in hand, it is time to create a document on the server and call it a day.  CouchDB is Json based. Creation of documents can be done by specifying an object to be serialized or hand supplying the Json. For simplicity, the latter will be done.

ICouchDocument doc1 = database.CreateDocument("{\"firstName\": \"Scott\", \"lastName\": \"Heckel\"}");
ICouchDocument doc2 = database.GetDocument(doc1.Id);

All CouchDB documents have Id and Rev(ision) properties.  These properties are used to identify specific documents. While the Id was supplied directly in the Json, CouchDB provided the Id for the document automatically. With the help of that Id, the program is able to retrieve the document that was just created.

A great start! Part 2 will show how to improve the code by creating custom objects that implement ICouchDocument.

18
May

It has been five months since I last got to tinker with my Netduino.  I have not purchased any new shields or accessories, but I wanted to get back on the horse.  I figured the easiest way to toy with it would be to go to the ever trusty Morse code project that has been done already to death already.  I took a fluent-like take on the project and posted the code to my GitHub under “NetDuino-MorseCode”.  It’s small, simple and works.

29
Mar

After careful research, I have discovered that PHP is quite possibly the worst language ever (* based on the smallest of small sampling sizes). Using the scientific query of “X sucks”, I tabulated which language has the most hits on Google.

Chart showing that PHP is the worst language ever!

If this isn’t definitive proof, I don’t know what is.  In case you were wondering, “erlang sucks” racks up a whopping 59,100 hits.

13
Mar

A little over a week ago, I released my second PlayOn script.  This time it is a PlayOn script for Microsoft’s MIX conference.  It provides a look into the future of the web and all related technologies.  The script currently supports MIX 2010 videos; however, I will be adding in support for the back-catalog soon.  As always, the script comes with auto-update support out of the box.  In case you still are wondering what MIX is, I will leave you with my script’s description.

Discover the next web with presentations from Microsoft’s MIX conference. MIX is a gathering of developers, designers, UX experts and business professionals creating the most innovative and profitable consumer sites on the web. Sessions range from technical, code-based topics to expert advice on content strategy, usability and design.

27
Jan

I’ve updated my Microsoft TechEd PlayOn Script to version 1.1.0. This version removed the broken “By Subject” category and adds in a new “By Region” category. The update also adds functionality to make a user bypass future automatic updates and continue to use an old version of the script. Users of version 1.0.0 of the script will be asked to update the next time that they load the Microsoft TechEd script from their PlayOn viewing device (TV/Xbox 360/Playstation 3/Roku/other DLNA).

For those that need a reminder, this script allows you to watch the following:

A collection of almost 3000 presentations recorded at Microsoft’s annual developer/IT conferences held around the world. Presentations revolve around the following areas: Application Integration & Interoperability, Application Server & Infrastructure, Architecture, Business Intelligence, Cloud Computing & Online Services, Database Platform, Developer Tools, Languages & Frameworks, Development Practices, Dynamics, IT Strategy, Management, Office & SharePoint, Security, Identity & Access, Unified Communications, Virtualization, Web Platform, Windows Client, Windows Phone, and Windows Server.

28
Dec

My Netduino arrived in the mail today, so I decided to create my first project for both the Netduino and the .NET Micro Framework. Instead of doing the standard hold the button down to turn on the LED, this simple class will toggle the LED as you start to push the button.

using Microsoft.SPOT.Hardware;
using Netduino = SecretLabs.NETMF.Hardware.Netduino;

namespace ToggleLED
{
    /// <summary>
    /// Toggle the Netduino LED on/off based on a button press.
    /// </summary>
    public class Program
    {
        /// <summary>Main</summary>
        public static void Main()
        {
            bool isOn = false; // initial state of LED
            bool lastButtonState = true; // assume button initially not pressed

            // Create our LED/Button objects
            OutputPort led = new OutputPort(Netduino.Pins.ONBOARD_LED, isOn);
            InputPort button = new InputPort(Netduino.Pins.ONBOARD_SW1, false, Port.ResistorMode.Disabled);            

            // Loop forever reading the button and turning on/off the LED
            while (true)
            {
                bool buttonState = button.Read();

                // Toggle light only if the Button is pushed
                if (buttonState != lastButtonState && !buttonState)
                {
                    isOn = !isOn;
                    led.Write(isOn);
                }

                // Store current state as last state
                lastButtonState = buttonState;
            }
        }
    }
}

This would (obviously) be even simpler if you were using event handlers.

09
Jul

A week and almost 150 downloads has gone by since the release of my Lua script that allows users of the PlayOn software to stream Microsoft Tech Ed presentations to their TV/Xbox 360/Playstation 3/Wii/DLNA device.  Anyways, the script is…

A collection of almost 3000 presentations recorded at Microsoft’s annual developer/IT conferences held around the world. Presentations revolve around the following areas: Application Integration & Interoperability, Application Server & Infrastructure, Architecture, Business Intelligence, Cloud Computing & Online Services, Database Platform, Developer Tools, Languages & Frameworks, Development Practices, Dynamics, IT Strategy, Management, Office & SharePoint, Security, Identity & Access, Unified Communications, Virtualization, Web Platform, Windows Client, Windows Phone, and Windows Server.

Version 1.0.0 contains an update mechanism, which allows the user to pull the latest version of the script from the comfort of their couches.  PlayOn users can feel free to download the Microsoft Tech Ed script. If you still don’t have PlayOn, you should head over to the PlayOn.tv site and download the trial now.  This was my first stab at Lua and my second stab at playing with the PlayOn plugin system; although, I never released my first PlayOn plugin.

02
May

Anyone else playing around with the HTML 5 AUDIO element with varying levels of success.  Keep in mind here that I only tested Opera 10.52, Firefox 3.6 and Chrome 4.1.  If you haven’t checked out the AUDIO element or even VIDEO element yet, it would be helpful if you read up about the AUDIO element on the Mozilla Developer Center and the HTMLMediaElement object in the HTML 5 specification.

Audio Format Suport

Format MP3 OGG
Opera 10.52 No Yes
Firefox 3.6 No Yes
Chrome 4.1 Yes Yes

Surprise, surprise!  No one wants to support MP3s!

Changing the Source Later with Javascript

The first functionality that I decided to tinker with was using Javascript to implement a basic “jukebox” like script to play through some files in a directory.  This is completely possible in Firefox and Chrome, but I couldn’t get it to function properly in Opera.  Opera just never wanted to load the new audio file.  My guess is they have not yet implemented the load function.

If you are not using the SOURCE element but relying on the src attribute, the javascript needed to load the file will look something like what is shown below.  Assume your AUDIO element has it’s id set to “audioElement”.

var song = document.getElementById("audioElement");
song.src = "song2.mp3";
song.load();
song.play();

If the autoplay attribute is set in the audio file, you can actually skip the play function as it will automatically play when the file is loaded.