From 38287c9a9c2d097e794ad979c2244c793a078757 Mon Sep 17 00:00:00 2001 From: oneRain Date: Tue, 28 Apr 2020 16:59:55 +0800 Subject: [PATCH] * LCApplication.cs: * LCHttpClient.cs: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * LCObject.cs: chore: 调整访问权限 --- Realtime/Conversation/LCIMConversation.cs | 1 - Realtime/Internal/Connection/LCConnection.cs | 2 +- Realtime/Internal/Connection/LCHeartBeat.cs | 2 +- .../Internal/Controller/LCIMController.cs | 2 +- .../Controller/LCIMConversationController.cs | 10 +- .../Controller/LCIMGoAwayController.cs | 2 +- .../Controller/LCIMMessageController.cs | 20 +- .../Controller/LCIMSessionController.cs | 2 +- Realtime/LCIMClient.cs | 2 +- Realtime/LCIMOperationFailure.cs | 25 ++ Realtime/{Result => }/LCIMPageResult.cs | 9 - .../LCIMPartiallySuccessResult.cs | 13 +- Realtime/Message/LCIMMessageSendOptions.cs | 8 +- Realtime/Realtime.csproj | 2 - Realtime/Result/LCIMOperationFailure.cs | 35 -- Realtime/Signature/ILCIMSignatureFactory.cs | 3 - Realtime/protobuf/compile-client-proto.sh | 2 +- Realtime/protobuf/messages2.proto.orig | 2 +- Storage/Internal/Http/LCHttpClient.cs | 6 +- Storage/LCApplication.cs | 6 +- Storage/LCObject.cs | 2 +- Test/RealtimeConsole/LocalSignatureFactory.cs | 96 ----- Test/RealtimeConsole/Program.cs | 327 ------------------ .../Properties/AssemblyInfo.cs | 26 -- Test/RealtimeConsole/RealtimeConsole.csproj | 73 ---- Test/RealtimeConsole/packages.config | 8 - 26 files changed, 47 insertions(+), 639 deletions(-) create mode 100644 Realtime/LCIMOperationFailure.cs rename Realtime/{Result => }/LCIMPageResult.cs (55%) rename Realtime/{Result => }/LCIMPartiallySuccessResult.cs (63%) delete mode 100644 Realtime/Result/LCIMOperationFailure.cs delete mode 100644 Test/RealtimeConsole/LocalSignatureFactory.cs delete mode 100644 Test/RealtimeConsole/Program.cs delete mode 100644 Test/RealtimeConsole/Properties/AssemblyInfo.cs delete mode 100644 Test/RealtimeConsole/RealtimeConsole.csproj delete mode 100644 Test/RealtimeConsole/packages.config diff --git a/Realtime/Conversation/LCIMConversation.cs b/Realtime/Conversation/LCIMConversation.cs index fb6c9a0..d6346a3 100644 --- a/Realtime/Conversation/LCIMConversation.cs +++ b/Realtime/Conversation/LCIMConversation.cs @@ -187,7 +187,6 @@ namespace LeanCloud.Realtime { return; } await Client.MessageController.Read(Id, LastMessage); - Unread = 0; } /// diff --git a/Realtime/Internal/Connection/LCConnection.cs b/Realtime/Internal/Connection/LCConnection.cs index 1a3e092..bef04cf 100644 --- a/Realtime/Internal/Connection/LCConnection.cs +++ b/Realtime/Internal/Connection/LCConnection.cs @@ -5,7 +5,7 @@ using System.Threading.Tasks; using Google.Protobuf; using LeanCloud.Realtime.Internal.Router; using LeanCloud.Realtime.Internal.WebSocket; -using LeanCloud.Realtime.Internal.Protocol; +using LeanCloud.Realtime.Protocol; using LeanCloud.Common; using LeanCloud.Storage; diff --git a/Realtime/Internal/Connection/LCHeartBeat.cs b/Realtime/Internal/Connection/LCHeartBeat.cs index fbaf599..fa343d5 100644 --- a/Realtime/Internal/Connection/LCHeartBeat.cs +++ b/Realtime/Internal/Connection/LCHeartBeat.cs @@ -2,7 +2,7 @@ using System.Threading; using System.Threading.Tasks; using LeanCloud.Common; -using LeanCloud.Realtime.Internal.Protocol; +using LeanCloud.Realtime.Protocol; namespace LeanCloud.Realtime.Internal.Connection { /// diff --git a/Realtime/Internal/Controller/LCIMController.cs b/Realtime/Internal/Controller/LCIMController.cs index 598a526..4a1e4dc 100644 --- a/Realtime/Internal/Controller/LCIMController.cs +++ b/Realtime/Internal/Controller/LCIMController.cs @@ -1,5 +1,5 @@ using System.Threading.Tasks; -using LeanCloud.Realtime.Internal.Protocol; +using LeanCloud.Realtime.Protocol; using LeanCloud.Realtime.Internal.Connection; namespace LeanCloud.Realtime.Internal.Controller { diff --git a/Realtime/Internal/Controller/LCIMConversationController.cs b/Realtime/Internal/Controller/LCIMConversationController.cs index cd7836a..6b3e38f 100644 --- a/Realtime/Internal/Controller/LCIMConversationController.cs +++ b/Realtime/Internal/Controller/LCIMConversationController.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Threading.Tasks; using Newtonsoft.Json; -using LeanCloud.Realtime.Internal.Protocol; +using LeanCloud.Realtime.Protocol; using LeanCloud.Storage.Internal; using LeanCloud.Storage.Internal.Codec; using LeanCloud.Common; @@ -552,12 +552,7 @@ namespace LeanCloud.Realtime.Internal.Controller { if (errors != null) { result.FailureList = new List(); foreach (ErrorCommand error in errors) { - LCIMOperationFailure failure = new LCIMOperationFailure { - Code = error.Code, - Reason = error.Reason, - IdList = error.Pids?.ToList() - }; - result.FailureList.Add(failure); + result.FailureList.Add(new LCIMOperationFailure(error)); } } return result; @@ -602,7 +597,6 @@ namespace LeanCloud.Realtime.Internal.Controller { message.Id = conv.Mid; message.FromClientId = conv.From; message.SentTimestamp = conv.Timestamp; - message.Mentioned = conv.Mentioned; conversation.LastMessage = message; } return conversation; diff --git a/Realtime/Internal/Controller/LCIMGoAwayController.cs b/Realtime/Internal/Controller/LCIMGoAwayController.cs index 1bcb57d..81616f5 100644 --- a/Realtime/Internal/Controller/LCIMGoAwayController.cs +++ b/Realtime/Internal/Controller/LCIMGoAwayController.cs @@ -1,5 +1,5 @@ using System.Threading.Tasks; -using LeanCloud.Realtime.Internal.Protocol; +using LeanCloud.Realtime.Protocol; namespace LeanCloud.Realtime.Internal.Controller { internal class LCIMGoAwayController : LCIMController { diff --git a/Realtime/Internal/Controller/LCIMMessageController.cs b/Realtime/Internal/Controller/LCIMMessageController.cs index 784a895..71707a5 100644 --- a/Realtime/Internal/Controller/LCIMMessageController.cs +++ b/Realtime/Internal/Controller/LCIMMessageController.cs @@ -4,7 +4,7 @@ using System.Threading.Tasks; using System.Collections.ObjectModel; using Newtonsoft.Json; using Google.Protobuf; -using LeanCloud.Realtime.Internal.Protocol; +using LeanCloud.Realtime.Protocol; namespace LeanCloud.Realtime.Internal.Controller { internal class LCIMMessageController : LCIMController { @@ -46,19 +46,6 @@ namespace LeanCloud.Realtime.Internal.Controller { if (options.Will) { direct.Will = options.Will; } - // 推送数据 - if (options.PushData != null) { - direct.PushData = JsonConvert.SerializeObject(options.PushData); - } - // 提醒所有人 - if (message.MentionAll) { - direct.MentionAll = message.MentionAll; - } - // 提醒用户列表 - if (message.MentionIdList != null && - message.MentionIdList.Count > 0) { - direct.MentionPids.AddRange(message.MentionIdList); - } GenericCommand command = NewCommand(CommandType.Direct); command.DirectMessage = direct; // 优先级 @@ -190,8 +177,6 @@ namespace LeanCloud.Realtime.Internal.Controller { message.PatchedTimestamp = item.PatchTimestamp; message.MentionAll = item.MentionAll; message.MentionIdList = item.MentionPids.ToList(); - message.Mentioned = message.MentionAll || - message.MentionIdList.Contains(Client.Id); return message; }).ToList().AsReadOnly(); } @@ -271,8 +256,6 @@ namespace LeanCloud.Realtime.Internal.Controller { message.SentTimestamp = direct.Timestamp; message.MentionAll = direct.MentionAll; message.MentionIdList = direct.MentionPids.ToList(); - message.Mentioned = message.MentionAll || - message.MentionIdList.Contains(Client.Id); message.PatchedTimestamp = direct.PatchTimestamp; message.IsTransient = direct.Transient; // 通知服务端已接收 @@ -282,7 +265,6 @@ namespace LeanCloud.Realtime.Internal.Controller { } // 获取对话 LCIMConversation conversation = await Client.GetOrQueryConversation(direct.Cid); - conversation.Unread++; conversation.LastMessage = message; Client.OnMessage?.Invoke(conversation, message); } diff --git a/Realtime/Internal/Controller/LCIMSessionController.cs b/Realtime/Internal/Controller/LCIMSessionController.cs index 28b913c..c3767dc 100644 --- a/Realtime/Internal/Controller/LCIMSessionController.cs +++ b/Realtime/Internal/Controller/LCIMSessionController.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using LeanCloud.Realtime.Internal.Protocol; +using LeanCloud.Realtime.Protocol; namespace LeanCloud.Realtime.Internal.Controller { internal class LCIMSessionController : LCIMController { diff --git a/Realtime/LCIMClient.cs b/Realtime/LCIMClient.cs index 4799c4a..978229b 100644 --- a/Realtime/LCIMClient.cs +++ b/Realtime/LCIMClient.cs @@ -5,7 +5,7 @@ using System.Linq; using System.Collections.ObjectModel; using LeanCloud.Common; using LeanCloud.Storage; -using LeanCloud.Realtime.Internal.Protocol; +using LeanCloud.Realtime.Protocol; using LeanCloud.Realtime.Internal.Controller; using LeanCloud.Realtime.Internal.Connection; diff --git a/Realtime/LCIMOperationFailure.cs b/Realtime/LCIMOperationFailure.cs new file mode 100644 index 0000000..68e7e19 --- /dev/null +++ b/Realtime/LCIMOperationFailure.cs @@ -0,0 +1,25 @@ +using System.Linq; +using System.Collections.Generic; +using LeanCloud.Realtime.Protocol; + +namespace LeanCloud.Realtime { + public class LCIMOperationFailure { + public int Code { + get; set; + } + + public string Reason { + get; set; + } + + public List MemberList { + get; set; + } + + public LCIMOperationFailure(ErrorCommand error) { + Code = error.Code; + Reason = error.Reason; + MemberList = error.Pids.ToList(); + } + } +} diff --git a/Realtime/Result/LCIMPageResult.cs b/Realtime/LCIMPageResult.cs similarity index 55% rename from Realtime/Result/LCIMPageResult.cs rename to Realtime/LCIMPageResult.cs index c0879b5..a559db6 100644 --- a/Realtime/Result/LCIMPageResult.cs +++ b/Realtime/LCIMPageResult.cs @@ -1,20 +1,11 @@ using System.Collections.ObjectModel; namespace LeanCloud.Realtime { - /// - /// 查询分页结果 - /// public class LCIMPageResult { - /// - /// 当前分页数据集 - /// public ReadOnlyCollection Results { get; internal set; } - /// - /// 下次请求的数据 - /// public string Next { get; internal set; } diff --git a/Realtime/Result/LCIMPartiallySuccessResult.cs b/Realtime/LCIMPartiallySuccessResult.cs similarity index 63% rename from Realtime/Result/LCIMPartiallySuccessResult.cs rename to Realtime/LCIMPartiallySuccessResult.cs index e91f336..d9e8247 100644 --- a/Realtime/Result/LCIMPartiallySuccessResult.cs +++ b/Realtime/LCIMPartiallySuccessResult.cs @@ -1,20 +1,13 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using LeanCloud.Storage; namespace LeanCloud.Realtime { - /// - /// 部分成功结果 - /// public class LCIMPartiallySuccessResult { - /// - /// 成功数据集 - /// public List SuccessfulClientIdList { get; internal set; } - /// - /// 失败原因 - /// public List FailureList { get; internal set; } diff --git a/Realtime/Message/LCIMMessageSendOptions.cs b/Realtime/Message/LCIMMessageSendOptions.cs index 4e61efd..165f8b7 100644 --- a/Realtime/Message/LCIMMessageSendOptions.cs +++ b/Realtime/Message/LCIMMessageSendOptions.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; - -namespace LeanCloud.Realtime { +namespace LeanCloud.Realtime { /// /// 消息优先级 /// @@ -42,10 +40,6 @@ namespace LeanCloud.Realtime { get; set; } - public Dictionary PushData { - get; set; - } - public static LCIMMessageSendOptions Default = new LCIMMessageSendOptions(); } } diff --git a/Realtime/Realtime.csproj b/Realtime/Realtime.csproj index e9eaffd..0a710df 100644 --- a/Realtime/Realtime.csproj +++ b/Realtime/Realtime.csproj @@ -23,7 +23,5 @@ - - diff --git a/Realtime/Result/LCIMOperationFailure.cs b/Realtime/Result/LCIMOperationFailure.cs deleted file mode 100644 index 73780e1..0000000 --- a/Realtime/Result/LCIMOperationFailure.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.Collections.Generic; - -namespace LeanCloud.Realtime { - /// - /// 操作失败 - /// - public class LCIMOperationFailure { - /// - /// 失败码 - /// - public int Code { - get; set; - } - - /// - /// 失败原因 - /// - public string Reason { - get; set; - } - - /// - /// 失败数据 - /// - public List IdList { - get; set; - } - - //public LCIMOperationFailure(ErrorCommand error) { - // Code = error.Code; - // Reason = error.Reason; - // MemberList = error.Pids.ToList(); - //} - } -} diff --git a/Realtime/Signature/ILCIMSignatureFactory.cs b/Realtime/Signature/ILCIMSignatureFactory.cs index 4690302..7b62de6 100644 --- a/Realtime/Signature/ILCIMSignatureFactory.cs +++ b/Realtime/Signature/ILCIMSignatureFactory.cs @@ -2,9 +2,6 @@ using System.Threading.Tasks; namespace LeanCloud.Realtime { - /// - /// 签名工程接口 - /// public interface ILCIMSignatureFactory { /// /// 登录签名 diff --git a/Realtime/protobuf/compile-client-proto.sh b/Realtime/protobuf/compile-client-proto.sh index c19f774..d917889 100644 --- a/Realtime/protobuf/compile-client-proto.sh +++ b/Realtime/protobuf/compile-client-proto.sh @@ -1 +1 @@ -protoc --proto_path=. --csharp_out=../Internal/Protocol messages2.proto.orig \ No newline at end of file +protoc --proto_path=. --csharp_out=. messages2.proto.orig \ No newline at end of file diff --git a/Realtime/protobuf/messages2.proto.orig b/Realtime/protobuf/messages2.proto.orig index 2786f55..93a2156 100644 --- a/Realtime/protobuf/messages2.proto.orig +++ b/Realtime/protobuf/messages2.proto.orig @@ -1,7 +1,7 @@ syntax = "proto2"; package push_server.messages2; -option csharp_namespace = "LeanCloud.Realtime.Internal.Protocol"; +option csharp_namespace = "LeanCloud.Realtime.Protocol"; // note that this line will be removed by out build script until we // finally upgraded to protobuffer 3 diff --git a/Storage/Internal/Http/LCHttpClient.cs b/Storage/Internal/Http/LCHttpClient.cs index e8bb135..9e9e306 100644 --- a/Storage/Internal/Http/LCHttpClient.cs +++ b/Storage/Internal/Http/LCHttpClient.cs @@ -67,7 +67,7 @@ namespace LeanCloud.Storage.Internal.Http { throw HandleErrorResponse(response.StatusCode, resultString); } - internal async Task Post(string path, + public async Task Post(string path, Dictionary headers = null, Dictionary data = null, Dictionary queryParams = null) { @@ -100,7 +100,7 @@ namespace LeanCloud.Storage.Internal.Http { throw HandleErrorResponse(response.StatusCode, resultString); } - internal async Task Put(string path, + public async Task Put(string path, Dictionary headers = null, Dictionary data = null, Dictionary queryParams = null) { @@ -133,7 +133,7 @@ namespace LeanCloud.Storage.Internal.Http { throw HandleErrorResponse(response.StatusCode, resultString); } - internal async Task Delete(string path) { + public async Task Delete(string path) { string url = await BuildUrl(path); HttpRequestMessage request = new HttpRequestMessage { RequestUri = new Uri(url), diff --git a/Storage/LCApplication.cs b/Storage/LCApplication.cs index db9c915..60e9a9d 100644 --- a/Storage/LCApplication.cs +++ b/Storage/LCApplication.cs @@ -46,9 +46,9 @@ namespace LeanCloud { AppKey = appKey; // 注册 LeanCloud 内部子类化类型 - LCObject.RegisterSubclass(LCUser.CLASS_NAME, () => new LCUser()); - LCObject.RegisterSubclass(LCRole.CLASS_NAME, () => new LCRole()); - LCObject.RegisterSubclass(LCFile.CLASS_NAME, () => new LCFile()); + LCObject.RegisterSubclass(LCUser.CLASS_NAME, () => new LCUser()); + LCObject.RegisterSubclass(LCRole.CLASS_NAME, () => new LCRole()); + LCObject.RegisterSubclass(LCFile.CLASS_NAME, () => new LCFile()); AppRouter = new LCAppRouter(appId, server); diff --git a/Storage/LCObject.cs b/Storage/LCObject.cs index f3cf750..c61cd33 100644 --- a/Storage/LCObject.cs +++ b/Storage/LCObject.cs @@ -412,7 +412,7 @@ namespace LeanCloud.Storage { return this; } - public static void RegisterSubclass(string className, Func constructor) where T : LCObject { + public static void RegisterSubclass(string className, Func constructor) where T : LCObject { Type classType = typeof(T); LCSubclassInfo subclassInfo = new LCSubclassInfo(className, classType, constructor); subclassNameDict[className] = subclassInfo; diff --git a/Test/RealtimeConsole/LocalSignatureFactory.cs b/Test/RealtimeConsole/LocalSignatureFactory.cs deleted file mode 100644 index e68f38a..0000000 --- a/Test/RealtimeConsole/LocalSignatureFactory.cs +++ /dev/null @@ -1,96 +0,0 @@ -using System; -using System.Text; -using System.Linq; -using System.Collections.Generic; -using System.Security.Cryptography; -using LeanCloud.Realtime; -using LeanCloud; - -namespace RealtimeConsole { - public class LocalSignatureFactory : ILCIMSignatureFactory { - const string MasterKey = "pyvbNSh5jXsuFQ3C8EgnIdhw"; - - public LCIMSignature CreateConnectSignature(string clientId) { - long timestamp = DateTimeOffset.Now.ToUnixTimeSeconds(); - string nonce = NewNonce(); - string signature = GenerateSignature(LCApplication.AppId, clientId, string.Empty, timestamp.ToString(), nonce); - return new LCIMSignature { - Signature = signature, - Timestamp = timestamp, - Nonce = nonce - }; - } - - public LCIMSignature CreateStartConversationSignature(string clientId, IEnumerable memberIds) { - string sortedMemberIds = string.Empty; - if (memberIds != null) { - List sortedMemberList = memberIds.ToList(); - sortedMemberList.Sort(); - sortedMemberIds = string.Join(":", sortedMemberList); - } - long timestamp = DateTimeOffset.Now.ToUnixTimeSeconds(); - string nonce = NewNonce(); - string signature = GenerateSignature(LCApplication.AppId, clientId, sortedMemberIds, timestamp.ToString(), nonce); - return new LCIMSignature { - Signature = signature, - Timestamp = timestamp, - Nonce = nonce - }; - } - - public LCIMSignature CreateConversationSignature(string conversationId, string clientId, IEnumerable memberIds, string action) { - string sortedMemberIds = string.Empty; - if (memberIds != null) { - List sortedMemberList = memberIds.ToList(); - sortedMemberList.Sort(); - sortedMemberIds = string.Join(":", sortedMemberList); - } - long timestamp = DateTimeOffset.Now.ToUnixTimeSeconds(); - string nonce = NewNonce(); - string signature = GenerateSignature(LCApplication.AppId, clientId, conversationId, sortedMemberIds, timestamp.ToString(), nonce, action); - return new LCIMSignature { - Signature = signature, - Timestamp = timestamp, - Nonce = nonce - }; - } - - public LCIMSignature CreateBlacklistSignature(string conversationId, string clientId, IEnumerable memberIds, string action) { - string sortedMemberIds = string.Empty; - if (memberIds != null) { - List sortedMemberList = memberIds.ToList(); - sortedMemberList.Sort(); - sortedMemberIds = string.Join(":", sortedMemberList); - } - long timestamp = DateTimeOffset.Now.ToUnixTimeSeconds(); - string nonce = NewNonce(); - string signature = GenerateSignature(LCApplication.AppId, clientId, conversationId, sortedMemberIds, timestamp.ToString(), nonce, action); - return new LCIMSignature { - Signature = signature, - Timestamp = timestamp, - Nonce = nonce - }; - } - - private static string SignSHA1(string key, string text) { - HMACSHA1 hmac = new HMACSHA1(Encoding.UTF8.GetBytes(key)); - byte[] bytes = hmac.ComputeHash(Encoding.UTF8.GetBytes(text)); - string signature = BitConverter.ToString(bytes).Replace("-", string.Empty); - return signature; - } - - private static string NewNonce() { - byte[] bytes = new byte[10]; - using (RandomNumberGenerator generator = RandomNumberGenerator.Create()) { - generator.GetBytes(bytes); - } - return Convert.ToBase64String(bytes); - } - - private static string GenerateSignature(params string[] args) { - string text = string.Join(":", args); - string signature = SignSHA1(MasterKey, text); - return signature; - } - } -} diff --git a/Test/RealtimeConsole/Program.cs b/Test/RealtimeConsole/Program.cs deleted file mode 100644 index c884c43..0000000 --- a/Test/RealtimeConsole/Program.cs +++ /dev/null @@ -1,327 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Threading; -using System.Threading.Tasks; -using LeanCloud; -using LeanCloud.Common; -using LeanCloud.Realtime; - -namespace RealtimeConsole { - class MainClass { - public static void Main(string[] args) { - Console.WriteLine($"Hello World at {Thread.CurrentThread.ManagedThreadId}"); - - LCLogger.LogDelegate += (level, info) => { - switch (level) { - case LCLogLevel.Debug: { - Console.ForegroundColor = ConsoleColor.Green; - Console.WriteLine($"{DateTime.Now} [DEBUG]\n{info}"); - Console.ResetColor(); - } - break; - case LCLogLevel.Warn: { - Console.ForegroundColor = ConsoleColor.Yellow; - Console.WriteLine($"{DateTime.Now} [WARNING]\n{info}"); - Console.ResetColor(); - } - break; - case LCLogLevel.Error: { - Console.ForegroundColor = ConsoleColor.Red; - Console.WriteLine($"{DateTime.Now} [ERROR]\n{info}"); - Console.ResetColor(); - } - break; - default: - Console.WriteLine(info); - break; - } - }; - LCApplication.Initialize("ikGGdRE2YcVOemAaRbgp1xGJ-gzGzoHsz", "NUKmuRbdAhg1vrb2wexYo1jo", "https://ikggdre2.lc-cn-n1-shared.com"); - - SingleThreadSynchronizationContext.Run(async () => { - Console.WriteLine($"start at {Thread.CurrentThread.ManagedThreadId}"); - //await Run("cc1"); - //await ChatRoom(); - //await TemporaryConversation(); - //await CreateConversation(); - //await QueryMyConversation(); - //await AutoSendMessage(); - - //await KeepAlive(); - - await OpenAndClose(); - - Console.WriteLine($"done at {Thread.CurrentThread.ManagedThreadId}"); - }); - - //AutoSendMessage().Wait(); - - //Conversation().Wait(); - - //_ = Signature(); - - //_ = Block(); - - //_ = Mute(); - - //QueryConversation().Wait(); - - //_ = OpenAndClose(); - - //SendMessage().Wait(); - - //Unread().Wait(); - - //DemoAsync().Wait(); - - //SingleThreadSynchronizationContext.Run(async () => { - // await DemoAsync(); - //}); - - Console.ReadKey(true); - } - - static async Task KeepAlive() { - LCIMClient client = new LCIMClient("cc1"); - await client.Open(); - } - - static async Task AutoSendMessage() { - LCIMClient client = new LCIMClient("cc1"); - await client.Open(); - LCIMConversation conversation = await client.CreateConversation(new string[] { "cc2", "cc3", "cc5" }); - int count = 0; - while (count < 10) { - LCIMTextMessage textMessage = new LCIMTextMessage($"hello, {count}"); - await conversation.Send(textMessage); - await Task.Delay(5000); - count++; - } - } - - static async Task DemoAsync() { - Dictionary d = new Dictionary(); - for (int i = 0; i < 10000; i++) { - int id = Thread.CurrentThread.ManagedThreadId; - int count; - d[id] = d.TryGetValue(id, out count) ? count + 1 : 1; - await Task.Yield(); - } - foreach (KeyValuePair kv in d) { - Console.WriteLine(kv); - } - } - - static async Task Run(string id) { - LCIMClient client = new LCIMClient(id); - await client.Open(); - client.OnUnreadMessagesCountUpdated = (conversations) => { - foreach (LCIMConversation conv in conversations) { - Console.WriteLine($"unread: {conv.Id}"); - } - }; - client.OnMessage = async (conversation, message) => { - Console.WriteLine($"recv: {conversation.Id}, {message.Id} at {Thread.CurrentThread.ManagedThreadId}"); - await conversation.Read(); - }; - } - - static async Task CreateConversation() { - LCIMClient cc1 = new LCIMClient("cc1"); - await cc1.Open(); - await cc1.CreateConversation(new string[] { "cc2", "cc3", "cc5" }); - } - - static async Task QueryMyConversation() { - LCIMClient cc1 = new LCIMClient("cc1"); - await cc1.Open(); - ReadOnlyCollection conversationList = await cc1.GetQuery() - .WhereEqualTo("objectId", "5e7c283790aef5aa846b5683") - .Find(); - foreach (LCIMConversation conv in conversationList) { - Console.WriteLine($"convId: {conv.Id}"); - } - } - - static async Task Unread() { - LCIMClient u2 = new LCIMClient("u2"); - await u2.Open(); - u2.OnUnreadMessagesCountUpdated = conversationList => { - foreach (LCIMConversation conv in conversationList) { - Console.WriteLine($"unread: {conv.Unread}"); - } - }; - } - - static async Task SendMessage() { - Console.WriteLine($"start at {Thread.CurrentThread.ManagedThreadId}"); - try { - LCIMClient u1 = new LCIMClient("u1"); - await u1.Open(); - LCIMConversation conversation = await u1.CreateConversation(new string[] { "u2" }); - - Console.WriteLine($"open at {Thread.CurrentThread.ManagedThreadId}"); - - LCIMTextMessage textMessage = new LCIMTextMessage("hello, text message"); - await conversation.Send(textMessage); - - Console.WriteLine($"send at {Thread.CurrentThread.ManagedThreadId}"); - - //LCFile file = new LCFile("avatar", "../../../Storage.Test/assets/hello.png"); - //await file.Save(); - //LCIMImageMessage imageMessage = new LCIMImageMessage(file); - //await conversation.Send(imageMessage); - } catch (Exception e) { - Console.WriteLine(e.ToString()); - } - } - - static async Task OpenAndClose() { - LCIMClient o1 = new LCIMClient("o1"); - await o1.Open(); - await Task.Delay(30000); - await o1.Close(); - } - - static async Task QueryConversation() { - LCIMClient m2 = new LCIMClient("m2"); - await m2.Open(); - - LCIMConversation conv = (await m2.GetQuery() - .WhereEqualTo("objectId", "5e7863bf90aef5aa849be75a") - .Find())[0]; - LCIMTextMessage textMessage = new LCIMTextMessage("hello, world"); - await conv.Send(textMessage); - } - - static async Task Mute() { - LCIMClient m1 = new LCIMClient("m0"); - await m1.Open(); - - LCIMClient m2 = new LCIMClient("m2"); - await m2.Open(); - - LCIMConversation conversation = await m1.CreateConversation(new string[] { "m2", "m3" }); - await conversation.MuteMembers(new string[] { "m2" }); - - LCIMConversation conv = (await m2.GetQuery() - .WhereEqualTo("objectId", conversation.Id) - .Find())[0]; - LCIMTextMessage textMessage = new LCIMTextMessage("hello, world"); - await conv.Send(textMessage); - } - - static async Task Block() { - LocalSignatureFactory signatureFactory = new LocalSignatureFactory(); - LCIMClient c1 = new LCIMClient("c0"); - await c1.Open(); - LCIMConversation conversation = await c1.CreateConversation(new string[] { "c2", "c3", "c4", "c5" }); - LCIMTextMessage textMessage = new LCIMTextMessage("hello"); - await conversation.Send(textMessage); - await conversation.BlockMembers(new string[] { "c5" }); - - LCIMClient c5 = new LCIMClient("c5"); - await c5.Open(); - await conversation.AddMembers(new string[] { "c5" }); - } - - static async Task Signature() { - LocalSignatureFactory signatureFactory = new LocalSignatureFactory(); - LCIMClient hello = new LCIMClient("hello111", signatureFactory); - await hello.Open(); - } - - static async Task ChatRoom() { - LocalSignatureFactory signatureFactory = new LocalSignatureFactory(); - LCIMClient hello = new LCIMClient("hello", signatureFactory); - await hello.Open(); - - string name = Guid.NewGuid().ToString(); - LCIMChatRoom chatRoom = await hello.CreateChatRoom(name); - Console.WriteLine(chatRoom.Name); - - await chatRoom.AddMembers(new string[] { "world" }); - - await chatRoom.RemoveMembers(new string[] { "world" }); - } - - static async Task TemporaryConversation() { - string c1Id = Guid.NewGuid().ToString(); - LCIMClient c1 = new LCIMClient(c1Id); - await c1.Open(); - - string c2Id = Guid.NewGuid().ToString(); - LCIMClient c2 = new LCIMClient(c2Id); - await c2.Open(); - - LCIMTemporaryConversation temporaryConversation = await c1.CreateTemporaryConversation(new string[] { c2Id }); - Console.WriteLine(temporaryConversation.Id); - } - - static async Task Conversation() { - LCIMClient hello = new LCIMClient("hello"); - - await hello.Open(); - - hello.OnInvited = (conv, initBy) => { - Console.WriteLine($"on invited: {initBy}"); - }; - - hello.OnMembersJoined = (conv, memberList, initBy) => { - Console.WriteLine($"on members joined: {initBy}"); - }; - - List memberIdList = new List { "world", "code" }; - string name = Guid.NewGuid().ToString(); - LCIMConversation conversation = await hello.CreateConversation(memberIdList, name: name, unique: true); - - LCIMClient world = new LCIMClient("world"); - await world.Open(); - - world.OnMessage = (conv, message) => { - Console.WriteLine(message); - if (message is LCIMTypedMessage typedMessage) { - Console.WriteLine(typedMessage["k1"]); - Console.WriteLine(typedMessage["k2"]); - Console.WriteLine(typedMessage["k3"]); - } - }; - - //LCIMTextMessage textMessage = new LCIMTextMessage("hello, world"); - //await conversation.Send(textMessage); - - //await Task.Delay(3000); - - //LCIMTextMessage newMessage = new LCIMTextMessage("hello, code"); - //await conversation.Update(textMessage, newMessage); - - //// 设置成员的角色 - //await conversation.UpdateMemberRole("world", LCIMConversationMemberInfo.Manager); - - //List members = await conversation.GetAllMemberInfo(); - - //foreach (LCIMConversationMemberInfo member in members) { - // Console.WriteLine(member.MemberId); - //} - - LCIMTextMessage textMessage = new LCIMTextMessage("hello, world"); - textMessage["k1"] = 123; - textMessage["k2"] = "abc"; - textMessage["k3"] = true; - await conversation.Send(textMessage); - - //LCFile file = new LCFile("avatar", "../../../Storage.Test/assets/hello.png"); - //file.MetaData["width"] = 225; - //file.MetaData["height"] = 225; - //file.MetaData["size"] = 1186; - //await file.Save(); - //LCIMImageMessage imageMessage = new LCIMImageMessage(file); - //await conversation.Send(imageMessage); - - //LCGeoPoint location = new LCGeoPoint(11, 12); - //LCIMLocationMessage locationMessage = new LCIMLocationMessage(location); - //await conversation.Send(locationMessage); - } - } -} diff --git a/Test/RealtimeConsole/Properties/AssemblyInfo.cs b/Test/RealtimeConsole/Properties/AssemblyInfo.cs deleted file mode 100644 index 4a11289..0000000 --- a/Test/RealtimeConsole/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; - -// Information about this assembly is defined by the following attributes. -// Change them to the values specific to your project. - -[assembly: AssemblyTitle("RealtimeConsole")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("")] -[assembly: AssemblyCopyright("")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". -// The form "{Major}.{Minor}.*" will automatically update the build and revision, -// and "{Major}.{Minor}.{Build}.*" will update just the revision. - -[assembly: AssemblyVersion("1.0.*")] - -// The following attributes are used to specify the signing key for the assembly, -// if desired. See the Mono documentation for more information about signing. - -//[assembly: AssemblyDelaySign(false)] -//[assembly: AssemblyKeyFile("")] diff --git a/Test/RealtimeConsole/RealtimeConsole.csproj b/Test/RealtimeConsole/RealtimeConsole.csproj deleted file mode 100644 index a31c966..0000000 --- a/Test/RealtimeConsole/RealtimeConsole.csproj +++ /dev/null @@ -1,73 +0,0 @@ - - - - Debug - AnyCPU - {7C563EE9-D130-4681-88B8-4523A31F6017} - Exe - RealtimeConsole - RealtimeConsole - v4.7.2 - 0.1.0 - - - true - full - false - bin\Debug - DEBUG; - prompt - 4 - true - - - true - bin\Release - prompt - 4 - true - - - - - ..\..\packages\System.Buffers.4.4.0\lib\netstandard2.0\System.Buffers.dll - - - ..\..\packages\System.Numerics.Vectors.4.4.0\lib\net46\System.Numerics.Vectors.dll - - - - - ..\..\packages\System.Runtime.CompilerServices.Unsafe.4.5.2\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll - - - ..\..\packages\System.Memory.4.5.2\lib\netstandard2.0\System.Memory.dll - - - ..\..\packages\Google.Protobuf.3.11.4\lib\net45\Google.Protobuf.dll - - - - - - - - - - {758DE75D-37D7-4392-B564-9484348B505C} - Common - - - {7084C9BD-6D26-4803-9E7F-A6D2E55D963A} - Realtime - - - {4DCA6CCF-DBD2-4184-9A7E-8775A024D194} - Storage - - - - - - - \ No newline at end of file diff --git a/Test/RealtimeConsole/packages.config b/Test/RealtimeConsole/packages.config deleted file mode 100644 index 0da1e27..0000000 --- a/Test/RealtimeConsole/packages.config +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file