daily pastebin goal
74%
SHARE
TWEET

Untitled

a guest Aug 21st, 2018 54 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
  1. Nested foreach loop slow
  2. SearchResultCollection absaUsers = ABSAds.FindAll();
  3. SearchResultCollection srcUsers = ds.FindAll();
  4.  
  5. foreach (SearchResult users in srcUsers)
  6. {
  7.     string cn = users.Properties["cn"][0].ToString();
  8.     string sn = users.Properties["sn"][0].ToString();
  9.     string userID = users.Properties["uid"][0].ToString();
  10.     string description = users.Properties["PersonnelAreaDesc"][0].ToString();
  11.     string jobCodeID = users.Properties["JobcodeID"][0].ToString();
  12.     string CostCentreID = users.Properties["costCentreID"][0].ToString();
  13.     string CostCentreDescription = users.Properties["CostCentreDescription"][0].ToString();
  14.     string givenName = users.Properties["givenName"][0].ToString();
  15.     string employmentStatus = users.Properties["EmploymentStatus"][0].ToString();
  16.     string EmploymentStatusDescription = users.Properties["EmploymentStatusDescription"][0].ToString();
  17.  
  18.     foreach (SearchResult absaUser in absaUsers)
  19.     {
  20.  
  21.         string absaUID = absaUser.Properties["uid"][0].ToString();
  22.         string absaEmploymentStatus = absaUser.Properties["EmploymentStatus"][0].ToString();
  23.         string absaEmploymentStatusDescription = absaUser.Properties["EmploymentStatusDescription"][0].ToString();
  24.         string absaEmployeeNumber = absaUser.Properties["employeeNumber"][0].ToString();
  25.  
  26.         if (absaUID == cn && absaEmployeeNumber==userID)
  27.         {
  28.             Console.WriteLine("User Record Found:" + cn);
  29.             sw.WriteLine("Modify" + "," + cn + "," + description + "," + userID + "," + givenName + "," + sn + "," + jobCodeID + "," + CostCentreID + "," + CostCentreDescription + "," + sn + "," + cn + "," + employmentStatus + "," + EmploymentStatusDescription);
  30.             sw.Flush();
  31.             break;
  32.         }
  33.     }
  34. }
  35.    
  36. var lookup = absaUsers.Cast<SearchResult>()
  37.                       .ToLookup(x => x.Properties["uid"][0].ToString());
  38.    
  39. foreach (SearchResult users in srcUsers)
  40. {
  41.     string cn = users.Properties["cn"][0].ToString();
  42.     foreach (SearchResult matches in lookup[cn])
  43.     {
  44.         ...
  45.     }
  46. }
  47.    
  48. List<SearchResult> allResultGroups=new  List<SearchResult>();
  49.     foreach (SearchResult absaUser in absaUsers)
  50.     {
  51.     resultGroups = srcUsers.Where(g => g.cn == absaUser.absaUID && absaUser.absaEmployeeNumber==g.userID ).ToList();
  52.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top