Esempio 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);
        }
Esempio n. 2
0
        private static void AtemporalExample()
        {
            var points = new Point[]
            {
                new Point {
                    x = 1, y = 2
                },
                new Point {
                    x = 2, y = 4
                },
                new Point {
                    x = 3, y = 6
                },
                new Point {
                    x = 4, y = 8
                },
                new Point {
                    x = 5, y = 10
                },
                new Point {
                    x = 6, y = 12
                },
                new Point {
                    x = 7, y = 14
                },
                new Point {
                    x = 8, y = 16
                },
                new Point {
                    x = 9, y = 18
                }
            };

            // Atemporal ingress operator.
            var input = points.ToObservable()
                        .ToAtemporalStreamable(TimelinePolicy.Sequence(5));

            Console.WriteLine("Input =");
            input.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait();

            var output = input;

            // Atemporal egress operator.
            Console.WriteLine();
            Console.WriteLine("Output =");
            output.ToAtemporalObservable().ForEachAsync(e => Console.WriteLine(e)).Wait();

            Console.ReadLine();
        }