Ejemplo n.º 1
0
        public static StreamCache <Empty, T> Sort <T, U>(this IStreamable <Empty, T> stream, Expression <Func <T, U> > sortBySelector)
        {
            var u_comparer = Utility.CreateCompoundComparer(sortBySelector, ComparerExpression <U> .Default.GetCompareExpr()).Compile();
            IStreamable <Empty, T> stream2 = stream;

            stream.GetProperties(out StreamProperties <Empty, T> properties);
            if (!properties.IsStartEdgeOnly)
            {
                var secondStream = new StreamEvent <T>[]
                {
                    StreamEvent.CreateStart(StreamEvent.MaxSyncTime, default(T)),
                    StreamEvent.CreatePunctuation <T>(StreamEvent.InfinitySyncTime),
                }.ToObservable().ToStreamable();

                stream2 = stream.Join(secondStream, (x, y) => x);
            }
            var observableCache = stream2.ToPayloadEnumerable().ToList();

            observableCache.Sort(new Comparison <T>(u_comparer));
            var str = observableCache.ToObservable()
                      .ToAtemporalStreamable(TimelinePolicy.Sequence(80000))
            ;
            var str2 = str
                       .SetProperty().IsConstantDuration(true, StreamEvent.InfinitySyncTime)
            ;
            var str3 = str2.Cache();

            return(str3);
        }