Exemple #1
0
        /// <summary>
        /// Runs pipeline's processors one by one in an order
        /// they are returned from <see cref="IPipeline.GetProcessors"/>.
        /// </summary>
        /// <typeparam name="TArgs">
        /// Type of the arguments used in each processors of the pipeline.
        /// </typeparam>
        /// <param name="pipeline">
        /// The pipeline which processors should be executed.
        /// </param>
        /// <param name="args">
        /// The arguments that has to be passed to each processor
        /// of the executed pipeline.
        /// </param>
        /// <returns>
        /// Returns a promise of the pipeline execution.
        /// </returns>
        public virtual async Task Run(IPipeline pipeline, Bag bag)
        {
            if (pipeline.HasNoValue())
            {
                bag.Debug("Cannot run the pipeline because its value is null.");
                return;
            }

            PipelineInfo pipelineInfo = null;

            if (OnPipelineStart != null || OnPipelineEnd != null)
            {
                pipelineInfo = new PipelineInfo()
                {
                    Context = bag, Pipeline = pipeline
                };
            }

            if (OnPipelineStart != null)
            {
                OnPipelineStart(this, pipelineInfo);
            }

            var processors = pipeline.GetProcessors();

            if (bag.Debug)
            {
                var pipelineName = pipeline.Name();
                var description  = pipeline.Description();

                if (description.HasValue())
                {
                    bag.Debug("Running pipeline [{0}]. Pipeline is {1}".FormatWith(pipelineName, description.ToLower()));
                }
                else
                {
                    bag.Debug("Running pipeline [{0}].".FormatWith(pipelineName));
                }

                await Run(processors, bag).ConfigureAwait(false);

                bag.Debug("Completed pipeline [{0}].".FormatWith(pipelineName));
            }
            else
            {
                await Run(processors, bag).ConfigureAwait(false);
            }

            if (OnPipelineEnd != null)
            {
                OnPipelineEnd(this, pipelineInfo);
            }
        }