Exemplo n.º 1
0
        /// <summary>
        /// Save user credentials.
        /// </summary>
        /// <param name="credentialRepository">
        /// The <see cref="ICredentialRepository"/> to save credentials to.
        /// </param>
        /// <param name="server">
        /// The Checkmarx server name. Cannot be null, empty or whitespace.
        /// </param>
        /// <param name="userName">
        /// The username to login with. Cannot be null, empty or whitespace.
        /// </param>
        /// <param name="password">
        /// The password to login with. Cannot be null.
        /// </param>
        /// <returns>
        /// The process return value.
        /// </returns>
        /// <exception cref="ArgumentException">
        /// <paramref name="server"/>,  <paramref name="userName"/> and <paramref name="password"/> cannot
        /// be null, empty or whitespace.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="credentialRepository"/> cannot be null.
        /// </exception>
        private static int SaveCredentials(ICredentialRepository credentialRepository, string server, string userName, string password)
        {
            if (credentialRepository == null)
            {
                throw new ArgumentNullException(nameof(credentialRepository));
            }
            if (string.IsNullOrWhiteSpace(server))
            {
                throw new ArgumentException("Argument is null or whitespace", nameof(server));
            }
            if (string.IsNullOrWhiteSpace(userName))
            {
                throw new ArgumentException("Argument is null or whitespace", nameof(userName));
            }
            if (string.IsNullOrWhiteSpace(password))
            {
                throw new ArgumentException("Argument is null or whitespace", nameof(password));
            }

            credentialRepository.Save(server, userName, password);

            return(ExitSuccess);
        }