22using System . Linq ;
33using Microsoft . TeamFoundation . WorkItemTracking . Client ;
44using System . Collections . Generic ;
5+ using System . Text . RegularExpressions ;
56
67namespace VSTS . DataBulkEditor . Engine
78{
@@ -34,9 +35,15 @@ public string CreateReflectedWorkItemId(WorkItem wi)
3435 public int GetReflectedWorkItemId ( WorkItem wi , string reflectedWotkItemIdField )
3536 {
3637 string rwiid = wi . Fields [ reflectedWotkItemIdField ] . Value . ToString ( ) ;
37- return int . Parse ( rwiid . Substring ( rwiid . LastIndexOf ( @"/" ) + 1 ) ) ;
38+ if ( Regex . IsMatch ( rwiid , @"(http(s)?://)?([\w-]+\.)+[\w-]+(/[\w- ;,./?%&=]*)?" ) )
39+ {
40+ return int . Parse ( rwiid . Substring ( rwiid . LastIndexOf ( @"/" ) + 1 ) ) ;
41+ }
42+ return 0 ;
3843 }
3944
45+
46+
4047 public WorkItem FindReflectedWorkItem ( WorkItem workItemToFind , string reflectedWotkItemIdField )
4148 {
4249 string ReflectedWorkItemId = CreateReflectedWorkItemId ( workItemToFind ) ;
@@ -49,11 +56,18 @@ public WorkItem FindReflectedWorkItem(WorkItem workItemToFind, string reflectedW
4956 {
5057 string rwiid = workItemToFind . Fields [ reflectedWotkItemIdField ] . Value . ToString ( ) ;
5158 int idToFind = GetReflectedWorkItemId ( workItemToFind , reflectedWotkItemIdField ) ;
52- found = Store . GetWorkItem ( idToFind ) ;
53- if ( ! ( found . Fields [ reflectedWotkItemIdField ] . Value . ToString ( ) == rwiid ) )
59+ if ( idToFind == 0 )
5460 {
5561 found = null ;
5662 }
63+ else
64+ {
65+ found = Store . GetWorkItem ( idToFind ) ;
66+ if ( ! ( found . Fields [ reflectedWotkItemIdField ] . Value . ToString ( ) == rwiid ) )
67+ {
68+ found = null ;
69+ }
70+ }
5771 }
5872 if ( found == null ) { found = FindReflectedWorkItemByReflectedWorkItemId ( ReflectedWorkItemId , reflectedWotkItemIdField ) ; }
5973 if ( found == null ) { found = FindReflectedWorkItemByMigrationRef ( ReflectedWorkItemId ) ; }
0 commit comments