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


C# Dictionary.AddItemIfNotEmpty方法代码示例

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


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

示例1: GetUserData

        protected override IDictionary<string, string> GetUserData(string accessToken)
        {
            var openid = GetOpenid(accessToken);
            var url = (UserInfoEndpoint + "?" + accessToken)
                .AddQueryParam("openid", openid)
                .AddQueryParam("oauth_consumer_key", this.appId)
                .AddQueryParam("format", "json");

            var text = WebRequestExtensions.Get(url);
            var graphData = JsonHelper.Deserialize<TencentGraphData>(text);

            var dictionary = new Dictionary<string, string>();
            dictionary.AddItemIfNotEmpty("id", openid);
            dictionary.AddItemIfNotEmpty("username", graphData.NickName);
            dictionary.AddItemIfNotEmpty("name", graphData.NickName);
            //dictionary.AddItemIfNotEmpty("msg", graphData.Msg);
            //dictionary.AddItemIfNotEmpty("gender", graphData.Gender);
            //dictionary.AddItemIfNotEmpty("figureurl", graphData.Figureurl);
            //dictionary.AddItemIfNotEmpty("figureurl_1", graphData.Figureurl_1);
            //dictionary.AddItemIfNotEmpty("figureurl_2", graphData.Figureurl_2);
            //dictionary.AddItemIfNotEmpty("figureurl_qq_1", graphData.Figureurl_qq_1);
            //dictionary.AddItemIfNotEmpty("figureurl_qq_2", graphData.Figureurl_qq_2);
            //dictionary.AddItemIfNotEmpty("is_yellow_vip", graphData.Is_yellow_vip.ToString());
            //dictionary.AddItemIfNotEmpty("vip", graphData.Vip.ToString());
            //dictionary.AddItemIfNotEmpty("level", graphData.Level.ToString());
            return dictionary;
        }
开发者ID:nikolai80,项目名称:CMS,代码行数:27,代码来源:TencentOAuthClient.cs

示例2: GetExtraData

		/// <summary>
		/// Gets the extra data obtained from the response message when authentication is successful.
		/// </summary>
		/// <param name="response">
		/// The response message. 
		/// </param>
		/// <returns>
		/// </returns>
		protected override Dictionary<string, string> GetExtraData(IAuthenticationResponse response) {
			FetchResponse fetchResponse = response.GetExtension<FetchResponse>();
			if (fetchResponse != null) {
				var extraData = new Dictionary<string, string>();
				extraData.AddItemIfNotEmpty("email", fetchResponse.GetAttributeValue(WellKnownAttributes.Contact.Email));
				extraData.AddItemIfNotEmpty("fullName", fetchResponse.GetAttributeValue(WellKnownAttributes.Name.FullName));

				return extraData;
			}

			return null;
		}
开发者ID:vonbv,项目名称:dotnetopenid,代码行数:20,代码来源:YahooOpenIdClient.cs

示例3: GetUserData

        protected override IDictionary<string, string> GetUserData(string accessToken)
        {
            var dict = new Dictionary<string, string> { { "access_token", accessToken } };
            dynamic graphData;
            var text = WebRequestExtensions.Get(UserInfoEndpoint, dict);
            graphData = JsonHelper.Deserialize<dynamic>(text);

            var dictionary = new Dictionary<string, string>();
            dictionary.AddItemIfNotEmpty("id", graphData["response"]["id"].ToString() as string);
            dictionary.AddItemIfNotEmpty("username", graphData["response"]["name"] as string);
            dictionary.AddItemIfNotEmpty("name", graphData["response"]["name"] as string);
            //dictionary.AddItemIfNotEmpty("url", graphData["response"]["avatar"][1]["url"] as string);
            return dictionary;
        }
开发者ID:Qupy,项目名称:Extensions,代码行数:14,代码来源:RenrenClient.cs

示例4: GetUserData

        protected override IDictionary<string, string> GetUserData(string accessToken)
        {
            var dict = new Dictionary<string, string>();
            dict["access_token"] = accessToken;
            dict["format"] = "json";
            var json = WebRequestExtensions.Get(UserInfoEndpoint, dict);
            var result = JsonHelper.Deserialize<dynamic>(json);

            var dictionary = new Dictionary<string, string>();
            dictionary.AddItemIfNotEmpty("id", result["uid"] as string);
            dictionary.AddItemIfNotEmpty("username", result["name"] as string);
            dictionary.AddItemIfNotEmpty("name", result["name"] as string);
            return dictionary;
        }
