public virtual Task RunPipeline <TArgs>(IPipeline pipeline, TArgs args) { if (pipeline.HasNoValue()) { return(Task.CompletedTask); } return(RunProcessors(pipeline.GetProcessors(), args)); }
/// <summary> /// Runs pipeline's processors one by one with a <see cref="ProcessorRunner"/> /// 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 Task Run(IPipeline pipeline, Bag args) { if (pipeline.HasNoValue()) { return(PipelineTask.CompletedTask); } return(RunProcessors(pipeline.GetProcessors(), args)); }
/// <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); } }
/// <summary> /// Returns pipeline wrapper that caches processors after the moment /// of processors first request from <paramref name="pipeline"/>. /// The processors will never be updated after first request. /// </summary> /// <param name="pipeline"> /// The pipeline which processors should be cached in memory. /// </param> /// <param name="useLazyLoading"> /// Defines whether processors should be cached after /// first request (true) or if processors should be /// cached during the call of this method (false). /// </param> /// <returns> /// Returns pipeline wrapper that caches processors. /// </returns> public static IPipeline Fix(this IPipeline pipeline, bool useLazyLoading = true) { if (!useLazyLoading) { return(Pipeline.From(pipeline.GetProcessors().ToArray())); } var loaded = false; return(new FixedPipeline(pipeline, () => { var result = !loaded; loaded = true; return result; }, useLazyLoading)); }