/// <summary> /// Creates a new AbstractPipe using the elements emitted /// by the given IEnumerator as input. /// </summary> /// <param name="InternalPipes">The array of all wrapped pipes.</param> /// <param name="IEnumerable">An IEnumerable<S> as element source.</param> /// <param name="IEnumerator">An IEnumerator<S> as element source.</param> public AbstractMetaPipe(IPipe[] InternalPipes, IEnumerable <S> IEnumerable, IEnumerator <S> IEnumerator) { #region Initial checks if (InternalPipes == null) { throw new ArgumentNullException("The array of wrapped pipes must not be null!"); } if (InternalPipes.Length < 2) { throw new ArgumentException("The array of wrapped pipes must at least wrap two pipes!"); } if (!(InternalPipes[0] is IStartPipe <S>)) { throw new ArgumentException("The first wrapped pipe must implement IStartPipe<S>!"); } if (!(InternalPipes[InternalPipes.Length - 1] is IEndPipe <E>)) { throw new ArgumentException("The last wrapped pipe must implement IEndPipe<E>!"); } if (IEnumerator != null && IEnumerable != null) { throw new ArgumentException("Please decide between IEnumerator and IEnumerable!"); } #endregion this.InternalPipes = InternalPipes; this.StartPipe = InternalPipes[0] as IStartPipe <S>; this.EndPipe = InternalPipes[InternalPipes.Length - 1] as IEndPipe <E>; if (IEnumerable != null) { this.StartPipe.SetSourceCollection(IEnumerable); } if (IEnumerator != null) { this.StartPipe.SetSource(IEnumerator); } for (var i = 1; i < InternalPipes.Length; i++) { InternalPipes[i].SetSource(InternalPipes[i - 1]); } }
/// <summary> /// Use when extending Pipeline and setting the pipeline chain without making use of the constructor. /// </summary> /// <param name="IPipes">the ordered array of pipes to chain together into a pipeline.</param> protected void SetPipes(params IPipe[] IPipes) { _Pipes = IPipes; var _PipeNames = new List <String>(); var _Length = IPipes.Length; _StartPipe = IPipes[0] as IStartPipe <S>; if (_StartPipe == null) { throw new ArgumentException("The first Pipe must implement 'IStartPipe<" + typeof(S) + ">', but '" + IPipes[0].GetType() + "' was provided!"); } _EndPipe = IPipes[_Length - 1] as IEndPipe <E>; if (_EndPipe == null) { throw new ArgumentException("The last Pipe must implement 'IEndPipe<" + typeof(E) + ">', but '" + IPipes[_Length - 1].GetType() + "' was provided!"); } _PipeNames.Add(_StartPipe.ToString()); Type[] _GenericArguments = null; Type _Consumes; Type _Emitts; #if SILVERLIGHT Type _GenericIPipeInterface = _StartPipe.GetType().GetInterface("IPipe`2", false); #else Type _GenericIPipeInterface = _StartPipe.GetType().GetInterface("IPipe`2"); #endif if (_GenericIPipeInterface == null) { throw new ArgumentException("IPipe<?,?> expected!"); } _Emitts = _GenericIPipeInterface.GetGenericArguments()[1]; for (var i = 1; i < _Length; i++) { #if SILVERLIGHT _GenericArguments = IPipes[i].GetType().GetInterface("IPipe`2", false).GetGenericArguments(); #else _GenericArguments = IPipes[i].GetType().GetInterface("IPipe`2").GetGenericArguments(); #endif _Consumes = _GenericArguments[0]; if (_Consumes != _Emitts) { throw new ArgumentException(IPipes[i - 1].GetType() + " emitts other objects than " + IPipes[i].GetType() + " consumes!"); } _Emitts = _GenericArguments[1]; IPipes[i].SetSource(IPipes[i - 1]); _PipeNames.Add(IPipes[i].ToString()); } if (_InternalEnumerator != null) { IPipes[0].SetSource(_InternalEnumerator); } _PipelineString = _PipeNames.ToString(); }
public BackFilterPipe(IStartPipe <S> pipe) { _Pipe = pipe; }