public TrackReporter(IObservable <Mix> currentMixObservable, IObservable <double> currentPositionObservable, IRequestExecutor requestExecutor) { this.requestExecutor = new RequestExecutionAdapter(requestExecutor); IObservable <bool> reportingMarkReached = currentPositionObservable .BufferWithCount(2, 1) .Select(positions => (positions[0] < reportingMark && positions[1] > reportingMark)); currentMixObservable.Subscribe(mix => { currentMix = mix; }); ReactiveAsyncCommand reportTrack = new ReactiveAsyncCommand(); reportTrack.Subscribe(_ => { int mixId = currentMix.MixId; Track track = currentMix.GetCurrentTrack(); Report(track, mixId); }); reportingMarkReached .Where(x => x) // we crossed the mark .Where(_ => !currentMix.GetCurrentTrack().IsReported) //it's not previously reported .Subscribe(_ => reportTrack.Execute(null)); }
/// <summary> /// Projects each value of an observable sequence into a buffer. /// </summary> public static IObservable <IList <TSource> > BufferWithCount <TSource>(this IObservable <TSource> source, int count) { if (source == null) { throw new ArgumentNullException("source"); } if (count <= 0) { throw new ArgumentOutOfRangeException("count"); } return(source.BufferWithCount(count, count)); }
public static IObservable <IList <T> > Buffer <T>(this IObservable <T> source, int count) { return(source.BufferWithCount(count)); }