/// <summary>
        /// Initializes a new instance of the <see cref="ForAllItemExecutionException{T}"/> class.
        /// </summary>
        /// <param name="context">The value for <see cref="ForAllItemExecutionException{T}.Context" /> property.</param>
        /// <param name="ex">The underyling exception.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="context" /> is <see langword="null" />.
        /// </exception>
        /// <exception cref="NullReferenceException">
        /// <paramref name="ex" /> is <see langword="null" />.
        /// </exception>
        public ForAllItemExecutionException(IForAllItemExecutionContext <T> context,
                                            Exception ex)
            : base(ex.Message, ex)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            this._CONTEXT = context;
        }
Beispiel #2
0
        /// <summary>
        /// Handles a job item.
        /// </summary>
        /// <param name="ctx">The underlying item context.</param>
        protected virtual void HandleJobItem(IForAllItemExecutionContext <IJob, DateTimeOffset> ctx)
        {
            List <Exception> occuredErrors = new List <Exception>();

            DateTimeOffset      completedAt;
            JobExecutionContext execCtx = new JobExecutionContext();

            try
            {
                execCtx.Job        = ctx.Item;
                execCtx.ResultVars = new Dictionary <string, object>(EqualityComparerFactory.CreateCaseInsensitiveStringComparer(true, true));
                execCtx.SyncRoot   = new object();
                execCtx.Time       = ctx.State;

                execCtx.Job
                .Execute(execCtx);

                completedAt = AppTime.Now;
            }
            catch (Exception ex)
            {
                completedAt = AppTime.Now;

                AggregateException aggEx = ex as AggregateException;
                if (aggEx != null)
                {
                    occuredErrors.AddRange(CollectionHelper.OfType <Exception>(aggEx.InnerExceptions));
                }
                else
                {
                    occuredErrors.Add(ex);
                }
            }

            JobExecutionResult result = new JobExecutionResult();

            result.Context = execCtx;
            result.Errors  = occuredErrors.ToArray();
            result.Vars    = new TMReadOnlyDictionary <string, object>(execCtx.ResultVars);
            result.Time    = completedAt;

            this.RaiseEventHandler(this.Executed,
                                   new JobExecutionResultEventArgs(result));
        }