/// <summary> /// Enumerate the diff items found based on the query passed in as well as the filterString and version passed /// to InitializeForDiff. The return type is IEnumerable<> so that adapter implementations do not need download and keep /// all of the IWITDiffItems in memory at once. /// </summary> /// <param name="queryCondition">A string that specifies a query used to select a subset of the work items defined by /// the set that the filter string identified.</param> /// <returns>An enumeration of IWITDiffItems each representing a work item to be compared by the WIT Diff operation</returns> public IEnumerable <IWITDiffItem> GetWITDiffItems(string queryCondition) { string columnList = "[System.Id], [System.Rev]"; StringBuilder conditionBuilder = new StringBuilder(m_filterString); if (!string.IsNullOrEmpty(queryCondition)) { if (conditionBuilder.Length > 0) { conditionBuilder.Append(" AND "); } conditionBuilder.Append(queryCondition); } string orderBy = "[System.Id]"; string wiql = TfsWITQueryBuilder.BuildWiqlQuery(columnList, conditionBuilder.ToString(), orderBy); // Run query with date precision off Dictionary <string, object> context = new Dictionary <string, object>(); context.Add("project", m_projectName); Query wiq = new Query(m_workItemStore, wiql, context, false); // Retrieve all results ICancelableAsyncResult car = wiq.BeginQuery(); WorkItemCollection workItems = wiq.EndQuery(car); foreach (WorkItem workItem in workItems) { yield return((IWITDiffItem) new TfsWITDiffItem(this, workItem)); } }
public ChangeSummary GetSummaryOfChangesSince(string lastProcessedChangeItemId, List <string> filterStrings) { if (string.IsNullOrEmpty(lastProcessedChangeItemId)) { throw new ArgumentException("lastProcessedChangeItemId"); } ChangeSummary changeSummary = new ChangeSummary(); changeSummary.ChangeCount = 0; changeSummary.FirstChangeModifiedTimeUtc = DateTime.MinValue; string[] changeItemIdParts = lastProcessedChangeItemId.Split(new char[] { ':' }); if (changeItemIdParts.Length != 2) { throw new ArgumentException(String.Format(CultureInfo.InvariantCulture, TfsWITAdapterResources.InvalidChangeItemIdFormat, lastProcessedChangeItemId)); } int lastProcessedWorkItemId = 0; WorkItem lastProcessedWorkItem = null; try { lastProcessedWorkItemId = int.Parse(changeItemIdParts[0]); lastProcessedWorkItem = m_workItemStore.GetWorkItem(lastProcessedWorkItemId); int revNumber = -1; try { revNumber = int.Parse(changeItemIdParts[1]); } catch (FormatException) { } DateTime changedDate; if (revNumber > 0) { Revision rev = lastProcessedWorkItem.Revisions[revNumber - 1]; changedDate = (DateTime)rev.Fields[CoreField.ChangedDate].Value; } else { changedDate = lastProcessedWorkItem.ChangedDate; } changeSummary.FirstChangeModifiedTimeUtc = changedDate.ToUniversalTime(); } catch (Exception ex) { Console.WriteLine(String.Format(CultureInfo.InvariantCulture, "Tfs2008WitAdapter.TfsWITSyncMonitorProvider: Exception finding last processed work item (Id {0}): {1}", lastProcessedWorkItemId, ex.ToString())); } WorkItem nextWorkItemToBeMigrated = null; foreach (string filterString in filterStrings) { Dictionary <string, object> context = new Dictionary <string, object>(); string columnList = "[System.Id], [System.ChangedDate]"; StringBuilder conditionBuilder = new StringBuilder(filterString); if (!string.IsNullOrEmpty(m_projectName)) { context.Add("project", m_projectName); if (conditionBuilder.Length > 0) { conditionBuilder.Append(" AND "); } conditionBuilder.Append("[System.TeamProject] = @project"); } if (!changeSummary.FirstChangeModifiedTimeUtc.Equals(default(DateTime))) { if (conditionBuilder.Length > 0) { conditionBuilder.Append(" AND "); } conditionBuilder.AppendFormat(CultureInfo.InvariantCulture, "[System.ChangedDate] > '{0:u}'", changeSummary.FirstChangeModifiedTimeUtc); } string orderBy = "[System.Id]"; string wiql = TfsWITQueryBuilder.BuildWiqlQuery(columnList, conditionBuilder.ToString(), orderBy); // Run query with date precision off Query wiq = new Query(m_workItemStore, wiql, context, false); // Retrieve all results ICancelableAsyncResult car = wiq.BeginQuery(); WorkItemCollection workItems = wiq.EndQuery(car); foreach (WorkItem wi in workItems) { if (!m_translationService.IsSyncGeneratedItemVersion( wi.Id.ToString(), wi.Rev.ToString(), new Guid(m_migrationSource.InternalUniqueId))) { changeSummary.ChangeCount++; if (nextWorkItemToBeMigrated == null || wi.ChangedDate < nextWorkItemToBeMigrated.ChangedDate) { nextWorkItemToBeMigrated = wi; } } } } if (nextWorkItemToBeMigrated != null) { changeSummary.FirstChangeModifiedTimeUtc = nextWorkItemToBeMigrated.ChangedDate.ToUniversalTime(); } return(changeSummary); }