diff --git a/Common/Common.AOT/Common.AOT.csproj b/Common/Common.AOT/Common.AOT.csproj index e5b34be..81fc26c 100644 --- a/Common/Common.AOT/Common.AOT.csproj +++ b/Common/Common.AOT/Common.AOT.csproj @@ -11,11 +11,9 @@ - - Common\Common.csproj - - - + + Common\LCCore.cs + Common\AppRouter\LCAppServer.cs @@ -31,8 +29,14 @@ Common\Http\LCHttpUtils.cs - - Common\Task\LCTaskExtensions.cs + + Common\Http\LCHttpClient.cs + + + Common\Persistence\PersistenceController.cs + + + Common\Persistence\IPersistence.cs Common\Log\LCLogger.cs diff --git a/Common/Common/Common.csproj b/Common/Common/Common.csproj index ac8b4ca..1c7a113 100644 --- a/Common/Common/Common.csproj +++ b/Common/Common/Common.csproj @@ -9,8 +9,8 @@ - + diff --git a/Storage/Storage/Internal/Http/LCHttpClient.cs b/Common/Common/Http/LCHttpClient.cs similarity index 84% rename from Storage/Storage/Internal/Http/LCHttpClient.cs rename to Common/Common/Http/LCHttpClient.cs index 7a4b0e9..bcd61de 100644 --- a/Storage/Storage/Internal/Http/LCHttpClient.cs +++ b/Common/Common/Http/LCHttpClient.cs @@ -8,9 +8,8 @@ using System.Net.Http.Headers; using System.Text; using System.Security.Cryptography; using LC.Newtonsoft.Json; -using LeanCloud.Common; -namespace LeanCloud.Storage.Internal.Http { +namespace LeanCloud.Common { public class LCHttpClient { private readonly string appId; @@ -26,6 +25,8 @@ namespace LeanCloud.Storage.Internal.Http { readonly MD5 md5; + private Dictionary>> runtimeHeaderTasks = new Dictionary>>(); + public LCHttpClient(string appId, string appKey, string server, string sdkVersion, string apiVersion) { this.appId = appId; this.appKey = appKey; @@ -42,6 +43,16 @@ namespace LeanCloud.Storage.Internal.Http { md5 = MD5.Create(); } + public void AddRuntimeHeaderTask(string key, Func> task) { + if (key == null) { + return; + } + if (task == null) { + return; + } + runtimeHeaderTasks[key] = task; + } + public Task Get(string path, Dictionary headers = null, Dictionary queryParams = null) { @@ -120,7 +131,7 @@ namespace LeanCloud.Storage.Internal.Http { } async Task BuildUrl(string path, Dictionary queryParams = null) { - string apiServer = await LCInternalApplication.AppRouter.GetApiServer(); + string apiServer = await LCCore.AppRouter.GetApiServer(); string url = $"{apiServer}/{apiVersion}/{path}"; if (queryParams != null) { IEnumerable queryPairs = queryParams.Select(kv => $"{kv.Key}={kv.Value}"); @@ -137,9 +148,9 @@ namespace LeanCloud.Storage.Internal.Http { headers.Add(kv.Key, kv.Value.ToString()); } } - if (LCInternalApplication.UseMasterKey && !string.IsNullOrEmpty(LCInternalApplication.MasterKey)) { + if (LCCore.UseMasterKey && !string.IsNullOrEmpty(LCCore.MasterKey)) { // Master Key - headers.Add("X-LC-Key", $"{LCInternalApplication.MasterKey},master"); + headers.Add("X-LC-Key", $"{LCCore.MasterKey},master"); } else { // 签名 long timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); @@ -148,15 +159,21 @@ namespace LeanCloud.Storage.Internal.Http { string sign = $"{hash},{timestamp}"; headers.Add("X-LC-Sign", sign); } - if (LCInternalApplication.AdditionalHeaders.Count > 0) { - foreach (KeyValuePair kv in LCInternalApplication.AdditionalHeaders) { + if (LCCore.AdditionalHeaders.Count > 0) { + foreach (KeyValuePair kv in LCCore.AdditionalHeaders) { headers.Add(kv.Key, kv.Value); } } - // 当前用户 Session Token - LCUser currentUser = await LCUser.GetCurrent(); - if (!headers.Contains("X-LC-Session") && currentUser != null) { - headers.Add("X-LC-Session", currentUser.SessionToken); + // 服务额外 headers + foreach (KeyValuePair>> kv in runtimeHeaderTasks) { + if (headers.Contains(kv.Key)) { + continue; + } + string value = await kv.Value.Invoke(); + if (value == null) { + continue; + } + headers.Add(kv.Key, value); } } diff --git a/Storage/Storage/LCInternalApplication.cs b/Common/Common/LCCore.cs similarity index 69% rename from Storage/Storage/LCInternalApplication.cs rename to Common/Common/LCCore.cs index b7094f0..4fb54e4 100644 --- a/Storage/Storage/LCInternalApplication.cs +++ b/Common/Common/LCCore.cs @@ -1,20 +1,16 @@ using System; using System.Collections.Generic; -using LeanCloud.Common; -using LeanCloud.Storage; -using LeanCloud.Storage.Internal.Http; -using LeanCloud.Storage.Internal.Storage; -namespace LeanCloud { +namespace LeanCloud.Common { /// /// LeanCloud Application /// - public class LCInternalApplication { + public class LCCore { // SDK 版本号,用于 User-Agent 统计 public const string SDKVersion = "0.7.3"; // 接口版本号,用于接口版本管理 - internal const string APIVersion = "1.1"; + public const string APIVersion = "1.1"; public static string AppId { get; private set; @@ -44,7 +40,7 @@ namespace LeanCloud { get; set; } - public static StorageController StorageController { + public static PersistenceController PersistenceController { get; set; } @@ -67,13 +63,6 @@ namespace LeanCloud { AppKey = appKey; MasterKey = masterKey; - // 注册 LeanCloud 内部子类化类型 - LCObject.RegisterSubclass(LCUser.CLASS_NAME, () => new LCUser()); - LCObject.RegisterSubclass(LCRole.CLASS_NAME, () => new LCRole()); - LCObject.RegisterSubclass(LCFile.CLASS_NAME, () => new LCFile()); - LCObject.RegisterSubclass(LCStatus.CLASS_NAME, () => new LCStatus()); - LCObject.RegisterSubclass(LCFriendshipRequest.CLASS_NAME, () => new LCFriendshipRequest()); - AppRouter = new LCAppRouter(appId, server); HttpClient = new LCHttpClient(appId, appKey, server, SDKVersion, APIVersion); diff --git a/Common/Common/Persistence/IPersistence.cs b/Common/Common/Persistence/IPersistence.cs new file mode 100644 index 0000000..2c5dc60 --- /dev/null +++ b/Common/Common/Persistence/IPersistence.cs @@ -0,0 +1,5 @@ +namespace LeanCloud.Common { + public interface IPersistence { + string GetPersistencePath(); + } +} diff --git a/Storage/Storage/Internal/Storage/StorageController.cs b/Common/Common/Persistence/PersistenceController.cs similarity index 76% rename from Storage/Storage/Internal/Storage/StorageController.cs rename to Common/Common/Persistence/PersistenceController.cs index 551d0ab..285d1c9 100644 --- a/Storage/Storage/Internal/Storage/StorageController.cs +++ b/Common/Common/Persistence/PersistenceController.cs @@ -1,23 +1,20 @@ using System; -using System.Reflection; -using System.Linq; using System.Threading.Tasks; using System.IO; using System.Text; -using System.Collections.Generic; using IOFile = System.IO.File; -namespace LeanCloud.Storage.Internal.Storage { - public class StorageController { - private readonly IStorage storage; +namespace LeanCloud.Common { + public class PersistenceController { + private readonly IPersistence persistence; - public StorageController(IStorage storage) { - this.storage = storage; + public PersistenceController(IPersistence persistence) { + this.persistence = persistence; } public async Task WriteText(string filename, string text) { - if (storage == null) { + if (persistence == null) { return; } @@ -31,7 +28,7 @@ namespace LeanCloud.Storage.Internal.Storage { } public async Task ReadText(string filename) { - if (storage == null) { + if (persistence == null) { return null; } @@ -51,7 +48,7 @@ namespace LeanCloud.Storage.Internal.Storage { } public Task Delete(string filename) { - if (storage == null) { + if (persistence == null) { return Task.CompletedTask; } @@ -62,10 +59,10 @@ namespace LeanCloud.Storage.Internal.Storage { } private string GetFileFullPath(string filename) { - if (storage == null) { + if (persistence == null) { throw new Exception("no IStrorage."); } - return Path.Combine(storage.GetStoragePath(), filename); + return Path.Combine(persistence.GetPersistencePath(), filename); } } } diff --git a/Common/Common/Task/LCTaskExtensions.cs b/Common/Common/Task/LCTaskExtensions.cs deleted file mode 100644 index bd0b0cb..0000000 --- a/Common/Common/Task/LCTaskExtensions.cs +++ /dev/null @@ -1,148 +0,0 @@ -// Copyright (c) 2015-present, Parse, LLC. All rights reserved. This source code is licensed under the BSD-style license found in the LICENSE file in the root directory of this source tree. An additional grant of patent rights can be found in the PATENTS file in the same directory. - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.ExceptionServices; -using System.Threading.Tasks; - -namespace LeanCloud.Common { - /// - /// Provides helper methods that allow us to use terser code elsewhere. - /// - public static class LCTaskExtensions { - /// - /// Ensures a task (even null) is awaitable. - /// - /// - /// - /// - public static Task Safe(this Task task) { - return task ?? Task.FromResult(default); - } - - /// - /// Ensures a task (even null) is awaitable. - /// - /// - /// - public static Task Safe(this Task task) { - return task ?? Task.FromResult(null); - } - - public delegate void PartialAccessor(ref T arg); - - public static TValue GetOrDefault(this IDictionary self, - TKey key, - TValue defaultValue) { - if (self.TryGetValue(key, out TValue value)) { - return value; - } - return defaultValue; - } - - public static bool CollectionsEqual(this IEnumerable a, IEnumerable b) { - return Equals(a, b) || - (a != null && b != null && - a.SequenceEqual(b)); - } - - public static Task OnSuccess(this Task task, - Func continuation) { - return task.ContinueWith(t => { - if (t.IsFaulted) { - var ex = t.Exception.Flatten(); - if (ex.InnerExceptions.Count == 1) { - ExceptionDispatchInfo.Capture(ex.InnerExceptions[0]).Throw(); - } else { - ExceptionDispatchInfo.Capture(ex).Throw(); - } - // Unreachable - return Task.FromResult(default(TResult)); - } else if (t.IsCanceled) { - var tcs = new TaskCompletionSource(); - tcs.SetCanceled(); - return tcs.Task; - } else { - return Task.FromResult(continuation(t)); - } - }).Unwrap(); - } - - public static Task OnSuccess(this Task task, - Func, TResult> continuation) { - return ((Task)task).OnSuccess(t => continuation((Task)t)); - } - - public static Task OnSuccess(this Task task, Action> continuation) { - return task.OnSuccess((Func, object>)(t => { - continuation(t); - return null; - })); - } - - public static Task OnSuccess(this Task task, Action continuation) { - return task.OnSuccess((Func)(t => { - continuation(t); - return null; - })); - } - - // TaskScheduler - public static Task OnSuccess(this Task task, - Func continuation, TaskScheduler scheduler) { - return task.ContinueWith(t => { - if (t.IsFaulted) { - var ex = t.Exception.Flatten(); - if (ex.InnerExceptions.Count == 1) { - ExceptionDispatchInfo.Capture(ex.InnerExceptions[0]).Throw(); - } else { - ExceptionDispatchInfo.Capture(ex).Throw(); - } - // Unreachable - return Task.FromResult(default(TResult)); - } else if (t.IsCanceled) { - var tcs = new TaskCompletionSource(); - tcs.SetCanceled(); - return tcs.Task; - } else { - return Task.FromResult(continuation(t)); - } - }, scheduler).Unwrap(); - } - - public static Task OnSuccess(this Task task, - Func, TResult> continuation, TaskScheduler scheduler) { - return ((Task)task).OnSuccess(t => continuation((Task)t), scheduler); - } - - public static Task OnSuccess(this Task task, - Action> continuation, TaskScheduler scheduler) { - return task.OnSuccess((Func, object>)(t => { - continuation(t); - return null; - }), scheduler); - } - - public static Task OnSuccess(this Task task, - Action continuation, TaskScheduler scheduler) { - return task.OnSuccess((Func)(t => { - continuation(t); - return null; - }), scheduler); - } - - public static Task WhileAsync(Func> predicate, Func body) { - Func iterate = null; - iterate = () => { - return predicate().OnSuccess(t => { - if (!t.Result) { - return Task.FromResult(0); - } - return body().OnSuccess(_ => iterate()).Unwrap(); - }).Unwrap(); - }; - return iterate(); - } - } -} diff --git a/Doxyfile b/Doxyfile index 267bc4f..514532a 100644 --- a/Doxyfile +++ b/Doxyfile @@ -6,7 +6,7 @@ OUTPUT_DIRECTORY = ./Doc/ EXTRACT_ALL = yes EXTRACT_PRIVATE = no EXTRACT_STATIC = yes -INPUT = ./Storage/Storage/ ./Realtime/Realtime/ ./LiveQuery/LiveQuery/ ./Engine/ +INPUT = ./Storage/Storage/Public ./Storage/Storage.Unity/Public ./Realtime/Realtime/Public ./LiveQuery/LiveQuery/Public ./Engine/Public #Do not add anything here unless you need to. Doxygen already covers all #common formats like .c/.cc/.cxx/.c++/.cpp/.inl/.h/.hpp FILE_PATTERNS = diff --git a/Engine/Engine.csproj b/Engine/Engine.csproj index 2e87b1a..4b573b5 100644 --- a/Engine/Engine.csproj +++ b/Engine/Engine.csproj @@ -14,6 +14,9 @@ - + + + + diff --git a/Engine/Controllers/LCClassHookController.cs b/Engine/Internal/Controllers/LCClassHookController.cs similarity index 100% rename from Engine/Controllers/LCClassHookController.cs rename to Engine/Internal/Controllers/LCClassHookController.cs diff --git a/Engine/Controllers/LCFunctionController.cs b/Engine/Internal/Controllers/LCFunctionController.cs similarity index 100% rename from Engine/Controllers/LCFunctionController.cs rename to Engine/Internal/Controllers/LCFunctionController.cs diff --git a/Engine/Controllers/LCPingController.cs b/Engine/Internal/Controllers/LCPingController.cs similarity index 88% rename from Engine/Controllers/LCPingController.cs rename to Engine/Internal/Controllers/LCPingController.cs index cb37ac6..0374541 100644 --- a/Engine/Controllers/LCPingController.cs +++ b/Engine/Internal/Controllers/LCPingController.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Cors; +using LeanCloud.Common; namespace LeanCloud.Engine { [ApiController] @@ -14,7 +15,7 @@ namespace LeanCloud.Engine { return new Dictionary { { "runtime", $"dotnet-{Environment.Version}" }, - { "version", LCInternalApplication.SDKVersion } + { "version", LCCore.SDKVersion } }; } } diff --git a/Engine/Controllers/LCUserHookController.cs b/Engine/Internal/Controllers/LCUserHookController.cs similarity index 100% rename from Engine/Controllers/LCUserHookController.cs rename to Engine/Internal/Controllers/LCUserHookController.cs diff --git a/Engine/Attributes/LCEngineClassHookAttribute.cs b/Engine/Public/Attributes/LCEngineClassHookAttribute.cs similarity index 100% rename from Engine/Attributes/LCEngineClassHookAttribute.cs rename to Engine/Public/Attributes/LCEngineClassHookAttribute.cs diff --git a/Engine/Attributes/LCEngineFunctionAttribute.cs b/Engine/Public/Attributes/LCEngineFunctionAttribute.cs similarity index 100% rename from Engine/Attributes/LCEngineFunctionAttribute.cs rename to Engine/Public/Attributes/LCEngineFunctionAttribute.cs diff --git a/Engine/Attributes/LCEngineFunctionParamAttribute.cs b/Engine/Public/Attributes/LCEngineFunctionParamAttribute.cs similarity index 100% rename from Engine/Attributes/LCEngineFunctionParamAttribute.cs rename to Engine/Public/Attributes/LCEngineFunctionParamAttribute.cs diff --git a/Engine/Attributes/LCEngineRealtimeHookAttribute.cs b/Engine/Public/Attributes/LCEngineRealtimeHookAttribute.cs similarity index 100% rename from Engine/Attributes/LCEngineRealtimeHookAttribute.cs rename to Engine/Public/Attributes/LCEngineRealtimeHookAttribute.cs diff --git a/Engine/Attributes/LCEngineUserHookAttribute.cs b/Engine/Public/Attributes/LCEngineUserHookAttribute.cs similarity index 100% rename from Engine/Attributes/LCEngineUserHookAttribute.cs rename to Engine/Public/Attributes/LCEngineUserHookAttribute.cs diff --git a/Engine/LCEngine.cs b/Engine/Public/LCEngine.cs similarity index 99% rename from Engine/LCEngine.cs rename to Engine/Public/LCEngine.cs index e9cf772..d507196 100644 --- a/Engine/LCEngine.cs +++ b/Engine/Public/LCEngine.cs @@ -99,7 +99,7 @@ namespace LeanCloud.Engine { LCApplication.Initialize(Environment.GetEnvironmentVariable("LEANCLOUD_APP_ID"), Environment.GetEnvironmentVariable("LEANCLOUD_APP_KEY"), Environment.GetEnvironmentVariable("LEANCLOUD_API_SERVER")); - LCInternalApplication.AddHeader(LCHookKeyName, Environment.GetEnvironmentVariable("LEANCLOUD_APP_HOOK_KEY")); + LCCore.AddHeader(LCHookKeyName, Environment.GetEnvironmentVariable("LEANCLOUD_APP_HOOK_KEY")); Assembly assembly = Assembly.GetCallingAssembly(); ClassHooks = assembly.GetTypes() diff --git a/Engine/LCEngineRequestContext.cs b/Engine/Public/LCEngineRequestContext.cs similarity index 100% rename from Engine/LCEngineRequestContext.cs rename to Engine/Public/LCEngineRequestContext.cs diff --git a/LiveQuery/LiveQuery.AOT/LiveQuery.AOT.csproj b/LiveQuery/LiveQuery.AOT/LiveQuery.AOT.csproj index 4633b07..a803f74 100644 --- a/LiveQuery/LiveQuery.AOT/LiveQuery.AOT.csproj +++ b/LiveQuery/LiveQuery.AOT/LiveQuery.AOT.csproj @@ -11,22 +11,17 @@ - - LiveQuery\LiveQuery.csproj - - - - - LiveQuery\LCLiveQuery.cs - - - LiveQuery\LCQueryExtension.cs - LiveQuery\Internal\LCLiveQueryHeartBeat.cs LiveQuery\Internal\LCLiveQueryConnection.cs + + LiveQuery\Public\LCLiveQuery.cs + + + LiveQuery\Public\LCQueryExtension.cs + diff --git a/LiveQuery/LiveQuery/LiveQuery.csproj b/LiveQuery/LiveQuery/LiveQuery.csproj index a705ffe..529b34e 100644 --- a/LiveQuery/LiveQuery/LiveQuery.csproj +++ b/LiveQuery/LiveQuery/LiveQuery.csproj @@ -11,5 +11,6 @@ + diff --git a/LiveQuery/LiveQuery/LCLiveQuery.cs b/LiveQuery/LiveQuery/Public/LCLiveQuery.cs similarity index 97% rename from LiveQuery/LiveQuery/LCLiveQuery.cs rename to LiveQuery/LiveQuery/Public/LCLiveQuery.cs index 8389832..1976ca5 100644 --- a/LiveQuery/LiveQuery/LCLiveQuery.cs +++ b/LiveQuery/LiveQuery/Public/LCLiveQuery.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Threading.Tasks; +using LeanCloud.Common; using LeanCloud.Storage; using LeanCloud.Storage.Internal.Object; using LeanCloud.LiveQuery.Internal; @@ -80,7 +81,7 @@ namespace LeanCloud.LiveQuery { data.Add("sessionToken", user.SessionToken); } string path = "LiveQuery/subscribe"; - Dictionary result = await LCInternalApplication.HttpClient.Post>(path, + Dictionary result = await LCCore.HttpClient.Post>(path, data: data); if (result.TryGetValue("query_id", out object id)) { Id = id as string; @@ -95,7 +96,7 @@ namespace LeanCloud.LiveQuery { { "query_id", Id } }; string path = "LiveQuery/unsubscribe"; - await LCInternalApplication.HttpClient.Post>(path, + await LCCore.HttpClient.Post>(path, data: data); // 移除 liveQueries.Remove(Id); @@ -104,7 +105,7 @@ namespace LeanCloud.LiveQuery { private static async Task Login() { Dictionary data = new Dictionary { { "cmd", "login" }, - { "appId", LCInternalApplication.AppId }, + { "appId", LCCore.AppId }, { "installationId", DeviceId }, { "clientTs", DateTimeOffset.Now.ToUnixTimeMilliseconds() }, { "service", 1 } diff --git a/LiveQuery/LiveQuery/LCQueryExtension.cs b/LiveQuery/LiveQuery/Public/LCQueryExtension.cs similarity index 100% rename from LiveQuery/LiveQuery/LCQueryExtension.cs rename to LiveQuery/LiveQuery/Public/LCQueryExtension.cs diff --git a/Realtime/Realtime.AOT/Realtime.AOT.csproj b/Realtime/Realtime.AOT/Realtime.AOT.csproj index 3f0f7b2..1b51c5b 100644 --- a/Realtime/Realtime.AOT/Realtime.AOT.csproj +++ b/Realtime/Realtime.AOT/Realtime.AOT.csproj @@ -12,83 +12,83 @@ - - Realtime\LCIMClient.cs + + Realtime\Public\LCIMClient.cs - - Realtime\LCRealtime.cs + + Realtime\Public\LCRealtime.cs - - Realtime\Result\LCIMOperationFailure.cs + + Realtime\Public\Result\LCIMOperationFailure.cs - - Realtime\Result\LCIMPageResult.cs + + Realtime\Public\Result\LCIMPageResult.cs - - Realtime\Result\LCIMPartiallySuccessResult.cs + + Realtime\Public\Result\LCIMPartiallySuccessResult.cs - - Realtime\Signature\LCIMSignature.cs + + Realtime\Public\Signature\LCIMSignature.cs - - Realtime\Signature\ILCIMSignatureFactory.cs + + Realtime\Public\Signature\ILCIMSignatureFactory.cs - - Realtime\Signature\LCIMSignatureAction.cs + + Realtime\Public\Signature\LCIMSignatureAction.cs - - Realtime\Message\LCIMVideoMessage.cs + + Realtime\Public\Message\LCIMVideoMessage.cs - - Realtime\Message\LCIMMessageSendOptions.cs + + Realtime\Public\Message\LCIMMessageSendOptions.cs - - Realtime\Message\LCIMBinaryMessage.cs + + Realtime\Public\Message\LCIMBinaryMessage.cs - - Realtime\Message\LCIMFileMessage.cs + + Realtime\Public\Message\LCIMFileMessage.cs - - Realtime\Message\LCIMRecalledMessage.cs + + Realtime\Public\Message\LCIMRecalledMessage.cs - - Realtime\Message\LCIMMessage.cs + + Realtime\Public\Message\LCIMMessage.cs - - Realtime\Message\LCIMTextMessage.cs + + Realtime\Public\Message\LCIMTextMessage.cs - - Realtime\Message\LCIMImageMessage.cs + + Realtime\Public\Message\LCIMImageMessage.cs - - Realtime\Message\LCIMAudioMessage.cs + + Realtime\Public\Message\LCIMAudioMessage.cs - - Realtime\Message\LCIMLocationMessage.cs + + Realtime\Public\Message\LCIMLocationMessage.cs - - Realtime\Message\LCIMTypedMessage.cs + + Realtime\Public\Message\LCIMTypedMessage.cs - - Realtime\Conversation\LCIMConversation.cs + + Realtime\Public\Conversation\LCIMConversation.cs - - Realtime\Conversation\LCIMServiceConversation.cs + + Realtime\Public\Conversation\LCIMServiceConversation.cs - - Realtime\Conversation\LCIMConversationMemberInfo.cs + + Realtime\Public\Conversation\LCIMConversationMemberInfo.cs - - Realtime\Conversation\LCIMConversationQuery.cs + + Realtime\Public\Conversation\LCIMConversationQuery.cs - - Realtime\Conversation\LCIMChatRoom.cs + + Realtime\Public\Conversation\LCIMChatRoom.cs - - Realtime\Conversation\LCIMMessageQueryOptions.cs + + Realtime\Public\Conversation\LCIMMessageQueryOptions.cs - - Realtime\Conversation\LCIMTemporaryConversation.cs + + Realtime\Public\Conversation\LCIMTemporaryConversation.cs Realtime\Internal\WebSocket\LCWebSocketClient.cs @@ -121,9 +121,4 @@ Realtime\Internal\Router\LCRTMRouter.cs - - - Realtime\Realtime.csproj - - diff --git a/Realtime/Realtime.Test/LocalSignatureFactory.cs b/Realtime/Realtime.Test/LocalSignatureFactory.cs index 1483914..7bf87ee 100644 --- a/Realtime/Realtime.Test/LocalSignatureFactory.cs +++ b/Realtime/Realtime.Test/LocalSignatureFactory.cs @@ -5,7 +5,7 @@ using System.Threading.Tasks; using System.Collections.Generic; using System.Security.Cryptography; using LeanCloud.Realtime; -using LeanCloud; +using LeanCloud.Common; namespace Realtime.Test { public class LocalSignatureFactory : ILCIMSignatureFactory { @@ -14,7 +14,7 @@ namespace Realtime.Test { public Task CreateConnectSignature(string clientId) { long timestamp = DateTimeOffset.Now.ToUnixTimeSeconds(); string nonce = NewNonce(); - string signature = GenerateSignature(LCInternalApplication.AppId, clientId, string.Empty, timestamp.ToString(), nonce); + string signature = GenerateSignature(LCCore.AppId, clientId, string.Empty, timestamp.ToString(), nonce); return Task.FromResult(new LCIMSignature { Signature = signature, Timestamp = timestamp, @@ -31,7 +31,7 @@ namespace Realtime.Test { } long timestamp = DateTimeOffset.Now.ToUnixTimeSeconds(); string nonce = NewNonce(); - string signature = GenerateSignature(LCInternalApplication.AppId, clientId, sortedMemberIds, timestamp.ToString(), nonce); + string signature = GenerateSignature(LCCore.AppId, clientId, sortedMemberIds, timestamp.ToString(), nonce); return Task.FromResult(new LCIMSignature { Signature = signature, Timestamp = timestamp, @@ -48,7 +48,7 @@ namespace Realtime.Test { } long timestamp = DateTimeOffset.Now.ToUnixTimeSeconds(); string nonce = NewNonce(); - string signature = GenerateSignature(LCInternalApplication.AppId, clientId, conversationId, sortedMemberIds, timestamp.ToString(), nonce, action); + string signature = GenerateSignature(LCCore.AppId, clientId, conversationId, sortedMemberIds, timestamp.ToString(), nonce, action); return Task.FromResult(new LCIMSignature { Signature = signature, Timestamp = timestamp, @@ -65,7 +65,7 @@ namespace Realtime.Test { } long timestamp = DateTimeOffset.Now.ToUnixTimeSeconds(); string nonce = NewNonce(); - string signature = GenerateSignature(LCInternalApplication.AppId, clientId, conversationId, sortedMemberIds, timestamp.ToString(), nonce, action); + string signature = GenerateSignature(LCCore.AppId, clientId, conversationId, sortedMemberIds, timestamp.ToString(), nonce, action); return Task.FromResult(new LCIMSignature { Signature = signature, Timestamp = timestamp, diff --git a/Realtime/Realtime/Internal/Connection/LCHeartBeat.cs b/Realtime/Realtime/Internal/Connection/LCHeartBeat.cs index 0948993..ea1b902 100644 --- a/Realtime/Realtime/Internal/Connection/LCHeartBeat.cs +++ b/Realtime/Realtime/Internal/Connection/LCHeartBeat.cs @@ -1,6 +1,7 @@ using System; using System.Threading; using System.Threading.Tasks; +using LeanCloud.Common; using LeanCloud.Realtime.Internal.Protocol; namespace LeanCloud.Realtime.Internal.Connection { @@ -56,7 +57,7 @@ namespace LeanCloud.Realtime.Internal.Connection { // 发送 ping 包 GenericCommand command = new GenericCommand { Cmd = CommandType.Echo, - AppId = LCInternalApplication.AppId, + AppId = LCCore.AppId, PeerId = connection.id }; try { diff --git a/Realtime/Realtime/Internal/Controller/LCIMController.cs b/Realtime/Realtime/Internal/Controller/LCIMController.cs index e3779fc..501aee3 100644 --- a/Realtime/Realtime/Internal/Controller/LCIMController.cs +++ b/Realtime/Realtime/Internal/Controller/LCIMController.cs @@ -1,4 +1,5 @@ -using LeanCloud.Realtime.Internal.Protocol; +using LeanCloud.Common; +using LeanCloud.Realtime.Internal.Protocol; using LeanCloud.Realtime.Internal.Connection; namespace LeanCloud.Realtime.Internal.Controller { @@ -15,7 +16,7 @@ namespace LeanCloud.Realtime.Internal.Controller { protected LCConnection Connection { get { - return LCRealtime.GetConnection(LCInternalApplication.AppId); + return LCRealtime.GetConnection(LCCore.AppId); } } @@ -28,7 +29,7 @@ namespace LeanCloud.Realtime.Internal.Controller { protected GenericCommand NewCommand(CommandType cmd) { return new GenericCommand { Cmd = cmd, - AppId = LCInternalApplication.AppId, + AppId = LCCore.AppId, PeerId = Client.Id, }; } diff --git a/Realtime/Realtime/Internal/Controller/LCIMConversationController.cs b/Realtime/Realtime/Internal/Controller/LCIMConversationController.cs index 99062fb..88f72c3 100644 --- a/Realtime/Realtime/Internal/Controller/LCIMConversationController.cs +++ b/Realtime/Realtime/Internal/Controller/LCIMConversationController.cs @@ -284,7 +284,7 @@ namespace LeanCloud.Realtime.Internal.Controller { { "client_id", Client.Id }, { "cid", convId } }; - Dictionary response = await LCInternalApplication.HttpClient.Get>(path, + Dictionary response = await LCCore.HttpClient.Get>(path, headers: headers, queryParams: queryParams); List results = response["results"] as List; return results.Select(item => { @@ -341,7 +341,7 @@ namespace LeanCloud.Realtime.Internal.Controller { GenericCommand command = new GenericCommand { Cmd = CommandType.Conv, Op = OpType.Query, - AppId = LCInternalApplication.AppId, + AppId = LCCore.AppId, PeerId = Client.Id, }; ConvCommand convMessage = new ConvCommand(); diff --git a/Realtime/Realtime/Internal/Controller/LCIMSessionController.cs b/Realtime/Realtime/Internal/Controller/LCIMSessionController.cs index 5bc041e..0c0def4 100644 --- a/Realtime/Realtime/Internal/Controller/LCIMSessionController.cs +++ b/Realtime/Realtime/Internal/Controller/LCIMSessionController.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; +using LeanCloud.Common; using LeanCloud.Realtime.Internal.Protocol; namespace LeanCloud.Realtime.Internal.Controller { @@ -83,7 +84,7 @@ namespace LeanCloud.Realtime.Internal.Controller { signature = await Client.SignatureFactory.CreateConnectSignature(Client.Id); } if (signature == null && !string.IsNullOrEmpty(Client.SessionToken)) { - Dictionary ret = await LCInternalApplication.HttpClient.Post>("rtm/sign", data: new Dictionary { + Dictionary ret = await LCCore.HttpClient.Post>("rtm/sign", data: new Dictionary { { "session_token", Client.SessionToken } }); signature = new LCIMSignature { diff --git a/Realtime/Realtime/Internal/Router/LCRTMRouter.cs b/Realtime/Realtime/Internal/Router/LCRTMRouter.cs index 9d8a27b..8fa7a69 100644 --- a/Realtime/Realtime/Internal/Router/LCRTMRouter.cs +++ b/Realtime/Realtime/Internal/Router/LCRTMRouter.cs @@ -22,8 +22,8 @@ namespace LeanCloud.Realtime.Internal.Router { } async Task Fetch() { - string server = await LCInternalApplication.AppRouter.GetRealtimeServer(); - string url = $"{server}/v1/route?appId={LCInternalApplication.AppId}&secure=1"; + string server = await LCCore.AppRouter.GetRealtimeServer(); + string url = $"{server}/v1/route?appId={LCCore.AppId}&secure=1"; HttpRequestMessage request = new HttpRequestMessage { RequestUri = new Uri(url), diff --git a/Realtime/Realtime/Conversation/LCIMChatRoom.cs b/Realtime/Realtime/Public/Conversation/LCIMChatRoom.cs similarity index 100% rename from Realtime/Realtime/Conversation/LCIMChatRoom.cs rename to Realtime/Realtime/Public/Conversation/LCIMChatRoom.cs diff --git a/Realtime/Realtime/Conversation/LCIMConversation.cs b/Realtime/Realtime/Public/Conversation/LCIMConversation.cs similarity index 100% rename from Realtime/Realtime/Conversation/LCIMConversation.cs rename to Realtime/Realtime/Public/Conversation/LCIMConversation.cs diff --git a/Realtime/Realtime/Conversation/LCIMConversationMemberInfo.cs b/Realtime/Realtime/Public/Conversation/LCIMConversationMemberInfo.cs similarity index 100% rename from Realtime/Realtime/Conversation/LCIMConversationMemberInfo.cs rename to Realtime/Realtime/Public/Conversation/LCIMConversationMemberInfo.cs diff --git a/Realtime/Realtime/Conversation/LCIMConversationQuery.cs b/Realtime/Realtime/Public/Conversation/LCIMConversationQuery.cs similarity index 100% rename from Realtime/Realtime/Conversation/LCIMConversationQuery.cs rename to Realtime/Realtime/Public/Conversation/LCIMConversationQuery.cs diff --git a/Realtime/Realtime/Conversation/LCIMMessageQueryOptions.cs b/Realtime/Realtime/Public/Conversation/LCIMMessageQueryOptions.cs similarity index 100% rename from Realtime/Realtime/Conversation/LCIMMessageQueryOptions.cs rename to Realtime/Realtime/Public/Conversation/LCIMMessageQueryOptions.cs diff --git a/Realtime/Realtime/Conversation/LCIMServiceConversation.cs b/Realtime/Realtime/Public/Conversation/LCIMServiceConversation.cs similarity index 100% rename from Realtime/Realtime/Conversation/LCIMServiceConversation.cs rename to Realtime/Realtime/Public/Conversation/LCIMServiceConversation.cs diff --git a/Realtime/Realtime/Conversation/LCIMTemporaryConversation.cs b/Realtime/Realtime/Public/Conversation/LCIMTemporaryConversation.cs similarity index 100% rename from Realtime/Realtime/Conversation/LCIMTemporaryConversation.cs rename to Realtime/Realtime/Public/Conversation/LCIMTemporaryConversation.cs diff --git a/Realtime/Realtime/LCIMClient.cs b/Realtime/Realtime/Public/LCIMClient.cs similarity index 100% rename from Realtime/Realtime/LCIMClient.cs rename to Realtime/Realtime/Public/LCIMClient.cs diff --git a/Realtime/Realtime/LCRealtime.cs b/Realtime/Realtime/Public/LCRealtime.cs similarity index 100% rename from Realtime/Realtime/LCRealtime.cs rename to Realtime/Realtime/Public/LCRealtime.cs diff --git a/Realtime/Realtime/Message/LCIMAudioMessage.cs b/Realtime/Realtime/Public/Message/LCIMAudioMessage.cs similarity index 100% rename from Realtime/Realtime/Message/LCIMAudioMessage.cs rename to Realtime/Realtime/Public/Message/LCIMAudioMessage.cs diff --git a/Realtime/Realtime/Message/LCIMBinaryMessage.cs b/Realtime/Realtime/Public/Message/LCIMBinaryMessage.cs similarity index 100% rename from Realtime/Realtime/Message/LCIMBinaryMessage.cs rename to Realtime/Realtime/Public/Message/LCIMBinaryMessage.cs diff --git a/Realtime/Realtime/Message/LCIMFileMessage.cs b/Realtime/Realtime/Public/Message/LCIMFileMessage.cs similarity index 100% rename from Realtime/Realtime/Message/LCIMFileMessage.cs rename to Realtime/Realtime/Public/Message/LCIMFileMessage.cs diff --git a/Realtime/Realtime/Message/LCIMImageMessage.cs b/Realtime/Realtime/Public/Message/LCIMImageMessage.cs similarity index 100% rename from Realtime/Realtime/Message/LCIMImageMessage.cs rename to Realtime/Realtime/Public/Message/LCIMImageMessage.cs diff --git a/Realtime/Realtime/Message/LCIMLocationMessage.cs b/Realtime/Realtime/Public/Message/LCIMLocationMessage.cs similarity index 100% rename from Realtime/Realtime/Message/LCIMLocationMessage.cs rename to Realtime/Realtime/Public/Message/LCIMLocationMessage.cs diff --git a/Realtime/Realtime/Message/LCIMMessage.cs b/Realtime/Realtime/Public/Message/LCIMMessage.cs similarity index 100% rename from Realtime/Realtime/Message/LCIMMessage.cs rename to Realtime/Realtime/Public/Message/LCIMMessage.cs diff --git a/Realtime/Realtime/Message/LCIMMessageSendOptions.cs b/Realtime/Realtime/Public/Message/LCIMMessageSendOptions.cs similarity index 100% rename from Realtime/Realtime/Message/LCIMMessageSendOptions.cs rename to Realtime/Realtime/Public/Message/LCIMMessageSendOptions.cs diff --git a/Realtime/Realtime/Message/LCIMRecalledMessage.cs b/Realtime/Realtime/Public/Message/LCIMRecalledMessage.cs similarity index 100% rename from Realtime/Realtime/Message/LCIMRecalledMessage.cs rename to Realtime/Realtime/Public/Message/LCIMRecalledMessage.cs diff --git a/Realtime/Realtime/Message/LCIMTextMessage.cs b/Realtime/Realtime/Public/Message/LCIMTextMessage.cs similarity index 100% rename from Realtime/Realtime/Message/LCIMTextMessage.cs rename to Realtime/Realtime/Public/Message/LCIMTextMessage.cs diff --git a/Realtime/Realtime/Message/LCIMTypedMessage.cs b/Realtime/Realtime/Public/Message/LCIMTypedMessage.cs similarity index 100% rename from Realtime/Realtime/Message/LCIMTypedMessage.cs rename to Realtime/Realtime/Public/Message/LCIMTypedMessage.cs diff --git a/Realtime/Realtime/Message/LCIMVideoMessage.cs b/Realtime/Realtime/Public/Message/LCIMVideoMessage.cs similarity index 100% rename from Realtime/Realtime/Message/LCIMVideoMessage.cs rename to Realtime/Realtime/Public/Message/LCIMVideoMessage.cs diff --git a/Realtime/Realtime/Result/LCIMOperationFailure.cs b/Realtime/Realtime/Public/Result/LCIMOperationFailure.cs similarity index 100% rename from Realtime/Realtime/Result/LCIMOperationFailure.cs rename to Realtime/Realtime/Public/Result/LCIMOperationFailure.cs diff --git a/Realtime/Realtime/Result/LCIMPageResult.cs b/Realtime/Realtime/Public/Result/LCIMPageResult.cs similarity index 100% rename from Realtime/Realtime/Result/LCIMPageResult.cs rename to Realtime/Realtime/Public/Result/LCIMPageResult.cs diff --git a/Realtime/Realtime/Result/LCIMPartiallySuccessResult.cs b/Realtime/Realtime/Public/Result/LCIMPartiallySuccessResult.cs similarity index 100% rename from Realtime/Realtime/Result/LCIMPartiallySuccessResult.cs rename to Realtime/Realtime/Public/Result/LCIMPartiallySuccessResult.cs diff --git a/Realtime/Realtime/Signature/ILCIMSignatureFactory.cs b/Realtime/Realtime/Public/Signature/ILCIMSignatureFactory.cs similarity index 100% rename from Realtime/Realtime/Signature/ILCIMSignatureFactory.cs rename to Realtime/Realtime/Public/Signature/ILCIMSignatureFactory.cs diff --git a/Realtime/Realtime/Signature/LCIMSignature.cs b/Realtime/Realtime/Public/Signature/LCIMSignature.cs similarity index 100% rename from Realtime/Realtime/Signature/LCIMSignature.cs rename to Realtime/Realtime/Public/Signature/LCIMSignature.cs diff --git a/Realtime/Realtime/Signature/LCIMSignatureAction.cs b/Realtime/Realtime/Public/Signature/LCIMSignatureAction.cs similarity index 100% rename from Realtime/Realtime/Signature/LCIMSignatureAction.cs rename to Realtime/Realtime/Public/Signature/LCIMSignatureAction.cs diff --git a/Realtime/Realtime/Realtime.csproj b/Realtime/Realtime/Realtime.csproj index 38d4b5c..9dc2e7f 100644 --- a/Realtime/Realtime/Realtime.csproj +++ b/Realtime/Realtime/Realtime.csproj @@ -10,14 +10,15 @@ - - - - + + + + + diff --git a/Storage/Storage.AOT/Storage.AOT.csproj b/Storage/Storage.AOT/Storage.AOT.csproj index 1442df4..6dc7cd7 100644 --- a/Storage/Storage.AOT/Storage.AOT.csproj +++ b/Storage/Storage.AOT/Storage.AOT.csproj @@ -11,77 +11,77 @@ - - Storage\LCCloud.cs + + Storage\Public\LCCloud.cs - - Storage\LCQuery.cs + + Storage\Public\LCQuery.cs - - Storage\LCFile.cs + + Storage\Public\LCFile.cs - - Storage\LCACL.cs + + Storage\Public\LCACL.cs - - Storage\LCCaptchaClient.cs + + Storage\Public\LCCaptchaClient.cs - - Storage\LCStatusQuery.cs + + Storage\Public\LCStatusQuery.cs - - Storage\LCHookObject.cs + + Storage\Public\LCHookObject.cs - - Storage\LCFriendshipRequest.cs + + Storage\Public\LCFriendshipRequest.cs - - Storage\LCFriendship.cs + + Storage\Public\LCFriendship.cs - - Storage\LCStatus.cs + + Storage\Public\LCStatus.cs - - Storage\LCInternalApplication.cs + + Storage\Public\LCUser.cs - - Storage\LCUser.cs + + Storage\Public\LCObject.cs - - Storage\LCObject.cs + + Storage\Public\LCSMSClient.cs - - Storage\LCSMSClient.cs + + Storage\Public\LCRelation.cs - - Storage\LCRelation.cs + + Storage\Public\LCGeoPoint.cs - - Storage\LCGeoPoint.cs + + Storage\Public\LCStorage.cs - - Storage\LCUserAuthDataLoginOption.cs + + Storage\Public\LCUserAuthDataLoginOption.cs - - Storage\LCRole.cs + + Storage\Public\LCRole.cs - - Storage\LCFollowersAndFollowees.cs + + Storage\Public\LCFollowersAndFollowees.cs - - Storage\LCStatusCount.cs + + Storage\Public\LCStatusCount.cs - - Storage\Leaderboard\LCLeaderboardArchive.cs + + Storage\Public\Leaderboard\LCLeaderboardArchive.cs - - Storage\Leaderboard\LCStatistic.cs + + Storage\Public\Leaderboard\LCStatistic.cs - - Storage\Leaderboard\LCLeaderboard.cs + + Storage\Public\Leaderboard\LCLeaderboard.cs - - Storage\Leaderboard\LCRanking.cs + + Storage\Public\Leaderboard\LCRanking.cs Storage\Internal\Operation\LCNumberOperation.cs @@ -140,9 +140,6 @@ Storage\Internal\Object\LCObjectData.cs - - Storage\Internal\Http\LCHttpClient.cs - Storage\Internal\Query\LCEqualCondition.cs @@ -158,16 +155,5 @@ Storage\Internal\Query\LCCompositionalCondition.cs - - Storage\Internal\Storage\StorageController.cs - - - Storage\Internal\Storage\IStorage.cs - - - - - Storage\Storage.csproj - diff --git a/Storage/Storage.Standard/LCApplication.cs b/Storage/Storage.Standard/LCApplication.cs deleted file mode 100644 index 714e264..0000000 --- a/Storage/Storage.Standard/LCApplication.cs +++ /dev/null @@ -1,16 +0,0 @@ -using LeanCloud.Storage.Internal.Storage; - -namespace LeanCloud { - public class LCApplication { - public static void Initialize(string appId, - string appKey, - string server = null, - string masterKey = null) { - LCLogger.Debug("Application Initializes on Standard."); - - LCInternalApplication.Initialize(appId, appKey, server, masterKey); - - LCInternalApplication.StorageController = new StorageController(null); - } - } -} diff --git a/Storage/Storage.Standard/Public/LCApplication.cs b/Storage/Storage.Standard/Public/LCApplication.cs new file mode 100644 index 0000000..bddc77c --- /dev/null +++ b/Storage/Storage.Standard/Public/LCApplication.cs @@ -0,0 +1,24 @@ +using LeanCloud.Common; +using LeanCloud.Storage; + +namespace LeanCloud { + public class LCApplication { + public static bool UseMasterKey { + get => LCCore.UseMasterKey; + set { + LCCore.UseMasterKey = value; + } + } + + public static void Initialize(string appId, + string appKey, + string server = null, + string masterKey = null) { + LCLogger.Debug("Application Initializes on Standard."); + + LCStorage.Initialize(appId, appKey, server, masterKey); + + LCCore.PersistenceController = new PersistenceController(null); + } + } +} diff --git a/Storage/Storage.Standard/StandardStorage.cs b/Storage/Storage.Standard/StandardStorage.cs deleted file mode 100644 index 4941ea9..0000000 --- a/Storage/Storage.Standard/StandardStorage.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System; - -namespace LeanCloud.Storage.Internal.Storage { - public class StandardStorage : IStorage { - public string GetStoragePath() { - throw new NotImplementedException(); - } - } -} diff --git a/Storage/Storage.Standard/Storage.Standard.csproj b/Storage/Storage.Standard/Storage.Standard.csproj index 7aa4f9c..1c2657b 100644 --- a/Storage/Storage.Standard/Storage.Standard.csproj +++ b/Storage/Storage.Standard/Storage.Standard.csproj @@ -11,4 +11,7 @@ + + + diff --git a/Storage/Storage.Test/ACLTest.cs b/Storage/Storage.Test/ACLTest.cs index 5271787..22be01f 100644 --- a/Storage/Storage.Test/ACLTest.cs +++ b/Storage/Storage.Test/ACLTest.cs @@ -48,8 +48,12 @@ namespace Storage.Test { Assert.NotNull(result.ObjectId); await LCUser.Logout(); - result = await query.Get(account.ObjectId); - Assert.IsNull(result); + + try { + await query.Get(account.ObjectId); + } catch (LCException e) { + Assert.AreEqual(e.Code, 403); + } } [Test] diff --git a/Storage/Storage.Test/FileTest.cs b/Storage/Storage.Test/FileTest.cs index d0e6d24..108b7f3 100644 --- a/Storage/Storage.Test/FileTest.cs +++ b/Storage/Storage.Test/FileTest.cs @@ -71,7 +71,7 @@ namespace Storage.Test { [Test] public async Task AWS() { - LCInternalApplication.Initialize("UlCpyvLm8aMzQsW6KnP6W3Wt-MdYXbMMI", "PyCTYoNoxCVoKKg394PBeS4r"); + LCApplication.Initialize("UlCpyvLm8aMzQsW6KnP6W3Wt-MdYXbMMI", "PyCTYoNoxCVoKKg394PBeS4r"); LCFile file = new LCFile("avatar", AvatarFilePath); await file.Save((count, total) => { TestContext.WriteLine($"progress: {count}/{total}"); diff --git a/Storage/Storage.Test/LeaderboardTest.cs b/Storage/Storage.Test/LeaderboardTest.cs index d4870d1..a294ac4 100644 --- a/Storage/Storage.Test/LeaderboardTest.cs +++ b/Storage/Storage.Test/LeaderboardTest.cs @@ -15,13 +15,13 @@ namespace Storage.Test { [SetUp] public void SetUp() { LCApplication.Initialize(Utils.AppId, Utils.AppKey, Utils.AppServer, Utils.MasterKey); - LCInternalApplication.UseMasterKey = true; + LCApplication.UseMasterKey = true; leaderboardName = $"Leaderboard_{DateTimeOffset.Now.DayOfYear}"; } [TearDown] public void TearDown() { - LCInternalApplication.UseMasterKey = false; + LCApplication.UseMasterKey = false; Utils.TearDown(); } diff --git a/Storage/Storage.Unity/Internal/UnityPersistence.cs b/Storage/Storage.Unity/Internal/UnityPersistence.cs new file mode 100644 index 0000000..552b9c3 --- /dev/null +++ b/Storage/Storage.Unity/Internal/UnityPersistence.cs @@ -0,0 +1,10 @@ +using UnityEngine; +using LeanCloud.Common; + +namespace LeanCloud.Storage.Internal.Persistence { + public class UnityPersistence : IPersistence { + public string GetPersistencePath() { + return Application.persistentDataPath; + } + } +} diff --git a/Storage/Storage.Unity/LCApplication.cs b/Storage/Storage.Unity/LCApplication.cs deleted file mode 100644 index ae6aff7..0000000 --- a/Storage/Storage.Unity/LCApplication.cs +++ /dev/null @@ -1,16 +0,0 @@ -using LeanCloud.Storage.Internal.Storage; - -namespace LeanCloud { - public class LCApplication { - public static void Initialize(string appId, - string appKey, - string server = null, - string masterKey = null) { - LCLogger.Debug("Application Initializes on Unity."); - - LCInternalApplication.Initialize(appId, appKey, server, masterKey); - - LCInternalApplication.StorageController = new StorageController(new UnityStorage()); - } - } -} diff --git a/Storage/Storage.Unity/Public/LCApplication.cs b/Storage/Storage.Unity/Public/LCApplication.cs new file mode 100644 index 0000000..56b7287 --- /dev/null +++ b/Storage/Storage.Unity/Public/LCApplication.cs @@ -0,0 +1,25 @@ +using LeanCloud.Common; +using LeanCloud.Storage; +using LeanCloud.Storage.Internal.Persistence; + +namespace LeanCloud { + public class LCApplication { + public static bool UseMasterKey { + get => LCCore.UseMasterKey; + set { + LCCore.UseMasterKey = value; + } + } + + public static void Initialize(string appId, + string appKey, + string server = null, + string masterKey = null) { + LCLogger.Debug("Application Initializes on Unity."); + + LCStorage.Initialize(appId, appKey, server, masterKey); + + LCCore.PersistenceController = new PersistenceController(new UnityPersistence()); + } + } +} diff --git a/Storage/Storage.Unity/Storage.Unity.csproj b/Storage/Storage.Unity/Storage.Unity.csproj index 8a3d717..844279a 100644 --- a/Storage/Storage.Unity/Storage.Unity.csproj +++ b/Storage/Storage.Unity/Storage.Unity.csproj @@ -15,4 +15,8 @@ ..\..\Unity\UnityEngine.dll + + + + diff --git a/Storage/Storage.Unity/UnityStorage.cs b/Storage/Storage.Unity/UnityStorage.cs deleted file mode 100644 index 039b744..0000000 --- a/Storage/Storage.Unity/UnityStorage.cs +++ /dev/null @@ -1,9 +0,0 @@ -using UnityEngine; - -namespace LeanCloud.Storage.Internal.Storage { - public class UnityStorage : IStorage { - public string GetStoragePath() { - return Application.persistentDataPath; - } - } -} diff --git a/Storage/Storage/Internal/Storage/IStorage.cs b/Storage/Storage/Internal/Storage/IStorage.cs deleted file mode 100644 index 4f0cf1e..0000000 --- a/Storage/Storage/Internal/Storage/IStorage.cs +++ /dev/null @@ -1,7 +0,0 @@ -using System; - -namespace LeanCloud.Storage.Internal.Storage { - public interface IStorage { - string GetStoragePath(); - } -} diff --git a/Storage/Storage/LCACL.cs b/Storage/Storage/Public/LCACL.cs similarity index 100% rename from Storage/Storage/LCACL.cs rename to Storage/Storage/Public/LCACL.cs diff --git a/Storage/Storage/LCCaptchaClient.cs b/Storage/Storage/Public/LCCaptchaClient.cs similarity index 89% rename from Storage/Storage/LCCaptchaClient.cs rename to Storage/Storage/Public/LCCaptchaClient.cs index 386e645..fb1635b 100644 --- a/Storage/Storage/LCCaptchaClient.cs +++ b/Storage/Storage/Public/LCCaptchaClient.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; +using LeanCloud.Common; namespace LeanCloud.Storage { /// @@ -33,7 +34,7 @@ namespace LeanCloud.Storage { { "width", width }, { "height", height } }; - Dictionary response = await LCInternalApplication.HttpClient.Get>(path, queryParams: queryParams); + Dictionary response = await LCCore.HttpClient.Get>(path, queryParams: queryParams); return new LCCapture { Url = response["captcha_url"] as string, Token = response["captcha_token"] as string @@ -60,7 +61,7 @@ namespace LeanCloud.Storage { { "captcha_code", code }, { "captcha_token", token } }; - await LCInternalApplication.HttpClient.Post>(path, data: data); + await LCCore.HttpClient.Post>(path, data: data); } } } diff --git a/Storage/Storage/LCCloud.cs b/Storage/Storage/Public/LCCloud.cs similarity index 93% rename from Storage/Storage/LCCloud.cs rename to Storage/Storage/Public/LCCloud.cs index 188ee3a..e957dd4 100644 --- a/Storage/Storage/LCCloud.cs +++ b/Storage/Storage/Public/LCCloud.cs @@ -1,5 +1,6 @@ using System.Threading.Tasks; using System.Collections.Generic; +using LeanCloud.Common; using LeanCloud.Storage.Internal.Codec; using LeanCloud.Storage.Internal.Object; @@ -30,7 +31,7 @@ namespace LeanCloud.Storage { { PRODUCTION_KEY, IsProduction ? 1 : 0 } }; object encodeParams = LCEncoder.Encode(parameters); - Dictionary response = await LCInternalApplication.HttpClient.Post>(path, + Dictionary response = await LCCore.HttpClient.Post>(path, headers: headers, data: encodeParams); return response; @@ -57,7 +58,7 @@ namespace LeanCloud.Storage { { PRODUCTION_KEY, IsProduction ? 1 : 0 } }; object encodeParams = Encode(parameters); - Dictionary response = await LCInternalApplication.HttpClient.Post>(path, + Dictionary response = await LCCore.HttpClient.Post>(path, headers: headers, data: encodeParams); return LCDecoder.Decode(response["result"]); diff --git a/Storage/Storage/LCFile.cs b/Storage/Storage/Public/LCFile.cs similarity index 90% rename from Storage/Storage/LCFile.cs rename to Storage/Storage/Public/LCFile.cs index cb7c892..01cabc4 100644 --- a/Storage/Storage/LCFile.cs +++ b/Storage/Storage/Public/LCFile.cs @@ -2,6 +2,7 @@ using System.IO; using System.Collections.Generic; using System.Threading.Tasks; +using LeanCloud.Common; using LeanCloud.Storage.Internal.File; using LeanCloud.Storage.Internal.Object; @@ -92,12 +93,12 @@ namespace LeanCloud.Storage { } LCObjectData objectData = LCObjectData.Decode(uploadToken); Merge(objectData); - _ = LCInternalApplication.HttpClient.Post>("fileCallback", data: new Dictionary { + _ = LCCore.HttpClient.Post>("fileCallback", data: new Dictionary { { "result", true }, { "token", token } }); } catch (Exception e) { - _ = LCInternalApplication.HttpClient.Post>("fileCallback", data: new Dictionary { + _ = LCCore.HttpClient.Post>("fileCallback", data: new Dictionary { { "result", false }, { "token", token } }); @@ -112,7 +113,7 @@ namespace LeanCloud.Storage { return; } string path = $"files/{ObjectId}"; - await LCInternalApplication.HttpClient.Delete(path); + await LCCore.HttpClient.Delete(path); } public string GetThumbnailUrl(int width, int height, int quality = 100, bool scaleToFit = true, string format = "png") { @@ -128,7 +129,7 @@ namespace LeanCloud.Storage { { "mime_type", MimeType }, { "metaData", MetaData } }; - return await LCInternalApplication.HttpClient.Post>("fileTokens", data: data); + return await LCCore.HttpClient.Post>("fileTokens", data: data); } public static LCQuery GetQuery() { diff --git a/Storage/Storage/LCFollowersAndFollowees.cs b/Storage/Storage/Public/LCFollowersAndFollowees.cs similarity index 100% rename from Storage/Storage/LCFollowersAndFollowees.cs rename to Storage/Storage/Public/LCFollowersAndFollowees.cs diff --git a/Storage/Storage/LCFriendship.cs b/Storage/Storage/Public/LCFriendship.cs similarity index 85% rename from Storage/Storage/LCFriendship.cs rename to Storage/Storage/Public/LCFriendship.cs index 4f91ab1..d128d84 100644 --- a/Storage/Storage/LCFriendship.cs +++ b/Storage/Storage/Public/LCFriendship.cs @@ -1,6 +1,7 @@ using System; using System.Threading.Tasks; using System.Collections.Generic; +using LeanCloud.Common; using LeanCloud.Storage.Internal.Codec; namespace LeanCloud.Storage { @@ -19,7 +20,7 @@ namespace LeanCloud.Storage { if (attributes != null) { data["friendship"] = attributes; } - await LCInternalApplication.HttpClient.Post>(path, data: data); + await LCCore.HttpClient.Post>(path, data: data); } public static async Task AcceptRequest(LCFriendshipRequest request, Dictionary attributes = null) { @@ -33,7 +34,7 @@ namespace LeanCloud.Storage { { "friendship", attributes } }; } - await LCInternalApplication.HttpClient.Put>(path, data: data); + await LCCore.HttpClient.Put>(path, data: data); } public static async Task DeclineRequest(LCFriendshipRequest request) { @@ -41,7 +42,7 @@ namespace LeanCloud.Storage { throw new ArgumentNullException(nameof(request)); } string path = $"users/friendshipRequests/{request.ObjectId}/decline"; - await LCInternalApplication.HttpClient.Put>(path); + await LCCore.HttpClient.Put>(path); } } } diff --git a/Storage/Storage/LCFriendshipRequest.cs b/Storage/Storage/Public/LCFriendshipRequest.cs similarity index 100% rename from Storage/Storage/LCFriendshipRequest.cs rename to Storage/Storage/Public/LCFriendshipRequest.cs diff --git a/Storage/Storage/LCGeoPoint.cs b/Storage/Storage/Public/LCGeoPoint.cs similarity index 100% rename from Storage/Storage/LCGeoPoint.cs rename to Storage/Storage/Public/LCGeoPoint.cs diff --git a/Storage/Storage/LCHookObject.cs b/Storage/Storage/Public/LCHookObject.cs similarity index 100% rename from Storage/Storage/LCHookObject.cs rename to Storage/Storage/Public/LCHookObject.cs diff --git a/Storage/Storage/LCObject.cs b/Storage/Storage/Public/LCObject.cs similarity index 94% rename from Storage/Storage/LCObject.cs rename to Storage/Storage/Public/LCObject.cs index 980c1e5..0b2398c 100644 --- a/Storage/Storage/LCObject.cs +++ b/Storage/Storage/Public/LCObject.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using LC.Newtonsoft.Json; +using LeanCloud.Common; using LeanCloud.Storage.Internal.Object; using LeanCloud.Storage.Internal.Operation; using LeanCloud.Storage.Internal.Codec; @@ -304,7 +305,7 @@ namespace LeanCloud.Storage { { "requests", LCEncoder.Encode(requestList) } }; - List> results = await LCInternalApplication.HttpClient.Post>>("batch", data: data); + List> results = await LCCore.HttpClient.Post>>("batch", data: data); List resultList = results.Select(item => { if (item.TryGetValue("error", out object error)) { Dictionary err = error as Dictionary; @@ -342,8 +343,8 @@ namespace LeanCloud.Storage { queryParams["where"] = query.BuildWhere(); } Dictionary response = ObjectId == null ? - await LCInternalApplication.HttpClient.Post>(path, data: LCEncoder.Encode(operationDict) as Dictionary, queryParams: queryParams) : - await LCInternalApplication.HttpClient.Put>(path, data: LCEncoder.Encode(operationDict) as Dictionary, queryParams: queryParams); + await LCCore.HttpClient.Post>(path, data: LCEncoder.Encode(operationDict) as Dictionary, queryParams: queryParams) : + await LCCore.HttpClient.Put>(path, data: LCEncoder.Encode(operationDict) as Dictionary, queryParams: queryParams); LCObjectData data = LCObjectData.Decode(response); Merge(data); return this; @@ -368,7 +369,7 @@ namespace LeanCloud.Storage { return; } string path = $"classes/{ClassName}/{ObjectId}"; - await LCInternalApplication.HttpClient.Delete(path); + await LCCore.HttpClient.Delete(path); } public static async Task DeleteAll(IEnumerable objects) { @@ -377,7 +378,7 @@ namespace LeanCloud.Storage { } HashSet objectSet = new HashSet(objects.Where(item => item.ObjectId != null)); List> requestList = objectSet.Select(item => { - string path = $"/{LCInternalApplication.APIVersion}/classes/{item.ClassName}/{item.ObjectId}"; + string path = $"/{LCCore.APIVersion}/classes/{item.ClassName}/{item.ObjectId}"; return new Dictionary { { "path", path }, { "method", "DELETE" } @@ -386,7 +387,7 @@ namespace LeanCloud.Storage { Dictionary data = new Dictionary { { "requests", LCEncoder.Encode(requestList) } }; - await LCInternalApplication.HttpClient.Post>("batch", data: data); + await LCCore.HttpClient.Post>("batch", data: data); } public async Task Fetch(IEnumerable keys = null, IEnumerable includes = null) { @@ -398,7 +399,7 @@ namespace LeanCloud.Storage { queryParams["include"] = string.Join(",", includes); } string path = $"classes/{ClassName}/{ObjectId}"; - Dictionary response = await LCInternalApplication.HttpClient.Get>(path, queryParams: queryParams); + Dictionary response = await LCCore.HttpClient.Get>(path, queryParams: queryParams); LCObjectData objectData = LCObjectData.Decode(response); Merge(objectData); return this; @@ -411,7 +412,7 @@ namespace LeanCloud.Storage { IEnumerable uniqueObjects = objects.Where(item => item.ObjectId != null); List> requestList = uniqueObjects.Select(item => { - string path = $"/{LCInternalApplication.APIVersion}/classes/{item.ClassName}/{item.ObjectId}"; + string path = $"/{LCCore.APIVersion}/classes/{item.ClassName}/{item.ObjectId}"; return new Dictionary { { "path", path }, { "method", "GET" } @@ -421,7 +422,7 @@ namespace LeanCloud.Storage { Dictionary data = new Dictionary { { "requests", LCEncoder.Encode(requestList) } }; - List> results = await LCInternalApplication.HttpClient.Post>>("batch", + List> results = await LCCore.HttpClient.Post>>("batch", data: data); Dictionary dict = new Dictionary(); foreach (Dictionary item in results) { diff --git a/Storage/Storage/LCQuery.cs b/Storage/Storage/Public/LCQuery.cs similarity index 96% rename from Storage/Storage/LCQuery.cs rename to Storage/Storage/Public/LCQuery.cs index 52b417f..5e37364 100644 --- a/Storage/Storage/LCQuery.cs +++ b/Storage/Storage/Public/LCQuery.cs @@ -4,6 +4,7 @@ using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Threading.Tasks; +using LeanCloud.Common; using LeanCloud.Storage.Internal.Query; using LeanCloud.Storage.Internal.Object; @@ -342,7 +343,7 @@ namespace LeanCloud.Storage { Dictionary parameters = BuildParams(); parameters["limit"] = 0; parameters["count"] = 1; - Dictionary ret = await LCInternalApplication.HttpClient.Get>(path, queryParams: parameters); + Dictionary ret = await LCCore.HttpClient.Get>(path, queryParams: parameters); return (int)ret["count"]; } @@ -358,14 +359,14 @@ namespace LeanCloud.Storage { { "include", includes } }; } - Dictionary response = await LCInternalApplication.HttpClient.Get>(path, queryParams: queryParams); + Dictionary response = await LCCore.HttpClient.Get>(path, queryParams: queryParams); return DecodeLCObject(response); } public async Task> Find() { string path = $"classes/{ClassName}"; Dictionary parameters = BuildParams(); - Dictionary response = await LCInternalApplication.HttpClient.Get>(path, queryParams: parameters); + Dictionary response = await LCCore.HttpClient.Get>(path, queryParams: parameters); List results = response["results"] as List; List list = new List(); foreach (object item in results) { diff --git a/Storage/Storage/LCRelation.cs b/Storage/Storage/Public/LCRelation.cs similarity index 100% rename from Storage/Storage/LCRelation.cs rename to Storage/Storage/Public/LCRelation.cs diff --git a/Storage/Storage/LCRole.cs b/Storage/Storage/Public/LCRole.cs similarity index 100% rename from Storage/Storage/LCRole.cs rename to Storage/Storage/Public/LCRole.cs diff --git a/Storage/Storage/LCSMSClient.cs b/Storage/Storage/Public/LCSMSClient.cs similarity index 88% rename from Storage/Storage/LCSMSClient.cs rename to Storage/Storage/Public/LCSMSClient.cs index d23947d..8f6e9ca 100644 --- a/Storage/Storage/LCSMSClient.cs +++ b/Storage/Storage/Public/LCSMSClient.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; +using LeanCloud.Common; namespace LeanCloud.Storage { /// @@ -43,7 +44,7 @@ namespace LeanCloud.Storage { data[kv.Key] = kv.Value; } } - await LCInternalApplication.HttpClient.Post>(path, data: data); + await LCCore.HttpClient.Post>(path, data: data); } /// @@ -57,7 +58,7 @@ namespace LeanCloud.Storage { { "mobilePhoneNumber", mobile }, { "smsType", "voice" } }; - await LCInternalApplication.HttpClient.Post>(path, data: data); + await LCCore.HttpClient.Post>(path, data: data); } public static async Task VerifyMobilePhone(string mobile, string code) { @@ -65,7 +66,7 @@ namespace LeanCloud.Storage { Dictionary data = new Dictionary { { "mobilePhoneNumber", mobile } }; - await LCInternalApplication.HttpClient.Post>(path, data: data); + await LCCore.HttpClient.Post>(path, data: data); } } } diff --git a/Storage/Storage/LCStatus.cs b/Storage/Storage/Public/LCStatus.cs similarity index 90% rename from Storage/Storage/LCStatus.cs rename to Storage/Storage/Public/LCStatus.cs index 33fe383..12f166c 100644 --- a/Storage/Storage/LCStatus.cs +++ b/Storage/Storage/Public/LCStatus.cs @@ -1,6 +1,7 @@ using System; using System.Threading.Tasks; using System.Collections.Generic; +using LeanCloud.Common; using LeanCloud.Storage.Internal.Codec; using LeanCloud.Storage.Internal.Object; using LC.Newtonsoft.Json; @@ -109,7 +110,7 @@ namespace LeanCloud.Storage { } formData["query"] = queryData; } - Dictionary response = await LCInternalApplication.HttpClient.Post>("statuses", + Dictionary response = await LCCore.HttpClient.Post>("statuses", data: formData); LCObjectData objectData = LCObjectData.Decode(response); Merge(objectData); @@ -125,14 +126,14 @@ namespace LeanCloud.Storage { LCUser source = (Data[SourceKey] ?? this[SourceKey]) as LCUser; if (source != null && source.ObjectId == user.ObjectId) { - await LCInternalApplication.HttpClient.Delete($"statuses/{ObjectId}"); + await LCCore.HttpClient.Delete($"statuses/{ObjectId}"); } else { Dictionary data = new Dictionary { { OwnerKey, JsonConvert.SerializeObject(LCEncoder.Encode(user)) }, { InboxTypeKey, InboxType }, { MessageIdKey, MessageId } }; - await LCInternalApplication.HttpClient.Delete("subscribe/statuses/inbox", queryParams: data); + await LCCore.HttpClient.Delete("subscribe/statuses/inbox", queryParams: data); } } @@ -148,7 +149,7 @@ namespace LeanCloud.Storage { if (!string.IsNullOrEmpty(inboxType)) { queryParams[InboxTypeKey] = inboxType; } - Dictionary response = await LCInternalApplication.HttpClient.Get>("subscribe/statuses/count", + Dictionary response = await LCCore.HttpClient.Get>("subscribe/statuses/count", queryParams: queryParams); LCStatusCount statusCount = new LCStatusCount { Total = (int)response["total"], @@ -169,7 +170,7 @@ namespace LeanCloud.Storage { if (!string.IsNullOrEmpty(inboxType)) { queryParams[InboxTypeKey] = inboxType; } - await LCInternalApplication.HttpClient.Post>("subscribe/statuses/resetUnreadCount", + await LCCore.HttpClient.Post>("subscribe/statuses/resetUnreadCount", queryParams:queryParams); } } diff --git a/Storage/Storage/LCStatusCount.cs b/Storage/Storage/Public/LCStatusCount.cs similarity index 100% rename from Storage/Storage/LCStatusCount.cs rename to Storage/Storage/Public/LCStatusCount.cs diff --git a/Storage/Storage/LCStatusQuery.cs b/Storage/Storage/Public/LCStatusQuery.cs similarity index 93% rename from Storage/Storage/LCStatusQuery.cs rename to Storage/Storage/Public/LCStatusQuery.cs index f035982..b3de9c5 100644 --- a/Storage/Storage/LCStatusQuery.cs +++ b/Storage/Storage/Public/LCStatusQuery.cs @@ -4,6 +4,7 @@ using System.Collections; using System.Collections.ObjectModel; using System.Collections.Generic; using LC.Newtonsoft.Json; +using LeanCloud.Common; using LeanCloud.Storage.Internal.Codec; using LeanCloud.Storage.Internal.Object; @@ -41,7 +42,7 @@ namespace LeanCloud.Storage { { "maxId", MaxId }, { "limit", Condition.Limit } }; - Dictionary response = await LCInternalApplication.HttpClient.Get>("subscribe/statuses", + Dictionary response = await LCCore.HttpClient.Get>("subscribe/statuses", queryParams: queryParams); List results = response["results"] as List; List statuses = new List(); diff --git a/Storage/Storage/Public/LCStorage.cs b/Storage/Storage/Public/LCStorage.cs new file mode 100644 index 0000000..9b5635d --- /dev/null +++ b/Storage/Storage/Public/LCStorage.cs @@ -0,0 +1,31 @@ +using System; +using LeanCloud.Common; + +namespace LeanCloud.Storage { + public class LCStorage { + private const string SessionHeaderKey = "X-LC-Session"; + + public static void Initialize(string appId, + string appKey, + string server = null, + string masterKey = null) { + + LCCore.Initialize(appId, appKey, server, masterKey); + + LCCore.HttpClient.AddRuntimeHeaderTask(SessionHeaderKey, async () => { + LCUser currentUser = await LCUser.GetCurrent(); + if (currentUser == null) { + return null; + } + return currentUser.SessionToken; + }); + + // 注册 LeanCloud 内部子类化类型 + LCObject.RegisterSubclass(LCUser.CLASS_NAME, () => new LCUser()); + LCObject.RegisterSubclass(LCRole.CLASS_NAME, () => new LCRole()); + LCObject.RegisterSubclass(LCFile.CLASS_NAME, () => new LCFile()); + LCObject.RegisterSubclass(LCStatus.CLASS_NAME, () => new LCStatus()); + LCObject.RegisterSubclass(LCFriendshipRequest.CLASS_NAME, () => new LCFriendshipRequest()); + } + } +} diff --git a/Storage/Storage/LCUser.cs b/Storage/Storage/Public/LCUser.cs similarity index 91% rename from Storage/Storage/LCUser.cs rename to Storage/Storage/Public/LCUser.cs index 0f4e29a..cf03635 100644 --- a/Storage/Storage/LCUser.cs +++ b/Storage/Storage/Public/LCUser.cs @@ -2,6 +2,7 @@ using System.Threading.Tasks; using System.Collections; using System.Collections.Generic; +using LeanCloud.Common; using LeanCloud.Storage.Internal.Object; namespace LeanCloud.Storage { @@ -83,13 +84,13 @@ namespace LeanCloud.Storage { return currentUser; } - string data = await LCInternalApplication.StorageController.ReadText(USER_DATA); + string data = await LCCore.PersistenceController.ReadText(USER_DATA); if (!string.IsNullOrEmpty(data)) { try { currentUser = ParseObject(data) as LCUser; } catch (Exception e) { LCLogger.Error(e); - await LCInternalApplication.StorageController.Delete(USER_DATA); + await LCCore.PersistenceController.Delete(USER_DATA); } } return currentUser; @@ -137,7 +138,7 @@ namespace LeanCloud.Storage { Dictionary data = new Dictionary { { "mobilePhoneNumber", mobile } }; - await LCInternalApplication.HttpClient.Post>("requestLoginSmsCode", data: data); + await LCCore.HttpClient.Post>("requestLoginSmsCode", data: data); } /// @@ -157,7 +158,7 @@ namespace LeanCloud.Storage { { "mobilePhoneNumber", mobile }, { "smsCode", code } }; - Dictionary response = await LCInternalApplication.HttpClient.Post>("usersByMobilePhone", data: data); + Dictionary response = await LCCore.HttpClient.Post>("usersByMobilePhone", data: data); LCObjectData objectData = LCObjectData.Decode(response); currentUser = new LCUser(objectData); @@ -370,7 +371,7 @@ namespace LeanCloud.Storage { Dictionary data = new Dictionary { { "email", email } }; - await LCInternalApplication.HttpClient.Post>("requestEmailVerify", data: data); + await LCCore.HttpClient.Post>("requestEmailVerify", data: data); } /// @@ -385,7 +386,7 @@ namespace LeanCloud.Storage { Dictionary data = new Dictionary { { "mobilePhoneNumber", mobile } }; - await LCInternalApplication.HttpClient.Post>("requestMobilePhoneVerify", data: data); + await LCCore.HttpClient.Post>("requestMobilePhoneVerify", data: data); } /// @@ -405,7 +406,7 @@ namespace LeanCloud.Storage { Dictionary data = new Dictionary { { "mobilePhoneNumber", mobile } }; - await LCInternalApplication.HttpClient.Post>(path, data: data); + await LCCore.HttpClient.Post>(path, data: data); } /// @@ -420,7 +421,7 @@ namespace LeanCloud.Storage { Dictionary headers = new Dictionary { { "X-LC-Session", sessionToken } }; - Dictionary response = await LCInternalApplication.HttpClient.Get>("users/me", + Dictionary response = await LCCore.HttpClient.Get>("users/me", headers: headers); LCObjectData objectData = LCObjectData.Decode(response); currentUser = new LCUser(objectData); @@ -439,7 +440,7 @@ namespace LeanCloud.Storage { Dictionary data = new Dictionary { { "email", email } }; - await LCInternalApplication.HttpClient.Post>("requestPasswordReset", + await LCCore.HttpClient.Post>("requestPasswordReset", data: data); } @@ -455,7 +456,7 @@ namespace LeanCloud.Storage { Dictionary data = new Dictionary { { "mobilePhoneNumber", mobile } }; - await LCInternalApplication.HttpClient.Post>("requestPasswordResetBySmsCode", + await LCCore.HttpClient.Post>("requestPasswordResetBySmsCode", data: data); } @@ -480,7 +481,7 @@ namespace LeanCloud.Storage { { "mobilePhoneNumber", mobile }, { "password", newPassword } }; - await LCInternalApplication.HttpClient.Put>($"resetPasswordBySmsCode/{code}", + await LCCore.HttpClient.Put>($"resetPasswordBySmsCode/{code}", data: data); } @@ -501,7 +502,7 @@ namespace LeanCloud.Storage { { "old_password", oldPassword }, { "new_password", newPassword } }; - Dictionary response = await LCInternalApplication.HttpClient.Put>( + Dictionary response = await LCCore.HttpClient.Put>( $"users/{ObjectId}/updatePassword", data:data); LCObjectData objectData = LCObjectData.Decode(response); Merge(objectData); @@ -513,7 +514,7 @@ namespace LeanCloud.Storage { public static Task Logout() { currentUser = null; // 清理持久化数据 - return LCInternalApplication.StorageController.Delete(USER_DATA); + return LCCore.PersistenceController.Delete(USER_DATA); } /// @@ -525,7 +526,7 @@ namespace LeanCloud.Storage { return false; } try { - await LCInternalApplication.HttpClient.Get>("users/me"); + await LCCore.HttpClient.Get>("users/me"); return true; } catch (Exception) { return false; @@ -578,7 +579,7 @@ namespace LeanCloud.Storage { } static async Task Login(Dictionary data) { - Dictionary response = await LCInternalApplication.HttpClient.Post>("login", data: data); + Dictionary response = await LCCore.HttpClient.Post>("login", data: data); LCObjectData objectData = LCObjectData.Decode(response); currentUser = new LCUser(objectData); @@ -592,7 +593,7 @@ namespace LeanCloud.Storage { { authType, data } }; string path = failOnNotExist ? "users?failOnNotExist=true" : "users"; - Dictionary response = await LCInternalApplication.HttpClient.Post>(path, data: new Dictionary { + Dictionary response = await LCCore.HttpClient.Post>(path, data: new Dictionary { { "authData", authData } }); LCObjectData objectData = LCObjectData.Decode(response); @@ -612,7 +613,7 @@ namespace LeanCloud.Storage { private static async Task SaveToLocal() { try { string json = currentUser.ToString(); - await LCInternalApplication.StorageController.WriteText(USER_DATA, json); + await LCCore.PersistenceController.WriteText(USER_DATA, json); } catch (Exception e) { LCLogger.Error(e.Message); } @@ -634,7 +635,7 @@ namespace LeanCloud.Storage { if (!string.IsNullOrEmpty(captchaToken)) { data["validate_token"] = captchaToken; } - await LCInternalApplication.HttpClient.Post>(path, data: data); + await LCCore.HttpClient.Post>(path, data: data); } /// @@ -649,7 +650,7 @@ namespace LeanCloud.Storage { { "mobilePhoneNumber", mobile }, { "code", code } }; - await LCInternalApplication.HttpClient.Post>(path, data: data); + await LCCore.HttpClient.Post>(path, data: data); } /// @@ -663,7 +664,7 @@ namespace LeanCloud.Storage { throw new ArgumentNullException(nameof(targetId)); } string path = $"users/self/friendship/{targetId}"; - await LCInternalApplication.HttpClient.Post>(path, data: attrs); + await LCCore.HttpClient.Post>(path, data: attrs); } /// @@ -676,7 +677,7 @@ namespace LeanCloud.Storage { throw new ArgumentNullException(nameof(targetId)); } string path = $"users/self/friendship/{targetId}"; - await LCInternalApplication.HttpClient.Delete(path); + await LCCore.HttpClient.Delete(path); } /// @@ -716,7 +717,7 @@ namespace LeanCloud.Storage { queryParams["include"] = string.Join(",", includes); } string path = $"users/{ObjectId}/followersAndFollowees"; - Dictionary response = await LCInternalApplication.HttpClient.Get>(path, + Dictionary response = await LCCore.HttpClient.Get>(path, queryParams: queryParams); LCFollowersAndFollowees result = new LCFollowersAndFollowees(); if (response.TryGetValue("followers", out object followersObj) && diff --git a/Storage/Storage/LCUserAuthDataLoginOption.cs b/Storage/Storage/Public/LCUserAuthDataLoginOption.cs similarity index 87% rename from Storage/Storage/LCUserAuthDataLoginOption.cs rename to Storage/Storage/Public/LCUserAuthDataLoginOption.cs index 0d88718..3d1a189 100644 --- a/Storage/Storage/LCUserAuthDataLoginOption.cs +++ b/Storage/Storage/Public/LCUserAuthDataLoginOption.cs @@ -1,7 +1,7 @@ -/// -/// LCUser UnionID login parameters. -/// -namespace LeanCloud.Storage { +namespace LeanCloud.Storage { + /// + /// LCUser UnionID login parameters. + /// public class LCUserAuthDataLoginOption { /// /// The platform of the UnionID. diff --git a/Storage/Storage/Leaderboard/LCLeaderboard.cs b/Storage/Storage/Public/Leaderboard/LCLeaderboard.cs similarity index 91% rename from Storage/Storage/Leaderboard/LCLeaderboard.cs rename to Storage/Storage/Public/Leaderboard/LCLeaderboard.cs index a6d3e31..9cab449 100644 --- a/Storage/Storage/Leaderboard/LCLeaderboard.cs +++ b/Storage/Storage/Public/Leaderboard/LCLeaderboard.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Collections.ObjectModel; using System.Threading.Tasks; using System.Collections.Generic; +using LeanCloud.Common; using LeanCloud.Storage.Internal.Codec; namespace LeanCloud.Storage { @@ -68,7 +69,7 @@ namespace LeanCloud.Storage { { "updateStrategy", updateStrategy.ToString().ToLower() }, }; string path = "leaderboard/leaderboards"; - Dictionary result = await LCInternalApplication.HttpClient.Post>(path, + Dictionary result = await LCCore.HttpClient.Post>(path, data:data); LCLeaderboard leaderboard = new LCLeaderboard(); leaderboard.Merge(result); @@ -112,7 +113,7 @@ namespace LeanCloud.Storage { if (overwrite) { path = $"{path}?overwrite=1"; } - Dictionary result = await LCInternalApplication.HttpClient.Post>(path, + Dictionary result = await LCCore.HttpClient.Post>(path, data: data); if (result.TryGetValue("results", out object results) && results is List list) { @@ -137,7 +138,7 @@ namespace LeanCloud.Storage { string names = string.Join(",", statisticNames); path = $"{path}?statistics={names}"; } - Dictionary result = await LCInternalApplication.HttpClient.Get>(path); + Dictionary result = await LCCore.HttpClient.Get>(path); if (result.TryGetValue("results", out object results) && results is List list) { List statistics = new List(); @@ -161,7 +162,7 @@ namespace LeanCloud.Storage { } string names = string.Join(",", statisticNames); string path = $"leaderboard/users/{user.ObjectId}/statistics?statistics={names}"; - await LCInternalApplication.HttpClient.Delete(path); + await LCCore.HttpClient.Delete(path); } /// @@ -179,7 +180,7 @@ namespace LeanCloud.Storage { throw new ArgumentOutOfRangeException(nameof(limit)); } string path = $"leaderboard/leaderboards/{StatisticName}/archives?skip={skip}&limit={limit}"; - Dictionary result = await LCInternalApplication.HttpClient.Get>(path); + Dictionary result = await LCCore.HttpClient.Get>(path); if (result.TryGetValue("results", out object results) && results is List list) { List archives = new List(); @@ -235,7 +236,7 @@ namespace LeanCloud.Storage { string statistics = string.Join(",", includeStatistics); path = $"{path}&includeStatistics={statistics}"; } - Dictionary result = await LCInternalApplication.HttpClient.Get>(path); + Dictionary result = await LCCore.HttpClient.Get>(path); if (result.TryGetValue("results", out object results) && results is List list) { List rankings = new List(); @@ -254,7 +255,7 @@ namespace LeanCloud.Storage { { "updateStrategy", updateStrategy.ToString().ToLower() } }; string path = $"leaderboard/leaderboards/{StatisticName}"; - Dictionary result = await LCInternalApplication.HttpClient.Put>(path, + Dictionary result = await LCCore.HttpClient.Put>(path, data: data); if (result.TryGetValue("updateStrategy", out object strategy) && Enum.TryParse(strategy as string, true, out LCLeaderboardUpdateStrategy s)) { @@ -269,7 +270,7 @@ namespace LeanCloud.Storage { { "versionChangeInterval", versionChangeInterval.ToString().ToLower() } }; string path = $"leaderboard/leaderboards/{StatisticName}"; - Dictionary result = await LCInternalApplication.HttpClient.Put>(path, + Dictionary result = await LCCore.HttpClient.Put>(path, data: data); if (result.TryGetValue("versionChangeInterval", out object interval) && Enum.TryParse(interval as string, true, out LCLeaderboardVersionChangeInterval i)) { @@ -284,7 +285,7 @@ namespace LeanCloud.Storage { /// public async Task Fetch() { string path = $"leaderboard/leaderboards/{StatisticName}"; - Dictionary result = await LCInternalApplication.HttpClient.Get>(path); + Dictionary result = await LCCore.HttpClient.Get>(path); Merge(result); return this; } @@ -295,7 +296,7 @@ namespace LeanCloud.Storage { /// public async Task Reset() { string path = $"leaderboard/leaderboards/{StatisticName}/incrementVersion"; - Dictionary result = await LCInternalApplication.HttpClient.Put>(path); + Dictionary result = await LCCore.HttpClient.Put>(path); Merge(result); return this; } @@ -306,7 +307,7 @@ namespace LeanCloud.Storage { /// public async Task Destroy() { string path = $"leaderboard/leaderboards/{StatisticName}"; - await LCInternalApplication.HttpClient.Delete(path); + await LCCore.HttpClient.Delete(path); } private void Merge(Dictionary data) { diff --git a/Storage/Storage/Leaderboard/LCLeaderboardArchive.cs b/Storage/Storage/Public/Leaderboard/LCLeaderboardArchive.cs similarity index 100% rename from Storage/Storage/Leaderboard/LCLeaderboardArchive.cs rename to Storage/Storage/Public/Leaderboard/LCLeaderboardArchive.cs diff --git a/Storage/Storage/Leaderboard/LCRanking.cs b/Storage/Storage/Public/Leaderboard/LCRanking.cs similarity index 100% rename from Storage/Storage/Leaderboard/LCRanking.cs rename to Storage/Storage/Public/Leaderboard/LCRanking.cs diff --git a/Storage/Storage/Leaderboard/LCStatistic.cs b/Storage/Storage/Public/Leaderboard/LCStatistic.cs similarity index 100% rename from Storage/Storage/Leaderboard/LCStatistic.cs rename to Storage/Storage/Public/Leaderboard/LCStatistic.cs diff --git a/Storage/Storage/Storage.csproj b/Storage/Storage/Storage.csproj index 3f79034..6adac5a 100644 --- a/Storage/Storage/Storage.csproj +++ b/Storage/Storage/Storage.csproj @@ -11,12 +11,11 @@ - - - + +