开发者ID:Qupy,项目名称:Extensions,代码行数:14,代码来源:KaixinClient.cs

示例5: GetUserData

        protected override IDictionary<string, string> GetUserData(string accessToken)
        {
            var dict = new Dictionary<string, string>();
            dict["access_token"] = accessToken;
            dict["id"] = NeteaseModel.Uid;
            var text = WebRequestExtensions.Get(UserInfoEndpoint, dict);
            var graphData = JsonHelper.Deserialize<NeteaseGraphData>(text);

            var dictionary = new Dictionary<string, string>();
            dictionary.AddItemIfNotEmpty("id", graphData.Id);
            dictionary.AddItemIfNotEmpty("username", graphData.Name);
            dictionary.AddItemIfNotEmpty("name", graphData.Screen_Name);
            //dictionary.AddItemIfNotEmpty("url", graphData.Url);
            //dictionary.AddItemIfNotEmpty("gender", graphData.Gender.ToString());
            return dictionary;
        }
开发者ID:Qupy,项目名称:Extensions,代码行数:16,代码来源:NeteaseClient.cs

示例6: GetUserData

        protected override IDictionary<string, string> GetUserData(string accessToken)
        {
            var dict = new Dictionary<string, string>();
            dict["access_token"] = accessToken;
            dict["uid"] = uid;
            var result = WebRequestExtensions.Get(UserData, dict);
            var graphData = JsonHelper.Deserialize<SinaGraphData>(result);
            var dictionary = new Dictionary<string, string>();
            dictionary.AddItemIfNotEmpty("id", graphData.Id);
            dictionary.AddItemIfNotEmpty("username", graphData.Screen_Name);
            dictionary.AddItemIfNotEmpty("name", graphData.Name);
            //foreach (var item in res)
            //{
            //    dictionary.AddItemIfNotEmpty(item.Key as string, item.Value.ToString() as string);
            //}

            return dictionary;
        }
开发者ID:Qupy,项目名称:Extensions,代码行数:18,代码来源:SinaClient.cs

示例7: GetUserData

        protected override IDictionary<string, string> GetUserData(string accessToken)
        {
            GoogleUserData graph;
            var request = WebRequest.Create($"{_userInfoEndpoint}");
            request.Headers.Add(HttpRequestHeader.Authorization.ToString(), $"Bearer {accessToken}");
            using (var response = request.GetResponse())
            {
                using (var responseStream = response.GetResponseStream())
                {
                    graph = JsonHelper.Deserialize<GoogleUserData>(responseStream);
                }
            }

            var userData = new Dictionary<string, string>();
            userData.AddItemIfNotEmpty("id", graph.id);
            userData.AddItemIfNotEmpty("name", graph.name);
            userData.AddItemIfNotEmpty("given_name", graph.given_name);
            userData.AddItemIfNotEmpty("email", graph.email);
            return userData;
        }
开发者ID:Teleopti,项目名称:authbridge,代码行数:20,代码来源:GoogleOAuthClient.cs

示例8: GetUserData

        protected override IDictionary<string, string> GetUserData(string accessToken)
        {
            AzureAdUserData graph;
            var request = WebRequest.Create($"{_graphApiEndpoint}/me?api-version={_graphApiVersion}");
            request.Headers.Add(HttpRequestHeader.Authorization.ToString(), $"Bearer {accessToken}");
            using (var response = request.GetResponse())
            {
                using (var responseStream = response.GetResponseStream())
                {
                    graph = JsonHelper.Deserialize<AzureAdUserData>(responseStream);
                }
            }

            var userData = new Dictionary<string, string>();
            userData.AddItemIfNotEmpty("id", graph.userPrincipalName);
            userData.AddItemIfNotEmpty("objectId", graph.objectId);
            userData.AddItemIfNotEmpty("username", graph.userPrincipalName);
            userData.AddItemIfNotEmpty("name", graph.displayName);
            return userData;
        }
开发者ID:Teleopti,项目名称:authbridge,代码行数:20,代码来源:AzureAdOAuthClient.cs

示例9: GetExtraData

        protected override Dictionary<string, string> GetExtraData(IAuthenticationResponse response)
        {
            var fetchResponse = response.GetExtension<FetchResponse>();
            if (fetchResponse != null)
            {
                var extraData = new Dictionary<string, string>();
                extraData.AddItemIfNotEmpty(ClaimTypes.IsPersistent, fetchResponse.GetAttributeValue(ClaimTypes.IsPersistent));

                return extraData;
            }
            return null;
        }
