コード例 #1
0
        private async Task <IList <WorkItemMigrationState> > FilterWorkItemIds(IValidationContext context, WorkItemTrackingHttpClient client, IDictionary <int, string> workItems)
        {
            // call GetWorkItemIdsForArtifactUrisAsync for target client to get the mapping of artifacturis and ids
            // do a check to see if any of them have already been migrated
            var artifactUris = workItems.Select(a => a.Value).ToList();
            var result       = await ClientHelpers.QueryArtifactUriToGetIdsFromUris(client, artifactUris);

            IList <WorkItemMigrationState> workItemStateList = new List <WorkItemMigrationState>();

            //check if any of the workitems have been migrated before
            foreach (var workItem in workItems)
            {
                try
                {
                    if (ClientHelpers.GetMigratedWorkItemId(result, workItem, out int id))
                    {
                        workItemStateList.Add(new WorkItemMigrationState {
                            SourceId = workItem.Key, TargetId = id, MigrationState = WorkItemMigrationState.State.Existing
                        });
                    }
                    else
                    {
                        workItemStateList.Add(new WorkItemMigrationState {
                            SourceId = workItem.Key, MigrationState = WorkItemMigrationState.State.Create
                        });
                    }
                }
                catch (Exception e)
                {
                    //edge case where we find more than one workitems in the target for the workitem
                    Logger.LogError(LogDestination.File, e, e.Message);
                    //Add this workitem to notmigratedworkitem list
                    workItemStateList.Add(new WorkItemMigrationState {
                        SourceId = workItem.Key, MigrationState = WorkItemMigrationState.State.Error
                    });
                }
            }

            return(workItemStateList);
        }