コード例 #1
0
ファイル: Int32ProgressSink.cs プロジェクト: tintoy/AWTY
        /// <summary>
        ///     Publish raw progress data to subscribers.
        /// </summary>
        /// <param name="current">
        ///     The current progress value.
        /// </param>
        /// <param name="total">
        ///     The total value against which progress is measured.
        /// </param>
        void PublishRawData(int current, int total)
        {
            _rawDataSubject.OnNext(
                RawProgressData.Create(current, total)
                );

            // AF: Do we want to (optionally) call OnCompleted when current >= total?
        }
コード例 #2
0
        /// <summary>
        ///     Notify the observer of the next value in the sequence.
        /// </summary>
        /// <param name="value">
        ///     The value.
        /// </param>
        void IObserver <RawProgressData <TValue> > .OnNext(RawProgressData <TValue> value)
        {
            if (value.Total.Equals(Zero))
            {
                _progressDataSubject.OnError(new ArgumentException(
                                                 message: "Invalid raw progress data (total cannot be 0)."
                                                 ));

                return;
            }

            ReportProgress(value.Current, value.Total);
        }
コード例 #3
0
        public void ReportProgress(long total, long increment, int chunkSize, int[] expectedPercentages)
        {
            List <int> actualPercentages = new List <int>();

            ProgressStrategy <long> strategy = ProgressStrategy.PercentComplete.Chunked.Int64(chunkSize);

            strategy.Subscribe(progress =>
            {
                actualPercentages.Add(progress.PercentComplete);
            });

            long adjustedTotal = AdjustTotalForIncrement(total, increment);

            for (long currentProgress = 0; currentProgress <= adjustedTotal; currentProgress += increment)
            {
                strategy.AsObserver().OnNext(
                    RawProgressData.Create(currentProgress, total)
                    );
            }

            Assert.Equal(expectedPercentages.Length, actualPercentages.Count);
            Assert.Equal(expectedPercentages, actualPercentages);
        }
コード例 #4
0
ファイル: ReactiveTests.cs プロジェクト: tintoy/AWTY
        public void ReportProgressToStrategy(int total, int increment, int chunkSize, int[] expectedPercentages)
        {
            List <int> actualPercentages = new List <int>();

            Int32ChunkedPercentageStrategy strategy = new Int32ChunkedPercentageStrategy(chunkSize);

            strategy.Subscribe(progressData =>
            {
                actualPercentages.Add(progressData.PercentComplete);
            });

            int adjustedTotal = AdjustTotalForIncrement(total, increment);

            for (int currentProgress = 0; currentProgress <= adjustedTotal; currentProgress += increment)
            {
                strategy.AsObserver().OnNext(
                    RawProgressData.Create(currentProgress, total)
                    );
            }

            Assert.Equal(expectedPercentages.Length, actualPercentages.Count);
            Assert.Equal(expectedPercentages, actualPercentages);
        }