private void btnFetchResults_Click(object sender, EventArgs e) { var filter = new CodeReviewResponseFilter { StartDate = datePickerStartDate.Value, EndDate = datePickerEndDate.Value, Reviewer = txtReviewer.Text }; CodeReviewResponseList = CodeReviewStatsHelper.RetrieveCodeReviewResponsesByFilter(filter); grdCodeReviewStats.DataSource = CodeReviewResponseList.ToList(); }
public static IEnumerable <CodeReviewResponse> RetrieveCodeReviewResponsesByFilter(CodeReviewResponseFilter filter) { var server = new TfsTeamProjectCollection(new Uri(formCodeReviewStats.TeamProjectCollectionUrl), CredentialCache.DefaultNetworkCredentials); var _workItemStore = server.GetService <WorkItemStore>(); TeamFoundationDiscussionService service = new TeamFoundationDiscussionService(); service.Initialize(server); var discussionManager = service.CreateDiscussionManager(); var query = "SELECT * FROM workitems " + "WHERE [System.WorkItemType] = 'Code Review Response' " + "AND [Microsoft.VSTS.CodeReview.ClosedStatusCode] In (1, 2, 3) " + "AND [Microsoft.VSTS.Common.ClosedDate] >= '{0}' " + "AND [Microsoft.VSTS.Common.ClosedDate] <= '{1}' "; query = string.Format(query, filter.StartDate.ToString("MM/dd/yyyy"), filter.EndDate.ToString("MM/dd/yyyy")); if (!string.IsNullOrWhiteSpace(filter.Reviewer)) { query += "AND [Microsoft.VSTS.Common.ReviewedBy] Contains '{0}' "; query = string.Format(query, filter.Reviewer); } var codeReviews = _workItemStore.Query(query).OfType <WorkItem>() .Select(r => new CodeReviewResponse { Id = r.Id, CreatedBy = r.CreatedBy, ReviewedBy = r.Fields.OfType <Field>().First(x => x.ReferenceName == "Microsoft.VSTS.Common.ReviewedBy").Value.ToString(), Title = r.Title, CreatedDate = r.Fields.OfType <Field>().First(x => x.ReferenceName == "System.CreatedDate").Value.ToString(), ClosedDate = r.Fields.OfType <Field>().First(x => x.ReferenceName == "Microsoft.VSTS.Common.ClosedDate").Value.ToString(), ClosedStatus = r.Fields.OfType <Field>().First(x => x.ReferenceName == "Microsoft.VSTS.CodeReview.ClosedStatus").Value.ToString(), CodeReviewRequestId = r.WorkItemLinks.OfType <WorkItemLink>().First().TargetId, CodeReviewComments = RetrieveComments(discussionManager, r.WorkItemLinks.OfType <WorkItemLink>().First().TargetId, r.Fields.OfType <Field>().First(x => x.ReferenceName == "Microsoft.VSTS.Common.ReviewedBy").Value.ToString()) }); return(codeReviews); }