コード例 #1
0
ファイル: SmtpConfig.cs プロジェクト: hmxlabs/core
        private bool GetEnableSsl(IConfigProvider configProvider_)
        {
            if (!configProvider_.Contains(ConfigKeys.EnableSsl))
            {
                return(false);
            }

            return(configProvider_.GetConfigAsBool(ConfigKeys.EnableSsl));
        }
コード例 #2
0
ファイル: MailSenderConfig.cs プロジェクト: hmxlabs/core
        private string GetSenderName(IConfigProvider configProvider_)
        {
            if (!configProvider_.Contains(MailSenderConfigKeys.SenderName))
            {
                throw new ArgumentException("The config provider does not have a sender name specified: " + MailSenderConfigKeys.SenderName);
            }

            var senderName = configProvider_.GetConfigAsString(MailSenderConfigKeys.SenderName);

            if (null == senderName)
            {
                throw new ArgumentException("The config provider contains a null sender name");
            }

            if (string.IsNullOrWhiteSpace(senderName))
            {
                throw new ArgumentException("The config provider containy an empty sender name");
            }

            return(senderName);
        }
コード例 #3
0
ファイル: SmtpConfig.cs プロジェクト: hmxlabs/core
        private string GetUserName(IConfigProvider configProvider_)
        {
            if (!configProvider_.Contains(ConfigKeys.UserName))
            {
                throw new ArgumentException("The config provider does not have a username specified: " + ConfigKeys.UserName);
            }

            var userName = configProvider_.GetConfigAsString(ConfigKeys.UserName);

            if (null == userName)
            {
                throw new ArgumentException("The config provider contains a null usernmae");
            }

            if (string.IsNullOrWhiteSpace(userName))
            {
                throw new ArgumentException("The config provider contains an empty server name");
            }

            return(userName);
        }
コード例 #4
0
ファイル: SmtpConfig.cs プロジェクト: hmxlabs/core
        private string GetPassword(IConfigProvider configProvider_)
        {
            if (!configProvider_.Contains(ConfigKeys.Password))
            {
                throw new ArgumentException("The config provider does not have a password specified: " + ConfigKeys.Password);
            }

            var password = configProvider_.GetConfigAsString(ConfigKeys.Password);

            if (null == password)
            {
                throw new ArgumentException("The config provider contains a null password");
            }

            if (string.IsNullOrWhiteSpace(password))
            {
                throw new ArgumentException("The config provider contains an empty password");
            }

            return(password);
        }
コード例 #5
0
ファイル: SmtpConfig.cs プロジェクト: hmxlabs/core
        /// <summary>
        /// Constructs an instance of <code>SmtpConfig</code> and initialises all the necessary values
        /// by reading the configuration from the provided <code>IConfigProvider</code>.
        ///
        /// The configuration keys it expects to find are in the nexted class <code>ConfigKeys</code>.
        ///
        /// ServerName: "smtp.server"
        /// Port: "smtp.port"
        /// Username: "******"
        /// Password: "******"
        /// </summary>
        /// <exception cref="ArgumentNullException">If a <code>null</code> <code>IConfigProvider</code> is passed in</exception>
        /// <param name="configProvider_">The configuration provider containing the required config keyed as specified</param>
        public SmtpConfig(IConfigProvider configProvider_)
        {
            if (null == configProvider_)
            {
                throw new ArgumentNullException(nameof(configProvider_));
            }

            ServerName = GetServerName(configProvider_);
            var userName = GetUserName(configProvider_);
            var password = GetPassword(configProvider_);

            UserCredentials = new NetworkCredential(userName, password);
            EnableSsl       = GetEnableSsl(configProvider_);

            if (!configProvider_.Contains(ConfigKeys.Port))
            {
                return;
            }

            Port = configProvider_.GetConfigAsInteger(ConfigKeys.Port);
        }