Пример #1
0
        /// <summary>
        /// Creates an new abstract side effect pipe using the given pipe as element source.
        /// </summary>
        /// <param name="SourcePipe">A pipe as element source.</param>
        /// <param name="SideEffect1">The initial value of the first side effect.</param>
        /// <param name="SideEffect2">The initial value of the second side effect.</param>
        public AbstractTwoSideEffectsPipe(IEndPipe <S> SourcePipe,
                                          T1 SideEffect1,
                                          T2 SideEffect2)

            : base(SourcePipe)

        {
            this.SideEffect1 = SideEffect1;
            this.SideEffect2 = SideEffect2;
        }
Пример #2
0
        /// <summary>
        /// Determines whether a pipe emits any items.
        /// </summary>
        /// <typeparam name="T">The type of the items emitted by the pipe.</typeparam>
        /// <param name="SourcePipe">A pipe.</param>
        /// <returns>True if the pipe emits any items; otherwise, false.</returns>
        public static Boolean Any <T>(this IEndPipe <T> SourcePipe)
        {
            if (SourcePipe == null)
            {
                return(false);
            }

            using (var Enumerator = SourcePipe)
                return(Enumerator.MoveNext());
        }
Пример #3
0
        public ZipMergePipe(IEndPipe <S1> SourcePipe1,
                            IEndPipe <S2> SourcePipe2,
                            Func <S1, S2, E> ZipDelegate)

            : base(SourcePipe1, SourcePipe2)

        {
            this.ZipDelegate        = ZipDelegate;
            this.ProcessingDelegate = GetProcessingDelegate();
        }
Пример #4
0
 /// <summary>
 /// Splits a given strings into elements by a given sperator.
 /// </summary>
 /// <param name="SourcePipe">An enumeration of strings.</param>
 /// <param name="IgnoreLines">A regular expression indicating which input strings should be ignored. Default: All lines starting with a '#'.</param>
 /// <param name="Seperators">An array of string used to split the input strings.</param>
 /// <param name="StringSplitOptions">Split options, e.g. remove empty entries.</param>
 /// <param name="ExpectedNumberOfColumns">If the CSV file had a schema, a specific number of columns can be expected. If instead it is a list of values no such value can be expected.</param>
 /// <param name="FailOnWrongNumberOfColumns">What to do when the current and expected number of columns do not match.</param>
 /// <param name="TrimColumns">Remove leading and trailing whitespaces.</param>
 /// <returns>An enumeration of string arrays.</returns>
 public static IEndPipe <String[]> ToCSV(this IEndPipe <String> SourcePipe,
                                         Regex IgnoreLines = null,
                                         String[]            Seperators        = null,
                                         StringSplitOptions StringSplitOptions = StringSplitOptions.None,
                                         UInt16?ExpectedNumberOfColumns        = null,
                                         Boolean FailOnWrongNumberOfColumns    = false,
                                         Boolean TrimColumns = true)
 {
     return(new CSVReaderPipe(SourcePipe, IgnoreLines, Seperators, StringSplitOptions, ExpectedNumberOfColumns, FailOnWrongNumberOfColumns, TrimColumns));
 }
Пример #5
0
        public ZipTuplePipe(IEndPipe <S1> SourcePipe1,
                            IEndPipe <S2> SourcePipe2,
                            Func <S1, S2, UInt64, IlliasC.Tuple <S1, S2> > CountedZipDelegate)

            : base(SourcePipe1, SourcePipe2)

        {
            this.CountedZipDelegate = CountedZipDelegate;
            this.ProcessingDelegate = GetProcessingDelegate();
        }
Пример #6
0
        /// <summary>
        /// Creates an new abstract side effect pipe using the given pipe as element source.
        /// </summary>
        /// <param name="SourcePipe">A pipe as element source.</param>
        /// <param name="SideEffect1">The initial value of the first side effect.</param>
        /// <param name="SideEffect2">The initial value of the second side effect.</param>
        /// <param name="SideEffect3">The initial value of the third side effect.</param>
        public AbstractThreeSideEffectsPipe(IEndPipe <S> SourcePipe,
                                            T1 SideEffect1,
                                            T2 SideEffect2,
                                            T3 SideEffect3)

            : base(SourcePipe)

        {
            this.SideEffect1 = SideEffect1;
            this.SideEffect2 = SideEffect2;
            this.SideEffect3 = SideEffect3;
        }
Пример #7
0
        /// <summary>
        /// Creates a new RangeFilterPipe.
        /// </summary>
        /// <param name="Low">The minimal value.</param>
        /// <param name="High">The maximum value.</param>
        /// <param name="IEnumerable">An optional enumation of directories as element source.</param>
        /// <param name="IEnumerator">An optional enumerator of directories as element source.</param>
        public RangeFilterPipe(IEndPipe <S> SourcePipe, Int32 Low, Int32 High)
            : base(SourcePipe)
        {
            if (Low > -1 && High > -1 && Low >= High)
            {
                throw new ArgumentOutOfRangeException("Low must be smaller than High!");
            }

            this.Low     = Low;
            this.High    = High;
            this.Counter = -1;
        }
