internal static void SetUp() { LCLogger.LogDelegate += Print; LCApplication.Initialize("3zWMOXuO9iSdnjXM942i6DdI-gzGzoHsz", "bkwiNq4Tj417eUaHlTWS5sPm", "https://3zwmoxuo.lc-cn-n1-shared.com"); }
public override void SetUp() { base.SetUp(); LCApplication.Initialize(AppId, AppKey, AppServer, MasterKey); LCApplication.UseMasterKey = true; leaderboardName = $"Leaderboard_{DateTimeOffset.Now.DayOfYear}"; }
void Awake() { instance = this; LCApplication.Initialize("iApERatxkBFcbuIOjnQrb8eK-gzGzoHsz", "oS2bLixYBn7E7ftuhcrOWaJJ", "https://iaperatx.lc-cn-n1-shared.com"); LCLogger.LogDelegate = (LCLogLevel level, string message) => { switch (level) { case LCLogLevel.Debug: Debug.Log(message); break; case LCLogLevel.Warn: Debug.LogWarning(message); break; case LCLogLevel.Error: Debug.LogError(message); break; default: break; } }; }
public async Task Setup() { LCLogger.LogDelegate += Print; LCApplication.Initialize("ikGGdRE2YcVOemAaRbgp1xGJ-gzGzoHsz", "NUKmuRbdAhg1vrb2wexYo1jo", "https://ikggdre2.lc-cn-n1-shared.com"); LCObject.RegisterSubclass("Account", () => new Account()); LCQuery <LCObject> query = new LCQuery <LCObject>("Account"); query.WhereGreaterThan("balance", 100); liveQuery = await query.Subscribe(); }
static void Main(string[] args) { WriteLine("Hello World!"); SingleThreadSynchronizationContext.Run(async() => { LCLogger.LogDelegate += Print; LCApplication.Initialize("ikGGdRE2YcVOemAaRbgp1xGJ-gzGzoHsz", "NUKmuRbdAhg1vrb2wexYo1jo", "https://ikggdre2.lc-cn-n1-shared.com"); LCIMClient client = new LCIMClient("lean") { OnPaused = () => { WriteLine("~~~~~~~~~~~~~~~ disconnected"); }, OnResume = () => { WriteLine("~~~~~~~~~~~~~~~ reconnected"); } }; await client.Open(); 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}"); } }); }
static void Main(string[] args) { WriteLine("Hello World!"); SingleThreadSynchronizationContext.Run(async() => { LCLogger.LogDelegate += Print; LCApplication.Initialize("ikGGdRE2YcVOemAaRbgp1xGJ-gzGzoHsz", "NUKmuRbdAhg1vrb2wexYo1jo", "https://ikggdre2.lc-cn-n1-shared.com"); await LCUser.Login("hello", "world"); LCQuery <LCUser> userQuery = LCUser.GetQuery(); userQuery.WhereEqualTo("username", "hello"); LCLiveQuery userLiveQuery = await userQuery.Subscribe(); userLiveQuery.OnLogin = (user) => { WriteLine($"login: {user.Username}"); }; LCQuery <LCObject> query = new LCQuery <LCObject>("Account"); query.WhereGreaterThan("balance", 100); LCLiveQuery liveQuery = await query.Subscribe(); liveQuery.OnCreate = (obj) => { WriteLine($"create: {obj}"); }; liveQuery.OnUpdate = (obj, keys) => { WriteLine($"update: {obj}"); WriteLine(keys.Count); }; liveQuery.OnDelete = (objId) => { WriteLine($"delete: {objId}"); }; liveQuery.OnEnter = (obj, keys) => { WriteLine($"enter: {obj}"); WriteLine(keys.Count); }; liveQuery.OnLeave = (obj, keys) => { WriteLine($"leave: {obj}"); WriteLine(keys.Count); }; }); }
/// <summary> /// Initializes the engine with the given services. /// </summary> /// <param name="services"></param> public static void Initialize(IServiceCollection services) { // 获取环境变量 LCLogger.Debug("-------------------------------------------------"); PrintEnvironmentVar("LEANCLOUD_APP_ID"); PrintEnvironmentVar("LEANCLOUD_APP_KEY"); PrintEnvironmentVar("LEANCLOUD_APP_MASTER_KEY"); PrintEnvironmentVar("LEANCLOUD_APP_HOOK_KEY"); PrintEnvironmentVar("LEANCLOUD_API_SERVER"); PrintEnvironmentVar("LEANCLOUD_APP_PROD"); PrintEnvironmentVar("LEANCLOUD_APP_ENV"); PrintEnvironmentVar("LEANCLOUD_APP_INSTANCE"); PrintEnvironmentVar("LEANCLOUD_REGION"); PrintEnvironmentVar("LEANCLOUD_APP_ID"); PrintEnvironmentVar("LEANCLOUD_APP_DOMAIN"); PrintEnvironmentVar("LEANCLOUD_APP_PORT"); LCLogger.Debug("-------------------------------------------------"); LCApplication.Initialize(Environment.GetEnvironmentVariable("LEANCLOUD_APP_ID"), Environment.GetEnvironmentVariable("LEANCLOUD_APP_KEY"), Environment.GetEnvironmentVariable("LEANCLOUD_API_SERVER"), Environment.GetEnvironmentVariable("LEANCLOUD_APP_MASTER_KEY")); LCCore.HttpClient.AddAddtionalHeader(LCHookKeyName, Environment.GetEnvironmentVariable("LEANCLOUD_APP_HOOK_KEY")); Assembly assembly = Assembly.GetCallingAssembly(); ClassHooks = assembly.GetTypes() .SelectMany(t => t.GetMethods()) .Where(m => m.GetCustomAttribute <LCEngineClassHookAttribute>() != null) .ToDictionary(mi => { LCEngineClassHookAttribute attr = mi.GetCustomAttribute <LCEngineClassHookAttribute>(); switch (attr.HookType) { case LCEngineObjectHookType.BeforeSave: return($"{BeforeSave}{attr.ClassName}"); case LCEngineObjectHookType.AfterSave: return($"{AfterSave}{attr.ClassName}"); case LCEngineObjectHookType.BeforeUpdate: return($"{BeforeUpdate}{attr.ClassName}"); case LCEngineObjectHookType.AfterUpdate: return($"{AfterUpdate}{attr.ClassName}"); case LCEngineObjectHookType.BeforeDelete: return($"{BeforeDelete}{attr.ClassName}"); case LCEngineObjectHookType.AfterDelete: return($"{AfterDelete}{attr.ClassName}"); default: throw new Exception($"Error hook type: {attr.HookType}"); } }); UserHooks = assembly.GetTypes() .SelectMany(t => t.GetMethods()) .Where(m => m.GetCustomAttribute <LCEngineUserHookAttribute>() != null) .ToDictionary(mi => { LCEngineUserHookAttribute attr = mi.GetCustomAttribute <LCEngineUserHookAttribute>(); switch (attr.HookType) { case LCEngineUserHookType.OnSMSVerified: return(OnSMSVerified); case LCEngineUserHookType.OnEmailVerified: return(OnEmailVerified); case LCEngineUserHookType.OnLogin: return(OnLogin); default: throw new Exception($"Error hook type: {attr.HookType}"); } }); Functions = assembly.GetTypes() .SelectMany(t => t.GetMethods()) .Where(m => m.GetCustomAttribute <LCEngineFunctionAttribute>() != null) .ToDictionary(mi => mi.GetCustomAttribute <LCEngineFunctionAttribute>().FunctionName); assembly.GetTypes() .SelectMany(t => t.GetMethods()) .Where(m => m.GetCustomAttribute <LCEngineRealtimeHookAttribute>() != null) .ToDictionary(mi => { LCEngineRealtimeHookAttribute attr = mi.GetCustomAttribute <LCEngineRealtimeHookAttribute>(); switch (attr.HookType) { case LCEngineRealtimeHookType.ClientOnline: return(ClientOnline); case LCEngineRealtimeHookType.ClientOffline: return(ClientOffline); case LCEngineRealtimeHookType.MessageSent: return(MessageSent); case LCEngineRealtimeHookType.MessageReceived: return(MessageReceived); case LCEngineRealtimeHookType.ReceiversOffline: return(ReceiversOffline); case LCEngineRealtimeHookType.MessageUpdate: return(MessageUpdate); case LCEngineRealtimeHookType.ConversationStart: return(ConversationStart); case LCEngineRealtimeHookType.ConversationStarted: return(ConversationStarted); case LCEngineRealtimeHookType.ConversationAdd: return(ConversationAdd); case LCEngineRealtimeHookType.ConversationAdded: return(ConversationAdded); case LCEngineRealtimeHookType.ConversationRemove: return(ConversationRemove); case LCEngineRealtimeHookType.ConversationRemoved: return(ConversationRemoved); case LCEngineRealtimeHookType.ConversationUpdate: return(ConversationUpdate); default: throw new Exception($"Error hook type: {attr.HookType}"); } }) .ToList() .ForEach(item => { Functions.TryAdd(item.Key, item.Value); }); services.AddCors(options => { options.AddPolicy(LCEngineCORS, builder => { builder.AllowAnyOrigin() .WithMethods(LCEngineCORSMethods) .WithHeaders(LCEngineCORSHeaders) .SetPreflightMaxAge(TimeSpan.FromSeconds(86400)); }); }); }