/// <summary> /// Retrieves a single user using an email address. If more or less than one result is found, that is treated /// as an error. /// </summary> /// <returns>Returns a User object if user is found, and null otherwise.</returns> public static User GetUser() { const string methodName = "GetUser()"; const string bwsApiName = "bwsService.getUsers()"; logMessage("Entering {0}", methodName); User returnValue = null; GetUsersRequest request = new GetUsersRequest(); request.metadata = Metadata; GetUsersSearchCriteria searchCriteria = new GetUsersSearchCriteria(); /* * Check if the value of the variable "DisplayUserDetailsEmail" is enclosed in double-quotes. * If it is, then the search will look for an email address that exactly matches this value. * Otherwise, this value will be used in a prefix match. */ if (!DisplayUserDetailsEmail.StartsWith("\"") || !DisplayUserDetailsEmail.EndsWith("\"")) { logMessage("Warning: Email Address \"{0}\" is not enclosed in double-quotes. A prefix match will occur.", DisplayUserDetailsEmail); } searchCriteria.emailAddress = DisplayUserDetailsEmail; request.searchCriteria = searchCriteria; /* * The pageSize value of 2 is used to help determine if exactly 1 unique user was found. Using a pageSize value * of 2 avoids the overhead of retrieving more than 2 search results. */ request.pageSize = 2; GetUsersSortBy sortBy = new GetUsersSortBy(); sortBy.EMAIL_ADDRESS = true; sortBy.value = "EMAIL_ADDRESS"; request.sortBy = sortBy; GetUsersResponse response = null; try { logRequest(bwsApiName); response = bwsService.getUsers(request); logResponse(bwsApiName, response.returnStatus.code, response.metadata); } catch (WebException e) { // Log and re-throw exception. logMessage("Exiting {0} with exception \"{1}\"", methodName, e.Message); throw e; } if (response.returnStatus.code.Equals("SUCCESS")) { if (response.users != null && response.users.Length == 1) { // Returns the first user object in the users array. returnValue = response.users[0]; } else if (response.users != null && response.users.Length > 1) { logMessage("More than one user was found with email address \"{0}\"", DisplayUserDetailsEmail); } else { logMessage("No user was found with email address \"{0}\"", DisplayUserDetailsEmail); } } else { logMessage("Error Message: \"{0}\"", response.returnStatus.message); } logMessage("Exiting {0} with {1}", methodName, returnValue == null ? "\"null\"" : "User object (UID \"" + returnValue.uid + "\")"); return(returnValue); }
/// <summary> /// Retrieves a single user using an email address. If more or less than one result is found, that is treated /// as an error. /// </summary> /// <returns>Returns a User object if user is found, and null otherwise.</returns> public static User GetUser() { const string methodName = "GetUser()"; const string bwsApiName = "bwsService.getUsers()"; logMessage("Entering {0}", methodName); User returnValue = null; GetUsersRequest request = new GetUsersRequest(); request.metadata = Metadata; GetUsersSearchCriteria searchCriteria = new GetUsersSearchCriteria(); // Note: Email searches are not case-sensitive. Wildcards and prefix or suffix matching are supported. /* * Check if the value of the variable "DisplayUserDetailsEmail" is enclosed in double-quotes, and if it's * not, then display a message. If the variable "DisplayUserDetailsEmail" is not enclosed in double-quotes, * then a substring match search will be performed. */ if (!DisplayUserDetailsEmail.StartsWith("\"") || !DisplayUserDetailsEmail.EndsWith("\"")) { logMessage("Warning: Email Address \"{0}\" is not enclosed in double-quotes", DisplayUserDetailsEmail); } searchCriteria.emailAddress = DisplayUserDetailsEmail; request.searchCriteria = searchCriteria; /* * The pageSize value of 2 is used to help determine if exactly 1 unique user was found. Using a pageSize value * of 2 avoids the overhead of retrieving more than 2 search results. */ request.pageSize = 2; GetUsersSortBy sortBy = new GetUsersSortBy(); sortBy.EMAIL_ADDRESS = true; sortBy.value = "EMAIL_ADDRESS"; request.sortBy = sortBy; GetUsersResponse response = null; try { logRequest(bwsApiName); response = bwsService.getUsers(request); logResponse(bwsApiName, response.returnStatus.code, response.metadata); } catch (WebException e) { // Log and re-throw exception. logMessage("Exiting {0} with exception \"{1}\"", methodName, e.Message); throw e; } if (response.returnStatus.code.Equals("SUCCESS")) { if (response.users != null && response.users.Length == 1) { // Returns the first user object in the users array. returnValue = response.users[0]; } else if (response.users != null && response.users.Length > 1) { logMessage("More than one user was found with email address \"{0}\"", DisplayUserDetailsEmail); } else { logMessage("No user was found with email address \"{0}\"", DisplayUserDetailsEmail); } } else { logMessage("Error Message: \"{0}\"", response.returnStatus.message); } logMessage("Exiting {0} with {1}", methodName, returnValue == null ? "\"null\"" : "User object (UID \"" + returnValue.uid + "\")"); return returnValue; }