static int _m_Add(RealStatePtr L) { try { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); SimpleJson.JsonObject gen_to_be_invoked = (SimpleJson.JsonObject)translator.FastGetCSObj(L, 1); int gen_param_count = LuaAPI.lua_gettop(L); if (gen_param_count == 2 && translator.Assignable <System.Collections.Generic.KeyValuePair <string, object> >(L, 2)) { System.Collections.Generic.KeyValuePair <string, object> _item; translator.Get(L, 2, out _item); gen_to_be_invoked.Add(_item); return(0); } if (gen_param_count == 3 && (LuaAPI.lua_isnil(L, 2) || LuaAPI.lua_type(L, 2) == LuaTypes.LUA_TSTRING) && translator.Assignable <object>(L, 3)) { string _key = LuaAPI.lua_tostring(L, 2); object _value = translator.GetObject(L, 3, typeof(object)); gen_to_be_invoked.Add(_key, _value); return(0); } } catch (System.Exception gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + gen_e)); } return(LuaAPI.luaL_error(L, "invalid arguments to SimpleJson.JsonObject.Add!")); }
private void OnDownloadMapAndVoiceData(object objData, ResponseData result) { ClientSocket cs = null; SslAppData sad = new SslAppData(); try { SimpleJson.JsonObject jsonPathData = new SimpleJson.JsonObject(); jsonPathData.Add("op", "UPLOAD_PATH_DATA"); jsonPathData.Add("data", (string)objData); //jsonPathData.Add("data", "no actual data."); string strJsonText = jsonPathData.ToString(); cs = Connect(); if (cs == null) { result.Code = ResponseData.RESP_SERVER_UNREACHABLE; result.Msg = TypeAndParameter.STR_CONNECT_WITH_SERVER_FAILED; return; } // 发送数据 sad.SetType(SslAppData.APP_TYPE_PLAIN_JSON); byte[] allBytes = System.Text.Encoding.Default.GetBytes(strJsonText); if (allBytes.Length > SslAppData.SSL_APP_CONTENT_MAX_SIZE) { sad.SetFirst(true); sad.SetLast(false); sad.SetData(allBytes, 0, SslAppData.SSL_APP_CONTENT_MAX_SIZE); cs.Send(sad); sad.SetFirst(false); int i = SslAppData.SSL_APP_CONTENT_MAX_SIZE; while (i < allBytes.Length) { if (allBytes.Length - i <= SslAppData.SSL_APP_CONTENT_MAX_SIZE) { sad.SetLast(true); sad.SetData(allBytes, i); i += allBytes.Length - i; } else { sad.SetData(allBytes, i, SslAppData.SSL_APP_CONTENT_MAX_SIZE); i += SslAppData.SSL_APP_CONTENT_MAX_SIZE; } cs.Send(sad); } } else { sad.SetData(allBytes); //sad.SetData(System.Text.Encoding.UTF8.GetBytes(strJsonText)); cs.Send(sad); } // 接收数据 cs.Recv(sad); byte[] jsonData = sad.GetData(); //strJsonText = System.Text.Encoding.Default.GetString(jsonData); strJsonText = System.Text.Encoding.UTF8.GetString(jsonData); var rsp = (IDictionary <string, object>)SimpleJson.SimpleJson.DeserializeObject(strJsonText); if ("AE_SUCCESS" == (rsp["err"] as string)) { result.Code = ResponseData.RESP_SUCCESS; result.Msg = TypeAndParameter.STR_UPLOAD_PATH_DATA_FINISHED; } else { result.Msg = rsp["msg"] as string; } } catch (Exception e) { XxdwDebugger.LogError(e.StackTrace); } finally { if (cs != null) { cs.Close(); } } }
internal virtual object ProcessResponse(GithubApiVersion version, FluentHttpAsyncResult asyncResult, Stream responseStream, Type resultType, out Exception exception) { // FluentHttpRequest has ended. // don't throw exception in this method but send it as an out parameter. // we can reuse this method for async methods too. // so the caller of this method decides whether to throw or not. exception = asyncResult.Exception; if (exception != null) { if (responseStream != null) responseStream.Dispose(); return null; } if (asyncResult.IsCancelled) { exception = new NotImplementedException(); return null; } var response = asyncResult.Response; // async request completed if (response.HttpWebResponse.StatusCode == HttpStatusCode.BadGateway) { if (responseStream != null) responseStream.Dispose(); exception = asyncResult.InnerException; return null; } var httpWebRequestHeaders = response.HttpWebResponse.Headers; var headers = new SimpleJson.JsonObject(); foreach (var headerKey in httpWebRequestHeaders.AllKeys) headers.Add(headerKey, httpWebRequestHeaders[headerKey]); var result = new SimpleJson.JsonObject { {"code", (int) response.HttpWebResponse.StatusCode}, {"headers", headers} }; if (response.Request.GetMethod().Equals("HEAD", StringComparison.OrdinalIgnoreCase)) { return result; } // convert the response stream to string. responseStream.Seek(0, SeekOrigin.Begin); switch (response.HttpWebResponse.StatusCode) { case HttpStatusCode.Created: case HttpStatusCode.OK: try { if (headers.ContainsKey("X-GitHub-Blob-Sha")) { // responseStream is a binary data // responseStream is always memory stream var ms = (MemoryStream)responseStream; var data = ms.ToArray(); ms.Dispose(); result["body"] = data; } else { // responseStream is a string. var responseString = FluentHttpRequest.ToString(responseStream); // we got the response string already, so dispose the memory stream. responseStream.Dispose(); result["body"] = (resultType == null) ? JsonSerializer.Current.DeserializeObject(responseString) : JsonSerializer.Current.DeserializeObject(responseString, resultType); } return result; } catch (Exception ex) { exception = ex; return null; } case HttpStatusCode.NoContent: responseStream.Dispose(); return result; default: { var responseString = FluentHttpRequest.ToString(responseStream); responseStream.Dispose(); // Github api responded with an error. object json; exception = ExceptionFactory.GetException(responseString, version, response, out json); result["body"] = json; return result; } } }