public NotificationSubscription FollowWorkItem() { NotificationSubscription newFollowSubscription; // Get a work item to follow. For this sample, just create a temporary work item. WorkItem newWorkItem; using (new ClientSampleHttpLoggerOutputSuppression()) { WorkItemsSample witSample = new WorkItemsSample(); witSample.Context = this.Context; newWorkItem = witSample.CreateWorkItem(); // Save the new work item so we can unfollow it later this.Context.SetValue <WorkItem>("$followedWorkItem", newWorkItem); } NotificationSubscriptionCreateParameters createParams = new NotificationSubscriptionCreateParameters() { Filter = new ArtifactFilter(null) { ArtifactType = "WorkItem", ArtifactId = newWorkItem.Id.ToString() } }; VssConnection connection = Context.Connection; NotificationHttpClient notificationClient = Context.Connection.GetClient <NotificationHttpClient>(); newFollowSubscription = notificationClient.CreateSubscriptionAsync(createParams).Result; LogSubscription(newFollowSubscription); return(newFollowSubscription); }
public NotificationSubscription UnfollowWorkItem() { NotificationSubscription newFollowSubscription; // Step 1: Get a work item to follow. For this sample, just create a temporary work item. WorkItem newWorkItem; using (new ClientSampleHttpLoggerOutputSuppression()) { WorkItemsSample witSample = new WorkItemsSample(); witSample.Context = this.Context; newWorkItem = witSample.CreateWorkItem(); } string workItemArtifactUri = "vstfs:///WorkItemTracking/WorkItem/" + newWorkItem.Id; // Step 2: Follow this workitem by creating a subscription NotificationSubscriptionCreateParameters createParams = new NotificationSubscriptionCreateParameters() { Filter = new ArtifactFilter(workItemArtifactUri), Channel = new UserSubscriptionChannel() }; VssConnection connection = Context.Connection; NotificationHttpClient notificationClient = Context.Connection.GetClient <NotificationHttpClient>(); newFollowSubscription = notificationClient.CreateSubscriptionAsync(createParams).Result; LogSubscription(newFollowSubscription); // Step 3: Query for the follow subscription SubscriptionQuery query = new SubscriptionQuery() { Conditions = new[] { new SubscriptionQueryCondition() { Filter = new ArtifactFilter(workItemArtifactUri) } } }; NotificationSubscription followSubscription = notificationClient.QuerySubscriptionsAsync(query).Result.FirstOrDefault(); // Step 4: Now, unfollow the above workitem, by deleting the subscription if (followSubscription != null) { notificationClient.DeleteSubscriptionAsync(followSubscription.Id).SyncResult(); } // Step 5: Cleanup the temporary work item using (new ClientSampleHttpLoggerOutputSuppression()) { WorkItemTrackingHttpClient witClient = connection.GetClient <WorkItemTrackingHttpClient>(); witClient.DeleteWorkItemAsync(newWorkItem.Id.Value, destroy: true); } return(followSubscription); }
public NotificationSubscription FollowWorkItem() { NotificationSubscription newFollowSubscription; // Get a work item to follow. For this sample, just create a temporary work item. WorkItem newWorkItem; using (new ClientSampleHttpLoggerOutputSuppression()) { WorkItemsSample witSample = new WorkItemsSample(); witSample.Context = this.Context; newWorkItem = witSample.CreateWorkItem(); } string workItemArtifactUri = "vstfs:///WorkItemTracking/WorkItem/" + newWorkItem.Id; NotificationSubscriptionCreateParameters createParams = new NotificationSubscriptionCreateParameters() { Filter = new ArtifactFilter(workItemArtifactUri), Channel = new UserSubscriptionChannel() }; VssConnection connection = Context.Connection; NotificationHttpClient notificationClient = Context.Connection.GetClient <NotificationHttpClient>(); newFollowSubscription = notificationClient.CreateSubscriptionAsync(createParams).Result; LogSubscription(newFollowSubscription); // Cleanup the temporary work item using (new ClientSampleHttpLoggerOutputSuppression()) { WorkItemTrackingHttpClient witClient = connection.GetClient <WorkItemTrackingHttpClient>(); witClient.DeleteWorkItemAsync(newWorkItem.Id.Value, destroy: true); } return(newFollowSubscription); }