Пример #1
0
        /// <summary>
        /// Executes the transaction, and returns the result.
        /// </summary>
        /// <returns>A TaskResult that has the ResultType Success if all tasks executed successfully,
        /// or the TaskResult returned by a failed task, depending on ErrorHandlingMode.</returns>
        public override TaskResult Execute()
        {
            var lock_obj = Lock ?? new object();

            lock (lock_obj)
            {
                foreach (var task in Tasks)
                {
                    var result = task.Execute();

                    if (ErrorHandlingMode != TransactionErrorHandlingMode.Ignore &&
                        result.Type != ResultType.Success &&
                        !result.Type.HasFlag(ResultType.Ignorable))
                    {
                        if (OnFailure != null)
                        {
                            OnFailure.Execute();
                        }

                        // fatal failure
                        return(result);
                    }
                    else if (result.Type == ResultType.StopExecution)
                    {
                        break;
                    }
                }
            }

            return(new TaskResult(this, ResultType.Success));
        }