chore: 整理接口

oneRain 2019-08-07 14:32:00 +08:00
parent 7d88d92a80
commit a3d477075a
1 changed files with 15 additions and 20 deletions

View File

@ -255,11 +255,9 @@ namespace LeanCloud
/// <param name="cql">CQL 语句</param> /// <param name="cql">CQL 语句</param>
/// <param name="cancellationToken">CancellationToken</param> /// <param name="cancellationToken">CancellationToken</param>
/// <returns>返回符合条件的对象集合</returns> /// <returns>返回符合条件的对象集合</returns>
public static Task<IEnumerable<T>> DoCloudQueryAsync(string cql, CancellationToken cancellationToken) public static Task<IEnumerable<T>> DoCloudQueryAsync(string cql, CancellationToken cancellationToken) {
{ var queryString = $"cloudQuery?cql={Uri.EscapeDataString(cql)}";
var queryString = string.Format("cloudQuery?cql={0}", Uri.EscapeDataString(cql)); return RebuildObjectFromCloudQueryResult(queryString);
return rebuildObjectFromCloudQueryResult(queryString);
} }
/// <summary> /// <summary>
@ -267,8 +265,7 @@ namespace LeanCloud
/// </summary> /// </summary>
/// <param name="cql"></param> /// <param name="cql"></param>
/// <returns></returns> /// <returns></returns>
public static Task<IEnumerable<T>> DoCloudQueryAsync(string cql) public static Task<IEnumerable<T>> DoCloudQueryAsync(string cql) {
{
return DoCloudQueryAsync(cql, CancellationToken.None); return DoCloudQueryAsync(cql, CancellationToken.None);
} }
@ -278,17 +275,15 @@ namespace LeanCloud
/// <param name="cqlTeamplate">带有占位符的模板 cql 语句</param> /// <param name="cqlTeamplate">带有占位符的模板 cql 语句</param>
/// <param name="pvalues">占位符对应的参数数组</param> /// <param name="pvalues">占位符对应的参数数组</param>
/// <returns></returns> /// <returns></returns>
public static Task<IEnumerable<T>> DoCloudQueryAsync(string cqlTeamplate, params object[] pvalues) public static Task<IEnumerable<T>> DoCloudQueryAsync(string cqlTeamplate, params object[] pvalues) {
{
string queryStringTemplate = "cloudQuery?cql={0}&pvalues={1}"; string queryStringTemplate = "cloudQuery?cql={0}&pvalues={1}";
string pSrting = JsonConvert.SerializeObject(pvalues); string pSrting = JsonConvert.SerializeObject(pvalues);
string queryString = string.Format(queryStringTemplate, Uri.EscapeDataString(cqlTeamplate), Uri.EscapeDataString(pSrting)); string queryString = string.Format(queryStringTemplate, Uri.EscapeDataString(cqlTeamplate), Uri.EscapeDataString(pSrting));
return rebuildObjectFromCloudQueryResult(queryString); return RebuildObjectFromCloudQueryResult(queryString);
} }
internal static Task<IEnumerable<T>> rebuildObjectFromCloudQueryResult(string queryString) internal static Task<IEnumerable<T>> RebuildObjectFromCloudQueryResult(string queryString) {
{
var command = new AVCommand { var command = new AVCommand {
Path = queryString, Path = queryString,
Method = HttpMethod.Get Method = HttpMethod.Get
@ -383,12 +378,12 @@ namespace LeanCloud
var other = obj as AVQuery<T>; var other = obj as AVQuery<T>;
return ClassName.Equals(other.ClassName) && return ClassName.Equals(other.ClassName) &&
this.where.CollectionsEqual(other.where) && where.CollectionsEqual(other.where) &&
this.orderBy.CollectionsEqual(other.orderBy) && orderBy.CollectionsEqual(other.orderBy) &&
this.includes.CollectionsEqual(other.includes) && includes.CollectionsEqual(other.includes) &&
this.selectedKeys.CollectionsEqual(other.selectedKeys) && selectedKeys.CollectionsEqual(other.selectedKeys) &&
object.Equals(this.skip, other.skip) && Equals(skip, other.skip) &&
object.Equals(this.limit, other.limit); Equals(limit, other.limit);
} }
public override int GetHashCode() { public override int GetHashCode() {
@ -554,7 +549,7 @@ namespace LeanCloud
"Only ECMAScript-compatible regexes are supported. Please use the ECMAScript RegexOptions flag when creating your regex."); "Only ECMAScript-compatible regexes are supported. Please use the ECMAScript RegexOptions flag when creating your regex.");
} }
MergeWhereClauses(new Dictionary<string, object> { MergeWhereClauses(new Dictionary<string, object> {
{ key, new Dictionary<string, object>{ { key, EncodeRegex(regex, modifiers) } } } { key, EncodeRegex(regex, modifiers) }
}); });
return this; return this;
} }
@ -563,7 +558,7 @@ namespace LeanCloud
return WhereMatches(key, regex, null); return WhereMatches(key, regex, null);
} }
public AVQuery<T> WhereMatches(string key, string pattern, string modifiers = null) { public AVQuery<T> WhereMatches(string key, string pattern, string modifiers) {
return WhereMatches(key, new Regex(pattern, RegexOptions.ECMAScript), modifiers); return WhereMatches(key, new Regex(pattern, RegexOptions.ECMAScript), modifiers);
} }