开发者ID:Teleopti,项目名称:authbridge,代码行数:12,代码来源:RelativeOpenIdClient.cs

示例10: GetUserData

        protected override IDictionary<string, string> GetUserData(string accessToken)
        {
            UriBuilder builder = new UriBuilder(ResourceEndpoint);
            builder.AppendQueryArgument("schema", Scope);

            var request = WebRequest.Create(builder.ToString());
            request.Headers["Authorization"] = string.Concat("Bearer ", accessToken);

            OpenIdConnectGraph data;
            using (WebResponse response = request.GetResponse())
            using (StreamReader reader = new StreamReader(response.GetResponseStream()))
            {
                data = JsonConvert.DeserializeObject<OpenIdConnectGraph>(reader.ReadToEnd());
            }

            Dictionary<string, string> dictionary = new Dictionary<string, string>();
            dictionary.AddItemIfNotEmpty("fullname", data.Name);
            dictionary.AddItemIfNotEmpty("id", data.Email);
            dictionary.AddItemIfNotEmpty("email", data.Email);
            dictionary.AddItemIfNotEmpty("firstname", data.Firstname);
            dictionary.AddItemIfNotEmpty("lastname", data.Lastname);
            return dictionary;
        }
开发者ID:radiantlogicinc,项目名称:.NET-Clients-for-CFS,代码行数:23,代码来源:OpenIdConnectClient.cs

示例11: GetUserData

		/// <summary>
		/// The get user data.
		/// </summary>
		/// <param name="accessToken">
		/// The access token.
		/// </param>
		/// <returns>A dictionary of profile data.</returns>
		protected override IDictionary<string, string> 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 Dictionary<string, string>();
			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;
		}
开发者ID:GrantDG,项目名称:DotNetOpenAuth,代码行数:28,代码来源:FacebookClient.cs

示例12: GetUserData

        /// <summary>
        /// The get user data.
        /// </summary>
        /// <param name="accessToken">
        /// The access token.
        /// </param>
        /// <returns>A dictionary of profile data.</returns>
        protected override IDictionary<string, string> GetUserData(string accessToken)
        {
            var graphData = new FacebookGraphData();
            var request =
                WebRequest.Create(
                    "https://graph.facebook.com/me?access_token=" + accessToken);

            using (var response = request.GetResponse())
            {
                using (var responseStream = response.GetResponseStream())
                {
                    var serializer = new DataContractJsonSerializer(typeof (FacebookGraphData));

                    if (responseStream != null)
                        graphData = (FacebookGraphData) serializer.ReadObject(responseStream);
                }
            }

            // this dictionary must contains
            var userData = new Dictionary<string, string>();
            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);
            userData.AddItemIfNotEmpty("photo", String.Format("http://graph.facebook.com/{0}/picture?width=156&height=156", graphData.Id));
            return userData;
        }
开发者ID:promorepublic,项目名称:oauth,代码行数:36,代码来源:FbClient.cs

示例13: GetUserData

        /// <summary>
        /// The get user data.
        /// </summary>
        /// <param name="accessToken">
        /// The access token.
        /// </param>
        /// <returns>A dictionary of profile data.</returns>
        protected override IDictionary<string, string> GetUserData(string accessToken)
        {
            var builder = new UriBuilder(GetUsersEndpoint);
            builder.AppendQueryArgs(
                new Dictionary<string, string> {
					{ "uid", _accessTokenResponse.user_id.ToString(CultureInfo.InvariantCulture) },
					{ "access_token", _accessTokenResponse.access_token }
				});


            using (var client = new WebClient { Encoding = Encoding.UTF8 })
            {
                string data = client.DownloadString(builder.Uri);
                if (string.IsNullOrEmpty(data))
                {
                    return null;
                }
                var response = JsonConvert.DeserializeObject<VkApiResponse>(data);
                if (response != null && response.response.Length == 1)
                {
                    var userData = new Dictionary<string, string>();
                    userData.AddItemIfNotEmpty("id", response.response[0].uid);
                    userData.AddItemIfNotEmpty("name", response.response[0].first_name + " " + response.response[0].last_name);

                    return userData;
                }
            }
            return new Dictionary<string, string>();
        }
开发者ID:odugen,项目名称:Odugen.VkOAuth2Client,代码行数:36,代码来源:VkClient.cs

