private IDictionary <string, CustomerAccount> LoadExistingAccounts(bool loadAllUsers) { _existingAccounts = new Dictionary <string, CustomerAccount>(); var customerAccountResource = new CustomerAccountResource(Context.ApiContext); // change the start value by the page size until the start value is greater than the total var pageSize = 20; var pageCount = 1; ReportProgress("Begin GetAccounts call at " + DateTime.Now.ToShortTimeString()); var customerAccounts = customerAccountResource.GetAccounts(null, pageSize); ReportProgress("Finish GetAccounts call at " + DateTime.Now.ToShortTimeString()); var addedCount = 0; var skippedCount = 0; ReportProgress("Begin GetAccounts page " + pageCount + " call at " + DateTime.Now.ToShortTimeString()); // skip paging for testing - comment out this for loop and its brackets - driven by checkbox on UI // skips loading all customer accounts into memory since it takes 3 hours on a production tenant with 39,000 users var upperLimit = 2; if (loadAllUsers) { upperLimit = customerAccounts.TotalCount; } for (pageCount = 1; pageCount < upperLimit; pageCount = pageCount + customerAccounts.PageSize) { customerAccounts = customerAccountResource.GetAccounts(pageCount, pageSize); foreach (CustomerAccount account in customerAccounts.Items) { // Add to accountid lookup dictionary //_existingAccounts.Add(account.Id.ToString(), account); string userName = account.UserName; if (string.IsNullOrEmpty(userName)) { userName = account.EmailAddress; } if (!string.IsNullOrEmpty(userName) & !_existingAccounts.ContainsKey(userName.ToLower())) { _existingAccounts.Add(userName.ToLower(), account); addedCount++; } else { skippedCount++; ReportProgress("skipping " + account.UserId + ":" + account.UserName + " - " + account.FirstName + " " + account.LastName + " with email address of " + account.EmailAddress); } } } ReportProgress("Finish GetAccounts page " + pageCount + " call at " + DateTime.Now.ToShortTimeString()); return(_existingAccounts); }
private IDictionary <string, CustomerAccount> LoadExistingAccounts() { _existingAccounts = new Dictionary <string, CustomerAccount>(); var customerAccountResource = new CustomerAccountResource(Context.ApiContext); var customerAccounts = customerAccountResource.GetAccounts(); foreach (CustomerAccount account in customerAccounts.Items) { // Add to accountid lookup dictionary //_existingAccounts.Add(account.Id.ToString(), account); if (!string.IsNullOrEmpty(account.UserName)) { _existingAccounts.Add(account.UserName, account); } } return(_existingAccounts); }