本文整理汇总了C#中QueryParameters.Single方法的典型用法代码示例。如果您正苦于以下问题:C# QueryParameters.Single方法的具体用法?C# QueryParameters.Single怎么用?C# QueryParameters.Single使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QueryParameters
的用法示例。
在下文中一共展示了QueryParameters.Single方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandleAccessTokenResponse
public void HandleAccessTokenResponse(string response)
{
QueryParameters responseCollection = new QueryParameters();
try
{
if (response.StartsWith("{")) // access token is returned in JSON format
{
// {"access_token":"asasdasdAA","expires_in":3600,"scope":"wl.basic","token_type":"bearer"}
JObject accessTokenJson = JObject.Parse(response);
responseCollection.Add("response", response);
ConnectionToken.AccessToken = accessTokenJson.SelectToken("access_token").ToString().Replace("\"", "");
if (accessTokenJson.SelectToken("expires_in") != null)
ConnectionToken.ExpiresOn = DateTime.Now.AddSeconds(int.Parse(accessTokenJson.SelectToken("expires_in").ToString().Replace("\"", "")) - 20);
//put in raw list
foreach (var t in accessTokenJson.AfterSelf())
ConnectionToken.ResponseCollection.Add(t.Type.ToString(), t.ToString());
logger.Info("Access Token successfully received");
isSuccess = true;
}
else // access token is returned as part of Query String
{
responseCollection = Utility.GetQuerystringParameters(response);
string keyForAccessToken = responseCollection.Single(x => x.Key.Contains("token")).Key;
ConnectionToken.AccessToken = responseCollection[keyForAccessToken].Replace("\"", "");
if (responseCollection.ToList().Exists(x => x.Key.ToLower().Contains("expir")))
{
string keyForExpiry = responseCollection.Single(x => x.Key.Contains("expir")).Key;
ConnectionToken.ExpiresOn = ConnectionToken.ExpiresOn = DateTime.Now.AddSeconds(int.Parse(responseCollection[keyForExpiry].Replace("\"", "")) - 20);
}
//put in raw list
responseCollection.ToList().ForEach(x => ConnectionToken.ResponseCollection.Add(x.Key, x.Value));
logger.Info("Access Token successfully received");
isSuccess = true;
}
}
catch (Exception ex)
{
logger.Error(ErrorMessages.AccessTokenResponseInvalid(responseCollection), ex);
throw new OAuthException(ErrorMessages.AccessTokenResponseInvalid(responseCollection), ex);
}
}