当前位置: 首页>>代码示例>>C#>>正文


C# NameValueCollection.AddDataIfNotEmpty方法代码示例

本文整理汇总了C#中System.Collections.Specialized.NameValueCollection.AddDataIfNotEmpty方法的典型用法代码示例。如果您正苦于以下问题:C# NameValueCollection.AddDataIfNotEmpty方法的具体用法?C# NameValueCollection.AddDataIfNotEmpty怎么用?C# NameValueCollection.AddDataIfNotEmpty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Collections.Specialized.NameValueCollection的用法示例。


在下文中一共展示了NameValueCollection.AddDataIfNotEmpty方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: VerifyAuthenticationCoreAsync

		protected override async Task<AuthenticationResult> VerifyAuthenticationCoreAsync(AccessTokenResponse response, CancellationToken cancellationToken) {
			string userId = response.ExtraData["user_id"];
			string userName = response.ExtraData["screen_name"];

			var profileRequestUrl = new Uri("https://api.twitter.com/1/users/show.xml?user_id="
									   + MessagingUtilities.EscapeUriDataStringRfc3986(userId));
			var authorizingHandler = this.WebWorker.CreateMessageHandler(response.AccessToken);

			var extraData = new NameValueCollection();
			extraData.Add("accesstoken", response.AccessToken.Token);
			extraData.Add("accesstokensecret", response.AccessToken.Secret);
			try {
				using (var httpClient = new HttpClient(authorizingHandler)) {
					using (HttpResponseMessage profileResponse = await httpClient.GetAsync(profileRequestUrl, cancellationToken)) {
						using (Stream responseStream = await profileResponse.Content.ReadAsStreamAsync()) {
							XDocument document = LoadXDocumentFromStream(responseStream);
							extraData.AddDataIfNotEmpty(document, "name");
							extraData.AddDataIfNotEmpty(document, "location");
							extraData.AddDataIfNotEmpty(document, "description");
							extraData.AddDataIfNotEmpty(document, "url");
						}
					}
				}
			}
			catch (Exception) {
				// At this point, the authentication is already successful.
				// Here we are just trying to get additional data if we can.
				// If it fails, no problem.
			}

			return new AuthenticationResult(
				isSuccessful: true, provider: this.ProviderName, providerUserId: userId, userName: userName, extraData: extraData);
		}
开发者ID:jiowei,项目名称:dotnetopenid,代码行数:33,代码来源:TwitterClient.cs

示例2: VerifyAuthenticationCoreAsync

		protected override async Task<AuthenticationResult> VerifyAuthenticationCoreAsync(AccessTokenResponse response, CancellationToken cancellationToken = default(CancellationToken)) {
			// See here for Field Selectors API http://developer.linkedin.com/docs/DOC-1014
			const string ProfileRequestUrl = "https://api.linkedin.com/v1/people/~:(id,first-name,last-name,headline,industry,summary)";

			var accessToken = response.AccessToken;
			var authorizingHandler = this.WebWorker.CreateMessageHandler(accessToken);
			try {
				using (var httpClient = new HttpClient(authorizingHandler)) {
					using (HttpResponseMessage profileResponse = await httpClient.GetAsync(ProfileRequestUrl, cancellationToken)) {
						using (Stream responseStream = await profileResponse.Content.ReadAsStreamAsync()) {
							XDocument document = LoadXDocumentFromStream(responseStream);
							string userId = document.Root.Element("id").Value;

							string firstName = document.Root.Element("first-name").Value;
							string lastName = document.Root.Element("last-name").Value;
							string userName = firstName + " " + lastName;

							var extraData = new NameValueCollection();
							extraData.Add("accesstoken", accessToken.Token);
							extraData.Add("accesstokensecret", accessToken.Secret);
							extraData.Add("name", userName);
							extraData.AddDataIfNotEmpty(document, "headline");
							extraData.AddDataIfNotEmpty(document, "summary");
							extraData.AddDataIfNotEmpty(document, "industry");

							return new AuthenticationResult(
								isSuccessful: true,
								provider: this.ProviderName,
								providerUserId: userId,
								userName: userName,
								extraData: extraData);
						}
					}
				}
			} catch (Exception exception) {
				return new AuthenticationResult(exception);
			}
		}
开发者ID:jiowei,项目名称:dotnetopenid,代码行数:38,代码来源:LinkedInClient.cs


注:本文中的System.Collections.Specialized.NameValueCollection.AddDataIfNotEmpty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。