diff --git a/Storage/Storage/Internal/Codec/LCDecoder.cs b/Storage/Storage/Internal/Codec/LCDecoder.cs index b4b9770..4d7a9ee 100644 --- a/Storage/Storage/Internal/Codec/LCDecoder.cs +++ b/Storage/Storage/Internal/Codec/LCDecoder.cs @@ -80,10 +80,10 @@ namespace LeanCloud.Storage.Internal.Codec { string key = kv.Key; Dictionary access = kv.Value as Dictionary; if (access.TryGetValue("read", out object ra)) { - acl.readAccess[key] = Convert.ToBoolean(ra); + acl.ReadAccess[key] = Convert.ToBoolean(ra); } if (access.TryGetValue("write", out object wa)) { - acl.writeAccess[key] = Convert.ToBoolean(wa); + acl.WriteAccess[key] = Convert.ToBoolean(wa); } } return acl; diff --git a/Storage/Storage/Internal/Codec/LCEncoder.cs b/Storage/Storage/Internal/Codec/LCEncoder.cs index a216200..453bee8 100644 --- a/Storage/Storage/Internal/Codec/LCEncoder.cs +++ b/Storage/Storage/Internal/Codec/LCEncoder.cs @@ -84,19 +84,19 @@ namespace LeanCloud.Storage.Internal.Codec { public static object EncodeACL(LCACL acl) { HashSet keys = new HashSet(); - if (acl.readAccess.Count > 0) { - keys.UnionWith(acl.readAccess.Keys); + if (acl.ReadAccess.Count > 0) { + keys.UnionWith(acl.ReadAccess.Keys); } - if (acl.writeAccess.Count > 0) { - keys.UnionWith(acl.writeAccess.Keys); + if (acl.WriteAccess.Count > 0) { + keys.UnionWith(acl.WriteAccess.Keys); } Dictionary result = new Dictionary(); foreach (string key in keys) { Dictionary access = new Dictionary(); - if (acl.readAccess.TryGetValue(key, out bool ra)) { + if (acl.ReadAccess.TryGetValue(key, out bool ra)) { access["read"] = ra; } - if (acl.writeAccess.TryGetValue(key, out bool wa)) { + if (acl.WriteAccess.TryGetValue(key, out bool wa)) { access["write"] = wa; } result[key] = access; diff --git a/Storage/Storage/Internal/Operation/ILCOperation.cs b/Storage/Storage/Internal/Operation/ILCOperation.cs index 5c6c375..1c9512d 100644 --- a/Storage/Storage/Internal/Operation/ILCOperation.cs +++ b/Storage/Storage/Internal/Operation/ILCOperation.cs @@ -1,8 +1,7 @@ using System.Collections; -using System.Collections.Generic; namespace LeanCloud.Storage.Internal.Operation { - internal interface ILCOperation { + public interface ILCOperation { ILCOperation MergeWithPrevious(ILCOperation previousOp); object Encode(); diff --git a/Storage/Storage/LCACL.cs b/Storage/Storage/LCACL.cs index d07e5c0..3180eae 100644 --- a/Storage/Storage/LCACL.cs +++ b/Storage/Storage/LCACL.cs @@ -10,8 +10,13 @@ namespace LeanCloud.Storage { const string RoleKeyPrefix = "role:"; - internal Dictionary readAccess = new Dictionary(); - internal Dictionary writeAccess = new Dictionary(); + public Dictionary ReadAccess { + get; + } = new Dictionary(); + + public Dictionary WriteAccess { + get; + } = new Dictionary(); public static LCACL CreateWithOwner(LCUser owner) { if (owner == null) { @@ -25,17 +30,17 @@ namespace LeanCloud.Storage { public bool PublicReadAccess { get { - return GetAccess(readAccess, PublicKey); + return GetAccess(ReadAccess, PublicKey); } set { - SetAccess(readAccess, PublicKey, value); + SetAccess(ReadAccess, PublicKey, value); } } public bool PublicWriteAccess { get { - return GetAccess(writeAccess, PublicKey); + return GetAccess(WriteAccess, PublicKey); } set { - SetAccess(writeAccess, PublicKey, value); + SetAccess(WriteAccess, PublicKey, value); } } @@ -43,28 +48,28 @@ namespace LeanCloud.Storage { if (string.IsNullOrEmpty(userId)) { throw new ArgumentNullException(nameof(userId)); } - return GetAccess(readAccess, userId); + return GetAccess(ReadAccess, userId); } public void SetUserIdReadAccess(string userId, bool value) { if (string.IsNullOrEmpty(userId)) { throw new ArgumentNullException(nameof(userId)); } - SetAccess(readAccess, userId, value); + SetAccess(ReadAccess, userId, value); } public bool GetUserIdWriteAccess(string userId) { if (string.IsNullOrEmpty(userId)) { throw new ArgumentNullException(nameof(userId)); } - return GetAccess(writeAccess, userId); + return GetAccess(WriteAccess, userId); } public void SetUserIdWriteAccess(string userId, bool value) { if (string.IsNullOrEmpty(userId)) { throw new ArgumentNullException(nameof(userId)); } - SetAccess(writeAccess, userId, value); + SetAccess(WriteAccess, userId, value); } public bool GetUserReadAccess(LCUser user) { @@ -100,7 +105,7 @@ namespace LeanCloud.Storage { throw new ArgumentNullException(nameof(role)); } string roleKey = $"{RoleKeyPrefix}{role.ObjectId}"; - return GetAccess(readAccess, roleKey); + return GetAccess(ReadAccess, roleKey); } public void SetRoleReadAccess(LCRole role, bool value) { @@ -108,7 +113,7 @@ namespace LeanCloud.Storage { throw new ArgumentNullException(nameof(role)); } string roleKey = $"{RoleKeyPrefix}{role.ObjectId}"; - SetAccess(readAccess, roleKey, value); + SetAccess(ReadAccess, roleKey, value); } public bool GetRoleWriteAccess(LCRole role) { @@ -116,7 +121,7 @@ namespace LeanCloud.Storage { throw new ArgumentNullException(nameof(role)); } string roleKey = $"{RoleKeyPrefix}{role.ObjectId}"; - return GetAccess(writeAccess, roleKey); + return GetAccess(WriteAccess, roleKey); } public void SetRoleWriteAccess(LCRole role, bool value) { @@ -124,7 +129,7 @@ namespace LeanCloud.Storage { throw new ArgumentNullException(nameof(role)); } string roleKey = $"{RoleKeyPrefix}{role.ObjectId}"; - SetAccess(writeAccess, roleKey, value); + SetAccess(WriteAccess, roleKey, value); } bool GetAccess(Dictionary access, string key) { diff --git a/Storage/Storage/LCObject.cs b/Storage/Storage/LCObject.cs index 0c302b2..739fca2 100644 --- a/Storage/Storage/LCObject.cs +++ b/Storage/Storage/LCObject.cs @@ -16,7 +16,9 @@ namespace LeanCloud.Storage { /// /// Last synced data. /// - LCObjectData data; + public LCObjectData Data { + get; + } /// /// Estimated data. @@ -33,25 +35,25 @@ namespace LeanCloud.Storage { public string ClassName { get { - return data.ClassName; + return Data.ClassName; } } public string ObjectId { get { - return data.ObjectId; + return Data.ObjectId; } } public DateTime CreatedAt { get { - return data.CreatedAt; + return Data.CreatedAt; } } public DateTime UpdatedAt { get { - return data.UpdatedAt; + return Data.UpdatedAt; } } @@ -75,11 +77,11 @@ namespace LeanCloud.Storage { if (string.IsNullOrEmpty(className)) { throw new ArgumentNullException(nameof(className)); } - data = new LCObjectData(); + Data = new LCObjectData(); estimatedData = new Dictionary(); operationDict = new Dictionary(); - data.ClassName = className; + Data.ClassName = className; isNew = true; } @@ -88,7 +90,7 @@ namespace LeanCloud.Storage { throw new ArgumentNullException(nameof(objectId)); } LCObject obj = Create(className); - obj.data.ObjectId = objectId; + obj.Data.ObjectId = objectId; obj.isNew = false; return obj; } @@ -454,7 +456,7 @@ namespace LeanCloud.Storage { /// /// public override string ToString() { - Dictionary originalData = LCObjectData.Encode(data); + Dictionary originalData = LCObjectData.Encode(Data); Dictionary currentData = estimatedData.Union(originalData.Where(kv => !estimatedData.ContainsKey(kv.Key))) .ToDictionary(k => k.Key, v => v.Value); return JsonConvert.SerializeObject(currentData); @@ -490,17 +492,17 @@ namespace LeanCloud.Storage { } public void Merge(LCObjectData objectData) { - data.ClassName = objectData.ClassName ?? data.ClassName; - data.ObjectId = objectData.ObjectId ?? data.ObjectId; - data.CreatedAt = objectData.CreatedAt != null ? objectData.CreatedAt : data.CreatedAt; - data.UpdatedAt = objectData.UpdatedAt != null ? objectData.UpdatedAt : data.UpdatedAt; + Data.ClassName = objectData.ClassName ?? Data.ClassName; + Data.ObjectId = objectData.ObjectId ?? Data.ObjectId; + Data.CreatedAt = objectData.CreatedAt != null ? objectData.CreatedAt : Data.CreatedAt; + Data.UpdatedAt = objectData.UpdatedAt != null ? objectData.UpdatedAt : Data.UpdatedAt; // 先将本地的预估数据直接替换 - data.CustomPropertyDict = estimatedData; + Data.CustomPropertyDict = estimatedData; // 再将服务端的数据覆盖 foreach (KeyValuePair kv in objectData.CustomPropertyDict) { string key = kv.Key; object value = kv.Value; - data.CustomPropertyDict[key] = value; + Data.CustomPropertyDict[key] = value; } // 最后重新生成预估数据,用于后续访问和操作 @@ -512,7 +514,7 @@ namespace LeanCloud.Storage { void RebuildEstimatedData() { estimatedData = new Dictionary(); - foreach (KeyValuePair kv in data.CustomPropertyDict) { + foreach (KeyValuePair kv in Data.CustomPropertyDict) { string key = kv.Key; object value = kv.Value; if (value is IList list) {