Ejemplo n.º 1
0
        public void Run()
        {
            var lastOrder = new OrderAttribute(int.MaxValue);
            var actions   = _actions
                            .Where(_ => !_.GetType().GetCustomAttribute(fallback: lastOrder).Ignore)
                            .OrderBy(_ => _.GetType().GetCustomAttribute(fallback: lastOrder).Order)
                            .ToArray();

            var arguments = new ProgressiveTaskArguments {
                ActualStep = 0,
                TotalSteps = actions.Length
            };

            _publisherSubscriber.ProgressiveTaskStart(
                title: Strings.Bootstrapper_ProgressiveTaskStart_Title,
                actualStep: arguments.ActualStep,
                totalSteps: arguments.TotalSteps
                );

            actions.Each((_, idx) => {
                try {
                    _publisherSubscriber.ProgressiveTaskPerformStep(
                        message: string.Format(Strings.Bootstrapper_ProgressiveTaskPerformStep_Message, _.Name),
                        actualStep: ++arguments.ActualStep,
                        totalSteps: arguments.TotalSteps
                        );

                    _.Execute();
                } catch (Exception ex) {
                    _publisherSubscriber.ProgressiveTaskError(
                        actualStep: arguments.ActualStep,
                        error: ex.Message,
                        totalSteps: arguments.TotalSteps
                        );

                    Log.Error(ex.Message);

                    throw new FatalException(Strings.FatalException_Message, ex);
                }
            });

            _publisherSubscriber.ProgressiveTaskComplete(
                message: Strings.Bootstrapper_ProgressiveTaskComplete_Message,
                actualStep: arguments.ActualStep,
                totalSteps: arguments.TotalSteps
                );
        }
Ejemplo n.º 2
0
        public static void TaskContinuation(this IPublisherSubscriber source, Task continuation, object state)
        {
            if (source == null)
            {
                return;
            }
            if (continuation == null)
            {
                return;
            }
            if (state == null)
            {
                return;
            }

            var error = string.Empty;
            var info  = (state as ProgressiveTaskContinuationInfo) ?? new ProgressiveTaskContinuationInfo();

            var ex = continuation.Exception as AggregateException;

            if (ex != null)
            {
                var stringBuilder = new StringBuilder();
                foreach (var exception in ex.InnerExceptions)
                {
                    stringBuilder.AppendLine(exception.Message);
                }
                error = stringBuilder.ToString();
                source.ProgressiveTaskError(error: error, actualStep: info.ActualStep, totalSteps: info.TotalSteps, log: info.Log);
                return;
            }

            if (continuation.IsCanceled)
            {
                source.ProgressiveTaskCancel(actualStep: info.ActualStep, totalSteps: info.TotalSteps, log: info.Log);
                return;
            }

            source.ProgressiveTaskComplete(error: error, actualStep: info.ActualStep, totalSteps: info.TotalSteps, log: info.Log);
        }