Ejemplo n.º 1
0
        /// <summary>
        /// Asynchronously executes the provided command
        /// </summary>
        /// <param name="command">Command object which contains the command to be executed</param>
        /// <param name="response">Response sent as result of command execution</param>
        private void AsyncExecutionThreadTask(Command command, out Response response)
        {
            // The running state is checked in all steps to discard execution on command abort

            //6. Default failed response
            response = Response.CreateFromCommand(command, false);

            // 7. Raise ExecutionStarted event
            if (running)
            {
                OnExecutionStarted(command);
            }

            // 8. Perform command execution
            if (running)
            {
                response = AsyncTask(command);
            }

            // 9. If a null response is provided (and required) generate failure response
            if (ResponseRequired && (response == null))
            {
                response = Response.CreateFromCommand(command, false);
            }

            // 10. Send the result of command execution (if any)
            if (response != null)
            {
                SendResponse(response);
            }

            // 11. Reset execution flags
            busy    = false;
            running = false;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Asynchronously executes the provided command
        /// </summary>
        /// <param name="command">Command object which contains the command to be executed</param>
        /// <param name="response">Response sent as result of command execution</param>
        private void AsyncExecutionThreadTask(Command command, out Response response)
        {
            // 7. Default failed response
            response = Response.CreateFromCommand(command, false);

            // 8. Raise ExecutionStarted event
            OnExecutionStarted(command);

            // 9. Perform command execution
            response = AsyncTask(command);

            // 10. If a null response is provided (and required) generate failure response
            if (ResponseRequired && (response == null))
            {
                response = Response.CreateFromCommand(command, false);
            }

            // 11. Send the result of command execution (if any)
            if (response != null)
            {
                SendResponse(response);
            }

            // 12. Reset execution flags
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Executes the provided command
        /// </summary>
        /// <param name="command">Command object which contains the command to be executed</param>
        /// <remarks>If the command execution is aborted a failure response is sent if required</remarks>
        public sealed override void Execute(Command command)
        {
            // 1. Check busy state and parameters
            #region Busy check
            if (Busy)
            {
                if (ResponseRequired)
                {
                    SendResponse(false, command);
                }
                return;
            }
            #endregion

            #region No params provided
            if (ParametersRequired && !command.HasParams)
            {
                SendResponse(false, command);
                return;
            }
            #endregion

            // 2. Set execution flags
            busy    = true;
            running = true;

            // 3. Create default failed response
            Response response = Response.CreateFromCommand(command, false);

            // 4. Raise ExecutionStarted event
            OnExecutionStarted(command);

            // 5. Perform command execution
            response = SyncTask(command);

            // 6. If a null response is provided (and required), generate failure response
            if (ResponseRequired && (response == null))
            {
                response = Response.CreateFromCommand(command, false);
            }

            // 7. Send the result of command execution (if any)
            if (response != null)
            {
                SendResponse(response);
            }

            // 8. Reset execution flags
            busy    = false;
            running = false;

            // 9. Raise ExecutionFinished event
            OnExecutionFinished(command, response);
        }