2020-04-30 13:34:41 +08:00
|
|
|
|
using System;
|
2020-06-24 12:15:19 +08:00
|
|
|
|
using System.Threading.Tasks;
|
2020-04-30 13:35:34 +08:00
|
|
|
|
using LeanCloud;
|
|
|
|
|
using LeanCloud.Realtime;
|
|
|
|
|
|
|
|
|
|
using static System.Console;
|
2020-04-30 13:34:41 +08:00
|
|
|
|
|
|
|
|
|
namespace RealtimeApp {
|
|
|
|
|
class Program {
|
|
|
|
|
static void Main(string[] args) {
|
2020-06-24 12:15:19 +08:00
|
|
|
|
WriteLine("Hello World!");
|
2020-04-30 13:35:34 +08:00
|
|
|
|
|
|
|
|
|
SingleThreadSynchronizationContext.Run(async () => {
|
|
|
|
|
LCLogger.LogDelegate += Print;
|
|
|
|
|
LCApplication.Initialize("ikGGdRE2YcVOemAaRbgp1xGJ-gzGzoHsz", "NUKmuRbdAhg1vrb2wexYo1jo", "https://ikggdre2.lc-cn-n1-shared.com");
|
|
|
|
|
|
2020-06-24 12:15:19 +08:00
|
|
|
|
LCIMClient client = new LCIMClient("lean") {
|
|
|
|
|
OnPaused = () => {
|
|
|
|
|
WriteLine("~~~~~~~~~~~~~~~ disconnected");
|
|
|
|
|
},
|
|
|
|
|
OnResume = () => {
|
|
|
|
|
WriteLine("~~~~~~~~~~~~~~~ reconnected");
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-04-30 13:35:34 +08:00
|
|
|
|
await client.Open();
|
2020-06-24 12:15:19 +08:00
|
|
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
|
while (count < 2) {
|
|
|
|
|
WriteLine($"pause : {count}");
|
|
|
|
|
|
|
|
|
|
await Task.Delay(5 * 1000);
|
|
|
|
|
LCRealtime.Pause();
|
|
|
|
|
|
|
|
|
|
await Task.Delay(5 * 1000);
|
|
|
|
|
LCRealtime.Resume();
|
|
|
|
|
|
|
|
|
|
await Task.Delay(5 * 1000);
|
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
await client.Close();
|
|
|
|
|
// Done
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
WriteLine($"xxxxxxxxxxxx {e.Message}");
|
|
|
|
|
}
|
2020-04-30 13:35:34 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void Print(LCLogLevel level, string info) {
|
|
|
|
|
switch (level) {
|
|
|
|
|
case LCLogLevel.Debug:
|
|
|
|
|
WriteLine($"[DEBUG] {DateTime.Now} {info}\n");
|
|
|
|
|
break;
|
|
|
|
|
case LCLogLevel.Warn:
|
|
|
|
|
WriteLine($"[WARNING] {DateTime.Now} {info}\n");
|
|
|
|
|
break;
|
|
|
|
|
case LCLogLevel.Error:
|
|
|
|
|
WriteLine($"[ERROR] {DateTime.Now} {info}\n");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
WriteLine(info);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-04-30 13:34:41 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|