コード例 #1
0
ファイル: ProgressManager.cs プロジェクト: dhq-boiler/Sunctum
        public void UpdateProgress(int current, int total, TimeKeeper timekeeper)
        {
            _TotalCount = total;
            _Current    = current;
            timekeeper.RecordTime();
            if (current > 100 && current < total)
            {
                var sum                        = (DateTime.Now - timekeeper.BeginTaskDatetime.Value);
                var avgMilliseconds            = sum.TotalMilliseconds / current;
                var remain                     = total - current;
                var remainTimesAvgMilliseconds = remain * avgMilliseconds;

                var now = DateTime.Now;

                if (_previousUpdateDateTime.HasValue)
                {
                    var duration = now - _previousUpdateDateTime.Value;
                    if (duration.Seconds >= 1)
                    {
                        EstimateRemainTime      = TimeSpan.FromMilliseconds(remainTimesAvgMilliseconds);
                        _previousUpdateDateTime = now;
                    }
                }
                else
                {
                    _previousUpdateDateTime = now;
                }
            }
            else if (current == total)
            {
                EstimateRemainTime      = null;
                _previousUpdateDateTime = null;
            }
            RaisePropertyChanged(PropertyNameUtility.GetPropertyName(() => Current));
            RaisePropertyChanged(PropertyNameUtility.GetPropertyName(() => Progress));
            RaisePropertyChanged(PropertyNameUtility.GetPropertyName(() => EstimateRemainTime));
        }