Example #1
0
        public async Task Ping()
        {
            Dictionary <string, object> response = await LCCloud.Run("ping");

            TestContext.WriteLine(response["result"]);
            Assert.AreEqual(response["result"], "pong");
        }
Example #2
0
        public async Task <object> RPC(string funcName, JsonElement body)
        {
            try {
                LCLogger.Debug($"RPC: {funcName}");
                LCLogger.Debug(body.ToString());

                if (Functions.TryGetValue(funcName, out MethodInfo mi))
                {
                    LCEngine.InitRequestContext(Request);

                    object[] ps     = ParseParameters(mi, body);
                    object   result = await LCEngine.Invoke(mi, ps);

                    if (result != null)
                    {
                        return(new Dictionary <string, object> {
                            { "result", LCCloud.Encode(result) }
                        });
                    }
                }
                return(body);
            } catch (Exception e) {
                return(StatusCode(500, e.Message));
            }
        }
Example #3
0
        public async Task Call()
        {
            Dictionary <string, object> response = await LCCloud.Run("hello", parameters : new Dictionary <string, object> {
                { "name", "world" }
            });

            TestContext.WriteLine(response["result"]);
            Assert.AreEqual(response["result"], "hello, world");
        }
Example #4
0
        public async Task Hello()
        {
            string result = await LCCloud.Run <string>("hello", new Dictionary <string, object> {
                { "name", "world" }
            });

            TestContext.WriteLine(result);
            Assert.AreEqual(result, "hello, world");
        }
Example #5
0
        public async Task RPC()
        {
            List <object> result = await LCCloud.RPC("getTycoonList") as List <object>;

            IEnumerable <LCObject> tycoonList = result.Cast <LCObject>();

            foreach (LCObject item in tycoonList)
            {
                TestContext.WriteLine(item.ObjectId);
                Assert.NotNull(item.ObjectId);
            }
        }
        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));
            }
        }
Example #7
0
        public async Task GetObjectMap()
        {
            object response = await LCCloud.RPC("getObjectMap");

            Dictionary <string, object> dict = response as Dictionary <string, object>;

            TestContext.WriteLine(dict.Count);
            Assert.Greater(dict.Count, 0);
            foreach (KeyValuePair <string, object> kv in dict)
            {
                LCObject obj = kv.Value as LCObject;
                Assert.AreEqual(kv.Key, obj.ObjectId);
            }
        }
Example #8
0
        public async Task GetObject()
        {
            LCObject hello = new LCObject("Hello");
            await hello.Save();

            object reponse = await LCCloud.RPC("getObject", new Dictionary <string, object> {
                { "className", "Hello" },
                { "id", hello.ObjectId }
            });

            LCObject obj = reponse as LCObject;

            Assert.AreEqual(obj.ObjectId, hello.ObjectId);
        }
Example #9
0
        public async Task GetObjects()
        {
            object response = await LCCloud.RPC("getObjects");

            List <object>          list    = response as List <object>;
            IEnumerable <LCObject> objects = list.Cast <LCObject>();

            TestContext.WriteLine(objects.Count());
            Assert.Greater(objects.Count(), 0);
            foreach (LCObject obj in objects)
            {
                int balance = (int)obj["balance"];
                Assert.Greater(balance, 100);
            }
        }
Example #10
0
 public async Task CallWithoutParams()
 {
     await LCCloud.Run("hello");
 }