static LCObject DecodeObject(IDictionary dict) { string className = dict["className"].ToString(); LCObject obj = LCObject.Create(className); LCObjectData objectData = LCObjectData.Decode(dict as Dictionary <string, object>); obj.Merge(objectData); return(obj); }
private static async Task <object> Invoke(MethodInfo mi, Dictionary <string, object> dict) { LCObjectData objectData = LCObjectData.Decode(dict["object"] as Dictionary <string, object>); objectData.ClassName = "_User"; LCObject user = LCObject.Create("_User"); user.Merge(objectData); return(await LCEngine.Invoke(mi, new object[] { user }) as LCObject); }
public async Task <object> Hook(string className, string hookName, JsonElement body) { try { LCLogger.Debug($"Hook: {className}#{hookName}"); LCLogger.Debug(body.ToString()); LCEngine.CheckHookKey(Request); string classHookName = GetClassHookName(className, hookName); if (ClassHooks.TryGetValue(classHookName, out MethodInfo mi)) { Dictionary <string, object> data = LCEngine.Decode(body); LCObjectData objectData = LCObjectData.Decode(data["object"] as Dictionary <string, object>); objectData.ClassName = className; LCObject obj = LCObject.Create(className); obj.Merge(objectData); // 避免死循环 if (hookName.StartsWith("before")) { obj.DisableBeforeHook(); } else { obj.DisableAfterHook(); } LCEngine.InitRequestContext(Request); LCUser user = null; if (data.TryGetValue("user", out object userObj) && userObj != null) { user = new LCUser(); user.Merge(LCObjectData.Decode(userObj as Dictionary <string, object>)); LCEngineRequestContext.CurrentUser = user; } LCObject result = await LCEngine.Invoke(mi, new object[] { obj }) as LCObject; if (result != null) { return(LCCloud.Encode(result)); } } return(body); } catch (Exception e) { return(StatusCode(500, e.Message)); } }
private static bool TryGetObject(Dictionary <string, object> data, out LCObject obj) { if (!data.TryGetValue("object", out object o) || !(o is Dictionary <string, object> dict)) { obj = null; return(false); } LCObjectData objectData = LCObjectData.Decode(dict); obj = LCObject.Create(dict["className"] as string); obj.Merge(objectData); return(true); }