コード例 #1
0
        public static IObservable<EcgSample> SimulateEcgAsObservable()
        {
            IEnumerable<EcgSample> list = CreateSampels();
            var sampleObservable = list.ToObservable(new EventLoopScheduler());

            IObservable<EcgSample> reapeted = sampleObservable.Repeat(1); //.Do(Print);
            IObservable<IList<EcgSample>> buffered = reapeted.Buffer(250);
            IObservable<object> timerObservable = new MMTimer().ToObservable(250);

            IObservable<EcgBuffer> zipped = timerObservable
                .TimeInterval()
                .Scan(initTs, (prevTs, currTs) => currTs.Interval + prevTs)
                .Zip(buffered, (interval, b) =>
                {
                    return new EcgBuffer { Buffer = b, TimeStamp = interval, Index = _globalBufferIndex++ };
                });

            var res = zipped.SelectMany(buf =>
            {
                buf.Buffer.ForEach(s => s.TimeStamp = buf.TimeStamp);
                Debug.WriteLine(buf);
                return buf.Buffer;
            })
            .Select((item, index) =>
            {
                item.X = index;
                return item;
            });

            return res;
        }
コード例 #2
0
        private IObservable<object> CreateTimerObservable()
        {
            MMTimer timer = new MMTimer();
            timer.Period = 250;

            return Observable.FromEventPattern(handler =>
            {
                timer.Tick += handler;
                timer.Start();
            },
            handler =>
            {
                timer.Tick -= handler;
                timer.Stop();
            });
        }