Пример #8
0
        /// <summary>
        /// Creates a new property filter pipe.
        /// </summary>
        /// <param name="SourcePipe">A pipe as element source.</param>
        /// <param name="Key">The property key.</param>
        /// <param name="ComparisonFilter">The comparison filter to use.</param>
        public APropertyFilterPipe(IEndPipe <S> SourcePipe,
                                   TKey Key,
                                   ComparisonFilter <TValue> ComparisonFilter)

            : base(SourcePipe)

        {
            ComparisonFilter.CheckNull("ComparisonFilter");

            this.Key = Key;
            this.ComparisonFilter = ComparisonFilter;
        }
Пример #9
0
        /// <summary>
        /// Scans the given directories for files matching the given filters.
        /// </summary>
        /// <param name="SearchPattern">A simple search pattern like "*.jpg".</param>
        /// <param name="SearchOption">Include or do not include subdirectories.</param>
        /// <param name="FileFilter">A delegate for filtering the found files.</param>
        /// <param name="IEnumerable">An optional enumation of directories as element source.</param>
        /// <param name="IEnumerator">An optional enumerator of directories as element source.</param>
        public FileFilterPipe(IEndPipe <String> SourcePipe,
                              String SearchPattern             = "*",
                              SearchOption SearchOption        = SearchOption.TopDirectoryOnly,
                              FileFilter FileFilter            = null,
                              IEnumerable <String> IEnumerable = null,
                              IEnumerator <String> IEnumerator = null)

            : base(SourcePipe)

        {
            _SearchPattern = SearchPattern;
            _SearchOption  = SearchOption;
            _FileFilter    = FileFilter;
        }
Пример #10
0
        /// <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&lt;S&gt; as element source.</param>
        /// <param name="IEnumerator">An IEnumerator&lt;S&gt; 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]);
            }
        }
Пример #11
0
        /// <summary>
        /// Creates an new abstract pipe using the given enumerable as element source.
        /// </summary>
        /// <param name="SourceEnumerable">An enumeration as element source.</param>
        /// <param name="SourceEnumerator">An enumerator as element source.</param>
        public AbstractPipe(IEnumerable <S> SourceEnumeration, IEnumerator <S> SourceEnumerator)
        {
            if (SourceEnumeration == null && SourceEnumerator == null)
            {
                throw new ArgumentNullException("The given sources must not both be null!");
            }

            if (SourceEnumeration != null)
            {
                this.SourcePipe = EndPipe.CreatePipe(SourceEnumeration);
            }

            if (SourceEnumerator != null)
            {
                this.SourcePipe = EndPipe.CreatePipe(SourceEnumerator);
            }
        }
