Exemple #1
0
        /**
         * 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 bool OnLoad(RSRenderCommand command, RSService service, byte[] data)
        {
            // Updating the texture has to be done in the game loop and not from a different thread.
            lock (DataLock)
            {
                CurrentData = data;
                HasNewData = true;
            }

            return true;
        }