本文整理汇总了C#中QueryParameters.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# QueryParameters.ToString方法的具体用法?C# QueryParameters.ToString怎么用?C# QueryParameters.ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QueryParameters
的用法示例。
在下文中一共展示了QueryParameters.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestNegateSimpleQuery
public void TestNegateSimpleQuery()
{
var query = new QueryParameters<Artist>();
query.Add("arid", "1", true);
Assert.AreEqual("NOT arid:1", query.ToString());
}
示例2: AccessTokenRequestError
public static string AccessTokenRequestError(string url, QueryParameters collection)
{
string message = "An error occurred while requesting Access Token at " + url;
if (collection != null)
if (collection.Count > 0)
message += Environment.NewLine + "with parameters " + collection.ToString();
return message;
}
示例3: TestInlineSimpleQuery
public void TestInlineSimpleQuery()
{
var query = new QueryParameters<Artist>();
query.Add("artist", "\"rolling stones\" OR jagger");
Assert.AreEqual("artist:(\"rolling stones\" OR jagger)", query.ToString());
}
示例4: TestAlreadyQuotedSimpleQuery
public void TestAlreadyQuotedSimpleQuery()
{
var query = new QueryParameters<Artist>();
query.Add("artist", "\"rolling stones\"");
Assert.AreEqual("artist:\"rolling stones\"", query.ToString());
}
示例5: TestNegateMultiQuery
public void TestNegateMultiQuery()
{
var query = new QueryParameters<Artist>();
query.Add("artist", "stones");
query.Add("tag", "rock", true);
Assert.AreEqual("artist:stones AND NOT tag:rock", query.ToString());
}
示例6: TestInlineMultiQuery
public void TestInlineMultiQuery()
{
var query = new QueryParameters<Artist>();
query.Add("artist", "\"rolling stones\" OR jagger");
query.Add("tag", "rock", true);
Assert.AreEqual("artist:(\"rolling stones\" OR jagger) AND NOT tag:rock", query.ToString());
}
示例7: GetLoginUrl
public override string GetLoginUrl(string returnUrl)
{
if(string.IsNullOrEmpty(ConnectionToken.RequestToken))
RequestForRequestToken();
var oauthParameters = new QueryParameters
{
new QueryParameter("oauth_token", ConnectionToken.RequestToken)
};
BeforeDirectingUserToServiceProvider(oauthParameters);
return provider.UserLoginEndpoint + "?" + oauthParameters.ToString();
}
示例8: CustomFeedExecutionError
public static string CustomFeedExecutionError(string feedUrl, QueryParameters collection)
{
return "An error occurred while executing " + feedUrl + Environment.NewLine + "Request Parameters: " + ((collection == null) ? "" : ((collection == null) ? "" : collection.ToString()));
}
示例9: SearchAsync
/// <summary>
/// Search for an artist in the MusicBrainz database, matching the given query.
/// </summary>
/// <param name="query">The query parameters.</param>
/// <param name="limit">The maximum number of artists to return (default = 25).</param>
/// <param name="offset">The offset to the artists list (enables paging, default = 0).</param>
/// <returns></returns>
public async static Task<ArtistList> SearchAsync(QueryParameters<Artist> query, int limit = 25, int offset = 0)
{
return (await SearchAsync<ArtistMetadata>(EntityName,
query.ToString(), limit, offset)).Collection;
}
示例10: ExecuteFeed
public override System.Net.WebResponse ExecuteFeed(string feedURL, IProvider provider, BusinessObjects.Token connectionToken, BusinessObjects.TRANSPORT_METHOD transportMethod, byte[] content = null, Dictionary<string, string> headers = null)
{
string signature = "";
OAuthHelper oauthHelper = new OAuthHelper();
string timestamp = oauthHelper.GenerateTimeStamp();
QueryParameters oauthParams = new QueryParameters();
oauthParams.Add("oauth_consumer_key", provider.Consumerkey);
oauthParams.Add("oauth_nonce", oauthHelper.GenerateNonce());
oauthParams.Add("oauth_signature_method", provider.SignatureMethod.ToString());
oauthParams.Add("oauth_timestamp", timestamp);
oauthParams.Add("oauth_token", connectionToken.AccessToken);
oauthParams.Add("oauth_version", "1.0");
signature = oauthHelper.GenerateSignature(new Uri(feedURL), oauthParams, provider.Consumerkey, provider.Consumersecret, provider.SignatureMethod, TRANSPORT_METHOD.POST, connectionToken.TokenSecret);
oauthParams.Add("oauth_signature", signature);
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(feedURL);
request.Method = transportMethod.ToString();
if (headers != null)
{
foreach (var header in headers)
{
switch (header.Key)
{
case "ContentLength":
{
request.ContentLength = long.Parse(header.Value);
break;
}
case "ContentType":
{
request.ContentType = header.Value;
break;
}
default:
{
request.Headers[header.Key] = header.Value;
break;
}
}
}
}
request.ContentLength = (content == null) ? 0 : content.Length;
request.Headers.Add("Authorization", oauthHelper.GetAuthorizationHeader(oauthParams));
request.GetRequestStream().Write(content, 0, content.Length);
WebResponse wr = null;
try
{
logger.Debug("Executing " + feedURL + " using " + transportMethod.ToString() + Environment.NewLine + "Request Parameters: " + oauthParams.ToString());
wr = (WebResponse)request.GetResponse();
logger.Info("Successfully executed " + feedURL + " using " + transportMethod.ToString());
}
catch (Exception ex)
{
logger.Error(ErrorMessages.CustomFeedExecutionError(feedURL, oauthParams), ex);
throw new OAuthException(ErrorMessages.CustomFeedExecutionError(feedURL, oauthParams), ex);
}
return wr;
}
示例11: RequestForAccessToken
public void RequestForAccessToken()
{
QueryParameters oauthParameters = new QueryParameters();
string signature = "";
OAuthHelper oauthHelper = new OAuthHelper();
////1. Generate Signature
oauthParameters.Add("oauth_consumer_key", provider.Consumerkey);
oauthParameters.Add("oauth_token", Utility.UrlEncode(ConnectionToken.RequestToken));
oauthParameters.Add("oauth_signature_method", provider.SignatureMethod.ToString());
oauthParameters.Add("oauth_timestamp", oauthHelper.GenerateTimeStamp());
oauthParameters.Add("oauth_nonce", oauthHelper.GenerateNonce());
oauthParameters.Add("oauth_version", "1.0");
BeforeRequestingAccessToken(oauthParameters); // hook called
signature = oauthHelper.GenerateSignature(new Uri(provider.AccessTokenEndpoint), oauthParameters, provider.Consumerkey, provider.Consumersecret, provider.SignatureMethod, provider.TransportName, string.Empty);
oauthParameters.Add("oauth_signature", Utility.UrlEncode(signature));
//2. Notify Consumer (if applicable)
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(provider.AccessTokenEndpoint + "?" + oauthParameters.ToString().Replace("HMACSHA1", "HMAC-SHA1"));
request.Method = "GET";// always get irrespective of provider.TransportName.ToString();
request.ContentLength = 0;
string response = "";
try
{
logger.Debug("Requesting Access Token at: " + request.RequestUri + Environment.NewLine + "Request Parameters: " + oauthParameters.ToString());
using (HttpWebResponse webResponse = (HttpWebResponse)request.GetResponse())
using (Stream responseStream = webResponse.GetResponseStream())
using (StreamReader reader = new StreamReader(responseStream))
{
response = reader.ReadToEnd();
HandleAccessTokenResponse(Utility.GetQuerystringParameters(response));
}
}
catch (Exception ex)
{
logger.Debug(ErrorMessages.AccessTokenRequestError(request.RequestUri.ToString(), oauthParameters), ex);
throw new OAuthException(ErrorMessages.AccessTokenRequestError(request.RequestUri.ToString(), oauthParameters), ex);
}
}
示例12: GenerateSignature
/// <summary>
/// Generate Signature
/// </summary>
/// <param name="requestURL"></param>
/// <param name="oauthParameters"></param>
/// <param name="consumerKey"></param>
/// <param name="consumerSecret"></param>
/// <param name="signatureType"></param>
/// <param name="httpMethod"></param>
/// <param name="tokenSecret"></param>
/// <returns></returns>
public string GenerateSignature(Uri requestURL, QueryParameters oauthParameters, string consumerKey, string consumerSecret,
SIGNATURE_TYPE signatureType, TRANSPORT_METHOD httpMethod, string tokenSecret)
{
QueryParameters tmpOauthParameters = new QueryParameters();
foreach (var param in oauthParameters)
{
if (param.Value.ToLower().Contains("http://") || param.Value.ToLower().Contains("https://"))
tmpOauthParameters.Add(new QueryParameter(param.Key, Utility.UrlEncode(param.Value)));
else
tmpOauthParameters.Add(new QueryParameter(param.Key, param.Value));
}
tmpOauthParameters[OAuthSignatureMethodKey] = ParseSignatureEnum(signatureType);
string signature = "";
StringBuilder signatureBase = new StringBuilder();
//1. URL encode and process Request URL
string normalizedRequestUrl;
normalizedRequestUrl = string.Format("{0}://{1}", requestURL.Scheme, requestURL.Host);
if (!((requestURL.Scheme == "http" && requestURL.Port == 80) || (requestURL.Scheme == "https" && requestURL.Port == 443)))
{
normalizedRequestUrl += ":" + requestURL.Port;
}
normalizedRequestUrl += requestURL.AbsolutePath;
normalizedRequestUrl = Utility.UrlEncode(normalizedRequestUrl);
//2. URL Encode callbackUrl (if present)
//if (tmpOauthParameters.HasName(OAuthCallbackKey))
// tmpOauthParameters[OAuthCallbackKey] = Utility.UrlEncode(tmpOauthParameters[OAuthCallbackKey]);
//tmpOauthParameters["scope"] = Utility.UrlEncode(tmpOauthParameters["scope"]);
foreach (var p in Utility.GetQuerystringParameters(requestURL.ToString()))
tmpOauthParameters.Add(p.Key, UrlEncode(HttpUtility.UrlDecode(p.Value)));
//following works for Twitter with spaces
//tmpOauthParameters.Add(p.Key, UrlEncode(HttpUtility.UrlDecode(p.Value)));
//3. Perform Lexographic Sorting
tmpOauthParameters.Sort();
//4. Generate Signature Base
signatureBase.AppendFormat("{0}&", httpMethod.ToString().ToUpper());
signatureBase.AppendFormat("{0}&", normalizedRequestUrl);
signatureBase.AppendFormat("{0}", Utility.UrlEncode(tmpOauthParameters.ToString()));
string sbase = signatureBase.ToString();
logger.Debug("signature base:" + sbase);
//5. Generate Signature
switch (signatureType)
{
case SIGNATURE_TYPE.PLAINTEXT:
{
signature = Utility.UrlEncode(string.Format("{0}&{1}", consumerSecret, tokenSecret));
break;
}
case SIGNATURE_TYPE.HMACSHA1:
{
HMACSHA1 hmacsha1 = new HMACSHA1();
hmacsha1.Key = Encoding.ASCII.GetBytes(string.Format("{0}&{1}", UrlEncode(consumerSecret), string.IsNullOrEmpty(tokenSecret) ? "" : tokenSecret));
signature = GenerateSignatureUsingHash(sbase, hmacsha1);
logger.Debug("HMACSHA1 signature:" + signature);
break;
}
default:
throw new ArgumentException("Unknown signature type", "signatureType");
}
return signature;
}
示例13: DirectUserToServiceProvider
public void DirectUserToServiceProvider()
{
QueryParameters oauthParameters = new QueryParameters();
try
{
oauthParameters.Add(new QueryParameter("oauth_token", connectionToken.RequestToken));
BeforeDirectingUserToServiceProvider(oauthParameters);
logger.Debug("redirecting user for login to: " + provider.UserLoginEndpoint + "?" + oauthParameters.ToString());
SocialAuthUser.Redirect(provider.UserLoginEndpoint + "?" + oauthParameters.ToString());
}
catch (Exception ex)
{
logger.Error(ErrorMessages.UserLoginRedirectionError(provider.UserLoginEndpoint + "?" + oauthParameters.ToString()), ex);
throw new OAuthException(ErrorMessages.UserLoginRedirectionError(provider.UserLoginEndpoint + "?" + oauthParameters.ToString()), ex);
}
}
示例14: UserLoginResponseError
public static string UserLoginResponseError(PROVIDER_TYPE providerType, QueryParameters collection)
{
return "An error occurred in user login." + Environment.NewLine + "Provider returned: " + ((collection == null) ? "" : collection.ToString());
}
示例15: RequestTokenRequestError
public static string RequestTokenRequestError(string url, QueryParameters collection)
{
return "An error occurred while requesting Request Token at " + url + Environment.NewLine + "with parameters " + ((collection == null) ? "" : collection.ToString());
}