public void SetFormValues(IEnumerable <KeyValuePair <string, string> > values) { var SmtpServerItem = values.FirstOrDefault(item => item.Key == "SmtpServer"); if (string.IsNullOrWhiteSpace(SmtpServerItem.Value)) { throw new Himall.Core.PluginConfigException("SMTP服务器不能为空"); } var SmtpPortItem = values.FirstOrDefault(item => item.Key == "SmtpPort"); if (!Core.Helper.ValidateHelper.IsNumeric(SmtpPortItem.Value)) { throw new Himall.Core.PluginConfigException("SMTP端口错误"); } var EmailNameItem = values.FirstOrDefault(item => item.Key == "EmailName"); if (string.IsNullOrWhiteSpace(EmailNameItem.Value)) { throw new Himall.Core.PluginConfigException("SMTP用户名不能为空"); } var PasswordItem = values.FirstOrDefault(item => item.Key == "Password"); if (string.IsNullOrWhiteSpace(PasswordItem.Value)) { throw new Himall.Core.PluginConfigException("SMTP密码不能为空"); } var SendAddressItem = values.FirstOrDefault(item => item.Key == "SendAddress"); if (string.IsNullOrWhiteSpace(SendAddressItem.Value)) { throw new Himall.Core.PluginConfigException("SMTP邮箱不能为空"); } if (!Core.Helper.ValidateHelper.IsEmail(SendAddressItem.Value)) { throw new Himall.Core.PluginConfigException("SMTP邮箱错误"); } var DisplayNameItem = values.FirstOrDefault(item => item.Key == "DisplayName"); if (string.IsNullOrWhiteSpace(DisplayNameItem.Value)) { throw new Himall.Core.PluginConfigException("SMTP显示名称不能为空"); } MessageEmailConfig oldConfig = EmailCore.GetConfig(); oldConfig.SmtpPort = SmtpPortItem.Value; oldConfig.SmtpServer = SmtpServerItem.Value; oldConfig.EmailName = EmailNameItem.Value; oldConfig.Password = PasswordItem.Value; oldConfig.SendAddress = SendAddressItem.Value; oldConfig.DisplayName = DisplayNameItem.Value; EmailCore.SaveConfig(oldConfig); }
public void SetFormValues(IEnumerable <KeyValuePair <string, string> > values) { KeyValuePair <string, string> keyValuePair = values.FirstOrDefault((KeyValuePair <string, string> item) => item.Key == "SmtpServer"); if (string.IsNullOrWhiteSpace(keyValuePair.Value)) { throw new PluginConfigException("SMTP服务器不能为空"); } KeyValuePair <string, string> keyValuePair1 = values.FirstOrDefault((KeyValuePair <string, string> item) => item.Key == "SmtpPort"); if (!ValidateHelper.IsNumeric(keyValuePair1.Value)) { throw new PluginConfigException("SMTP端口错误"); } KeyValuePair <string, string> keyValuePair2 = values.FirstOrDefault((KeyValuePair <string, string> item) => item.Key == "EmailName"); if (string.IsNullOrWhiteSpace(keyValuePair2.Value)) { throw new PluginConfigException("SMTP用户名不能为空"); } KeyValuePair <string, string> keyValuePair3 = values.FirstOrDefault((KeyValuePair <string, string> item) => item.Key == "Password"); if (string.IsNullOrWhiteSpace(keyValuePair3.Value)) { throw new PluginConfigException("SMTP密码不能为空"); } KeyValuePair <string, string> keyValuePair4 = values.FirstOrDefault((KeyValuePair <string, string> item) => item.Key == "SendAddress"); if (string.IsNullOrWhiteSpace(keyValuePair4.Value)) { throw new PluginConfigException("SMTP邮箱不能为空"); } if (!ValidateHelper.IsEmail(keyValuePair4.Value)) { throw new PluginConfigException("SMTP邮箱错误"); } KeyValuePair <string, string> keyValuePair5 = values.FirstOrDefault((KeyValuePair <string, string> item) => item.Key == "DisplayName"); if (string.IsNullOrWhiteSpace(keyValuePair5.Value)) { throw new PluginConfigException("SMTP显示名称不能为空"); } MessageEmailConfig config = EmailCore.GetConfig(); config.SmtpPort = keyValuePair1.Value; config.SmtpServer = keyValuePair.Value; config.EmailName = keyValuePair2.Value; config.Password = keyValuePair3.Value; config.SendAddress = keyValuePair4.Value; config.DisplayName = keyValuePair5.Value; EmailCore.SaveConfig(config); }