Пример #12
0
        /// <summary>
        /// Determines whether any item emitted by a pipe satisfies a condition.
        /// </summary>
        /// <typeparam name="T">The type of the items emitted by the pipe.</typeparam>
        /// <param name="SourcePipe">A pipe.</param>
        /// <param name="IncludeFilter">A delegate to test each item emitted by the pipe for a condition.</param>
        /// <returns>True if the pipe emits any matching items; otherwise, false.</returns>
        public static Boolean Any <T>(this IEndPipe <T> SourcePipe, Func <T, Boolean> IncludeFilter)
        {
            if (SourcePipe == null)
            {
                return(false);
            }

            foreach (var Item in SourcePipe)
            {
                if (IncludeFilter(Item))
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #13
0
        /// <summary>
        /// Advances the enumerator to the next element of the collection.
        /// </summary>
        /// <returns>
        /// True if the enumerator was successfully advanced to the next
        /// element; false if the enumerator has passed the end of the
        /// collection.
        /// </returns>
        public Boolean MoveNext()
        {
            if (_InternalEnumerator == null)
            {
                return(false);
            }

            if (_EndPipe == null && _PipelineDefinition == null)
            {
                return(false);
            }

            if (_EndPipe != null)
            {
                if (_EndPipe.MoveNext())
                {
                    _CurrentElement = _EndPipe.Current;
                    return(true);
                }
            }

            else if (_PipelineDefinition != null)
            {
                while (true)
                {
                    if (_TmpIterator != null && _TmpIterator.MoveNext())
                    {
                        _CurrentElement = _TmpIterator.Current;
                        return(true);
                    }

                    else if (_InternalEnumerator.MoveNext())
                    {
                        _TmpIterator = _PipelineDefinition(_InternalEnumerator.Current);
                    }

                    else
                    {
                        return(false);
                    }
                }
            }

            return(false);
        }
Пример #14
0
        /// <summary>
        /// Splits a given strings into elements by a given sperator.
        /// </summary>
        /// <param name="SourcePipe"></param>
        /// <param name="IgnoreLines">A regular expression indicating which input strings should be ignored. Default: All lines starting with a '#'.</param>
        /// <param name="Seperators">An array of string used to split the input strings.</param>
        /// <param name="StringSplitOptions">Split options, e.g. remove empty entries.</param>
        /// <param name="ExpectedNumberOfColumns">If the CSV file had a schema, a specific number of columns can be expected. If instead it is a list of values no such value can be expected.</param>
        /// <param name="FailOnWrongNumberOfColumns">What to do when the current and expected number of columns do not match.</param>
        /// <param name="TrimColumns">Remove leading and trailing whitespaces.</param>
        public CSVReaderPipe(IEndPipe <String> SourcePipe,
                             Regex IgnoreLines = null,
                             String[]            Seperators        = null,
                             StringSplitOptions StringSplitOptions = StringSplitOptions.None,
                             UInt16?ExpectedNumberOfColumns        = null,
                             Boolean FailOnWrongNumberOfColumns    = false,
                             Boolean TrimColumns = true)

            : base(SourcePipe, 0UL)

        {
            this.IgnoreLines                = (IgnoreLines == null) ? new Regex(@"^\#")  : IgnoreLines;
            this.Seperators                 = (Seperators == null) ? new String[] { "," } : Seperators;
            this.StringSplitOptions         = StringSplitOptions;
            this.ExpectedNumberOfColumns    = ExpectedNumberOfColumns;
            this.FailOnWrongNumberOfColumns = FailOnWrongNumberOfColumns;
            this.TrimColumns                = TrimColumns;

            this.EmptyColumRegex = new Regex("\\" + this.Seperators[0] + "\\s\\" + this.Seperators[0]);
        }
Пример #15
0
        /// <summary>
        /// Safely aggregates the items emitted by the given pipe. If the pipe is null
        /// or has no elements the default value will be returned.
        /// </summary>
        /// <typeparam name="T">The type of the items emitted by the pipe.</typeparam>
        /// <param name="SourcePipe">A pipe.</param>
        /// <param name="DefaultValue">The default value to return for an empty pipe.</param>
        public static T Aggregate <T>(this IEndPipe <T> SourcePipe,
                                      T Prefix,
                                      Func <T, T> Map,
                                      Func <T, T, T> Reduce,
                                      T Suffix,
                                      T DefaultValue = default(T))
        {
            if (SourcePipe == null)
            {
                return(DefaultValue);
            }

            try
            {
                return(Reduce(Reduce(Prefix, SourcePipe.Select(Item => Map(Item)).Aggregate(Reduce)), Suffix));
            }
            catch (Exception e)
            {
                return(DefaultValue);
            }
        }
Пример #16
0
        /// <summary>
        /// Returns the last item of the given pipe that satisfies a condition
        /// or the given default value if no such item was found.
        /// </summary>
        /// <typeparam name="T">The type of the items emitted by the pipe.</typeparam>
        /// <param name="SourcePipe">A pipe.</param>
        /// <param name="IncludeFilter">A delegate to test each item emitted by the pipe for a condition.</param>
        /// <param name="DefaultValue">A default value.</param>
        public static T LastOrDefault <T>(this IEndPipe <T> SourcePipe,
                                          Func <T, Boolean> IncludeFilter = null,
                                          T DefaultValue = default(T))
        {
            if (SourcePipe == null)
            {
                return(DefaultValue);
            }

            T Value = DefaultValue;

            foreach (var Item in SourcePipe)
            {
                if (IncludeFilter(Item))
                {
                    Value = Item;
                }
            }

            return(Value);
        }
Пример #17
0
        /// <summary>
        /// Advances the enumerator to the next element of the collection.
        /// </summary>
        /// <returns>
        /// True if the enumerator was successfully advanced to the next
        /// element; false if the enumerator has passed the end of the
        /// collection.
        /// </returns>
        public override Boolean MoveNext()
        {
            while (true)
            {
                if (CurrentPipe == null)
                {
                    if (!SourcePipe2.MoveNext())
                    {
                        return(false);
                    }

                    CurrentPipe = SourcePipe2.Current;
                }

                if (CurrentPipe.MoveNext())
                {
                    _CurrentElement = CurrentPipe.Current;
                    return(true);
                }

                CurrentPipe = null;
            }
        }
Пример #18
0
        public static List <T> ToList <T>(this IEndPipe <T> SourcePipe,
                                          Boolean ResetPipeBefore = false,
                                          Boolean ResetPipeAfter  = false)
        {
            var List = new List <T>();

            if (ResetPipeBefore)
            {
                SourcePipe.Reset();
            }

            foreach (var Item in SourcePipe)
            {
                List.Add(Item);
            }

            if (ResetPipeAfter)
            {
                SourcePipe.Reset();
            }

            return(List);
        }
Пример #19
0
        /// <summary>
        /// Determines whether a pipe emits the specified element by
        /// using the default equality comparer.
        /// </summary>
        /// <typeparam name="T">The type of the items emitted by the pipe.</typeparam>
        /// <param name="SourcePipe">A pipe.</param>
        /// <param name="Value">The value to locate in the pipe.</param>
        /// <param name="ValueComparer">An equality comparer to compare values.</param>
        /// <returns>True if the pipe contains an item that has the specified value; otherwise, false.</returns>
        public static Boolean Contains <T>(this IEndPipe <T> SourcePipe,
                                           T Value,
                                           IEqualityComparer <T> ValueComparer = null)
        {
            if (SourcePipe == null)
            {
                return(false);
            }

            if (ValueComparer == null)
            {
                ValueComparer = EqualityComparer <T> .Default;
            }

            foreach (var Item in SourcePipe)
            {
                if (ValueComparer.Equals(Item, Value))
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #20
0
        /// <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();
        }
Пример #21
0
 /// <summary>
 /// Creates an new random filter pipe using the given pipe as element source.
 /// </summary>
 /// <param name="SourcePipe">A pipe as element source.</param>
 /// <param name="Bias">The bias.</param>
 /// <param name="Random">An optional source of randomness.</param>
 public RandomFilterPipe(IEndPipe <S> SourcePipe, Double Bias, Random Random = null)
     : base(SourcePipe)
 {
     this.Bias   = Bias;
     this.Random = (Random == null) ? new Random(DateTime.Now.Millisecond) : Random;
 }
Пример #22
0
 /// <summary>
 /// Starts with 1!
 /// </summary>
 public static WhereCountedPipe <S> Where <S, E>(this IEndPipe <S> SourcePipe,
                                                 CountedPredicate <S> CountedInclude)
 {
     return(new WhereCountedPipe <S>(SourcePipe, CountedInclude));
 }
Пример #23
0
 public static WherePipe <S> Where <S, E>(this IEndPipe <S> SourcePipe,
                                          Predicate <S> Include)
 {
     return(new WherePipe <S>(SourcePipe, Include));
 }
Пример #24
0
 /// <summary>
 /// Starts with 1!
 /// </summary>
 public static ZipMergePipe <S1, S2, E> Zip <S1, S2, E>(this IEndPipe <S1> SourcePipe1,
                                                        IEndPipe <S2> SourcePipe2,
                                                        Func <S1, S2, UInt64, E> CountedZipDelegate)
 {
     return(new ZipMergePipe <S1, S2, E>(SourcePipe1, SourcePipe2, CountedZipDelegate));
 }
Пример #25
0
 public PathPipe(IEndPipe <S> SourcePipe)
     : base(SourcePipe)
 {
 }
Пример #26
0
 public EndPipeEnumerable(IEndPipe <E> EndPipe)
 {
     this.EndPipe = EndPipe;
 }
Пример #27
0
 /// <summary>
 /// Creates a new StdDevPipe calculating a side effect that is the
 /// sliding standard deviation and the average of the input.
 /// </summary>
 /// <param name="SourcePipe">A pipe as element source.</param>
 public StdDevPipe(IEndPipe <Double> SourcePipe)
     : base(SourcePipe, 0, 0)
 {
     this.Counter = 0;
 }
Пример #28
0
 public EndPipeEnumerator(IEndPipe <E> EndPipe)
 {
     this.EndPipe = EndPipe;
 }
Пример #29
0
 /// <summary>
 /// The RangeFilter will only allow a sequential subset of its incoming
 /// objects to be emitted to its output. This pipe can be provided -1 for
 /// both its high and low range to denote a wildcard for high and/or low.
 /// Note that -1 for both high and low is equivalent to the IdentityPipe.
 /// </summary>
 /// <param name="Low">The minimal value.</param>
 /// <param name="High">The maximum value.</param>
 /// <param name="IEnumerable">An enumeration of objects of type S.</param>
 /// <typeparam name="S">The type of the elements within the filter.</typeparam>
 public static RangeFilterPipe <S> RangeFilter <S>(this IEndPipe <S> SourcePipe, Int32 Low, Int32 High)
 {
     return(new RangeFilterPipe <S>(SourcePipe, Low, High));
 }
Пример #30
0
 public static EndPipeEnumerable <E> AsEnumerable <E>(this IEndPipe <E> EndPipe)
 {
     return(new EndPipeEnumerable <E>(EndPipe));
 }