/// <summary> /// Initializes a new instance of the <see cref="UserImportRequest"/> class by verifying /// the supplied user's <c>IEnumerable</c> is valid (non-empty and not greater than /// <c>MaxImportUsers</c>), and a valid <see cref="UserImportHash"/> is supplied when a /// password is provided to at least one of the users. /// </summary> /// <param name="usersToImport">List of users to be imported.</param> /// <param name="options">Options for user imports. Possibly null.</param> internal UserImportRequest( IEnumerable <ImportUserRecordArgs> usersToImport, UserImportOptions options) { if (usersToImport == null || usersToImport.Count() == 0) { throw new ArgumentException("Users must not be null or empty."); } if (usersToImport.Count() > MaxImportUsers) { throw new ArgumentException( $"Users list must not contain more than {MaxImportUsers} items."); } this.Users = usersToImport.Select((user) => user.ToRequest()); if (usersToImport.Any((user) => user.HasPassword())) { if (options?.Hash == null) { throw new ArgumentException( "UserImportHash option is required when at least one user has a password."); } this.HashProperties = options.GetHashProperties(); } }
/// <summary> /// Initializes a new instance of the <see cref="UserImportRequest"/> class by verifying /// the supplied user's <c>IEnumerable</c> is valid (non-empty and not greater than /// <c>MaxImportUsers</c>), and a valid <see cref="UserImportHash"/> is supplied when a /// password is provided to at least one of the users. /// </summary> /// <param name="usersToImport"> List of users to be imported.</param> /// <param name="options"> Options for user imports, see /// <a cref="UserImportOptions">UserImportOptions</a>.</param> /// <returns>Dictionary containing key/values for the password hashing algorithm.</returns> public UserImportRequest( IEnumerable <ImportUserRecordArgs> usersToImport, UserImportOptions options) { if (usersToImport.Count() == 0) { throw new ArgumentException("users must not be empty"); } if (usersToImport.Count() > MaxImportUsers) { throw new ArgumentException("users list must not contain more than" + $" {MaxImportUsers} items"); } this.Users = usersToImport.Select((user) => user.ToRequest()); var hasPassword = usersToImport.Any((user) => user.HasPassword()); if (hasPassword) { if (options?.Hash == null) { throw new ArgumentNullException("UserImportHash option is required when at" + " least one user has a password. Provide a UserImportHash via the" + " Hash setter."); } this.HashProperties = (Dictionary <string, object>)options.GetHashProperties(); } }