/// <summary> /// Maps the specified workitem to the bug model. /// </summary> /// <param name="workitem">The workitem.</param> /// <param name="propertyMappingList">The property mapping list.</param> /// <param name="redFilter">The red bug filter.</param> /// <returns></returns> private Bug Map(WorkItem workitem, PropertyMappingDictionary propertyMappingList, IEnumerable <string> redFilter) { Bug bug = new Bug(); object value = null; // ID value = workitem.Fields[propertyMappingList["ID"]].Value; bug.ID = value == null ? 0 : (int)value; // Title value = workitem.Fields[propertyMappingList["Title"]].Value; bug.Title = value == null ? string.Empty : value.ToString(); // Description value = workitem.Fields[propertyMappingList["Description"]].Value; bug.Description = value == null ? string.Empty : value.ToString(); // AssignedTo value = workitem.Fields[propertyMappingList["AssignedTo"]].Value; bug.AssignedTo = value == null ? string.Empty : value.ToString(); // State value = workitem.Fields[propertyMappingList["State"]].Value; bug.State = value == null ? string.Empty : value.ToString(); // ChangedDate value = workitem.Fields[propertyMappingList["ChangedDate"]].Value; bug.ChangedDate = value == null ? DateTime.Today : (DateTime)value; // CreatedBy value = workitem.Fields[propertyMappingList["CreatedBy"]].Value; bug.CreatedBy = value == null ? string.Empty : value.ToString(); // Priority value = workitem.Fields[propertyMappingList["Priority"]].Value; bug.Priority = value == null ? string.Empty : value.ToString(); // Severity if (string.IsNullOrWhiteSpace(propertyMappingList["Severity"])) { bug.Severity = string.Empty; } else { value = workitem.Fields[propertyMappingList["Severity"]].Value; bug.Severity = value == null ? string.Empty : value.ToString(); } bug.Type = string.IsNullOrWhiteSpace(bug.Priority) ? BugType.Yellow : (redFilter.Contains(bug.Priority) ? BugType.Red : BugType.Yellow); return(bug); }
/// <summary> /// Gets the bugs from TFS. /// </summary> /// <param name="tpc">The TFS Team Project Collection.</param> /// <param name="userName">The user name.</param> /// <param name="isFilterCreatedBy">if set to <c>true</c> [is filter created by].</param> /// <param name="propertyMappingList">The property mapping list.</param> /// <param name="bugFilterField">The bug filter field.</param> /// <param name="bugFilterValue">The bug filter value.</param> /// <param name="redFilter">The red filter.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException"> /// userName /// or /// propertyMappingList /// or /// usebugFilterFieldrName /// or /// bugFilterValue /// or /// redFilter /// or /// tpc /// </exception> public List <Bug> GetBugs( TfsTeamProjectCollection tpc, string userName, bool isFilterCreatedBy, PropertyMappingDictionary propertyMappingList, string bugFilterField, string bugFilterValue, IEnumerable <string> redFilter) { if (tpc == null) { throw new ArgumentNullException("tpc"); } if (string.IsNullOrWhiteSpace(userName)) { throw new ArgumentNullException("userName"); } if (propertyMappingList == null) { throw new ArgumentNullException("propertyMappingList"); } if (string.IsNullOrWhiteSpace(bugFilterField)) { throw new ArgumentNullException("usebugFilterFieldrName"); } if (string.IsNullOrWhiteSpace(bugFilterValue)) { throw new ArgumentNullException("bugFilterValue"); } if (redFilter == null) { throw new ArgumentNullException("redFilter"); } try { WorkItemStore workItemStore = (WorkItemStore)tpc.GetService(typeof(WorkItemStore)); string fields = string.Join(", ", propertyMappingList.Where(x => !string.IsNullOrWhiteSpace(x.Value)) .Select(x => "[" + x.Value + "]")); string filter = "[" + propertyMappingList["AssignedTo"] + "] = '" + userName + "'"; if (isFilterCreatedBy) { filter = "( " + filter + " OR [" + propertyMappingList["CreatedBy"] + "] = '" + userName + "' )"; } filter = "[" + bugFilterField + "] = '" + bugFilterValue + "' And " + filter; string queryString = "SELECT " + fields + " FROM WorkItems WHERE " + filter; Query query = new Query(workItemStore, queryString); var collection = query.RunQuery(); if (collection == null) { return(null); } var bugs = new List <Bug>(); foreach (WorkItem item in collection) { bugs.Add(Map(item, propertyMappingList, redFilter)); } return(bugs); } catch { return(null); } }