static int _m_TryGetValue(RealStatePtr L) { try { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); SimpleJson.JsonObject gen_to_be_invoked = (SimpleJson.JsonObject)translator.FastGetCSObj(L, 1); { string _key = LuaAPI.lua_tostring(L, 2); object _value; bool gen_ret = gen_to_be_invoked.TryGetValue(_key, out _value); LuaAPI.lua_pushboolean(L, gen_ret); translator.PushAny(L, _value); return(2); } } catch (System.Exception gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + gen_e)); } }
/// <summary> /// Get Draft Details /// </summary> /// <param name="client">tp! Rest Client</param> /// <returns>Draft Details</returns> public IDictionary <string, object> GetDetails(RestClient client) { dynamic drafts = client.ExecuteRequest(this.Url, RestSharp.Method.GET).ToDictionary(p => p.Key, p => p.Value); SimpleJson.JsonObject data = drafts["draft"]; return(data.ToDictionary(p => p.Key, p => p.Value)); }
public static EtcdResult Parse(string jsonStr) { Object obj; if (!SimpleJson.SimpleJson.TryDeserializeObject(jsonStr, out obj)) { return(null); } SimpleJson.JsonObject jsonObj = (SimpleJson.JsonObject)obj; EtcdResult result = new EtcdResult(); if (jsonObj.ContainsKey("errorCode")) { result.action = "unknown"; result.error = EtcdError.Parse(jsonObj); } else { if (jsonObj.ContainsKey("action")) { result.action = (string)jsonObj["action"]; } if (jsonObj.ContainsKey("node")) { result.node = EtcdResultNode.Parse((SimpleJson.JsonObject)jsonObj["node"]); } if (jsonObj.ContainsKey("prevNode")) { result.prevNode = EtcdResultNode.Parse((SimpleJson.JsonObject)jsonObj["prevNode"]); } } return(result); }
public string eth_submitHashrate(string strHash, string strID) { string strCmd = "{\"jsonrpc\":\"2.0\",\"method\":\"eth_submitHashrate\",\"params\":[\"" + strHash + "\",\"" + strID + "\"],\"id\":73}"; byte[] rgCmd = Encoding.UTF8.GetBytes(strCmd); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(m_strUrl); request.ContentType = "application/json"; request.Method = "POST"; request.ContentLength = rgCmd.Length; Stream strm = request.GetRequestStream(); strm.Write(rgCmd, 0, rgCmd.Length); strm.Close(); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); string strStatus = response.StatusDescription; HttpStatusCode status = response.StatusCode; strm = response.GetResponseStream(); string strContent = ""; using (StreamReader sr = new StreamReader(strm)) { strContent = sr.ReadToEnd(); } SimpleJson.JsonObject json = SimpleJson.SimpleJson.DeserializeObject(strContent) as SimpleJson.JsonObject; if (json.Count == 3) { if (!verifyValue(json, "jsonrpc", "2.0")) { return(json.ToString()); } if (!verifyValue(json, "id", "73")) { return(json.ToString()); } bool?bResult = getValueAsBool(json, "result"); if (bResult.HasValue) { if (bResult.Value) { return("ACCEPTED"); } else { return("REJECTED"); } } } return(json.ToString()); }
private async Task <dynamic> FetchAsync(string jsRequest) { // await Task.Delay(10); //var hello = new { hello = jsRequest }; dynamic response = new SimpleJson.JsonObject(); response.hello = jsRequest; return(response); }
public bool?getValueAsBool(SimpleJson.JsonObject json, string strKey) { object obj = getValue(json, strKey); if (obj.GetType() != typeof(bool)) { return(null); } return((bool)obj); }
/// <summary> /// Serialises key-value dictionary using embedded JSON serialiser with zero dependencies. /// This is using source code from https://github.com/facebook-csharp-sdk/simple-json. /// </summary> /// <param name="dictionary">Dictionary to serialise</param> /// <returns>JSON string</returns> public static string JsonSerialise(this IDictionary <string, object> dictionary) { var sjo = new SimpleJson.JsonObject(); foreach (KeyValuePair <string, object> item in dictionary) { sjo[item.Key] = item.Value; } return(SimpleJson.SimpleJson.SerializeObject(sjo)); }
static int _g_get_IsReadOnly(RealStatePtr L) { try { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); SimpleJson.JsonObject gen_to_be_invoked = (SimpleJson.JsonObject)translator.FastGetCSObj(L, 1); LuaAPI.lua_pushboolean(L, gen_to_be_invoked.IsReadOnly); } catch (System.Exception gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + gen_e)); } return(1); }
public static EtcdError Parse(SimpleJson.JsonObject jsonObj) { EtcdError error = new EtcdError(); error.errorCode = (long)jsonObj["errorCode"]; error.index = (long)jsonObj["index"]; if (jsonObj.ContainsKey("cause")) { error.cause = (string)jsonObj["cause"]; } error.message = (string)jsonObj["message"]; return(error); }
public static JsonData Extract(SimpleJson.JsonObject json) { JsonData root = new JsonData("root"); extract(json, root); if (root.Children.Count == 1) { return(root.Children[0]); } return(root); }
public async Task <IActionResult> Get(string name) { // read notebook if (!name.EndsWith(".notebook.md")) { name = name + ".notebook.md"; } string fileName = _webHostEnvironment.ContentRootPath + "\\..\\notebooks\\" + (name.Replace("..", "").Replace("\\", "-").Replace("/", "")); if (!System.IO.File.Exists(fileName)) { return(new StatusCodeResult(404)); } string content = System.IO.File.ReadAllText(fileName); // extract worker and connector cells string pattern = @"```javascript (worker|connector)[\s\S]*?\n([\s\S]*?\n)```"; var blocks = Regex.Matches(content, pattern); // ensure at least one executable cell is found if (blocks.Count == 0) { return new ObjectResult("No worker or connector cell found in notebook") { StatusCode = 400 } } ; // initialize request dynamic request = new SimpleJson.JsonObject(); dynamic response = request; foreach (var q in Request.Query) { request[q.Key] = q.Value.ToString(); } foreach (Match m in blocks) { string cellContent = m.Groups[2].Value; response = await Execute(cellContent, request); request = response; } return(new JsonResult(response)); }
private object getValue(SimpleJson.JsonObject json, string strKey) { string[] rgstrKeys = json.Keys.ToArray(); object[] rgVal = json.Values.ToArray(); for (int i = 0; i < rgstrKeys.Length; i++) { if (rgstrKeys[i] == strKey) { return(rgVal[i]); } } return(null); }
public IssueItem(SimpleJson.JsonObject obj) { _issueNumber = (int)(long)obj["number"]; _issueSummary = (string)obj["title"]; var user = (SimpleJson.JsonObject)obj["user"]; _openedBy = (string)user["login"]; var assignee = (SimpleJson.JsonObject)obj["assignee"]; if (assignee != null) { _assignedTo = (string)assignee["login"]; } }
static int __CreateInstance(RealStatePtr L) { try { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); if (LuaAPI.lua_gettop(L) == 1) { SimpleJson.JsonObject gen_ret = new SimpleJson.JsonObject(); translator.Push(L, gen_ret); return(1); } } catch (System.Exception gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + gen_e)); } return(LuaAPI.luaL_error(L, "invalid arguments to SimpleJson.JsonObject constructor!")); }
public static SimpleJson.JsonObject StringToJo(string str, bool defaultNull = false) { try { if (!string.IsNullOrEmpty(str)) { SimpleJson.JsonObject jo = SimpleJson.SimpleJson.DeserializeObject <SimpleJson.JsonObject>(str); if (jo != null) { return(jo); } } } catch (Exception e) { Debugger.LogError(string.Format("Can not convert {0} to JsonObject with {1}", str, e)); } return(defaultNull ? null : new SimpleJson.JsonObject()); }
static int _m_Clear(RealStatePtr L) { try { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); SimpleJson.JsonObject gen_to_be_invoked = (SimpleJson.JsonObject)translator.FastGetCSObj(L, 1); { gen_to_be_invoked.Clear( ); return(0); } } catch (System.Exception gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + gen_e)); } }
public static int __CSIndexer(RealStatePtr L) { try { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); if (translator.Assignable <SimpleJson.JsonObject>(L, 1) && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 2)) { SimpleJson.JsonObject gen_to_be_invoked = (SimpleJson.JsonObject)translator.FastGetCSObj(L, 1); int index = LuaAPI.xlua_tointeger(L, 2); LuaAPI.lua_pushboolean(L, true); translator.PushAny(L, gen_to_be_invoked[index]); return(2); } } catch (System.Exception gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + gen_e)); } LuaAPI.lua_pushboolean(L, false); return(1); }
static int _m_Remove(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 && (LuaAPI.lua_isnil(L, 2) || LuaAPI.lua_type(L, 2) == LuaTypes.LUA_TSTRING)) { string _key = LuaAPI.lua_tostring(L, 2); bool gen_ret = gen_to_be_invoked.Remove(_key); LuaAPI.lua_pushboolean(L, gen_ret); return(1); } 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); bool gen_ret = gen_to_be_invoked.Remove(_item); LuaAPI.lua_pushboolean(L, gen_ret); return(1); } } catch (System.Exception gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + gen_e)); } return(LuaAPI.luaL_error(L, "invalid arguments to SimpleJson.JsonObject.Remove!")); }
static int _m_GetEnumerator(RealStatePtr L) { try { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); SimpleJson.JsonObject gen_to_be_invoked = (SimpleJson.JsonObject)translator.FastGetCSObj(L, 1); { System.Collections.Generic.IEnumerator <System.Collections.Generic.KeyValuePair <string, object> > gen_ret = gen_to_be_invoked.GetEnumerator( ); translator.PushAny(L, gen_ret); return(1); } } catch (System.Exception gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + gen_e)); } }
static int _m_ToString(RealStatePtr L) { try { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); SimpleJson.JsonObject gen_to_be_invoked = (SimpleJson.JsonObject)translator.FastGetCSObj(L, 1); { string gen_ret = gen_to_be_invoked.ToString( ); LuaAPI.lua_pushstring(L, gen_ret); return(1); } } catch (System.Exception gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + gen_e)); } }
public static EtcdResultNode Parse(SimpleJson.JsonObject jsonObj) { EtcdResultNode node = new EtcdResultNode(); node.key = (string)jsonObj["key"]; node.createdIndex = (long)jsonObj["createdIndex"]; node.modifiedIndex = (long)jsonObj["modifiedIndex"]; if (jsonObj.ContainsKey("dir")) { node.dir = (bool)jsonObj["dir"]; } if (jsonObj.ContainsKey("ttl")) { node.ttl = (long)jsonObj["ttl"]; } if (jsonObj.ContainsKey("expiration")) { DateTime expiration; if (DateTime.TryParse((string)jsonObj["expiration"], out expiration)) { node.expiration = expiration; } } if (jsonObj.ContainsKey("value")) { node.value = (string)jsonObj["value"]; } if (jsonObj.ContainsKey("nodes")) { SimpleJson.JsonArray children = (SimpleJson.JsonArray)jsonObj["nodes"]; node.nodes = new EtcdResultNode[children.Count]; for (int i = 0; i < children.Count; ++i) { node.nodes[i] = Parse((SimpleJson.JsonObject)children[i]); } } return(node); }
private bool verifyValue(SimpleJson.JsonObject json, string strKey, string strExpected) { string[] rgstrKeys = json.Keys.ToArray(); object[] rgVal = json.Values.ToArray(); for (int i = 0; i < rgstrKeys.Length; i++) { if (rgstrKeys[i] == strKey) { string strVal = rgVal[i].ToString(); if (strVal == strExpected) { return(true); } else { return(false); } } } return(false); }
static int _m_onResume(RealStatePtr L) { try { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); GameMgr gen_to_be_invoked = (GameMgr)translator.FastGetCSObj(L, 1); { SimpleJson.JsonObject _data = (SimpleJson.JsonObject)translator.GetObject(L, 2, typeof(SimpleJson.JsonObject)); gen_to_be_invoked.onResume(_data); return(0); } } catch (System.Exception gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + gen_e)); } }
static int _m_Contains(RealStatePtr L) { try { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); SimpleJson.JsonObject gen_to_be_invoked = (SimpleJson.JsonObject)translator.FastGetCSObj(L, 1); { System.Collections.Generic.KeyValuePair <string, object> _item; translator.Get(L, 2, out _item); bool gen_ret = gen_to_be_invoked.Contains(_item); LuaAPI.lua_pushboolean(L, gen_ret); return(1); } } catch (System.Exception gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + gen_e)); } }
static int _m_CopyTo(RealStatePtr L) { try { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); SimpleJson.JsonObject gen_to_be_invoked = (SimpleJson.JsonObject)translator.FastGetCSObj(L, 1); { System.Collections.Generic.KeyValuePair <string, object>[] _array = (System.Collections.Generic.KeyValuePair <string, object>[])translator.GetObject(L, 2, typeof(System.Collections.Generic.KeyValuePair <string, object>[])); int _arrayIndex = LuaAPI.xlua_tointeger(L, 3); gen_to_be_invoked.CopyTo(_array, _arrayIndex); return(0); } } catch (System.Exception gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + gen_e)); } }
static int _m_ContainsKey(RealStatePtr L) { try { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); SimpleJson.JsonObject gen_to_be_invoked = (SimpleJson.JsonObject)translator.FastGetCSObj(L, 1); { string _key = LuaAPI.lua_tostring(L, 2); bool gen_ret = gen_to_be_invoked.ContainsKey(_key); LuaAPI.lua_pushboolean(L, gen_ret); return(1); } } catch (System.Exception gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + gen_e)); } }
static int _m_SendJsonMsg(RealStatePtr L) { try { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); JW.Framework.Network.NetConnector __cl_gen_to_be_invoked = (JW.Framework.Network.NetConnector)translator.FastGetCSObj(L, 1); { string route = LuaAPI.lua_tostring(L, 2); SimpleJson.JsonObject data = (SimpleJson.JsonObject)translator.GetObject(L, 3, typeof(SimpleJson.JsonObject)); __cl_gen_to_be_invoked.SendJsonMsg(route, data); return(0); } } catch (System.Exception __gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + __gen_e)); } }
static int _m_createRoom(RealStatePtr L) { try { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); GameMgr gen_to_be_invoked = (GameMgr)translator.FastGetCSObj(L, 1); { SimpleJson.JsonObject _conf = (SimpleJson.JsonObject)translator.GetObject(L, 2, typeof(SimpleJson.JsonObject)); System.Action <SimpleJson.JsonObject> _cb = translator.GetDelegate <System.Action <SimpleJson.JsonObject> >(L, 3); gen_to_be_invoked.createRoom(_conf, _cb); return(0); } } catch (System.Exception gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + gen_e)); } }
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; } } }
private static string format(SimpleJson.JsonObject json, string strTab = "", bool bAddComma = false) { string strOut = strTab + "{" + Environment.NewLine; string strOriginalTab = strTab; bool bOriginalAddComma = bAddComma; strTab += " "; KeyValuePair <string, object>[] rgItems = json.ToArray(); for (int i = 0; i < rgItems.Length; i++) { string strKey = rgItems[i].Key; SimpleJson.JsonArray children = rgItems[i].Value as SimpleJson.JsonArray; strOut += strTab + "\"" + strKey + "\":"; if (children != null) { if (children.Count > 1) { strOut += "["; } strOut += Environment.NewLine; bAddComma = true; int nIdx = 0; foreach (object objChild in children) { if (nIdx >= children.Count - 1) { bAddComma = false; } SimpleJson.JsonObject child = objChild as SimpleJson.JsonObject; if (child != null) { strOut += format(child, strTab + " ", bAddComma); } else { strOut += strTab + " "; if (objChild == null) { strOut += "null"; } else { strOut += "\"" + objChild.ToString() + "\""; } strOut += (bAddComma ? "," : "") + Environment.NewLine; } nIdx++; } if (children.Count > 1) { strOut += strTab + "]" + Environment.NewLine; } } else { SimpleJson.JsonObject child = rgItems[i].Value as SimpleJson.JsonObject; if (child != null) { strOut += format(child, strTab + " ", bAddComma); } else { if (rgItems[i].Value == null) { strOut += "null"; } else { strOut += "\"" + rgItems[i].Value.ToString() + "\""; } if (bAddComma) { strOut += ","; } strOut += Environment.NewLine; } } } strOut += strOriginalTab + "}" + (bOriginalAddComma ? "," : "") + Environment.NewLine; return(strOut); }
public static string Format(SimpleJson.JsonObject json) { return(format(json)); }