public void SetFormValues(IEnumerable <KeyValuePair <string, string> > values) { KeyValuePair <string, string> keyValuePair = values.FirstOrDefault((KeyValuePair <string, string> item) => item.Key == "AppKey"); if (string.IsNullOrWhiteSpace(keyValuePair.Value)) { throw new ArgumentNullException("AppKey不能为空"); } KeyValuePair <string, string> keyValuePair1 = values.FirstOrDefault((KeyValuePair <string, string> item) => item.Key == "AppSecret"); if (string.IsNullOrWhiteSpace(keyValuePair1.Value)) { throw new ArgumentNullException("AppSecret不能为空"); } KeyValuePair <string, string> keyValuePair2 = values.FirstOrDefault((KeyValuePair <string, string> item) => item.Key == "ValidateContent"); if (!string.IsNullOrWhiteSpace(keyValuePair2.Value)) { string lower = keyValuePair2.Value.ToLower(); if (!lower.StartsWith("<meta ")) { throw new PluginException("验证内容必须以meta标签开头"); } if (!lower.EndsWith(" />")) { throw new PluginException("验证内容必须以 /> 结尾"); } } OAuthWeiboConfig config = WeiboCore.GetConfig(); config.AppSecret = keyValuePair1.Value; config.AppKey = keyValuePair.Value; config.ValidateContent = keyValuePair2.Value; WeiboCore.SaveConfig(config); }
public void SetFormValues(IEnumerable <KeyValuePair <string, string> > values) { var appKeyItem = values.FirstOrDefault(item => item.Key == "AppKey"); if (string.IsNullOrWhiteSpace(appKeyItem.Value)) { throw new Himall.Core.PluginConfigException("AppKey不能为空"); } var appidItem = values.FirstOrDefault(item => item.Key == "AppSecret"); if (string.IsNullOrWhiteSpace(appidItem.Value)) { throw new Himall.Core.PluginConfigException("AppSecret不能为空"); } var validateContent = values.FirstOrDefault(item => item.Key == "ValidateContent"); if (!string.IsNullOrWhiteSpace(validateContent.Value))//如果验证内容不为空,则该内容必须是<meta>节点 { var lowerValidate = validateContent.Value.ToLower(); if (!lowerValidate.StartsWith("<meta ")) { throw new PluginException("验证内容必须以meta标签开头"); } if (!lowerValidate.EndsWith(" />")) { throw new PluginException("验证内容必须以 /> 结尾"); } } var oldConfig = WeiboCore.GetConfig(); oldConfig.AppSecret = appidItem.Value; oldConfig.AppKey = appKeyItem.Value; oldConfig.ValidateContent = validateContent.Value; WeiboCore.SaveConfig(oldConfig); }