How to retreive TFS server uri in a Subscriber's ProcessEvent method
-
Friday, August 12, 2011 7:08 AM
Hi,
I have implemented a Subscriber (ISubscriber) to handle checkin events on tfs (server side) and validate some stuff.
I deploy this subscriber on several TFS (a test server, the production server, ...) in the adhoc folder C:\Program Files\Microsoft Team Foundation Server 2010\Application Tier\Web Services\bin\Plugins.
In the ProcessEvent method of my Subscriber, I have to get the checked-in file do to some validations. However, for that purpose, I need the TFS uri. I may not hardcode this one (as the dll is deployed on several servers) and don't want to search for it in the registry or whatever... So, I was wondering if I couldn't get it from the RequestContext instead. Unfortunately, it seems to me that there is NO usefull documentation at all about the TeamFoundationRequestContext in the MSDN :/
Could anyone help me to find this uri ?
public EventNotificationStatus ProcessEvent(TeamFoundationRequestContext requestContext, NotificationType notificationType, object notificationEventArgs, out int statusCode, out string statusMessage, out ExceptionPropertyCollection properties) {
CheckinNotification ev = notificationEventArgs as CheckinNotification;
foreach (var checkin in ev.SubmittedItems)
{var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(???)); var versionControl = tfs.GetService<VersionControlServer>(); //Get the checked-in item var item = versionControl.GetItem(checkin); //Get the version of this item related to the checkin's changset item = versionControl.GetItem(item.ItemId, ev.Changeset); //Check that this item is not deleted if (item.DeletionId == 0) { //Download the file in a temporary folder item.DownloadFile(...);
Thx a lot in advance for any tip or help.
V.
- Edited by Valéry Letroye Wednesday, September 05, 2012 1:41 PM
All Replies
-
Friday, August 12, 2011 2:03 PM
Debugging TFS, I was able to explore the TFS Server Object Model and found I can directly get a TeamFoundationControlService (server equivalent to the client VersionControlServer)
CheckinNotification ev = notificationEventArgs as CheckinNotification;
var tfsService = requestContext.GetService<TeamFoundationVersionControlService>();
foreach (var checkin in ev.SubmittedItems)
tfsService.DownloadFile(requestContext, checkin, 0, new ChangesetVersionSpec(ev.Changeset), "...");
I can also get a uri if required, but only during DecisionPoint... This URI contains the server address.
if (notificationType == NotificationType.DecisionPoint)
Uri tfsUri = requestContext.Items["$OriginalRequestPath"] as Uri;- Marked As Answer by Valéry Letroye Friday, August 12, 2011 2:03 PM
-
Monday, August 15, 2011 1:52 AMModerator
Hi V,
Thanks for your post.
And thank you for sharing your experience here. It will be very beneficial for other community members having the similar questions.
All your participation and support are very important to build such harmonious/ pleasant / learning environment for MSDN community.
John Qiao [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.

-
Monday, March 19, 2012 6:23 PM
I have tried this code,
tfsService.DownloadFile(requestContext, checkin, 0, new ChangesetVersionSpec(ev.Changeset), "...");
The ev.changeset is always -1 and errors out.
What am i missing
Trent Bielejeski
-
Wednesday, September 05, 2012 1:40 PM
For information, I found here the best way to get the TFS uri from a ISubscriber : http://colinsalmcorner.blogspot.be/2011/12/isubscriber-getting-tfs-url-for-client.html
Trent, I presume you solved your issue... On my own, I did not continue with this code. During the "DecisionPoint" you may not get the new version of the file. It's not yet in TFS... You can get it during the "Notification". But instead of using DownloadFile in that part, I do update a Workspace created on the server.
Valéry Letroye
- Marked As Answer by Valéry Letroye Monday, September 10, 2012 9:23 AM

