private NAAS_USRMGR.UserAccountType GetUserAccount(string userName) { NAAS_USRMGR.GetUserList getUserList = new NAAS_USRMGR.GetUserList(); getUserList.adminName = _usermgrRuntimeCredential.UserName; getUserList.credential = _usermgrRuntimeCredential.Password; getUserList.domain = _usermgrRuntimeCredentialDomain; getUserList.rowId = "0"; getUserList.maxRows = "-1"; getUserList.userId = userName; getUserList.status = string.Empty; getUserList.affiliate = string.Empty; NAAS_USRMGR.GetUserListResponse response = _usermgrClient.GetUserList(getUserList); if (CollectionUtils.IsNullOrEmpty(response.@return)) { return(null); } foreach (NAAS_USRMGR.UserAccountType userAcct in response.@return) { if (string.Equals(userAcct.userId, userName, StringComparison.InvariantCultureIgnoreCase)) { return(userAcct); } } return(null); }
private int GetAllUserAccountsXmlError(NAAS_USRMGR.GetUserList getUserList, int startIndex, int count, OrderedSet <CachedUserAccountInfo> userAccounts) { int firstHalfCount = (count + 1) / 2; if (firstHalfCount <= 0) { throw new ArgumentException("Invalid startIndex: " + startIndex.ToString()); } int numAddedFirst = GetAllUserAccounts(getUserList, startIndex, firstHalfCount, userAccounts); if (numAddedFirst == 0) { return(0); } int secondHalfCount = count - firstHalfCount; if (secondHalfCount == 0) { return(numAddedFirst); } int numAddedSecond = GetAllUserAccounts(getUserList, startIndex + firstHalfCount, secondHalfCount, userAccounts); if (numAddedSecond == 0) { return(0); } return(numAddedFirst + numAddedSecond); }
private OrderedSet <CachedUserAccountInfo> GetAllUserAccounts(bool forceFreshFromNaas) { OrderedSet <CachedUserAccountInfo> userAccounts = null; if (!forceFreshFromNaas) { if (_objectCacheDao.GetObject(CACHE_NAAS_USER_ACCOUNTS, false, out userAccounts)) { return(userAccounts); } } const int getBatchCount = 1000; NAAS_USRMGR.GetUserList getUserList = new NAAS_USRMGR.GetUserList(); getUserList.adminName = _usermgrRuntimeCredential.UserName; getUserList.credential = _usermgrRuntimeCredential.Password; getUserList.domain = _usermgrRuntimeCredentialDomain; getUserList.userId = string.Empty; getUserList.status = string.Empty; getUserList.affiliate = string.Empty; userAccounts = new OrderedSet <CachedUserAccountInfo>(); for (int i = 0; ;) { int length = GetAllUserAccounts(getUserList, i, getBatchCount, userAccounts); if (length <= 0) { break; } i += length; } _objectCacheDao.CacheObject(userAccounts, CACHE_NAAS_USER_ACCOUNTS, _cacheNaasUsernamesDuration); return(userAccounts); }
private int GetAllUserAccounts(NAAS_USRMGR.GetUserList getUserList, int startIndex, int count, OrderedSet <CachedUserAccountInfo> userAccounts) { getUserList.rowId = startIndex.ToString(); getUserList.maxRows = count.ToString(); NAAS_USRMGR.GetUserListResponse response = null; bool processedError = false; try { response = _usermgrClient.GetUserList(getUserList); } catch (Exception e) { processedError = true; if (IsNaasXmlErrorMessage(e.Message)) { if (count == 1) { // This is the error, skip it return(1); } else { return(GetAllUserAccountsXmlError(getUserList, startIndex, count, userAccounts)); } } else { throw; } } if (!processedError) { if ([email protected] == 0) { return(0); } foreach (NAAS_USRMGR.UserAccountType userAcct in response.@return) { userAccounts.Add(new CachedUserAccountInfo(userAcct)); } return([email protected]); } return(0); }