chore: for leanengine

oneRain 2021-03-18 11:25:01 +08:00
parent 70e5b6c3bb
commit e5b9f29575
5 changed files with 38 additions and 6 deletions

View File

@ -15,7 +15,7 @@ namespace LeanCloud.Storage.Internal.Codec {
return DecodeBytes(dict); return DecodeBytes(dict);
} else if (type == "Object") { } else if (type == "Object") {
return DecodeObject(dict); return DecodeObject(dict);
} else if (type == "Pointer") { } else if (type == "Pointer" || type == "Object") {
return DecodeObject(dict); return DecodeObject(dict);
} else if (type == "Relation") { } else if (type == "Relation") {
return DecodeRelation(dict); return DecodeRelation(dict);

View File

@ -65,10 +65,10 @@ namespace LeanCloud.Storage.Internal.Object {
if (!string.IsNullOrEmpty(objectData.ObjectId)) { if (!string.IsNullOrEmpty(objectData.ObjectId)) {
dict["objectId"] = objectData.ObjectId; dict["objectId"] = objectData.ObjectId;
} }
if (objectData.CreatedAt != null) { if (!objectData.CreatedAt.Equals(default)) {
dict["createdAt"] = objectData.CreatedAt.ToUniversalTime(); dict["createdAt"] = objectData.CreatedAt.ToUniversalTime();
} }
if (objectData.UpdatedAt != null) { if (!objectData.UpdatedAt.Equals(default)) {
dict["updatedAt"] = objectData.UpdatedAt.ToUniversalTime(); dict["updatedAt"] = objectData.UpdatedAt.ToUniversalTime();
} }
if (objectData.CustomPropertyDict != null) { if (objectData.CustomPropertyDict != null) {

View File

@ -9,7 +9,7 @@ namespace LeanCloud {
/// </summary> /// </summary>
public class LCApplication { public class LCApplication {
// SDK 版本号,用于 User-Agent 统计 // SDK 版本号,用于 User-Agent 统计
internal const string SDKVersion = "0.6.4"; public const string SDKVersion = "0.6.4";
// 接口版本号,用于接口版本管理 // 接口版本号,用于接口版本管理
internal const string APIVersion = "1.1"; internal const string APIVersion = "1.1";

View File

@ -1,6 +1,7 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Collections.Generic; using System.Collections.Generic;
using LeanCloud.Storage.Internal.Codec; using LeanCloud.Storage.Internal.Codec;
using LeanCloud.Storage.Internal.Object;
namespace LeanCloud.Storage { namespace LeanCloud.Storage {
/// <summary> /// <summary>
@ -46,11 +47,38 @@ namespace LeanCloud.Storage {
Dictionary<string, object> headers = new Dictionary<string, object> { Dictionary<string, object> headers = new Dictionary<string, object> {
{ PRODUCTION_KEY, IsProduction ? 1 : 0 } { PRODUCTION_KEY, IsProduction ? 1 : 0 }
}; };
object encodeParams = LCEncoder.Encode(parameters); object encodeParams = Encode(parameters);
Dictionary<string, object> response = await LCApplication.HttpClient.Post<Dictionary<string, object>>(path, Dictionary<string, object> response = await LCApplication.HttpClient.Post<Dictionary<string, object>>(path,
headers: headers, headers: headers,
data: encodeParams); data: encodeParams);
return LCDecoder.Decode(response["result"]); return LCDecoder.Decode(response["result"]);
} }
public static object Encode(object parameters) {
if (parameters is LCObject lcObj) {
return EncodeLCObject(lcObj);
} else if (parameters is IList<LCObject> list) {
List<object> l = new List<object>();
foreach (LCObject obj in list) {
l.Add(EncodeLCObject(obj));
}
return l;
} else if (parameters is IDictionary<string, LCObject> dict) {
Dictionary<string, object> d = new Dictionary<string, object>();
foreach (KeyValuePair<string, LCObject> item in dict) {
d[item.Key] = EncodeLCObject(item.Value);
}
return d;
}
return parameters;
}
static object EncodeLCObject(LCObject obj) {
obj.ApplyCustomProperties();
Dictionary<string, object> dict = LCObjectData.Encode(obj.Data);
dict["__type"] = "Object";
return dict;
}
} }
} }

View File

@ -497,7 +497,7 @@ namespace LeanCloud.Storage {
Data.CreatedAt = objectData.CreatedAt != null ? objectData.CreatedAt : Data.CreatedAt; Data.CreatedAt = objectData.CreatedAt != null ? objectData.CreatedAt : Data.CreatedAt;
Data.UpdatedAt = objectData.UpdatedAt != null ? objectData.UpdatedAt : Data.UpdatedAt; Data.UpdatedAt = objectData.UpdatedAt != null ? objectData.UpdatedAt : Data.UpdatedAt;
// 先将本地的预估数据直接替换 // 先将本地的预估数据直接替换
Data.CustomPropertyDict = estimatedData; ApplyCustomProperties();
// 再将服务端的数据覆盖 // 再将服务端的数据覆盖
foreach (KeyValuePair<string, object> kv in objectData.CustomPropertyDict) { foreach (KeyValuePair<string, object> kv in objectData.CustomPropertyDict) {
string key = kv.Key; string key = kv.Key;
@ -512,6 +512,10 @@ namespace LeanCloud.Storage {
isNew = false; isNew = false;
} }
public void ApplyCustomProperties() {
Data.CustomPropertyDict = estimatedData;
}
void RebuildEstimatedData() { void RebuildEstimatedData() {
estimatedData = new Dictionary<string, object>(); estimatedData = new Dictionary<string, object>();
foreach (KeyValuePair<string, object> kv in Data.CustomPropertyDict) { foreach (KeyValuePair<string, object> kv in Data.CustomPropertyDict) {