Ejemplo n.º 1
0
        /// <summary>
        /// Standard command execution.
        /// </summary>
        protected ServerResponse StandardExecution
        (
            [NotNull] ExecutionContext context
        )
        {
            Sure.NotNull(context, nameof(context));
            Log.Trace(nameof(AbstractEngine) + "::" + nameof(StandardExecution));

            AbstractCommand command    = context.Command.ThrowIfNull(nameof(context.Command));
            IrbisConnection connection = (context.Connection as IrbisConnection)
                                         .ThrowIfNull(nameof(context.Connection));

            if (!command.Verify(ThrowOnVerify))
            {
                Log.Error
                (
                    nameof(AbstractEngine) + "::" + nameof(StandardExecution)
                    + ": " + nameof(command) + "." + nameof(command.Verify) + " failed"
                );
            }

            using (new BusyGuard(connection.Busy))
            {
                ServerResponse result = ServerResponse.GetEmptyResponse(connection);
                connection.Interrupted = false;

                try
                {
                    ClientQuery query = command.CreateQuery();
                    if (!query.Verify(ThrowOnVerify))
                    {
                        Log.Error
                        (
                            nameof(AbstractEngine) + "::" + nameof(StandardExecution)
                            + ": " + nameof(query) + "." + nameof(query.Verify) + " failed"
                        );
                    }

                    result = command.Execute(query);
                    if (!result.Verify(ThrowOnVerify))
                    {
                        Log.Error
                        (
                            nameof(AbstractEngine) + "::" + nameof(StandardExecution)
                            + ": " + nameof(result) + "." + nameof(result.Verify) + " failed"
                        );
                    }

                    command.CheckResponse(result);
                }
                catch (Exception exception)
                {
                    Log.TraceException
                    (
                        nameof(AbstractEngine) + "::" + nameof(StandardExecution),
                        exception
                    );

                    context.Exception = exception;

                    OnException(context);

                    if (!context.ExceptionHandled)
                    {
                        throw;
                    }
                }

                context.Response = result;

                return(result);
            }
        }