Example #1
0
        public static async Task <object> RPC(string name, Dictionary <string, object> parameters = null)
        {
            string path = $"call/{name}";
            Dictionary <string, object> response = await LeanCloud.HttpClient.Post <Dictionary <string, object> >(path, data : parameters);

            return(LCDecoder.Decode(response["result"]));
        }
Example #2
0
        internal static LCObjectData Decode(IDictionary dict)
        {
            if (dict == null)
            {
                return(null);
            }
            LCObjectData objectData = new LCObjectData();

            foreach (DictionaryEntry kv in dict)
            {
                string key   = kv.Key.ToString();
                object value = kv.Value;
                if (key == "className")
                {
                    objectData.ClassName = value.ToString();
                }
                else if (key == "objectId")
                {
                    objectData.ObjectId = value.ToString();
                }
                else if (key == "createdAt" && DateTime.TryParse(value.ToString(), out DateTime createdAt))
                {
                    objectData.CreatedAt = createdAt;
                }
                else if (key == "updatedAt" && DateTime.TryParse(value.ToString(), out DateTime updatedAt))
                {
                    objectData.UpdatedAt = updatedAt;
                }
                else
                {
                    objectData.CustomPropertyDict[key] = LCDecoder.Decode(value);
                }
            }
            return(objectData);
        }
Example #3
0
        private static object[] ParseParameters(MethodInfo mi, JsonElement body)
        {
            Dictionary <string, object> parameters = LCEngine.Decode(body);
            List <object> ps = new List <object>();

            if (mi.GetParameters().Length > 0)
            {
                if (Array.Exists(mi.GetParameters(),
                                 p => p.GetCustomAttribute <LCEngineFunctionParamAttribute>() != null))
                {
                    // 如果包含 LCEngineFunctionParamAttribute 的参数,则按照配对方式传递参数
                    foreach (ParameterInfo pi in mi.GetParameters())
                    {
                        LCEngineFunctionParamAttribute attr = pi.GetCustomAttribute <LCEngineFunctionParamAttribute>();
                        if (attr != null)
                        {
                            string paramName = attr.ParamName;
                            ps.Add(parameters[paramName]);
                        }
                    }
                }
                else
                {
                    ps.Add(LCDecoder.Decode(LCEngine.Decode(body)));
                }
            }

            return(ps.ToArray());
        }
        internal static LCLeaderboardArchive Parse(IDictionary <string, object> data)
        {
            LCLeaderboardArchive archive = new LCLeaderboardArchive();

            if (data.TryGetValue("statisticName", out object statisticName))
            {
                archive.StatisticName = statisticName as string;
            }
            if (data.TryGetValue("version", out object version))
            {
                archive.Version = Convert.ToInt32(version);
            }
            if (data.TryGetValue("status", out object status))
            {
                archive.Status = status as string;
            }
            if (data.TryGetValue("url", out object url))
            {
                archive.Url = url as string;
            }
            if (data.TryGetValue("activatedAt", out object activatedAt) &&
                activatedAt is System.Collections.IDictionary actDt)
            {
                archive.ActivatedAt = LCDecoder.DecodeDate(actDt);
            }
            if (data.TryGetValue("deactivatedAt", out object deactivatedAt) &&
                deactivatedAt is System.Collections.IDictionary deactDt)
            {
                archive.DeactivatedAt = LCDecoder.DecodeDate(deactDt);
            }
            return(archive);
        }
Example #5
0
 private void Merge(Dictionary <string, object> data)
 {
     if (data.TryGetValue("statisticName", out object statisticName))
     {
         StatisticName = statisticName as string;
     }
     if (data.TryGetValue("order", out object order) &&
         Enum.TryParse(order as string, true, out LCLeaderboardOrder o))
     {
         Order = o;
     }
     if (data.TryGetValue("updateStrategy", out object strategy) &&
         Enum.TryParse(strategy as string, true, out LCLeaderboardUpdateStrategy s))
     {
         UpdateStrategy = s;
     }
     if (data.TryGetValue("versionChangeInterval", out object interval) &&
         Enum.TryParse(interval as string, true, out LCLeaderboardVersionChangeInterval i))
     {
         VersionChangeInterval = i;
     }
     if (data.TryGetValue("version", out object version))
     {
         Version = Convert.ToInt32(version);
     }
     if (data.TryGetValue("createdAt", out object createdAt) &&
         createdAt is DateTime dt)
     {
         CreatedAt = dt;
     }
     if (data.TryGetValue("expiredAt", out object expiredAt) &&
         expiredAt is IDictionary dict)
     {
         NextResetAt = LCDecoder.DecodeDate(dict);
     }
 }