本文整理汇总了C#中System.Collections.Specialized.NameValueCollection.AddItemIfNotEmpty方法的典型用法代码示例。如果您正苦于以下问题:C# NameValueCollection.AddItemIfNotEmpty方法的具体用法?C# NameValueCollection.AddItemIfNotEmpty怎么用?C# NameValueCollection.AddItemIfNotEmpty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Specialized.NameValueCollection
的用法示例。
在下文中一共展示了NameValueCollection.AddItemIfNotEmpty方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetExtraData
/// <summary>
/// Gets the extra data obtained from the response message when authentication is successful.
/// </summary>
/// <param name="response">
/// The response message.
/// </param>
/// <returns>A dictionary of profile data; or null if no data is available.</returns>
protected override NameValueCollection GetExtraData(IAuthenticationResponse response) {
FetchResponse fetchResponse = response.GetExtension<FetchResponse>();
if (fetchResponse != null) {
var extraData = new NameValueCollection();
extraData.AddItemIfNotEmpty("email", fetchResponse.GetAttributeValue(WellKnownAttributes.Contact.Email));
extraData.AddItemIfNotEmpty("fullName", fetchResponse.GetAttributeValue(WellKnownAttributes.Name.FullName));
return extraData;
}
return null;
}
示例2: GetUserData
/// <summary>
/// Given the access token, gets the logged-in user's data. The returned dictionary must include two keys 'id', and 'username'.
/// </summary>
/// <param name="accessToken">
/// The access token of the current user.
/// </param>
/// <returns>
/// A dictionary contains key-value pairs of user data
/// </returns>
protected override NameValueCollection GetUserData(string accessToken) {
MicrosoftClientUserData graph;
var request =
WebRequest.Create(
"https://apis.live.net/v5.0/me?access_token=" + MessagingUtilities.EscapeUriDataStringRfc3986(accessToken));
using (var response = request.GetResponse()) {
using (var responseStream = response.GetResponseStream()) {
graph = JsonHelper.Deserialize<MicrosoftClientUserData>(responseStream);
}
}
var userData = new NameValueCollection();
userData.AddItemIfNotEmpty("id", graph.Id);
userData.AddItemIfNotEmpty("username", graph.Name);
userData.AddItemIfNotEmpty("name", graph.Name);
userData.AddItemIfNotEmpty("link", graph.Link == null ? null : graph.Link.AbsoluteUri);
userData.AddItemIfNotEmpty("gender", graph.Gender);
userData.AddItemIfNotEmpty("firstname", graph.FirstName);
userData.AddItemIfNotEmpty("lastname", graph.LastName);
return userData;
}
示例3: GetUserData
/// <summary>
/// Given the access token, gets the logged-in user's data.
/// The returned dictionary must include two keys 'id', and 'username'.
/// </summary>
/// <param name="accessToken">The access token of the current user.</param>
/// <returns>A dictionary contains key-value pairs of user data</returns>
protected override NameValueCollection GetUserData(string accessToken)
{
var uri = new Uri(userEndpoint + "?access_token=" + accessToken);
var webRequest = (HttpWebRequest)WebRequest.Create(uri);
using (var webResponse = webRequest.GetResponse())
{
using (var stream = webResponse.GetResponseStream())
{
if (stream == null)
return null;
NameValueCollection c = new NameValueCollection();
var result = JsonSerializer.DeserializeFromStream<Dictionary<string, string>>(stream);
foreach (var item in result)
{
c.AddItemIfNotEmpty(item.Key, item.Value);
}
return c;
}
}
}
示例4: GetUserData
/// <summary>
/// The get user data.
/// </summary>
/// <param name="accessToken">
/// The access token.
/// </param>
/// <returns>A dictionary of profile data.</returns>
protected override NameValueCollection GetUserData(string accessToken) {
var userData = new NameValueCollection();
try {
AzureADGraph graphData;
WebRequest request =
WebRequest.Create(
GraphEndpoint + this.tenantid + "/users/" + this.userid + "?api-version=2013-04-05");
request.Headers = new WebHeaderCollection();
request.Headers.Add("authorization", accessToken);
using (var response = request.GetResponse()) {
using (var responseStream = response.GetResponseStream()) {
graphData = JsonHelper.Deserialize<AzureADGraph>(responseStream);
}
}
// this dictionary must contains
userData.AddItemIfNotEmpty("id", graphData.ObjectId);
userData.AddItemIfNotEmpty("username", graphData.UserPrincipalName);
userData.AddItemIfNotEmpty("name", graphData.DisplayName);
return userData;
} catch (Exception e) {
System.Diagnostics.Debug.WriteLine(e.ToStringDescriptive());
return userData;
}
}
示例5: GetUserData
/// <summary>
/// Given the access token, gets the logged-in user's data.
/// The returned dictionary must include two keys 'id', and 'username'.
/// </summary>
/// <param name="accessToken">The access token of the current user.</param>
/// <returns>A dictionary contains key-value pairs of user data</returns>
protected override NameValueCollection GetUserData(string accessToken)
{
FacebookMe graphData = null;
string requestUrl = "https://graph.facebook.com/me?access_token=" + UriHelper.EscapeUriDataStringRfc3986(accessToken);
var request = System.Net.WebRequest.Create(requestUrl);
using (var response = request.GetResponse())
{
using (var responseStream = response.GetResponseStream())
{
if (responseStream != null)
{
var serializer = new DataContractJsonSerializer(typeof(FacebookMe));
graphData = (FacebookMe)serializer.ReadObject(responseStream);
}
}
}
// this dictionary must contains
var userData = new NameValueCollection();
if (graphData != null)
{
userData.AddItemIfNotEmpty("id", graphData.Id);
userData.AddItemIfNotEmpty("username", graphData.Email);
userData.AddItemIfNotEmpty("name", graphData.Name);
userData.AddItemIfNotEmpty("link", graphData.Link == null ? null : graphData.Link.AbsoluteUri);
userData.AddItemIfNotEmpty("gender", graphData.Gender);
userData.AddItemIfNotEmpty("birthday", graphData.Birthday);
}
return userData;
}
示例6: GetUserData
/// <summary>
/// The get user data.
/// </summary>
/// <param name="accessToken">
/// The access token.
/// </param>
/// <returns>A dictionary of profile data.</returns>
protected override NameValueCollection GetUserData(string accessToken) {
FacebookGraphData graphData;
var request =
WebRequest.Create(
"https://graph.facebook.com/me?access_token=" + MessagingUtilities.EscapeUriDataStringRfc3986(accessToken));
using (var response = request.GetResponse()) {
using (var responseStream = response.GetResponseStream()) {
graphData = JsonHelper.Deserialize<FacebookGraphData>(responseStream);
}
}
// this dictionary must contains
var userData = new NameValueCollection();
userData.AddItemIfNotEmpty("id", graphData.Id);
userData.AddItemIfNotEmpty("username", graphData.Email);
userData.AddItemIfNotEmpty("name", graphData.Name);
userData.AddItemIfNotEmpty("link", graphData.Link == null ? null : graphData.Link.AbsoluteUri);
userData.AddItemIfNotEmpty("gender", graphData.Gender);
userData.AddItemIfNotEmpty("birthday", graphData.Birthday);
return userData;
}