public RSOutgoingCommand(RSService service, IRSCommand command, ResponseHandler callback = null, int commandId = -1) { Service = service; Command = command; Callback = callback; CommandId = commandId; }
/** * Adds a command to be processed. The service guarantees that * all added commands will be processed and any response handler will * always be called regardless of if previous commands experience * errors. Furthermore added commands will always be executed in the * order they were added. * <p> * Note that adding commands using this method is equivalent to * registering a process commands callback and adding commands * when the process commands callback is made. This means that any * callbacks already registered will be executed before the command * (or commands if the delayProcessing flag is used) added using this * method. * <p> * Example: Adding commands A, B, and C with delayProcessing set to * true for A and B, but false for C will be equivalent to register a * callback and add A, B, and C when the callback is made. * * @param command The command to add. * * @param handler Optional. If specified, this is * a callback that will be called when the command has been * processed. The object passed in the callback can be used to check * if the command succeeded and to access any returned data. * * @param stateData Optional. The state data to use. If null or omitted * the default state data will be used as specified in the constructor. * * @param delayProcessing Optional. A hint that tells the service not to try to send the * command immediately. This hint is useful when adding a sequence * of commands in one go. Specifying this flag to true for all * commands except the last one added will ensure that the Service * don't start processing the events immediately, but holds * processing until the last command in the sequence has been added. **/ public void AddCommand(IRSCommand command, ResponseHandler handler, RSStateData stateData = null, bool delayProcessing = false) { if (stateData == null) { stateData = DefaultStateData; } lock (callbackQueue) { if (currentServiceCallback == null) { currentServiceCallback = new RSCommandSequence(this, stateData); } else if (currentServiceCallback.StateData != stateData) { AddCommandSequence(currentServiceCallback); currentServiceCallback = new RSCommandSequence(this, stateData); } currentServiceCallback.AddCommand(command, handler); if (!delayProcessing) { AddCommandSequence(currentServiceCallback); currentServiceCallback = null; } } }
/** * Adds a command to the batch. Batch sub-commands will be processed * in the same order they are added and their responses can be * accessed from the Response object passed to a response handler * of the batch command itself. */ public void AddCommand(IRSCommand command) { CommandValues.Add(new Hashtable() { {"name", command.Name()}, {"params", command.Parameters()} }); Commands.Add(command); }
/** * Adds a command to the batch. Batch sub-commands will be processed * in the same order they are added and their responses can be * accessed from the Response object passed to a response handler * of the batch command itself. */ public void AddCommand(IRSCommand command) { CommandValues.Add(new Hashtable() { { "name", command.Name() }, { "params", command.Parameters() } }); Commands.Add(command); }
/** * Adds a command to this command sequence. */ public void AddCommand(IRSCommand command, ResponseHandler handler) { int id = -1; if (handler != null) { id = Service.NextCommandId(); ContainsResponseHandlers = true; } if (command is RSRenderCommand) { ContainsRenderCommands = true; } commands.Add(new RSOutgoingCommand(Service, command, handler, id)); }
public void AddCommand(IRSCommand command) { AddCommand(command, null); }
public RSResponse(IRSCommand command, object serverResponse) { Command = command; ServerResponse = serverResponse; Hashtable tableResponse = serverResponse as Hashtable; if (tableResponse == null) { IsErrorResponse = true; return; } if (tableResponse.Contains("result")) { Result = tableResponse["result"]; } if (tableResponse.Contains("error")) { Hashtable error = tableResponse["error"] as Hashtable; if (error != null && error.Contains("code") && Convert.ToInt32(error["code"]) != 0) { IsErrorResponse = true; Error = error; } } // Is this a response for a batch command? RSBatchCommand batch = command as RSBatchCommand; if (batch != null) { if (!tableResponse.Contains("responses") || !tableResponse.Contains("has_sub_error_response")) { // Error return; } ArrayList responses = tableResponse["responses"] as ArrayList; bool subErrors = (bool)tableResponse["has_sub_error_response"]; IsBatchResponse = true; if (responses.Count != batch.Commands.Count) { // Error return; } SubResponses = new List<RSResponse>(); for (int i = 0; i < batch.Commands.Count; i++) { SubResponses.Add(new RSResponse(batch.Commands[i], responses[i])); } HasSubErrorResponse = subErrors; } else { IsBatchResponse = false; SubResponses = null; HasSubErrorResponse = false; } }
public RSResponse(IRSCommand command, object serverResponse) { Command = command; ServerResponse = serverResponse; Hashtable tableResponse = serverResponse as Hashtable; if (tableResponse == null) { IsErrorResponse = true; return; } if (tableResponse.Contains("result")) { Result = tableResponse["result"]; } if (tableResponse.Contains("error")) { Hashtable error = tableResponse["error"] as Hashtable; if (error != null && error.Contains("code") && Convert.ToInt32(error["code"]) != 0) { IsErrorResponse = true; Error = error; } } // Is this a response for a batch command? RSBatchCommand batch = command as RSBatchCommand; if (batch != null) { if (!tableResponse.Contains("responses") || !tableResponse.Contains("has_sub_error_response")) { // Error return; } ArrayList responses = tableResponse["responses"] as ArrayList; bool subErrors = (bool)tableResponse["has_sub_error_response"]; IsBatchResponse = true; if (responses.Count != batch.Commands.Count) { // Error return; } SubResponses = new List <RSResponse>(); for (int i = 0; i < batch.Commands.Count; i++) { SubResponses.Add(new RSResponse(batch.Commands[i], responses[i])); } HasSubErrorResponse = subErrors; } else { IsBatchResponse = false; SubResponses = null; HasSubErrorResponse = false; } }