/// <summary>
        /// Processes the model.
        /// </summary>
        /// <param name="inputModel">The input model.</param>
        /// <returns>
        /// The activity result.
        /// </returns>
        public ActivityResult ProcessModel(IDataModel inputModel)
        {
            var context = new ActivityContext(inputModel, DateTime.UtcNow);

            this.ActivityExecuting?.Invoke(this, new ActivityExecutingEventArgs(context));

            IDataModel        outputModel       = null;
            ActivityException activityException = null;

            var stopwatch = new Stopwatch();

            stopwatch.Start();

            try
            {
                outputModel = this.ProcessModelAsync(context).GetAwaiter().GetResult();
            }
            catch (ActivityException aex)
            {
                activityException = aex;
            }
            catch (Exception ex)
            {
                activityException =
                    new ActivityException(
                        PipelineErrorMessages.ActivityProcessModelFailed,
                        ex,
                        PipelineErrorCodes.ActivityProcessModelFailed,
                        context);
            }

            stopwatch.Stop();

            var activityResult = new ActivityResult(outputModel, stopwatch.Elapsed, activityException);

            context.Result        = activityResult;
            context.CompletedTime = DateTime.UtcNow;

            this.ActivityExecuted?.Invoke(this, new ActivityExecutedEventArgs(context));

            return(activityResult);
        }
예제 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ActivityResult"/> class.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <param name="elapsedTime">The elapsed time.</param>
 /// <param name="exception">The exception.</param>
 public ActivityResult(IDataModel value, TimeSpan elapsedTime, ActivityException exception = null)
 {
     this.Value       = value;
     this.ElapsedTime = elapsedTime;
     this.Exception   = exception;
 }