Sample checkin policy: make sure the comment isn't empty

I'm not actually the original author, but it seems pretty useful so I thought I'd pass it along - you'll need a reference to Microsoft.TeamFoundation.VersionControl.Client.dll, of course, which should be in your GAC if you have the Team Explorer bits installed.

using System;

using System.Windows.Forms;

using Microsoft.TeamFoundation.VersionControl.Client;

namespace CheckForCommentsPolicy

{

[Serializable]

public class CheckForComments : PolicyBase

{

public override string Description

{

get { return "Remind users to add meaningful comments to their checkins"; }

}

// This is a string that is stored with the policy definition on the source

// control server. If a user does not have our policy plugin installed, this string

// will be displayed. We can use this as an opportunity to explain to the user

// how they might go about installing our policy plugin.

public override string InstallationInstructions

{

get { return "To install this policy, follow the instructions in CheckForComments.cs."; }

}

// This string is the type of our policy. It will be displayed to the user in a list

// of all installed policy types when they are creating a new policy.

public override string Type

{

get { return "Check for Comments Policy"; }

}

// This string is a description of the type of our policy. It will be displayed to the

// user when they select our policy type in the list of policies installed on the system

// as mentioned above.

public override string TypeDescription

{

get { return "This policy will prompt the user to decide whether or not they should be allowed to check in."; }

}

// This method is invoked by the policy framework when the user creates a new checkin

// policy or edits an existing checkin policy. We can use this as an opportunity to

// display UI specific to this policy type allowing the user to change the parameters

// of the policy.

public override bool Edit(IPolicyEditArgs args)

{

// no configuration to save

return true;

}

// This method performs the actual evaluation. It is called by the policy framework at various points in time

// when policy should be evaluated. In this example, we invoke this method ourselves when various asyc

// events occur that may have invalidated the current list of failures.

public override PolicyFailure[] Evaluate()

{

string proposedComment = PendingCheckin.PendingChanges.Comment;

if (String.IsNullOrEmpty(proposedComment))

{

return new PolicyFailure[] {

new PolicyFailure("Please provide some comments about your checkin", this),

};

}

else

{

return new PolicyFailure[0];

}

}

// This method is called if the user double-clicks on a policy failure in the UI.

// We can handle this as we please, potentially prompting the user to perform

// some activity that would eliminate the policy failure.

public override void Activate(PolicyFailure failure)

{

MessageBox.Show("Please provide comments for your checkin.", "How to fix your policy failure");

}

// This method is called if the user presses F1 when a policy failure is active in the UI.

// We can handle this as we please, displaying help in whatever format is appropriate.

// For this example, we'll just pop up a dialog.

public override void DisplayHelp(PolicyFailure failure)

{

MessageBox.Show("This policy helps you to remember to add comments to your checkins.", "Prompt Policy Help");

}

}

}