I've created a custom check-in policy for TFS by writing a class that extends PolicyBase
(as per MSDN How To: Create Custom Check-in Policies in Visual Studio Team Foundation). The overridden Evaluate()
method is where I've got my logic.
Evaluate()
gets called when the user clicks the Check In button in TFS which is great as that is what I want.
However, it also seems like Evaluate()
gets called when:
- Visual Studio is launched AND
- The user navigates to the Pending Changes tab for the first time (or if this is already the active tab when VS is launched) AND
- The user has items in the pending changes tab.
How can I check under what scenario Evaluate is called? I would only like Evaluate to be called when the user explicitly clicks the Check In button in TFS.
The actual Evaluate method I'm using is quite complicated but I've simplified it to something that still exhibits the same problem:
public override PolicyFailure[] Evaluate()
{
List<PolicyFailure> policyFailures = new List<PolicyFailure>();
if (_isPolicyEnabled)
{
if (PendingCheckin.PendingChanges.Comment.Contains("*"))
{
string msg = "Star in comment";
MessageBox.Show(msg);
policyFailures.Add(new PolicyFailure(msg, this));
}
}
return policyFailures.ToArray();
}
With the above code, if there is a star in the check-in comment and there are Pending Changes, close Visual Studio, when you re-open it will throw up the MessageBox as soon as you navigate to the Pending Changes tab.
The way the check-in policy is being used in my situation is that I check the user's comment for references to items in another system. If they are not present then I throw up an interactive dialog that shows the user a list of items which can be filtered and selected. These are then inserted into their check-in comment. Is there a way within the Evaluate()
to find out under which scenario it is called? I could avoid throwing up the dialog under all calls except those triggered by a Check-In.