* LCApplication.cs:
* LCHttpClient.cs: * LCObject.cs: chore: 调整访问权限
parent
a95977e055
commit
38287c9a9c
|
@ -187,7 +187,6 @@ namespace LeanCloud.Realtime {
|
|||
return;
|
||||
}
|
||||
await Client.MessageController.Read(Id, LastMessage);
|
||||
Unread = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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 {
|
||||
/// <summary>
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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<LCIMOperationFailure>();
|
||||
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;
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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<string> MemberList {
|
||||
get; set;
|
||||
}
|
||||
|
||||
public LCIMOperationFailure(ErrorCommand error) {
|
||||
Code = error.Code;
|
||||
Reason = error.Reason;
|
||||
MemberList = error.Pids.ToList();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,20 +1,11 @@
|
|||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace LeanCloud.Realtime {
|
||||
/// <summary>
|
||||
/// 查询分页结果
|
||||
/// </summary>
|
||||
public class LCIMPageResult {
|
||||
/// <summary>
|
||||
/// 当前分页数据集
|
||||
/// </summary>
|
||||
public ReadOnlyCollection<string> Results {
|
||||
get; internal set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 下次请求的数据
|
||||
/// </summary>
|
||||
public string Next {
|
||||
get; internal set;
|
||||
}
|
|
@ -1,20 +1,13 @@
|
|||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using LeanCloud.Storage;
|
||||
|
||||
namespace LeanCloud.Realtime {
|
||||
/// <summary>
|
||||
/// 部分成功结果
|
||||
/// </summary>
|
||||
public class LCIMPartiallySuccessResult {
|
||||
/// <summary>
|
||||
/// 成功数据集
|
||||
/// </summary>
|
||||
public List<string> SuccessfulClientIdList {
|
||||
get; internal set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 失败原因
|
||||
/// </summary>
|
||||
public List<LCIMOperationFailure> FailureList {
|
||||
get; internal set;
|
||||
}
|
|
@ -1,6 +1,4 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace LeanCloud.Realtime {
|
||||
namespace LeanCloud.Realtime {
|
||||
/// <summary>
|
||||
/// 消息优先级
|
||||
/// </summary>
|
||||
|
@ -42,10 +40,6 @@ namespace LeanCloud.Realtime {
|
|||
get; set;
|
||||
}
|
||||
|
||||
public Dictionary<string, object> PushData {
|
||||
get; set;
|
||||
}
|
||||
|
||||
public static LCIMMessageSendOptions Default = new LCIMMessageSendOptions();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,5 @@
|
|||
<Folder Include="Signature\" />
|
||||
<Folder Include="Internal\Controller\" />
|
||||
<Folder Include="Internal\Connection\" />
|
||||
<Folder Include="Internal\Protocol\" />
|
||||
<Folder Include="Result\" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace LeanCloud.Realtime {
|
||||
/// <summary>
|
||||
/// 操作失败
|
||||
/// </summary>
|
||||
public class LCIMOperationFailure {
|
||||
/// <summary>
|
||||
/// 失败码
|
||||
/// </summary>
|
||||
public int Code {
|
||||
get; set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 失败原因
|
||||
/// </summary>
|
||||
public string Reason {
|
||||
get; set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 失败数据
|
||||
/// </summary>
|
||||
public List<string> IdList {
|
||||
get; set;
|
||||
}
|
||||
|
||||
//public LCIMOperationFailure(ErrorCommand error) {
|
||||
// Code = error.Code;
|
||||
// Reason = error.Reason;
|
||||
// MemberList = error.Pids.ToList();
|
||||
//}
|
||||
}
|
||||
}
|
|
@ -2,9 +2,6 @@
|
|||
using System.Threading.Tasks;
|
||||
|
||||
namespace LeanCloud.Realtime {
|
||||
/// <summary>
|
||||
/// 签名工程接口
|
||||
/// </summary>
|
||||
public interface ILCIMSignatureFactory {
|
||||
/// <summary>
|
||||
/// 登录签名
|
||||
|
|
|
@ -1 +1 @@
|
|||
protoc --proto_path=. --csharp_out=../Internal/Protocol messages2.proto.orig
|
||||
protoc --proto_path=. --csharp_out=. 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
|
||||
|
|
|
@ -67,7 +67,7 @@ namespace LeanCloud.Storage.Internal.Http {
|
|||
throw HandleErrorResponse(response.StatusCode, resultString);
|
||||
}
|
||||
|
||||
internal async Task<T> Post<T>(string path,
|
||||
public async Task<T> Post<T>(string path,
|
||||
Dictionary<string, object> headers = null,
|
||||
Dictionary<string, object> data = null,
|
||||
Dictionary<string, object> queryParams = null) {
|
||||
|
@ -100,7 +100,7 @@ namespace LeanCloud.Storage.Internal.Http {
|
|||
throw HandleErrorResponse(response.StatusCode, resultString);
|
||||
}
|
||||
|
||||
internal async Task<T> Put<T>(string path,
|
||||
public async Task<T> Put<T>(string path,
|
||||
Dictionary<string, object> headers = null,
|
||||
Dictionary<string, object> data = null,
|
||||
Dictionary<string, object> 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),
|
||||
|
|
|
@ -46,9 +46,9 @@ namespace LeanCloud {
|
|||
AppKey = appKey;
|
||||
|
||||
// 注册 LeanCloud 内部子类化类型
|
||||
LCObject.RegisterSubclass<LCUser>(LCUser.CLASS_NAME, () => new LCUser());
|
||||
LCObject.RegisterSubclass<LCRole>(LCRole.CLASS_NAME, () => new LCRole());
|
||||
LCObject.RegisterSubclass<LCFile>(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);
|
||||
|
||||
|
|
|
@ -412,7 +412,7 @@ namespace LeanCloud.Storage {
|
|||
return this;
|
||||
}
|
||||
|
||||
public static void RegisterSubclass<T>(string className, Func<LCObject> constructor) where T : LCObject {
|
||||
public static void RegisterSubclass<T>(string className, Func<T> constructor) where T : LCObject {
|
||||
Type classType = typeof(T);
|
||||
LCSubclassInfo subclassInfo = new LCSubclassInfo(className, classType, constructor);
|
||||
subclassNameDict[className] = subclassInfo;
|
||||
|
|
|
@ -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<string> memberIds) {
|
||||
string sortedMemberIds = string.Empty;
|
||||
if (memberIds != null) {
|
||||
List<string> 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<string> memberIds, string action) {
|
||||
string sortedMemberIds = string.Empty;
|
||||
if (memberIds != null) {
|
||||
List<string> 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<string> memberIds, string action) {
|
||||
string sortedMemberIds = string.Empty;
|
||||
if (memberIds != null) {
|
||||
List<string> 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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<int, int> d = new Dictionary<int, int>();
|
||||
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<int, int> 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<LCIMConversation> 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<string> memberIdList = new List<string> { "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<LCIMConversationMemberInfo> 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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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("")]
|
|
@ -1,73 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{7C563EE9-D130-4681-88B8-4523A31F6017}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>RealtimeConsole</RootNamespace>
|
||||
<AssemblyName>RealtimeConsole</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
||||
<ReleaseVersion>0.1.0</ReleaseVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug</OutputPath>
|
||||
<DefineConstants>DEBUG;</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ExternalConsole>true</ExternalConsole>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release</OutputPath>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ExternalConsole>true</ExternalConsole>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Buffers">
|
||||
<HintPath>..\..\packages\System.Buffers.4.4.0\lib\netstandard2.0\System.Buffers.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Numerics.Vectors">
|
||||
<HintPath>..\..\packages\System.Numerics.Vectors.4.4.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="mscorlib" />
|
||||
<Reference Include="System.Numerics" />
|
||||
<Reference Include="System.Runtime.CompilerServices.Unsafe">
|
||||
<HintPath>..\..\packages\System.Runtime.CompilerServices.Unsafe.4.5.2\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Memory">
|
||||
<HintPath>..\..\packages\System.Memory.4.5.2\lib\netstandard2.0\System.Memory.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Google.Protobuf">
|
||||
<HintPath>..\..\packages\Google.Protobuf.3.11.4\lib\net45\Google.Protobuf.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="LocalSignatureFactory.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Common\Common.csproj">
|
||||
<Project>{758DE75D-37D7-4392-B564-9484348B505C}</Project>
|
||||
<Name>Common</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\Realtime\Realtime.csproj">
|
||||
<Project>{7084C9BD-6D26-4803-9E7F-A6D2E55D963A}</Project>
|
||||
<Name>Realtime</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\Storage\Storage.csproj">
|
||||
<Project>{4DCA6CCF-DBD2-4184-9A7E-8775A024D194}</Project>
|
||||
<Name>Storage</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
|
@ -1,8 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Google.Protobuf" version="3.11.4" targetFramework="net472" />
|
||||
<package id="System.Buffers" version="4.4.0" targetFramework="net472" />
|
||||
<package id="System.Memory" version="4.5.2" targetFramework="net472" />
|
||||
<package id="System.Numerics.Vectors" version="4.4.0" targetFramework="net472" />
|
||||
<package id="System.Runtime.CompilerServices.Unsafe" version="4.5.2" targetFramework="net472" />
|
||||
</packages>
|
Loading…
Reference in New Issue