Пример #1
0
        public TimeSpan RemainingTimeSpan(double part, double whole)
        {
            try
            {
                Update();

                double percent = 0;

                if (part > 0)
                {
                    percent = Math.IsWhatPercentOf(part, whole) / 100;
                }
                else
                {
                    percent = 1;
                }

                double totalTicks = 0;

                if (percent > 0)
                {
                    totalTicks = TimeSpan.Ticks / percent;
                }

                var timeSpan2 = new TimeSpan(Convert.ToInt64(totalTicks));

                totalTicks = totalTicks - TimeSpan.Ticks;

                var timeSpan = new TimeSpan(Convert.ToInt64(totalTicks));

                return(timeSpan);
            }
            catch (Exception exception)
            {
                Log.Error(exception);

                return(default(TimeSpan));
            }
        }
Пример #2
0
            protected virtual void UpdateProgress(StatusType status, long bytesProcessed, long totalBytes, Exception exception)
            {
                try
                {
                    _TotalBytes = totalBytes;

                    if (status == StatusType.Completed)
                    {
                        _BytesProcessed   = _TotalBytes;
                        _PercentCompleted = 100;
                        _RemainingTime    = new TimeSpan(0);

                        if (!Processed)
                        {
                            InvokeOnProgressChanged();
                        }

                        _Status = StatusType.Completed;
                    }
                    else if (status == StatusType.Failed)
                    {
                        _RemainingTime = new TimeSpan(0);

                        if (!Processed)
                        {
                            InvokeOnProgressChanged();
                        }

                        if (IsCancellationRequested)
                        {
                            _Status = StatusType.Cancelled;
                        }
                        else
                        {
                            _Status = StatusType.Failed;

                            if (exception != null)
                            {
                                _ExceptionMessage = exception.Message;
                            }

                            if (String.IsNullOrEmpty(_ExceptionMessage))
                            {
                                _ExceptionMessage = "Unknown error";
                            }
                        }
                    }
                    else
                    {
                        _Status = IsCancellationRequested ? StatusType.Cancelling : status;

                        if (_BytesProcessed < bytesProcessed)
                        {
                            _BytesProcessed = bytesProcessed;

                            try
                            {
                                _PercentCompleted =
                                    Convert.ToInt32(Math.IsWhatPercentOf(_BytesProcessed, _TotalBytes, 0));
                            }
                            catch
                            {
                            }

                            try
                            {
                                _RemainingTime = StopWatch.RemainingTimeSpan(_BytesProcessed, _TotalBytes);
                            }
                            catch
                            {
                            }
                        }
                    }

                    if (Processed)
                    {
                        CloseFileStream();
                    }
                }
                catch (Exception exception2)
                {
                    Log.Error(exception2, false);
                }
            }