/** * Process the given data and error for a render response. */ public void ProcessRenderResponse(byte[] data, string error, bool valid = true) { RSOutgoingCommand lastCommand = currentCommands[currentCommands.Count - 1]; RSRenderCommand renderCommand = lastCommand.Command as RSRenderCommand; if (renderCommand == null) { Logger.Log("error", "Error getting last render command."); ResponseCompleted(); return; } // If our render target can't be used anymore then ignore if (renderCommand.Target != null && !renderCommand.Target.Valid()) { return; } try { if (data != null && data.Length >= 2 && (char)data[0] == '[' && (char)data[1] == '{') { ArrayList errors = JSON.JsonDecode(System.Text.Encoding.UTF8.GetString(data)) as ArrayList; Hashtable errorResp = errors[0] as Hashtable; Hashtable errorObj = errorResp["error"] as Hashtable; error = errorObj["message"].ToString(); } if (error != null) { lastCommand.DoClientErrorCallback(error, -2); renderCommand.Target.OnError(error); } else if (valid) { if (valid) { bool continueProcessing = renderCommand.Target.OnLoad(renderCommand, this, data); if (!continueProcessing) { return; } } lastCommand.DoResultCallback(new Hashtable() { { "result", new Hashtable() }, { "valid", valid } }); } } catch (Exception e) { Logger.Log("error", "Error handling render callback: " + e.ToString()); } ResponseCompleted(); }
public void ProcessResponses(string str) { Logger.Log("debug", "Received: " + str); ArrayList responses = null; try { responses = JSON.JsonDecode(str) as ArrayList; } catch (Exception exp) { // Error Logger.Log("error", "Error parsing responses: " + exp.ToString()); ResponseCompleted(); return; } if (responses == null) { Logger.Log("error", "Error parsing responses: parsed responses was null."); ResponseCompleted(); return; } for (int i = 0; i < responses.Count; i++) { Hashtable resp = responses[i] as Hashtable; if (resp == null) { // Error Logger.Log("error", "Unable to get response as hashtable: " + responses[i]); continue; } if (resp.Contains("id")) { int id = Convert.ToInt32(resp["id"]); RSOutgoingCommand cmd = currentCommandsResponseMap[id]; cmd.DoResultCallback(resp); } else { Logger.Log("error", "Response does not contain an id: " + resp); } } ResponseCompleted(); }