@@ -81,8 +81,6 @@ private static void RunMainWorkflow()
8181 {
8282 Logger . Log ( 1 , "DEBUG: SPOUser created" ) ;
8383
84- var list1 = new SPOList { SPOUser = spoUser } ;
85- var list2 = new SPOList { SPOUser = spoUser } ;
8684 Logger . Log ( 3 , "DEBUG: SPOList objects configured" ) ;
8785
8886 ProcessCommandLineArguments ( ) ;
@@ -274,33 +272,28 @@ public static void GetAllLists()
274272 Logger . Log ( 1 , "DEBUG: Entering GetAllLists" ) ;
275273 try
276274 {
277- // Get SharePoint credentials
278275 var ( username , password ) = ConfigurationReader . GetSharePointCredentials ( ) ;
279- SPOUser spoUser = new SPOUser ( username , password ) ;
280- // Set up a context for the SharePoint site named "seed"
281- Context context = new Context ( )
276+ using ( SPOUser spoUser = new SPOUser ( username , password ) )
282277 {
283- Site = "seed" ,
284- SPOUser = spoUser
285- } ;
286- // Iterate through all lists in the SharePoint site
287- foreach ( Microsoft . SharePoint . Client . List allList in context . GetAllLists ( ) )
288- {
289- try
278+ Context context = new Context ( )
290279 {
291- Logger . Log ( 1 , "DEBUG: Loading list - " + allList . Title ) ;
292- // Load the IsSystemList property to determine if the list is a system list
293- context . Ctx . Load < IList > ( allList , new Expression < Func < Microsoft . SharePoint . Client . List , object > > [ 1 ]
294- {
295- l => ( object ) l . IsSystemList
296- } ) ;
297- context . Ctx . ExecuteQuery ( ) ; // Execute the query to retrieve the data
298- Logger . Log ( 2 , "List Name: " + allList . Title + "; is: " + allList . IsSystemList . ToString ( ) ) ;
299- }
300- catch ( Exception ex )
280+ Site = "seed" ,
281+ SPOUser = spoUser
282+ } ;
283+ foreach ( Microsoft . SharePoint . Client . List allList in context . GetAllLists ( ) )
301284 {
302- Console . WriteLine ( "ERROR: Failed to load or display list '" + allList . Title + "'." ) ;
303- Console . WriteLine ( "Exception: " + ex . Message ) ;
285+ try
286+ {
287+ Logger . Log ( 1 , "DEBUG: Loading list - " + allList . Title ) ;
288+ context . Ctx . Load ( allList , l => l . IsSystemList ) ;
289+ context . Ctx . ExecuteQuery ( ) ;
290+ Logger . Log ( 2 , "List Name: " + allList . Title + "; is: " + allList . IsSystemList . ToString ( ) ) ;
291+ }
292+ catch ( Exception ex )
293+ {
294+ Console . WriteLine ( "ERROR: Failed to load or display list '" + allList . Title + "'." ) ;
295+ Console . WriteLine ( "Exception: " + ex . Message ) ;
296+ }
304297 }
305298 }
306299 }
@@ -522,25 +515,25 @@ private static void RefreshListsSPO(SPOList sourceList, SPOList destList)
522515 int index1 = 0 ;
523516 int index2 = 0 ;
524517
525- // Match fields by title and store their internal names
526518 foreach ( Field field1 in fields1 )
527519 {
528- Field field2 ;
529- do
520+ bool found = false ;
521+ while ( index2 < fields2 . Count )
530522 {
531- field2 = fields2 [ index2 ] ;
523+ Field field2 = fields2 [ index2 ] ;
532524 if ( field1 . Title == field2 . Title )
533525 {
534- strArray [ index1 , 0 ] = field2 . InternalName ; // Destination field
535- strArray [ index1 , 1 ] = field1 . InternalName ; // Source field
526+ strArray [ index1 , 0 ] = field2 . InternalName ;
527+ strArray [ index1 , 1 ] = field1 . InternalName ;
528+ found = true ;
536529 Logger . Log ( 1 , "DEBUG: Match found - " + field1 . Title ) ;
537530 }
538531 ++ index2 ;
532+ if ( found ) break ;
539533 }
540- while ( field1 . Title != field2 . Title && index2 < fields2 . Count ) ;
541534
542535 ++ index1 ;
543- index2 = 0 ; // Reset index2 for the next field
536+ index2 = 0 ;
544537 }
545538
546539 return strArray ; // Return the field mappings
0 commit comments