/// <summary>
        /// Certaines réponses (body) peuvent contenir une erreur et pourtant renvoyer un code http 200
        /// </summary>
        /// <param name="retourWS"></param>
        /// <returns></returns>
        public static RESTErrorDTO CheckBodyIfHaveError(Newtonsoft.Json.Linq.JToken retourWS)
        {
            JToken jtError, jtErrorCode, jtErrorMessage, jtHttpBody;

            jtError        = retourWS.SelectToken("error");
            jtErrorCode    = retourWS.SelectToken("ErrorCode");
            jtErrorMessage = retourWS.SelectToken("ErrorMessage");
            jtHttpBody     = retourWS.SelectToken("HttpBody");

            if (jtErrorCode != null || jtErrorMessage != null || jtHttpBody != null)
            {
                int    code    = 0;
                string message = string.Empty;

                if (jtError != null)
                {
                    // message = ToolsJsonNet.GetValue<string>(jtError);
                    throw new Exception("check jtError");
                }
                if (jtErrorCode != null)
                {
                    // code = ToolsJsonNet.GetValue<int>(jtErrorCode);
                    throw new Exception("check jtErrorCode");
                }
                if (jtErrorMessage != null)
                {
                    // message = ToolsJsonNet.GetValue<string>(jtErrorMessage).Trim();
                    throw new Exception("check jtErrorMessage");
                }
                if (jtHttpBody != null)
                {
                    throw new Exception("check jtHttpBody");

                    /*
                     * if (!String.IsNullOrEmpty(message) && ToolsJsonNet.GetValue<string>(jtHttpBody).Trim().Length > 0)
                     * {
                     *  message += Environment.NewLine;
                     * }
                     *
                     * message += ToolsJsonNet.GetValue<string>(jtHttpBody).Replace("{", string.Empty)
                     *                                      .Replace("}", string.Empty)
                     *                                      .Replace("\\\"", string.Empty)
                     *                                      .Replace("\"", string.Empty)
                     *                                      .Replace("  ", " ").Replace("  ", " ")
                     *                                      .Trim();
                     */
                }

                return(new RESTErrorDTO(RESTErrorType.InBody, code, message));
            }
            else
            {
                return(null);
            }
        }
    static int SelectToken(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 2 && TypeChecker.CheckTypes(L, 1, typeof(Newtonsoft.Json.Linq.JToken), typeof(string)))
            {
                Newtonsoft.Json.Linq.JToken obj = (Newtonsoft.Json.Linq.JToken)ToLua.ToObject(L, 1);
                string arg0 = ToLua.ToString(L, 2);
                Newtonsoft.Json.Linq.JToken o = obj.SelectToken(arg0);
                ToLua.PushObject(L, o);
                return(1);
            }
            else if (count == 3 && TypeChecker.CheckTypes(L, 1, typeof(Newtonsoft.Json.Linq.JToken), typeof(string), typeof(bool)))
            {
                Newtonsoft.Json.Linq.JToken obj = (Newtonsoft.Json.Linq.JToken)ToLua.ToObject(L, 1);
                string arg0 = ToLua.ToString(L, 2);
                bool   arg1 = LuaDLL.lua_toboolean(L, 3);
                Newtonsoft.Json.Linq.JToken o = obj.SelectToken(arg0, arg1);
                ToLua.PushObject(L, o);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: Newtonsoft.Json.Linq.JToken.SelectToken"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Esempio n. 3
0
    static int SelectToken(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 2)
            {
                Newtonsoft.Json.Linq.JToken obj = (Newtonsoft.Json.Linq.JToken)ToLua.CheckObject <Newtonsoft.Json.Linq.JToken>(L, 1);
                string arg0 = ToLua.CheckString(L, 2);
                Newtonsoft.Json.Linq.JToken o = obj.SelectToken(arg0);
                ToLua.PushObject(L, o);
                return(1);
            }
            else if (count == 3)
            {
                Newtonsoft.Json.Linq.JToken obj = (Newtonsoft.Json.Linq.JToken)ToLua.CheckObject <Newtonsoft.Json.Linq.JToken>(L, 1);
                string arg0 = ToLua.CheckString(L, 2);
                bool   arg1 = LuaDLL.luaL_checkboolean(L, 3);
                Newtonsoft.Json.Linq.JToken o = obj.SelectToken(arg0, arg1);
                ToLua.PushObject(L, o);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: Newtonsoft.Json.Linq.JToken.SelectToken"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Esempio n. 4
0
        //处理"msg_attach"值,发送消息的时候需要把json object 转换成string
        internal static void ConvertAttachObjectToString(Newtonsoft.Json.Linq.JToken token)
        {
            var attachmentToken = token.SelectToken(NIMIMMessage.AttachmentPath);

            if (attachmentToken == null)
            {
                return;
            }
            if (attachmentToken.Type == Newtonsoft.Json.Linq.JTokenType.Object)
            {
                var attachValue = attachmentToken.ToString(Formatting.None);
                attachmentToken.Replace(attachValue);
            }
        }
Esempio n. 5
0
        public string CurrencyConversion(decimal amount, string fromCurrency, string toCurrency)
        {
            string url = string.Format(urlPattern, fromCurrency, toCurrency);

            using (var wc = new WebClient())
            {
                var json = wc.DownloadString(url);

                Newtonsoft.Json.Linq.JToken token = Newtonsoft.Json.Linq.JObject.Parse(json);
                decimal exchangeRate = (decimal)token.SelectToken("rate");

                return(Math.Round(amount * exchangeRate, 2).ToString());
            }
        }
Esempio n. 6
0
 public static T GetValue <T>(Newtonsoft.Json.Linq.JToken jtoken, string path)
 {
     return(GetValue <T>(jtoken.SelectToken(path)));
 }