示例14: GetUserData

        protected override IDictionary<string, string> GetUserData(string accessToken)
        {
            if (accessToken == null) throw new ArgumentNullException("accessToken");
            var data = HttpContext.Current.Session["OdnoklassnikiOAuthProvider.Token"] as OdnoklassnikiTokenResponse;
            if (data == null || data.AccessToken != accessToken)
                return null;
            var res = new Dictionary<string, string>();
            var builder = new UriBuilder("http://api.odnoklassniki.ru/fb.do");
            //$curl = curl_init('http://api.odnoklassniki.ru/fb.do?access_token=' . $auth['access_token'] .
            //'&application_key=' . $AUTH['application_key'] . '&method=users.getCurrentUser&sig=' .
            //md5('application_key=' . $AUTH['application_key'] . 'method=users.getCurrentUser' . md5($auth['access_token'] . $AUTH['client_secret'])));

            var sign = String.Format("{0}{1}", accessToken, AppSecret).CalculateMd5Hash().ToLower();
            sign = String.Format("application_key={0}method=users.getCurrentUser{1}", AppPublic, sign).CalculateMd5Hash().ToLower();
            var args = new Dictionary<string, string>
                {
                    {"method", "users.getCurrentUser"},
                    {"access_token", accessToken},
                    {"application_key", AppPublic},
                    {"sig", sign},
                };
            builder.AppendQueryArgs(args);
            using (var client = new WebClient())
            {
                using (var stream = client.OpenRead(builder.Uri))
                {
                    var serializer = new DataContractJsonSerializer(typeof (OdnoklassnikiDataItem));
                    if (stream != null)
                    {
                        var info = (OdnoklassnikiDataItem) serializer.ReadObject(stream);
                        if (info != null)
                        {
                            var item = info;
                            res.AddItemIfNotEmpty("id", item.UserId);
                            res.AddItemIfNotEmpty("username", item.UserId);
                            res.AddItemIfNotEmpty("name",
                                                  item.Name ??
                                                  (((item.FirstName ?? "") + " " + (item.LastName ?? "")).Trim()));
                            res.AddItemIfNotEmpty("birthday", item.Birthdate);
                            res.AddItemIfNotEmpty("gender", item.Sex);
                            res.AddItemIfNotEmpty("link", String.Format("http://odnoklassniki.ru/profile/{0}", item.UserId));
                            res.AddItemIfNotEmpty("photo", item.Photo ?? item.Photo2);
                        }
                    }
                }
            }
            return res;
        }
开发者ID:promorepublic,项目名称:oauth,代码行数:48,代码来源:OkClient.cs

示例15: GetUserData

        /// <summary>
        /// The get user data.
        /// </summary>
        /// <param name="accessToken">
        /// The access token.
        /// </param>
        /// <returns>A dictionary of profile data.</returns>
        protected override IDictionary<string, string> GetUserData(string accessToken)
        {
            // Source documents
            // http://api.mail.ru/docs/guides/restapi/
            // http://api.mail.ru/docs/reference/rest/users.getInfo/

            var uriBuilder = new UriBuilder(UserInfoServiceEndpoint);

            var args = new Dictionary<string, string>();

            args.Add("app_id", this.appId);
            args.Add("method", "users.getInfo");
            args.Add("secure", "1");
            args.Add("session_key", accessToken);

            // workaround for current design, oauth_token is always present in URL, so we need emulate it for correct request signing 
            args.Add("oauth_token", accessToken);

            // sign=hex_md5('app_id={client_id}method=users.getInfosecure=1session_key={access_token}{secret_key}')
            var signature = string.Concat(args.OrderBy(x => x.Key).Select(x => string.Format("{0}={1}", x.Key, x.Value)).ToList());
            signature = (signature + this.appSecret).GetMd5Hash();

            // removing fake param to prevent dups
            args.Remove("oauth_token");

            args.Add("sig", signature);

            uriBuilder.AppendQueryArgs(args);

            using (var webClient = new WebClient())
            {
                webClient.Encoding = Encoding.UTF8;

                var text = webClient.DownloadString(uriBuilder.Uri);
                if (string.IsNullOrEmpty(text))
                    return null;

                var data = JObject.Parse(text);

                var user = data[0];

                var dictionary = new Dictionary<string, string>();
                dictionary.AddItemIfNotEmpty("id", user["uid"].Value<string>());
                dictionary.AddItemIfNotEmpty("firstName", user["first_name"].Value<string>());
                dictionary.AddItemIfNotEmpty("lastName", user["last_name"].Value<string>());
                dictionary.AddItemIfNotEmpty("email", user["email"].Value<string>());
                return dictionary;
            }
        }
开发者ID:NorDroN,项目名称:DotNetOpenAuth.AspNet.Extensions,代码行数:56,代码来源:MailRuClient.cs


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